@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<Integer> 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<Integer>().toString())); }
@Nullable @Override public List<Integer> apply(@Nullable String input) { if (input == null) { return null; } if (input.length() == 0) { return new ArrayList<Integer>(); } String[] ss = input.split(SEPARATOR); List<Integer> r = new ArrayList<Integer>(); for (int i = 0; i < ss.length; i++) { r.add(Integer.parseInt(ss[i])); } return r; }
StringToIntegerListFunction implements SetterFunction<String, List<Integer>> { @Nullable @Override public List<Integer> apply(@Nullable String input) { if (input == null) { return null; } if (input.length() == 0) { return new ArrayList<Integer>(); } String[] ss = input.split(SEPARATOR); List<Integer> r = new ArrayList<Integer>(); for (int i = 0; i < ss.length; i++) { r.add(Integer.parseInt(ss[i])); } return r; } }
StringToIntegerListFunction implements SetterFunction<String, List<Integer>> { @Nullable @Override public List<Integer> apply(@Nullable String input) { if (input == null) { return null; } if (input.length() == 0) { return new ArrayList<Integer>(); } String[] ss = input.split(SEPARATOR); List<Integer> r = new ArrayList<Integer>(); for (int i = 0; i < ss.length; i++) { r.add(Integer.parseInt(ss[i])); } return r; }  }
StringToIntegerListFunction implements SetterFunction<String, List<Integer>> { @Nullable @Override public List<Integer> apply(@Nullable String input) { if (input == null) { return null; } if (input.length() == 0) { return new ArrayList<Integer>(); } String[] ss = input.split(SEPARATOR); List<Integer> r = new ArrayList<Integer>(); for (int i = 0; i < ss.length; i++) { r.add(Integer.parseInt(ss[i])); } return r; }  @Nullable @Override List<Integer> apply(@Nullable String input); }
StringToIntegerListFunction implements SetterFunction<String, List<Integer>> { @Nullable @Override public List<Integer> apply(@Nullable String input) { if (input == null) { return null; } if (input.length() == 0) { return new ArrayList<Integer>(); } String[] ss = input.split(SEPARATOR); List<Integer> r = new ArrayList<Integer>(); for (int i = 0; i < ss.length; i++) { r.add(Integer.parseInt(ss[i])); } return r; }  @Nullable @Override List<Integer> apply(@Nullable String input);  }