StringUtil { public static <T extends Collection<? super String>> T copyPartialMatches(final String token, final Iterable<String> originals, final T collection) throws UnsupportedOperationException, IllegalArgumentException { Validate.notNull(token, "Search token cannot be null"); Validate.notNull(collection, "Collection cannot be null"); Validate.notNull(originals, "Originals cannot be null"); for (String string : originals) { if (startsWithIgnoreCase(string, token)) { collection.add(string); } } return collection; }  static T copyPartialMatches(final String token, final Iterable<String> originals, final T collection); static boolean startsWithIgnoreCase(final String string, final String prefix);  }
@Test(expected=IllegalArgumentException.class) public void nullCollectionTest() { StringUtil.copyPartialMatches("Token", ImmutableList.<String>of(), null); }
@Test(expected=IllegalArgumentException.class) public void nullIterableTest() { StringUtil.copyPartialMatches("Token", null, new ArrayList<String>()); }
@Test(expected=IllegalArgumentException.class) public void nullTokenTest() { StringUtil.copyPartialMatches(null, ImmutableList.<String>of(), new ArrayList<String>()); }
@Test public void copyTokenTest() { String token = "ab"; Iterable<String> original = ImmutableList.of("ab12", "aC561", "AB5195", "Ab76", "", "a"); List<String> expected = ImmutableList.of("ab12", "AB5195", "Ab76" ); List<String> list = new ArrayList<String>(); assertThat(StringUtil.copyPartialMatches(token, original, list), is(expected)); assertThat(StringUtil.copyPartialMatches(token, original, list), is(sameInstance(list))); assertThat(list.size(), is(expected.size() * 2)); }
@Test(expected=UnsupportedOperationException.class) public void copyUnsupportedTest() { StringUtil.copyPartialMatches("token", ImmutableList.of("token1", "token2"), ImmutableList.of()); }
@Test(expected=IllegalArgumentException.class) public void copyNullTest() { StringUtil.copyPartialMatches("token", Arrays.asList("token1", "token2", null), new ArrayList<String>()); }