SplitCommaReverseService implements SplitGeocoderStringService { public List<String> split(String location) { List<String> res = new ArrayList<String>(); String remaining = location; for (int pos = remaining.indexOf(','); pos >= 0; pos = remaining.indexOf(',')) { String part = remaining.substring(0, pos).trim(); if (part.length() > 0) { res.add(0, part); } remaining = remaining.substring(pos + 1); } remaining = remaining.trim(); if (remaining.length() > 0) { res.add(0, remaining.trim()); } return res; }  List<String> split(String location); String combine(List<String> matchedStrings);  }
@Test public void testSplit() throws Exception { SplitCommaReverseService service = new SplitCommaReverseService(); List<String> res = service.split(FULL); Assert.assertNotNull(res); Assert.assertEquals(3, res.size()); Assert.assertEquals(PART0, res.get(0)); Assert.assertEquals(PART1, res.get(1)); Assert.assertEquals(PART2, res.get(2)); }
@Test public void testSplit2() throws Exception { SplitCommaReverseService service = new SplitCommaReverseService(); List<String> res = service.split(""); Assert.assertNotNull(res); Assert.assertEquals(0, res.size()); res = service.split("x, , y"); Assert.assertEquals(2, res.size()); Assert.assertEquals("y", res.get(0)); Assert.assertEquals("x", res.get(1)); res = service.split(" , "); Assert.assertNotNull(res); Assert.assertEquals(0, res.size()); }