MintActivityRule.java 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. package com.izouma.nineth.dto;
  2. import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
  3. import com.fasterxml.jackson.annotation.JsonInclude;
  4. import com.izouma.nineth.domain.Tag;
  5. import lombok.Data;
  6. import org.apache.commons.collections.CollectionUtils;
  7. import java.util.Collections;
  8. import java.util.HashSet;
  9. import java.util.List;
  10. import java.util.Set;
  11. import java.util.stream.Collectors;
  12. @Data
  13. @JsonInclude(JsonInclude.Include.NON_NULL)
  14. @JsonIgnoreProperties(value = {"hibernateLazyInitializer"}, ignoreUnknown = true)
  15. public class MintActivityRule {
  16. private MintActivityRuleDetail detail;
  17. private List<MintActivityRule> and;
  18. private List<MintActivityRule> or;
  19. public Set<Tag> getTags() {
  20. return getTags(this);
  21. }
  22. public static Set<Tag> getTags(MintActivityRule rule) {
  23. if (rule == null) return Collections.emptySet();
  24. Set<Tag> tags = new HashSet<>();
  25. if (rule.getDetail() != null) {
  26. tags.add(rule.getDetail().getTag());
  27. }
  28. if (CollectionUtils.isNotEmpty(rule.getAnd())) {
  29. tags.addAll(rule.getAnd().stream().flatMap(child -> getTags(child).stream()).collect(Collectors.toList()));
  30. }
  31. if (CollectionUtils.isNotEmpty(rule.getOr())) {
  32. tags.addAll(rule.getOr().stream().flatMap(child -> getTags(child).stream()).collect(Collectors.toList()));
  33. }
  34. return tags;
  35. }
  36. }