StringPlus { @SuppressWarnings("rawtypes") public static List<String> normalize(Object object) { if (object instanceof String) { String s = (String)object; String[] values = s.split(","); List<String> list = new ArrayList<>(); for (String val : values) { String actualValue = val.trim(); if (!actualValue.isEmpty()) { list.add(actualValue); } } return list; } if (object instanceof String[]) { return Arrays.asList((String[])object); } if (object instanceof Collection) { Collection col = (Collection)object; List<String> ar = new ArrayList<>(col.size()); for (Object o : col) { if (o instanceof String) { String s = (String)o; ar.add(s); } else { LOG.warn("stringPlus contained non string element in list! Element was skipped"); } } return ar; } return null; } private  StringPlus(); @SuppressWarnings("rawtypes") static List<String> normalize(Object object);  }
@Test public void testSplitString() { List<String> values = StringPlus.normalize("1, 2"); assertEquals(2, values.size()); assertEquals("1", values.get(0)); assertEquals("2", values.get(1)); }
@Test public void testNormalizeStringPlus() { String s1 = "s1"; String s2 = "s2"; String s3 = "s3"; List<String> sa = Arrays.asList(s1, s2, s3); Collection<Object> sl = Arrays.asList(s1, s2, s3, new Object()); assertNull(StringPlus.normalize(new Object())); assertEquals(Collections.singletonList(s1), StringPlus.normalize(s1)); assertEquals(sa, StringPlus.normalize(sa)); assertEquals(sa, StringPlus.normalize(sl)); }