Tokenizers { public static Tokenizer filter(Tokenizer tokenizer, Predicate<String> predicate) { if (tokenizer instanceof Filter) { return Filter.createCombined( (Filter) tokenizer, predicate); } else if (tokenizer instanceof Transform) { return Filter.createCombined( (Transform) tokenizer, predicate); } return new Filter(tokenizer, predicate); } private  Tokenizers(); static Tokenizer pattern(Pattern pattern); static Tokenizer pattern(String regex); static Tokenizer qGram(int q); static Tokenizer qGramWithFilter(int q); static Tokenizer qGramWithPadding(int q); static Tokenizer qGramWithPadding(int q, String padding); static Tokenizer qGramWithPadding(int q, String startPadding,
			String endPadding); static Tokenizer whitespace(); static Tokenizer transform(Tokenizer tokenizer,
			Function<String, String> function); static Tokenizer chain(List<Tokenizer> tokenizers); static Tokenizer chain(Tokenizer tokenizer, Tokenizer... tokenizers); static Tokenizer filter(Tokenizer tokenizer,
			Predicate<String> predicate);  }
@Test public void shouldReturnFilter() { Tokenizer tokenizer = Tokenizers.filter(whitespace, alwaysTrue); assertEquals(Filter.class, tokenizer.getClass()); Filter filter = (Filter) tokenizer; assertSame(whitespace, filter.getTokenizer()); assertSame(alwaysTrue, filter.getPredicate()); }
@Test public void shouldReturnFilterForFilter() { Filter t = new Filter(whitespace, alwaysTrue); Tokenizer tokenizer = Tokenizers.filter(t, alwaysFalse); assertEquals(Filter.class, tokenizer.getClass()); Filter filter = (Filter) tokenizer; assertSame(whitespace, filter.getTokenizer()); assertEquals(and(alwaysTrue, alwaysFalse),filter.getPredicate()); }
@Test public void shouldReturnFilterForTransform() { Transform t = new Transform(whitespace, identity); Tokenizer tokenizer = Tokenizers.filter(t, alwaysTrue); assertEquals(TransformFilter.class, tokenizer.getClass()); TransformFilter filter = (TransformFilter) tokenizer; assertSame(t, filter.getTokenizer()); assertEquals(alwaysTrue,filter.getPredicate()); }