AbstractRuleBucket { public List<T> match(String pattern) throws RuleException { List<T> matches = new ArrayList<>(); if (pattern.contains("?") || pattern.contains("*")) { for (Map.Entry<String, T> entry : rules.entrySet()) { if (RuleFilter.getInstance().matches(entry.getKey(), pattern)) { matches.add(entry.getValue()); } } } else { matches.add(getById(pattern)); } return matches; }  int size(); Collection<T> getAll(); Set<String> getIds(); T getById(String id); List<T> match(String pattern); void add(B bucket);  }
@Test public void match() throws RuleException { Concept c1 = mock(Concept.class); Concept c2 = mock(Concept.class); Concept c3 = mock(Concept.class); when(c1.getId()).thenReturn("concept1"); when(c2.getId()).thenReturn("concept2"); when(c3.getId()).thenReturn("concept3"); TestBucket bucket = new TestBucket(); bucket.add(c1); bucket.add(c2); bucket.add(c3); assertThat(bucket.match("concept1"), equalTo(singletonList(c1))); assertThat(bucket.match("c?ncept1"), equalTo(singletonList(c1))); assertThat(bucket.match("concept?"), equalTo(asList(c1, c2, c3))); assertThat(bucket.match("c*ncept1"), equalTo(singletonList(c1))); assertThat(bucket.match("concept*"), equalTo(asList(c1, c2, c3))); }