@Test public void testApply() throws Exception { A a = new A(); Method m = A.class.getDeclaredMethod("getX"); GetterInvoker invoker = FunctionalGetterInvoker.create("x", m); a.setX(new int[]{1, 2, 3}); assertThat((String) invoker.invoke(a), is("1,2,3")); a.setX(null); assertThat(invoker.invoke(a), nullValue()); a.setX(new int[]{}); assertThat((String) invoker.invoke(a), is("")); }
@Nullable @Override public String apply(@Nullable int[] input) { if (input == null) { return null; } if (input.length == 0) { return ""; } StringBuilder builder = new StringBuilder(); builder.append(input[0]); for (int i = 1; i < input.length; i++) { builder.append(SEPARATOR).append(input[i]); } return builder.toString(); }
IntArrayToStringFunction implements GetterFunction<int[], String> { @Nullable @Override public String apply(@Nullable int[] input) { if (input == null) { return null; } if (input.length == 0) { return ""; } StringBuilder builder = new StringBuilder(); builder.append(input[0]); for (int i = 1; i < input.length; i++) { builder.append(SEPARATOR).append(input[i]); } return builder.toString(); } }
IntArrayToStringFunction implements GetterFunction<int[], String> { @Nullable @Override public String apply(@Nullable int[] input) { if (input == null) { return null; } if (input.length == 0) { return ""; } StringBuilder builder = new StringBuilder(); builder.append(input[0]); for (int i = 1; i < input.length; i++) { builder.append(SEPARATOR).append(input[i]); } return builder.toString(); }  }
IntArrayToStringFunction implements GetterFunction<int[], String> { @Nullable @Override public String apply(@Nullable int[] input) { if (input == null) { return null; } if (input.length == 0) { return ""; } StringBuilder builder = new StringBuilder(); builder.append(input[0]); for (int i = 1; i < input.length; i++) { builder.append(SEPARATOR).append(input[i]); } return builder.toString(); }  @Nullable @Override String apply(@Nullable int[] input); }
IntArrayToStringFunction implements GetterFunction<int[], String> { @Nullable @Override public String apply(@Nullable int[] input) { if (input == null) { return null; } if (input.length == 0) { return ""; } StringBuilder builder = new StringBuilder(); builder.append(input[0]); for (int i = 1; i < input.length; i++) { builder.append(SEPARATOR).append(input[i]); } return builder.toString(); }  @Nullable @Override String apply(@Nullable int[] input);  }