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