Example usage for org.apache.commons.lang3.tuple Triple getMiddle

List of usage examples for org.apache.commons.lang3.tuple Triple getMiddle

Introduction

In this page you can find the example usage for org.apache.commons.lang3.tuple Triple getMiddle.

Prototype

public abstract M getMiddle();

Source Link

Document

Gets the middle element from this triple.

Usage

From source file:org.lightjason.agentspeak.action.builtin.TestCActionCrypto.java

/**
 * test encrypting & decrypting//from w  ww .j  a  v  a 2  s.c  om
 */
@Test
@UseDataProvider("generatecrypt")
public final void encryptdecreypt(final Triple<String, Integer, Integer> p_crypt) {
    final List<ITerm> l_returnkey = new ArrayList<>();

    new CCreateKey().execute(false, IContext.EMPTYPLAN,
            Stream.of(CRawTerm.from(p_crypt.getLeft())).collect(Collectors.toList()), l_returnkey);

    Assert.assertEquals(l_returnkey.size(), p_crypt.getMiddle().intValue());

    final List<ITerm> l_returnencrypt = new ArrayList<>();

    new CEncrypt().execute(false, IContext.EMPTYPLAN,
            Stream.of(l_returnkey.get(0), CRawTerm.from("test string"), CRawTerm.from(12345))
                    .collect(Collectors.toList()),
            l_returnencrypt);

    final List<ITerm> l_return = new ArrayList<>();

    new CDecrypt().execute(false, IContext.EMPTYPLAN,
            Stream.concat(Stream.of(l_returnkey.get(p_crypt.getRight())), l_returnencrypt.stream())
                    .collect(Collectors.toList()),
            l_return);

    Assert.assertEquals(l_return.size(), 2);
    Assert.assertEquals(l_return.get(0).raw(), "test string");
    Assert.assertEquals(l_return.get(1).<Number>raw(), 12345);
}

From source file:org.lightjason.agentspeak.action.builtin.TestCActionDateTime.java

/**
 * test apply-days minus//from  w  w  w .  ja  v a 2  s  .c  om
 */
@Test
@UseDataProvider("generateapplyminus")
public final void applysminus(final Triple<IAction, Pair<ZonedDateTime, Integer>, String> p_value) {
    final List<ITerm> l_return = new ArrayList<>();

    p_value.getLeft().execute(false, IContext.EMPTYPLAN,
            Stream.of("minus", p_value.getMiddle().getRight(), p_value.getMiddle().getLeft())
                    .map(CRawTerm::from).collect(Collectors.toList()),
            l_return);

    Assert.assertEquals(l_return.size(), 1);
    Assert.assertEquals(l_return.get(0).raw(), ZonedDateTime.parse(p_value.getRight()));
}

From source file:org.lightjason.agentspeak.action.builtin.TestCActionDateTime.java

/**
 * test apply-days plus/*w  w  w  . ja va 2  s  . co m*/
 */
@Test
@UseDataProvider("generateapplyplus")
public final void applyplus(final Triple<IAction, Pair<ZonedDateTime, Integer>, String> p_value) {
    final List<ITerm> l_return = new ArrayList<>();

    p_value.getLeft().execute(false, IContext.EMPTYPLAN,
            Stream.of("plus", p_value.getMiddle().getRight(), p_value.getMiddle().getLeft()).map(CRawTerm::from)
                    .collect(Collectors.toList()),
            l_return);

    Assert.assertEquals(l_return.size(), 1);
    Assert.assertEquals(l_return.get(0).raw(), ZonedDateTime.parse(p_value.getRight()));
}

From source file:org.lightjason.agentspeak.action.builtin.TestCActionDateTime.java

/**
 * test between//from  w  w  w .ja  v a2 s. c om
 */
@Test
@UseDataProvider("generatebetween")
public final void between(final Triple<IAction, Stream<ITerm>, Stream<Number>> p_value) {
    final List<ITerm> l_return = new ArrayList<>();

    p_value.getLeft().execute(false, IContext.EMPTYPLAN, p_value.getMiddle().collect(Collectors.toList()),
            l_return);

    Assert.assertArrayEquals(l_return.stream().map(ITerm::<Number>raw).mapToLong(Number::longValue).toArray(),
            p_value.getRight().mapToLong(Number::longValue).toArray());
}

From source file:org.lightjason.agentspeak.action.builtin.TestCActionMath.java

/**
 * test all aggregation-value actions//from   w ww  .j a v  a2  s. c o m
 *
 * @param p_input test data
 *
 * @throws IllegalAccessException is thrown on instantiation error
 * @throws InstantiationException is thrown on instantiation error
 */
@Test
@UseDataProvider("aggregationvaluegenerate")
public final void aggregationvalueaction(
        final Triple<List<ITerm>, Class<? extends IAction>, Function<Stream<Number>, ?>> p_input)
        throws IllegalAccessException, InstantiationException {
    final List<ITerm> l_return = new ArrayList<>();

    p_input.getMiddle().newInstance().execute(false, IContext.EMPTYPLAN, p_input.getLeft(), l_return);

    Assert.assertEquals(l_return.size(), 1);
    Assert.assertEquals(l_return.get(0).raw(),
            p_input.getRight().apply(p_input.getLeft().stream().map(ITerm::<Number>raw)));
}

From source file:org.lightjason.agentspeak.action.builtin.TestCActionMath.java

/**
 * test all single-value actions//from w w w  . j  ava  2  s. co m
 *
 * @param p_input test data
 *
 * @throws IllegalAccessException is thrown on instantiation error
 * @throws InstantiationException is thrown on instantiation error
 */
@Test
@UseDataProvider("singlevaluegenerate")
public final void singlevalueaction(
        final Triple<List<ITerm>, Class<? extends IAction>, Function<Number, ?>> p_input)
        throws IllegalAccessException, InstantiationException {
    final List<ITerm> l_return = new ArrayList<>();

    p_input.getMiddle().newInstance().execute(false, IContext.EMPTYPLAN, p_input.getLeft(), l_return);

    Assert.assertArrayEquals(p_input.getMiddle().toGenericString(), l_return.stream().map(ITerm::raw).toArray(),
            p_input.getLeft().stream().map(ITerm::<Number>raw).map(p_input.getRight()).toArray());
}

From source file:org.lightjason.agentspeak.action.builtin.TestCActionMathBitMatrix.java

/**
 * test all input actions/*  ww  w.ja va2s  .c  o m*/
 *
 * @throws IllegalAccessException is thrown on instantiation error
 * @throws InstantiationException is thrown on instantiation error
 */
@Test
@UseDataProvider("generator")
public final void action(final Triple<List<ITerm>, Class<? extends IAction>, Stream<Object>> p_input)
        throws IllegalAccessException, InstantiationException {
    final List<ITerm> l_return = new ArrayList<>();

    p_input.getMiddle().newInstance().execute(false, IContext.EMPTYPLAN, p_input.getLeft(), l_return);

    Assert.assertArrayEquals(p_input.getMiddle().toGenericString(), l_return.stream().map(ITerm::raw).toArray(),
            p_input.getRight().toArray());
}

From source file:org.lightjason.agentspeak.language.execution.action.CLambdaExpression.java

/**
 * run sequential execution/* ww w .  j a v  a  2 s.  c  o  m*/
 *
 * @param p_context execution context
 * @param p_input input list
 * @return return list
 */
private List<?> executeSequential(final IContext p_context, final List<ITerm> p_input) {
    final Triple<IContext, IVariable<?>, IVariable<?>> l_localcontext = this.getLocalContext(p_context);

    return CCommon.flatcollection(p_input).map(i -> {

        l_localcontext.getMiddle().set(i.raw());
        m_body.forEach(j -> j.execute(l_localcontext.getLeft(), m_parallel, Collections.<ITerm>emptyList(),
                new LinkedList<>(), Collections.<ITerm>emptyList()));
        return l_localcontext.getRight() != null ? l_localcontext.getRight().raw() : null;

    }).filter(Objects::nonNull).collect(Collectors.toList());
}

From source file:org.lightjason.agentspeak.language.execution.action.CLambdaExpression.java

/**
 * run parallel execution// w w w  . ja v a 2 s. com
 *
 * @param p_context execution context
 * @param p_input input list
 * @return return list
 */
private List<?> executeParallel(final IContext p_context, final List<ITerm> p_input) {
    return CCommon.flatcollection(p_input).parallel().map(i -> {

        final Triple<IContext, IVariable<?>, IVariable<?>> l_localcontext = this.getLocalContext(p_context);
        l_localcontext.getMiddle().set(i.raw());
        m_body.forEach(j -> j.execute(l_localcontext.getLeft(), m_parallel, Collections.<ITerm>emptyList(),
                new LinkedList<>(), Collections.<ITerm>emptyList()));
        return l_localcontext.getRight() != null ? l_localcontext.getRight().raw() : null;

    }).filter(Objects::nonNull).collect(Collectors.toList());
}

From source file:org.matsim.contrib.drt.optimizer.rebalancing.mincostflow.AggregatedMinCostRelocationCalculator.java

private List<Relocation> calcRelocations(Map<String, List<Vehicle>> rebalancableVehiclesPerZone,
        List<Triple<String, String, Integer>> interZonalRelocations) {
    List<Relocation> relocations = new ArrayList<>();
    for (Triple<String, String, Integer> r : interZonalRelocations) {
        List<Vehicle> rebalancableVehicles = rebalancableVehiclesPerZone.get(r.getLeft());

        String toZone = r.getMiddle();
        Geometry z = zonalSystem.getZone(toZone);
        Coord zoneCentroid = MGC.point2Coord(z.getCentroid());
        Link destinationLink = NetworkUtils.getNearestLink(network, zoneCentroid);

        int flow = r.getRight();
        for (int f = 0; f < flow; f++) {
            // TODO use BestDispatchFinder (needs to be moved from taxi to dvrp) instead
            Vehicle nearestVehicle = findNearestVehicle(rebalancableVehicles, destinationLink);
            relocations.add(new Relocation(nearestVehicle, destinationLink));
            rebalancableVehicles.remove(nearestVehicle);// TODO use map to have O(1) removal
        }/*from  ww w.  ja v a  2 s.c o  m*/
    }
    return relocations;
}