1 package jalview.datamodel.features;
3 import jalview.datamodel.SequenceFeature;
4 import jalview.util.MessageManager;
6 import java.util.ArrayList;
9 public class FeatureMatcherSet implements FeatureMatcherSetI
11 private static final String OR_I18N = MessageManager
12 .getString("label.or");
14 private static final String AND_18N = MessageManager
15 .getString("label.and");
17 List<FeatureMatcherI> matchConditions;
19 boolean andConditions;
24 public FeatureMatcherSet()
26 matchConditions = new ArrayList<>();
30 public boolean matches(SequenceFeature feature)
33 * no conditions matches anything
35 if (matchConditions.isEmpty())
45 for (FeatureMatcherI m : matchConditions)
47 if (!m.matches(feature))
58 for (FeatureMatcherI m : matchConditions)
60 if (m.matches(feature))
69 public FeatureMatcherSetI and(FeatureMatcherI m)
71 if (!andConditions && matchConditions.size() > 1)
73 throw new IllegalStateException("Can't add an AND to OR conditions");
75 matchConditions.add(m);
82 public FeatureMatcherSetI or(FeatureMatcherI m)
84 if (andConditions && matchConditions.size() > 1)
86 throw new IllegalStateException("Can't add an OR to AND conditions");
88 matchConditions.add(m);
89 andConditions = false;
95 public boolean isAnded()
101 public Iterable<FeatureMatcherI> getMatchers()
103 return matchConditions;
107 public String toString()
109 StringBuilder sb = new StringBuilder();
110 boolean first = true;
111 for (FeatureMatcherI matcher : matchConditions)
115 String joiner = andConditions ? AND_18N : OR_I18N;
116 sb.append(" ").append(joiner.toLowerCase()).append(" ");
119 sb.append("(").append(matcher.toString()).append(")");
121 return sb.toString();
125 public boolean isEmpty()
127 return matchConditions == null || matchConditions.isEmpty();