TokenGroup { public static @Nonnull List<String> from(@Nonnull final String csv, char delim) { List<String> strings = breakInput(csv, new char[] { delim }); if (strings.size() == 1) return strings; ArrayList<String> ret = new ArrayList<>(strings.size() / 2 + 1); for (int i = 0; i < strings.size(); i+=2) { ret.add(strings.get(i)); } return ret; }  static @Nonnull List<String> from(@Nonnull final String csv, char delim); static @Nonnull List<List<String>> from(@Nonnull final String csv, char delim1, char delim2);  }
@Test public void securityGroups() { assertEquals(l("foo"), TokenGroup.from("\"foo\"", ',')); assertEquals(l("foo bar"), TokenGroup.from("foo bar", ',')); assertEquals(l("foo bar", "baz"), TokenGroup.from("foo bar,baz", ',')); assertEquals(l("a,b|c\"\\"), TokenGroup.from("\"a,b|c\\\"\\\\\"", ',')); assertEquals(l("foo", " bar"), TokenGroup.from("\"foo\", bar", ',')); assertEquals(l("'foo'"), TokenGroup.from("'foo'", ',')); assertEquals(l("foo\\bar"), TokenGroup.from("foo\\\\bar", ',')); }
@Test public void networks() { assertEquals(l(l("foo")), TokenGroup.from("\"foo\"", ',', '|')); assertEquals(l(l("foo bar")), TokenGroup.from("foo bar", ',', '|')); assertEquals(l(l("foo bar"), l("baz")), TokenGroup.from("foo bar,baz", ',', '|')); assertEquals(l(l("a,b|c\"\\")), TokenGroup.from("\"a,b|c\\\"\\\\\"", ',', '|')); assertEquals(l(l("foo"), l(" bar")), TokenGroup.from("\"foo\", bar", ',', '|')); assertEquals(l(l("'foo'")), TokenGroup.from("'foo'", ',', '|')); assertEquals(l(l("foo\\bar")), TokenGroup.from("foo\\\\bar", ',', '|')); assertEquals(l(l("foo"), l("bar", "baz")), TokenGroup.from("foo,bar|baz", ',', '|')); assertEquals(l(l("doo", "foo"), l("xoo"), l("bar", "baz"), l("bax")), TokenGroup.from("doo|foo,xoo,bar|baz,bax", ',', '|')); assertEquals(l(l("foo bar", "baz")), TokenGroup.from("foo bar|baz", ',', '|')); }