SparseSet implements Set<String> { @Override public boolean contains(Object item) { if (!(item instanceof String)) { return false; } String itemString = (String) item; String paddedPattern = " " + getPattern() + " "; StringBuilder check = new StringBuilder(itemString.length() + 3); check.append(" ").append(itemString).append(' '); for (int slashAt;;) { check.setCharAt(1, '-'); if (paddedPattern.contains(check)) { return false; } else { check.setCharAt(1, '+'); if (paddedPattern.contains(check)) { return true; } } slashAt = check.lastIndexOf("/", check.length() - 3); if (slashAt < 0) { break; } else { check.setLength(slashAt + 2); check.setCharAt(slashAt + 1, ' '); } } return paddedPattern.contains(" +/ "); } SparseSet(String pattern);  SparseSet(); String getPattern(); void setPattern(String pattern); @Override boolean add(String item); @Override boolean addAll(Collection<? extends String> collection); @Override void clear(); @Override boolean contains(Object item); @Override boolean containsAll(Collection<?> collection); @Override boolean isEmpty(); @Override Iterator<String> iterator(); @Override boolean remove(Object item); @Override boolean removeAll(Collection<?> collection); @Override boolean retainAll(Collection<?> collection); @Override int size(); @Override Object[] toArray(); @Override T[] toArray(T[] array); @Override boolean equals(Object object); @Override int hashCode(); @Override String toString();  }
@Test public void contains_basic_true() { assertEquals(true, (new SparseSet("+a")).contains("a")); }
@Test public void contains_basic_false() { assertEquals(false, (new SparseSet("+a")).contains("b")); }
@Test public void contains_children() { assertEquals(true, (new SparseSet("+a/")).contains("a/b")); assertEquals(true, (new SparseSet("+a/")).contains("a/b/c")); }
@Test public void contains_children_noslash() { assertEquals(false, (new SparseSet("+a")).contains("a/b")); }
@Test public void contains_children_noparent() { assertEquals(false, (new SparseSet("+a/")).contains("a")); }
@Test public void contains_subsetexclude_1() { assertEquals(false, (new SparseSet("+a/ -a/b")).contains("a/b")); }
@Test public void contains_subsetexclude_2() { assertEquals(false, (new SparseSet("+a/ -a/b/")).contains("a/b/c")); }
@Test public void contains_subsetexclude_others() { assertEquals(true, (new SparseSet("+a/ -a/b")).contains("a/c")); }
@Test public void contains_subsetinclude_1() { assertEquals(true, (new SparseSet("-a/ +a/b")).contains("a/b")); }
@Test public void contains_subsetinclude_2() { assertEquals(true, (new SparseSet("-a/ +a/b/")).contains("a/b/c")); }
@Test public void contains_subsetinclude_others() { assertEquals(false, (new SparseSet("-a/ +a/b")).contains("a/c")); }
@Test public void contains_order() { assertEquals(false, (new SparseSet("-a/b +a/")).contains("a/b")); assertEquals(false, (new SparseSet("-a/b/ +a/")).contains("a/b/c")); assertEquals(true, (new SparseSet("-a/b/ +a/")).contains("a/c")); assertEquals(true, (new SparseSet("-a/b/ +a/b/c")).contains("a/b/c")); }
@Test public void contains_everything() { assertEquals(true, (new SparseSet("+/")).contains("a")); }
@Test public void contains_emptystring() { assertEquals(true, (new SparseSet("+ -foo/ +foo/bar")).contains("")); assertEquals(false, (new SparseSet("-foo/ +foo/bar")).contains("")); }
@Test public void contains_paradox_1() { assertEquals(false, (new SparseSet("+a -a")).contains("a")); }
@Ignore @Test public void contains_paradox_2() { assertEquals(true, (new SparseSet("-a +a")).contains("a")); }