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:alfio.util.TemplateResourceTest.java

private Pair<ZonedDateTime, ZonedDateTime> getDates() {
    ZonedDateTime eventBegin = ZonedDateTime.now().plusDays(1);
    ZonedDateTime eventEnd = ZonedDateTime.now().plusDays(3);
    ZonedDateTime validityStart = ZonedDateTime.now().plusDays(2);

    when(event.getBegin()).thenReturn(eventBegin);
    when(event.getZoneId()).thenReturn(ZoneId.systemDefault());
    when(event.getEnd()).thenReturn(eventEnd);
    when(ticketCategory.getTicketValidityStart(eq(ZoneId.systemDefault()))).thenReturn(validityStart);
    when(ticket.ticketCode(anyString())).thenReturn("abcd");
    return Pair.of(validityStart, eventEnd);
}

From source file:com.github.jknack.handlebars.cache.ConcurrentMapTemplateCache.java

/**
 * Get/Parse a template source.//  w w w .j  a v a2s. c  om
 *
 * @param source The template source.
 * @param parser The parser.
 * @return A Handlebars template.
 * @throws IOException If we can't read input.
 */
private Template cacheGet(final TemplateSource source, final Parser parser) throws IOException {
    Pair<TemplateSource, Template> entry = cache.get(source);
    if (entry == null) {
        logger.debug("Loading: {}", source);
        entry = Pair.of(source, parser.parse(source));
        cache.put(source, entry);
    } else if (source.lastModified() != entry.getKey().lastModified()) {
        // remove current entry.
        evict(source);
        logger.debug("Reloading: {}", source);
        entry = Pair.of(source, parser.parse(source));
        cache.put(source, entry);
    } else {
        logger.debug("Found in cache: {}", source);
    }
    return entry.getValue();
}

From source file:com.uber.hoodie.io.HoodieCleanHelper.java

public HoodieCleanHelper(HoodieTable<T> hoodieTable, HoodieWriteConfig config) {
    this.hoodieTable = hoodieTable;
    this.fileSystemView = hoodieTable.getCompletedFileSystemView();
    this.commitTimeline = hoodieTable.getCompletedCommitTimeline();
    this.config = config;
    this.fileIdToPendingCompactionOperations = ((HoodieTableFileSystemView) hoodieTable.getRTFileSystemView())
            .getFileIdToPendingCompaction().entrySet().stream()
            .map(entry -> Pair.of(entry.getKey(), entry.getValue().getValue()))
            .collect(Collectors.toMap(Pair::getKey, Pair::getValue));
}

From source file:ee.ria.xroad.common.RequestInputDataMultipart.java

@Override
public Pair<String, InputStream> getRequestInput() throws IOException {
    PipedOutputStream os = new PipedOutputStream();
    MultipartWriter mpWriter = attachmentInputStream == null
            ? new BigAttachmentWriter(os, testRequest, attachmentSize)
            : new CustomAttachmentWriter(os, soapBytes, attachmentInputStream);

    PipedInputStream is = new PipedInputStream(os);
    MultiPartOutputStream mpos = mpWriter.getMultipartOutputStream();

    new Thread(mpWriter).start();

    return Pair.of("multipart/related; charset=UTF-8; " + "boundary=" + mpos.getBoundary(), (InputStream) is);
}

From source file:edu.wpi.checksims.algorithm.AlgorithmRunnerTest.java

@Test
public void TestRunAlgorithmSinglePair() {
    Set<Pair<Submission, Submission>> submissions = singleton(Pair.of(a, b));
    Collection<AlgorithmResults> results = AlgorithmRunner.runAlgorithm(submissions, detectNothing);

    AlgorithmUtils.checkResultsContainsPairs(results, submissions);
}

From source file:enumj.NanoTimer.java

public static <T, U1, U2, R1, R2> Pair<Long, Long>[] compareBuildNanos(Function<T, U1> firstConstruction,
        Function<U1, R1> firstAction, Function<T, U2> secondConstruction, Function<U2, R2> secondAction,
        T... args) {//from w w  w .  j av  a 2 s .c o m
    final long[] firstResults = buildNanos(firstConstruction, firstAction, arg -> "First: " + arg, args);
    final long[] secondResults = buildNanos(secondConstruction, secondAction, arg -> "Second: " + arg, args);
    final Pair[] results = new Pair[args.length];
    for (int i = 0; i < results.length; ++i) {
        results[i] = Pair.of(firstResults[i], secondResults[i]);
    }
    return results;
}

From source file:com.yahoo.bullet.storm.StormUtilsTest.java

private void assertContains(List<Pair<String, String>> componentStreams, String component, String stream) {
    Pair<String, String> pair = Pair.of(component, stream);
    Assert.assertTrue(componentStreams.stream().anyMatch(pair::equals));
}

From source file:com.cybernostics.jsp2thymeleaf.api.expressions.DefaultExpressionVisitor.java

@Override
public List<Pair<? extends BinaryOperator, ? extends Expression>> getBinaryOperatorOperatorExpressionPairs(
        BinaryOperatorExpression binaryOperatorExpression) {
    final List operators = binaryOperatorExpression.getOperators();
    final List expressions = binaryOperatorExpression.getExpressions();
    List<Pair<? extends BinaryOperator, ? extends Expression>> pairs = new ArrayList<>();
    for (int i = 0; i < operators.size(); i++) {
        pairs.add(Pair.of((BinaryOperator) operators.get(i), (Expression) expressions.get(i)));
    }/*from   w  w  w  .jav a2s.c  o  m*/
    return pairs;
}

From source file:com.yahoo.elide.parsers.state.CollectionTerminalState.java

@Override
public Supplier<Pair<Integer, JsonNode>> handleGet(StateContext state) {
    JsonApiDocument jsonApiDocument = new JsonApiDocument();
    RequestScope requestScope = state.getRequestScope();
    ObjectMapper mapper = requestScope.getMapper().getObjectMapper();
    Optional<MultivaluedMap<String, String>> queryParams = requestScope.getQueryParams();

    Set<PersistentResource> collection = getResourceCollection(requestScope);

    // Set data/*w  w  w . jav  a2 s. c  o m*/
    jsonApiDocument.setData(getData(requestScope, collection));

    // Run include processor
    DocumentProcessor includedProcessor = new IncludedProcessor();
    includedProcessor.execute(jsonApiDocument, collection, queryParams);

    DocumentProcessor sortProcessor = new SortProcessor();
    sortProcessor.execute(jsonApiDocument, collection, queryParams);

    JsonNode responseBody = mapper.convertValue(jsonApiDocument, JsonNode.class);
    return () -> Pair.of(HttpStatus.SC_OK, responseBody);
}

From source file:mase.evorbc.KdTreeRepertoire.java

@Override
public void load(File repo, File coordinates) throws IOException {
    repFile = repo;/* w ww . jav a 2s. com*/
    repFileHash = FileUtils.checksumCRC32(repFile);
    if (coordinates != null) {
        coordsFile = coordinates;
        coordsFileHash = FileUtils.checksumCRC32(coordsFile);
    }

    List<PersistentSolution> solutions;
    try {
        solutions = SolutionPersistence.readSolutionsFromTar(repo);
    } catch (Exception ex) {
        Logger.getLogger(ArbitratorFactory.class.getName()).log(Level.SEVERE, null, ex);
        return;
    }

    Map<Integer, double[]> coords = null;
    if (coordinates != null) {
        coords = fileCoordinates(coordinates);
        if (coords.size() != solutions.size()) {
            throw new IOException("Number of solutions in repertoire does not match number of coordinates");
        }
    } else {
        coords = encodedCoordinates(solutions);
    }

    int n = coords.get(solutions.get(0).getIndex()).length;

    bounds = new Pair[n];
    for (int i = 0; i < n; i++) {
        double min = Double.POSITIVE_INFINITY;
        double max = Double.NEGATIVE_INFINITY;
        for (double[] c : coords.values()) {
            min = Math.min(min, c[i]);
            max = Math.max(max, c[i]);
        }
        bounds[i] = Pair.of(min, max);
    }

    tree = new KdTree.Euclidean<>(n);
    for (int i = 0; i < solutions.size(); i++) {
        PersistentSolution sol = solutions.get(i);
        AgentController ac = sol.getController().getAgentControllers(1)[0];
        double[] c = coords.get(sol.getIndex());
        if (c == null) {
            throw new IOException("Coordinate not found for index " + sol.getIndex());
        }
        tree.addPoint(c, ac);
    }
}