@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, "100000000000000000,2,3"); List<Long> list = Lists.newArrayList(100000000000000000L, 2L, 3L); 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<Long>().toString())); }
@Nullable @Override public List<Long> apply(@Nullable String input) { if (input == null) { return null; } if (input.length() == 0) { return new ArrayList<Long>(); } String[] ss = input.split(SEPARATOR); List<Long> r = new ArrayList<Long>(); for (int i = 0; i < ss.length; i++) { r.add(Long.parseLong(ss[i])); } return r; }
StringToLongListFunction implements SetterFunction<String, List<Long>> { @Nullable @Override public List<Long> apply(@Nullable String input) { if (input == null) { return null; } if (input.length() == 0) { return new ArrayList<Long>(); } String[] ss = input.split(SEPARATOR); List<Long> r = new ArrayList<Long>(); for (int i = 0; i < ss.length; i++) { r.add(Long.parseLong(ss[i])); } return r; } }
StringToLongListFunction implements SetterFunction<String, List<Long>> { @Nullable @Override public List<Long> apply(@Nullable String input) { if (input == null) { return null; } if (input.length() == 0) { return new ArrayList<Long>(); } String[] ss = input.split(SEPARATOR); List<Long> r = new ArrayList<Long>(); for (int i = 0; i < ss.length; i++) { r.add(Long.parseLong(ss[i])); } return r; }  }
StringToLongListFunction implements SetterFunction<String, List<Long>> { @Nullable @Override public List<Long> apply(@Nullable String input) { if (input == null) { return null; } if (input.length() == 0) { return new ArrayList<Long>(); } String[] ss = input.split(SEPARATOR); List<Long> r = new ArrayList<Long>(); for (int i = 0; i < ss.length; i++) { r.add(Long.parseLong(ss[i])); } return r; }  @Nullable @Override List<Long> apply(@Nullable String input); }
StringToLongListFunction implements SetterFunction<String, List<Long>> { @Nullable @Override public List<Long> apply(@Nullable String input) { if (input == null) { return null; } if (input.length() == 0) { return new ArrayList<Long>(); } String[] ss = input.split(SEPARATOR); List<Long> r = new ArrayList<Long>(); for (int i = 0; i < ss.length; i++) { r.add(Long.parseLong(ss[i])); } return r; }  @Nullable @Override List<Long> apply(@Nullable String input);  }