SubstrFunction implements Function<String> { @Override public String apply(List<Object> objects) { String string = String.valueOf(objects.get(0)); Integer from = Integer.valueOf(String.valueOf(objects.get(1))); Optional<Integer> to = objects.size() == 3 ? Optional.of(Integer.valueOf(String.valueOf(objects.get(2)))) : Optional.empty(); return to.isPresent() ? string.substring(from, to.get()) : string.substring(from); }  @Override Set<String> validateInput(List<Object> args); @Override Class<String> getReturnType(); @Override FunctionName getName(); @Override String apply(List<Object> objects); @Override String getSignature(); @Override String getDescription();  }
@Test public void apply() throws Exception { assertThat(function.apply(Arrays.asList("abcd", 1)), equalTo("bcd")); assertThat(function.apply(Arrays.asList("abcd", 1, 3)), equalTo("bc")); }