@Test
  public void test0() {
    Function<Integer, Integer> f = ((Integer) 0)::compareTo;
    Function<Integer, Integer> f1 = f.compose(f);

    // f1 does what?!
  }
  @Test
  public void test1() {
    Function<Integer, Integer> f = ((Integer) 0)::compareTo;
    f = f.compose(f);

    Assert.assertEquals(Integer.valueOf(0), f.apply(0));
    Assert.assertEquals(Integer.valueOf(1), f.apply(100));
    Assert.assertEquals(Integer.valueOf(-1), f.apply(-100));
  }
Exemplo n.º 3
0
  @Override
  public Function<Object[], ?> visit(LambdaExpression<?> e) {

    final Function<Object[], ?> f = e.getBody().accept(this);

    int size = e.getParameters().size();
    List<Function<Object[], ?>> ppe = new ArrayList<>(size);
    for (ParameterExpression p : e.getParameters()) ppe.add(p.accept(this));

    Function<Object[], Object[]> params =
        pp -> {
          Object[] r = new Object[ppe.size()];
          int index = 0;
          for (Function<Object[], ?> pe : ppe) {
            r[index++] = pe.apply(pp);
          }
          return r;
        };

    return f.compose(params);
  }
Exemplo n.º 4
0
  @Override
  public Function<Object[], ?> visit(InvocationExpression e) {

    final Function<Object[], ?> m = e.getTarget().accept(this);

    int size = e.getArguments().size();
    List<Function<Object[], ?>> ppe = new ArrayList<>(size);
    for (Expression p : e.getArguments()) ppe.add(p.accept(this));

    Function<Object[], Object[]> params =
        pp -> {
          Object[] r = new Object[ppe.size()];
          int index = 0;
          for (Function<Object[], ?> pe : ppe) {
            r[index++] = pe.apply(pp);
          }

          return r;
        };

    return m.compose(params);
  }
Exemplo n.º 5
0
 /**
  * Create a new evolution {@code Engine.Builder} with the given fitness function and problem
  * {@code codec}.
  *
  * @since 3.2
  * @param ff the fitness function
  * @param codec the problem codec
  * @param <T> the fitness function input type
  * @param <C> the fitness function result type
  * @param <G> the gene type
  * @return a new engine builder
  * @throws java.lang.NullPointerException if one of the arguments is {@code null}.
  */
 public static <T, G extends Gene<?, G>, C extends Comparable<? super C>> Builder<G, C> builder(
     final Function<? super T, ? extends C> ff, final Codec<T, G> codec) {
   return builder(ff.compose(codec.decoder()), codec.encoding());
 }