JAL-2808 refactor KeyedMatcher as FeatureMatcher with byLabel, byScore, byAttribute...
[jalview.git] / src / jalview / util / matcher / KeyedMatcherSet.java
diff --git a/src/jalview/util/matcher/KeyedMatcherSet.java b/src/jalview/util/matcher/KeyedMatcherSet.java
deleted file mode 100644 (file)
index a4be48a..0000000
+++ /dev/null
@@ -1,121 +0,0 @@
-package jalview.util.matcher;
-
-import java.util.ArrayList;
-import java.util.List;
-import java.util.function.Function;
-
-public class KeyedMatcherSet implements KeyedMatcherSetI
-{
-  List<KeyedMatcherI> matchConditions;
-
-  boolean andConditions;
-
-  /**
-   * Constructor
-   */
-  public KeyedMatcherSet()
-  {
-    matchConditions = new ArrayList<>();
-  }
-
-  @Override
-  public boolean matches(Function<String[], String> valueProvider)
-  {
-    /*
-     * no conditions matches anything
-     */
-    if (matchConditions.isEmpty())
-    {
-      return true;
-    }
-
-    /*
-     * AND until failure
-     */
-    if (andConditions)
-    {
-      for (KeyedMatcherI m : matchConditions)
-      {
-        if (!m.matches(valueProvider))
-        {
-          return false;
-        }
-      }
-      return true;
-    }
-
-    /*
-     * OR until match
-     */
-    for (KeyedMatcherI m : matchConditions)
-    {
-      if (m.matches(valueProvider))
-      {
-        return true;
-      }
-    }
-    return false;
-  }
-
-  @Override
-  public KeyedMatcherSetI and(KeyedMatcherI m)
-  {
-    if (!andConditions && matchConditions.size() > 1)
-    {
-      throw new IllegalStateException("Can't add an AND to OR conditions");
-    }
-    matchConditions.add(m);
-    andConditions = true;
-
-    return this;
-  }
-
-  @Override
-  public KeyedMatcherSetI or(KeyedMatcherI m)
-  {
-    if (andConditions && matchConditions.size() > 1)
-    {
-      throw new IllegalStateException("Can't add an OR to AND conditions");
-    }
-    matchConditions.add(m);
-    andConditions = false;
-
-    return this;
-  }
-
-  @Override
-  public boolean isAnded()
-  {
-    return andConditions;
-  }
-
-  @Override
-  public Iterable<KeyedMatcherI> getMatchers()
-  {
-    return matchConditions;
-  }
-
-  @Override
-  public String toString()
-  {
-    StringBuilder sb = new StringBuilder();
-    boolean first = true;
-    for (KeyedMatcherI matcher : matchConditions)
-    {
-      if (!first)
-      {
-        sb.append(andConditions ? " AND " : " OR ");
-      }
-      first = false;
-      sb.append("(").append(matcher.toString()).append(")");
-    }
-    return sb.toString();
-  }
-
-  @Override
-  public boolean isEmpty()
-  {
-    return matchConditions == null || matchConditions.isEmpty();
-  }
-
-}