@Test public void testApply() throws Exception { A a = new A(); Method m = A.class.getDeclaredMethod("setX", List.class); SetterInvoker invoker = FunctionalSetterInvoker.create("x", m); invoker.invoke(a, "1,2,3"); List<String> list = Lists.newArrayList("1", "2", "3"); assertThat(a.getX().toString(), is(list.toString())); invoker.invoke(a, null); assertThat(a.getX(), nullValue()); invoker.invoke(a, ""); assertThat(a.getX().toString(), is(new ArrayList<String>().toString())); }
@Nullable @Override public List<String> apply(@Nullable String input) { if (input == null) { return null; } if (input.length() == 0) { return new ArrayList<String>(); } String[] ss = input.split(SEPARATOR); List<String> r = new ArrayList<String>(); for (int i = 0; i < ss.length; i++) { r.add(ss[i]); } return r; }
StringToStringListFunction implements SetterFunction<String, List<String>> { @Nullable @Override public List<String> apply(@Nullable String input) { if (input == null) { return null; } if (input.length() == 0) { return new ArrayList<String>(); } String[] ss = input.split(SEPARATOR); List<String> r = new ArrayList<String>(); for (int i = 0; i < ss.length; i++) { r.add(ss[i]); } return r; } }
StringToStringListFunction implements SetterFunction<String, List<String>> { @Nullable @Override public List<String> apply(@Nullable String input) { if (input == null) { return null; } if (input.length() == 0) { return new ArrayList<String>(); } String[] ss = input.split(SEPARATOR); List<String> r = new ArrayList<String>(); for (int i = 0; i < ss.length; i++) { r.add(ss[i]); } return r; }  }
StringToStringListFunction implements SetterFunction<String, List<String>> { @Nullable @Override public List<String> apply(@Nullable String input) { if (input == null) { return null; } if (input.length() == 0) { return new ArrayList<String>(); } String[] ss = input.split(SEPARATOR); List<String> r = new ArrayList<String>(); for (int i = 0; i < ss.length; i++) { r.add(ss[i]); } return r; }  @Nullable @Override List<String> apply(@Nullable String input); }
StringToStringListFunction implements SetterFunction<String, List<String>> { @Nullable @Override public List<String> apply(@Nullable String input) { if (input == null) { return null; } if (input.length() == 0) { return new ArrayList<String>(); } String[] ss = input.split(SEPARATOR); List<String> r = new ArrayList<String>(); for (int i = 0; i < ss.length; i++) { r.add(ss[i]); } return r; }  @Nullable @Override List<String> apply(@Nullable String input);  }