Example usage for org.apache.commons.lang3.tuple Pair of

List of usage examples for org.apache.commons.lang3.tuple Pair of

Introduction

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

Prototype

public static <L, R> Pair<L, R> of(final L left, final R right) 

Source Link

Document

Obtains an immutable pair of from two objects inferring the generic types.

This factory allows the pair to be created using inference to obtain the generic types.

Usage

From source file:eu.crydee.alignment.aligner.ae.MetricsOneVsOneC.java

@Override
public void process(JCas jcas) throws AnalysisEngineProcessException {
    String name = JCasUtil.selectSingle(jcas, Document.class).getName();
    try {// w w  w .  j a va 2 s .  c  o m
        Alignment alignment1 = Alignment.fromTAF(
                FileUtils.readFileToString(new File(tafFolder1, name + ".taf"), StandardCharsets.UTF_8)),
                alignment2 = Alignment.fromTAF(FileUtils.readFileToString(new File(tafFolder2, name + ".taf"),
                        StandardCharsets.UTF_8));
        for (String k : keys) {
            double r1 = (double) methodsMetadata.get(k).getLeft().invoke(alignment1.complete),
                    r2 = (double) methodsMetadata.get(k).getLeft().invoke(alignment2.complete);
            results.put(name, k, Pair.of(r1, r2));
        }
    } catch (TAFParseException ex) {
        logger.error("Couldn't parse the TAF when trying to compute graph " + "metrics.");
        throw new AnalysisEngineProcessException(ex);
    } catch (IOException ex) {
        logger.error("Couldn't read the TAF when trying to compute graph " + "metrics.");
        throw new AnalysisEngineProcessException(ex);
    } catch (IllegalArgumentException | IllegalAccessException | InvocationTargetException ex) {
        logger.error("Couldn't compute one of the metrics.");
        throw new AnalysisEngineProcessException(ex);
    }
}

From source file:edu.uci.ics.hyracks.api.client.impl.JobActivityGraphBuilder.java

public void finish() {
    Map<ConnectorDescriptorId, Pair<Pair<IActivity, Integer>, Pair<IActivity, Integer>>> caMap = jag
            .getConnectorActivityMap();/*from  w w  w.ja v a 2  s . c o m*/
    for (Map.Entry<ConnectorDescriptorId, Pair<IActivity, Integer>> e : connectorProducerMap.entrySet()) {
        ConnectorDescriptorId cdId = e.getKey();
        Pair<IActivity, Integer> producer = e.getValue();
        Pair<IActivity, Integer> consumer = connectorConsumerMap.get(cdId);
        caMap.put(cdId, Pair.of(producer, consumer));
    }
}

From source file:com.hortonworks.streamline.streams.metrics.storm.ambari.AmbariMetricsServiceWithStormQuerierTest.java

@Test
public void testAggregateWithWeightedAverage() {
    Map<Long, List<Pair<String, Double>>> keyMetric = new HashMap<>();

    List<Pair<String, Double>> keyPoints1 = new ArrayList<>();
    keyPoints1.add(Pair.of("stream1", 10.0));
    keyPoints1.add(Pair.of("stream2", 20.0));
    keyMetric.put(1L, keyPoints1);//  www. j ava  2 s. c  o  m

    List<Pair<String, Double>> keyPoints2 = new ArrayList<>();
    keyPoints2.add(Pair.of("stream1", 10.0));
    keyPoints2.add(Pair.of("stream2", 20.0));
    keyMetric.put(2L, keyPoints2);

    Map<Long, List<Pair<String, Double>>> weightMetric = new HashMap<>();

    List<Pair<String, Double>> weightPoints1 = new ArrayList<>();
    weightPoints1.add(Pair.of("stream1", 10.0));
    weightPoints1.add(Pair.of("stream2", 5.0));
    weightMetric.put(1L, weightPoints1);

    List<Pair<String, Double>> weightPoints2 = new ArrayList<>();
    weightPoints2.add(Pair.of("stream1", 5.0));
    weightPoints2.add(Pair.of("stream2", 10.0));
    weightMetric.put(2L, weightPoints2);

    Map<Long, Double> ret = querier.aggregateWithApplyingWeightedAverage(keyMetric, weightMetric);
    Assert.assertEquals(2, ret.size());

    Double aggregated = ret.get(1L);
    Assert.assertNotNull(aggregated);
    Double expected = 10.0 * 10.0 / (10.0 + 5.0) + 20.0 * 5.0 / (10.0 + 5.0);
    Assert.assertEquals(expected, aggregated, 0.00001d);

    aggregated = ret.get(2L);
    Assert.assertNotNull(aggregated);
    expected = 10.0 * 5.0 / (5.0 + 10.0) + 20.0 * 10.0 / (5.0 + 10.0);
    Assert.assertEquals(expected, aggregated, 0.00001d);
}

From source file:enumj.EnumerableTest.java

@Test
public void testOf_Spliterator() {
    System.out.println("of");
    EnumerableGenerator.generatorPairs().limit(100)
            .map(p -> Pair.of(p.getLeft().ofSpliteratorEnumerable(), p.getRight().ofSpliteratorEnumerable()))
            .forEach(p -> assertTrue(p.getLeft().elementsEqual(p.getRight())));
}

From source file:enumj.StreamComparator.java

private Pair<Function<Stream<T>, Stream<T>>, Function<E, E>> getMapFuns() {
    final int seed = rnd.nextInt();
    final Function<T, T> mapper = mapperOfSeed.apply(seed);
    final Function<Stream<T>, Stream<T>> lhs = s -> s.map(mapper);
    final Function<E, E> rhs = e -> map(e, mapper);
    if (statistics != null) {
        statistics.map();/*from w ww.  j  a v  a 2 s .  co  m*/
    }
    return Pair.of(lhs, rhs);
}

From source file:io.atomix.core.list.DistributedListTest.java

/**
 * Tests a map with complex types.//from www.jav a 2 s  .  c  om
 */
@Test
public void testComplexTypes() throws Throwable {
    DistributedList<Pair<String, Integer>> list = atomix()
            .<Pair<String, Integer>>listBuilder("testComplexTypes").withProtocol(protocol()).build();

    list.add(Pair.of("foo", 1));
    assertEquals("foo", list.iterator().next().getLeft());
    assertEquals(Integer.valueOf(1), list.iterator().next().getRight());
}

From source file:mase.spec.StochasticHybridExchanger.java

protected Pair<MetaPopulation, MetaPopulation> findNextMerge(double[][] distanceMatrix, EvolutionState state) {
    MetaPopulation closeI = null, closeJ = null;
    double closest = 0;
    for (int i = 0; i < metaPops.size(); i++) {
        for (int j = i + 1; j < metaPops.size(); j++) {
            double d = distanceMatrix[i][j];
            if (metaPops.get(i).age >= metaPops.get(i).lockDown
                    && metaPops.get(j).age >= metaPops.get(j).lockDown && (closeI == null || d < closest)) {
                closeI = metaPops.get(i);
                closeJ = metaPops.get(j);
                closest = d;/* w w w .j  a  v  a  2  s  . co m*/
            }
        }
    }
    if (closeI != null) {
        state.output.message("*** Closest: " + closeI + " " + closeJ + " -- " + closest + " ***");
    }
    if (closeI != null && closest <= mergeThreshold) {
        return Pair.of(closeI, closeJ);
    }
    return null;
}

From source file:com.baifendian.swordfish.common.utils.CommonUtil.java

/**
 * ???,  host,port/*from   w w w . ja  v  a2 s  .  com*/
 */
public static Pair<String, Integer> parseWorker(String worker) {
    if (StringUtils.isEmpty(worker)) {
        return null;
    }

    int index = worker.indexOf(":");

    if (index >= 0) {
        return Pair.of(worker.substring(0, index), Integer.parseInt(worker.substring(index + 1)));
    }

    return null;
}

From source file:alfio.manager.AdminReservationRequestManager.java

Pair<Integer, Integer> processPendingReservations() {
    Map<Boolean, List<MapSqlParameterSource>> result = adminReservationRequestRepository
            .findPendingForUpdate(1000).stream().map(id -> {
                AdminReservationRequest request = adminReservationRequestRepository.fetchCompleteById(id);

                Result<Triple<TicketReservation, List<Ticket>, Event>> reservationResult = Result
                        .fromNullable(optionally(() -> eventRepository.findById((int) request.getEventId()))
                                .orElse(null), ErrorCode.EventError.NOT_FOUND)
                        .flatMap(e -> Result.fromNullable(
                                optionally(() -> userRepository.findById((int) request.getUserId()))
                                        .map(u -> Pair.of(e, u)).orElse(null),
                                ErrorCode.EventError.ACCESS_DENIED))
                        .flatMap(p -> processReservation(request, p));
                return buildParameterSource(id, reservationResult);
            }).collect(Collectors.partitioningBy(
                    ps -> AdminReservationRequest.Status.SUCCESS.name().equals(ps.getValue("status"))));

    result.values().forEach(list -> {
        try {//from  ww  w  .  j  a va 2 s. c om
            jdbc.batchUpdate(adminReservationRequestRepository.updateStatus(),
                    list.toArray(new MapSqlParameterSource[list.size()]));
        } catch (Exception e) {
            log.fatal("cannot update the status of " + list.size() + " reservations", e);
        }
    });

    return Pair.of(CollectionUtils.size(result.get(true)), CollectionUtils.size(result.get(false)));

}

From source file:controllers.admin.AttachmentsController.java

/**
 * Get the attachment management table.//w w w  .  j a va  2  s  . c o  m
 *
 * @param filterConfig the table filter configuration
 */
private Pair<Table<AttachmentManagementListView>, Pagination<Attachment>> getTable(
        FilterConfig<AttachmentManagementListView> filterConfig) {

    ExpressionList<Attachment> expressionList = filterConfig.updateWithSearchExpression(
            FileAttachmentHelper.getAllAttachmentsForDisplay(getUserSessionManagerPlugin()));
    filterConfig.updateWithSortExpression(expressionList);

    Pagination<Attachment> pagination = new Pagination<>(getPreferenceManagerPlugin(), expressionList);
    pagination.setCurrentPage(filterConfig.getCurrentPage());

    List<AttachmentManagementListView> attachmentManagementListViews = pagination.getListOfObjects().stream()
            .map(AttachmentManagementListView::new).collect(Collectors.toList());

    Table<AttachmentManagementListView> table = getTableProvider().get().attachmentManagement.templateTable
            .fillForFilterConfig(attachmentManagementListViews, filterConfig.getColumnsToHide());

    return Pair.of(table, pagination);
}