1 package jalview.datamodel.features;
3 import jalview.datamodel.SequenceFeature;
5 import java.util.ArrayList;
8 public class FeatureMatcherSet implements FeatureMatcherSetI
10 List<FeatureMatcherI> matchConditions;
12 boolean andConditions;
17 public FeatureMatcherSet()
19 matchConditions = new ArrayList<>();
23 public boolean matches(SequenceFeature feature)
26 * no conditions matches anything
28 if (matchConditions.isEmpty())
38 for (FeatureMatcherI m : matchConditions)
40 if (!m.matches(feature))
51 for (FeatureMatcherI m : matchConditions)
53 if (m.matches(feature))
62 public FeatureMatcherSetI and(FeatureMatcherI m)
64 if (!andConditions && matchConditions.size() > 1)
66 throw new IllegalStateException("Can't add an AND to OR conditions");
68 matchConditions.add(m);
75 public FeatureMatcherSetI or(FeatureMatcherI m)
77 if (andConditions && matchConditions.size() > 1)
79 throw new IllegalStateException("Can't add an OR to AND conditions");
81 matchConditions.add(m);
82 andConditions = false;
88 public boolean isAnded()
94 public Iterable<FeatureMatcherI> getMatchers()
96 return matchConditions;
100 public String toString()
102 StringBuilder sb = new StringBuilder();
103 boolean first = true;
104 for (FeatureMatcherI matcher : matchConditions)
108 sb.append(andConditions ? " AND " : " OR ");
111 sb.append("(").append(matcher.toString()).append(")");
113 return sb.toString();
117 public boolean isEmpty()
119 return matchConditions == null || matchConditions.isEmpty();