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

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

Introduction

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

Prototype

public abstract L getLeft();

Source Link

Document

Gets the left element from this pair.

When treated as a key-value pair, this is the key.

Usage

From source file:gobblin.ingestion.google.webmaster.UrlTriePostOrderIteratorTest.java

@Test
public void testTrie1TraversalWithSize1() {
    UrlTrie trie = getUrlTrie1(_property);
    UrlTriePostOrderIterator iterator = new UrlTriePostOrderIterator(trie, 1);
    ArrayList<String> chars = new ArrayList<>();
    while (iterator.hasNext()) {
        Pair<String, UrlTrieNode> next = iterator.next();
        chars.add(next.getLeft());
    }// www  .  j  av a2s. co m
    Assert.assertEquals(
            new String[] { _property + "0", _property + "13", _property + "14", _property + "1", _property },
            chars.toArray());
}

From source file:it.polimi.diceH2020.SPACE4CloudWS.core.DataProcessor.java

Pair<Optional<Double>, Long> simulateClass(@NonNull SolutionPerJob solPerJob) {
    Pair<Optional<Double>, Long> result = solverCache.evaluate(solPerJob);
    Optional<Double> optionalValue = result.getLeft();
    if (optionalValue.isPresent()) {
        String message = String.format(
                "%s-> A metric with %d VMs, %d Containers, and h = %d has been simulated: %f",
                solPerJob.getId(), solPerJob.getNumberVM(), solPerJob.getNumberContainers(),
                solPerJob.getNumberUsers(), optionalValue.get());
        logger.info(message);/*  w ww  .  ja v  a2  s  .co  m*/
    } else
        solverCache.invalidate(solPerJob);
    return result;
}

From source file:gobblin.ingestion.google.webmaster.UrlTriePostOrderIteratorTest.java

@Test
public void testTrie2TraversalWithSize1() {
    UrlTrie trie = getUrlTrie2(_property);
    UrlTriePostOrderIterator iterator = new UrlTriePostOrderIterator(trie, 1);
    ArrayList<String> chars = new ArrayList<>();
    while (iterator.hasNext()) {
        Pair<String, UrlTrieNode> next = iterator.next();
        chars.add(next.getLeft());
    }//from  w  w w.  j  a  va2s . co m
    Assert.assertEquals(
            new String[] { _property + "03", _property + "04", _property + "0", _property + "1",
                    _property + "257", _property + "25", _property + "26", _property + "2", _property },
            chars.toArray());
}

From source file:cherry.sqlman.tool.clause.SqlClauseControllerImpl.java

@Override
public ModelAndView execute(SqlClauseForm form, BindingResult binding, Authentication auth, Locale locale,
        SitePreference sitePref, NativeWebRequest request) {

    if (hasErrors(form, binding)) {
        return withViewname(viewnameOfStart).build();
    }//from   ww w.  j av a 2s  .  co  m

    try {
        Pair<PageSet, ResultSet> pair = search(form);
        return withViewname(viewnameOfStart).addObject(pair.getLeft()).addObject(pair.getRight()).build();
    } catch (BadSqlGrammarException ex) {
        LogicalErrorUtil.reject(binding, LogicError.BadSqlGrammer, Util.getRootCause(ex).getMessage());
        return withViewname(viewnameOfStart).build();
    }
}

From source file:com.netflix.genie.web.data.entities.AgentConnectionEntityTest.java

/**
 * Verify validated fields value.//from ww  w  .  ja  va 2  s . c o  m
 */
@Test
public void cantCreateAgentConnectionEntityDueToSize() {

    final List<Pair<String, String>> invalidParameterPairs = Lists.newArrayList();

    invalidParameterPairs.add(Pair.of(JOB, null));
    invalidParameterPairs.add(Pair.of(null, HOST));
    invalidParameterPairs.add(Pair.of(JOB, " "));
    invalidParameterPairs.add(Pair.of(" ", HOST));
    invalidParameterPairs.add(Pair.of(StringUtils.rightPad(JOB, 256), HOST));
    invalidParameterPairs.add(Pair.of(JOB, StringUtils.rightPad(HOST, 256)));

    for (final Pair<String, String> invalidParameters : invalidParameterPairs) {
        final AgentConnectionEntity entity = new AgentConnectionEntity(invalidParameters.getLeft(),
                invalidParameters.getRight());

        try {
            this.validate(entity);
        } catch (final ConstraintViolationException e) {
            // Expected, move on to the next pair.
            continue;
        }

        Assert.fail("Entity unexpectedly passed validation: " + entity.toString());
    }
}

From source file:de.hasait.clap.impl.CLAPParseContext.java

public AbstractCLAPNode getDecision(final AbstractCLAPDecision pDecisionNode) {
    AbstractCLAPNode lastBranchNode = null;
    for (final Pair<? extends AbstractCLAPNode, ? extends Object> entry : _nodeContextMap) {
        if (entry.getLeft().equals(pDecisionNode)) {
            lastBranchNode = (AbstractCLAPNode) entry.getRight();
        }/*  w  w w.jav a2  s  . c  o  m*/
    }
    return lastBranchNode;
}

From source file:com.pinterest.terrapin.client.FileSetViewManagerTest.java

@Test
public void testWithBackup() throws Exception {
    boolean exception = false;
    try {// w  w w  .jav a  2s  .co m
        manager.getFileSetViewInfo(FILE_SET);
    } catch (TerrapinGetException e) {
        assertEquals(TerrapinGetErrorCode.FILE_SET_NOT_FOUND, e.getErrorCode());
        exception = true;
    }
    assertTrue(exception);
    // Now, a fileset watch is triggered but the external view is not triggered.
    FileSetInfo fsInfo1 = new FileSetInfo("file_set", "/terrapin/data/file_set/1", 1,
            (List) Lists.newArrayList(), new Options());
    triggerFileSetInfoWatch(FILE_SET, fsInfo1);
    exception = false;
    try {
        manager.getFileSetViewInfo(FILE_SET);
    } catch (TerrapinGetException e) {
        assertEquals(TerrapinGetErrorCode.INVALID_FILE_SET_VIEW, e.getErrorCode());
        exception = true;
    }
    assertTrue(exception);

    // Now the watch for the first view is triggered.
    ExternalView externalView1 = new ExternalView("$terrapin$data$file_set$1");
    externalView1.setStateMap("0", ImmutableMap.of("host1", "ONLINE"));
    ViewInfo viewInfo1 = new ViewInfo(externalView1);
    triggerViewInfoWatch(viewInfo1);

    Pair<FileSetInfo, ViewInfo> pair = manager.getFileSetViewInfo(FILE_SET);
    assertEquals(fsInfo1, pair.getLeft());
    assertEquals(viewInfo1, pair.getRight());

    // The fileset info alone gets updated but the other watch is not yet triggered.
    FileSetInfo fsInfo2 = new FileSetInfo(FILE_SET, "/terrapin/data/file_set/2", 1, (List) Lists.newArrayList(),
            new Options());
    triggerFileSetInfoWatch(FILE_SET, fsInfo2);
    pair = manager.getFileSetViewInfo(FILE_SET);
    // We should see the view from the backup only.
    assertEquals(fsInfo1, pair.getLeft());
    assertEquals(viewInfo1, pair.getRight());

    // Finally, a watch is triggered for the resource corresponding to the second fileset.
    ExternalView externalView2 = new ExternalView("$terrapin$data$file_set$2");
    externalView2.setStateMap("0", ImmutableMap.of("host2", "ONLINE"));
    ViewInfo viewInfo2 = new ViewInfo(externalView2);
    triggerViewInfoWatch(viewInfo2);

    pair = manager.getFileSetViewInfo(FILE_SET);
    assertEquals(fsInfo2, pair.getLeft());
    assertEquals(viewInfo2, pair.getRight());

    // Watches execute in the correct order. Firs the view is propagated.
    ExternalView externalView3 = new ExternalView("$terrapin$data$file_set$3");
    externalView3.setStateMap("0", ImmutableMap.of("host3", "ONLINE"));
    ViewInfo viewInfo3 = new ViewInfo(externalView3);
    triggerViewInfoWatch(viewInfo3);

    // We should still continue to serve previous view.
    pair = manager.getFileSetViewInfo(FILE_SET);
    assertEquals(fsInfo2, pair.getLeft());
    assertEquals(viewInfo2, pair.getRight());

    // Finally, the fileset version update watch is propagated.
    FileSetInfo fsInfo3 = new FileSetInfo(FILE_SET, "/terrapin/data/file_set/3", 1, (List) Lists.newArrayList(),
            new Options());
    triggerFileSetInfoWatch(FILE_SET, fsInfo3);

    pair = manager.getFileSetViewInfo(FILE_SET);
    assertEquals(fsInfo3, pair.getLeft());
    assertEquals(viewInfo3, pair.getRight());
}

From source file:gobblin.ingestion.google.webmaster.UrlTriePostOrderIteratorTest.java

@Test
public void testTrie2TraversalWithSize3() {
    UrlTrie trie = getUrlTrie2(_property);
    UrlTriePostOrderIterator iterator = new UrlTriePostOrderIterator(trie, 3);
    ArrayList<String> chars = new ArrayList<>();
    while (iterator.hasNext()) {
        Pair<String, UrlTrieNode> next = iterator.next();
        chars.add(next.getLeft());
    }// www.  ja v  a2 s.com
    Assert.assertEquals(new String[] { //
            _property + "0", //group size 3, contains
            _property + "1", //group size 1, contains
            _property + "25", //group size 2, contains
            _property + "26", //group size 1, contains
            _property + "2", //group size 1(count is 4), equals
            _property //group size 1(count is 9), equals
    }, chars.toArray());
}

From source file:at.gridtec.lambda4j.consumer.bi.BiConsumer2.java

/**
 * Applies this consumer to the given tuple.
 *
 * @param tuple The tuple to be applied to the consumer
 * @throws NullPointerException If given argument is {@code null}
 * @see org.apache.commons.lang3.tuple.Pair
 *//*from   ww w . jav a 2 s .com*/
default void accept(@Nonnull Pair<T, U> tuple) {
    Objects.requireNonNull(tuple);
    accept(tuple.getLeft(), tuple.getRight());
}

From source file:de.hasait.clap.impl.CLAPParseContext.java

public int getArgCount(final CLAPOptionNode<?> pOptionNode) {
    int count = 0;

    for (final Pair<? extends AbstractCLAPNode, ? extends Object> entry : _nodeContextMap) {
        if (entry.getLeft().equals(pOptionNode)) {
            count += ((List<String>) entry.getRight()).size();
        }/*from  www . java 2s.  com*/
    }

    return count;
}