Tokenizers { public static Tokenizer chain(List<Tokenizer> tokenizers) { if (tokenizers.size() == 1) { return tokenizers.get(0); } return new Recursive(flatten(tokenizers)); } 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 shouldChainSingletonList() { List<Tokenizer> tokenizers = asList(whitespace); Tokenizer tokenizer = Tokenizers.chain(tokenizers); assertSame(whitespace, tokenizer); }
@Test public void shouldChainPlusOne() { Tokenizer tokenizer = Tokenizers.chain(whitespace); assertSame(whitespace, tokenizer); }
@Test public void shouldChainList() { List<Tokenizer> tokenizers = asList(whitespace, whitespace, whitespace); Tokenizer tokenizer = Tokenizers.chain(tokenizers); assertEquals(Recursive.class, tokenizer.getClass()); Recursive recursive = (Recursive) tokenizer; assertEquals(tokenizers, recursive.getTokenizers()); }
@Test public void shouldChainArrayPlusOne() { Tokenizer tokenizer = Tokenizers.chain(whitespace, whitespace, whitespace); assertEquals(Recursive.class, tokenizer.getClass()); Recursive recursive = (Recursive) tokenizer; assertEquals(asList(whitespace, whitespace, whitespace), recursive.getTokenizers()); }
@Test public void shouldChainRecursiveList() { List<Tokenizer> tokenizers = asList(whitespace, chain(whitespace, whitespace), whitespace); Tokenizer tokenizer = Tokenizers.chain(tokenizers); assertEquals(Recursive.class, tokenizer.getClass()); Recursive recursive = (Recursive) tokenizer; assertEquals(asList(whitespace, whitespace, whitespace, whitespace), recursive.getTokenizers()); }
@Test public void shouldChainRecursiveArrayPlusOne() { Tokenizer tokenizer = Tokenizers.chain(whitespace, chain(whitespace, whitespace), whitespace); assertEquals(Recursive.class, tokenizer.getClass()); Recursive recursive = (Recursive) tokenizer; assertEquals(asList(whitespace, whitespace, whitespace, whitespace), recursive.getTokenizers()); }