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:com.vmware.photon.controller.api.frontend.utils.SecurityGroupUtils.java

/**
 * Merge the security inherited from parent to the current security groups.
 *
 * @param existingSecurityGroups Existing security groups including both inherited and self ones.
 * @param parentSecurityGroups   Security groups inherited from parent.
 * @return The merged security groups and the ones removed from 'self' ones due to duplication with parent.
 *///from ww w  . j  a  v a2s. c o  m
public static Pair<List<SecurityGroup>, List<String>> mergeParentSecurityGroups(
        List<SecurityGroup> existingSecurityGroups, List<String> parentSecurityGroups) {

    checkNotNull(existingSecurityGroups, "Provided value for existingSecurityGroups is unacceptably null");
    checkNotNull(parentSecurityGroups, "Provided value for parentSecurityGroups is unacceptably null");

    List<SecurityGroup> mergedSecurityGroups = new ArrayList<>();
    List<String> selfSecurityGroupsRemoved = new ArrayList<>();
    Set<String> inheritedSecurityGroupsNames = new HashSet<>();

    parentSecurityGroups.forEach(g -> {
        mergedSecurityGroups.add(new SecurityGroup(g, true));
        inheritedSecurityGroupsNames.add(g);
    });

    existingSecurityGroups.stream().filter(g -> !g.isInherited()).forEach(g -> {
        if (inheritedSecurityGroupsNames.contains(g.getName())) {
            selfSecurityGroupsRemoved.add(g.getName());
        } else {
            mergedSecurityGroups.add(g);
        }
    });

    return Pair.of(mergedSecurityGroups, selfSecurityGroupsRemoved);
}

From source file:io.knotx.rxjava.splitter.HtmlFragmentSplitterVerticleTest.java

private void callFragmentSplitterWithAssertions(TestContext context, String template,
        Action1<KnotContext> testFunction) {
    Async async = context.async();//from  ww  w.j a v  a 2s  . co m
    KnotProxy service = KnotProxy.createProxy(new Vertx(vertx.vertx()), ADDRESS);

    service.rxProcess(KnotContextFactory.empty(template)).map(ctx -> Pair.of(async, ctx)).subscribe(success -> {
        testFunction.call(success.getRight());
        async.complete();
    }, error -> context.fail(error));
}

From source file:com.flowpowered.api.util.SyncedStringMap.java

@Override
public boolean register(String key, int id) {
    Integer local = store.get(key);
    if (local != null) {
        return false;
    }/*ww w .  j a v  a  2s. c o m*/
    callEvent(new SyncedMapEvent(this, SyncedMapEvent.Action.ADD, Arrays.asList(Pair.of(id, key))));
    return super.register(key, id);
}

From source file:com.netflix.genie.agent.execution.statemachine.StateMachineConfig.java

@Bean
@Lazy/*  www  .  j a  v  a  2  s  . co m*/
Collection<Pair<States, StateAction>> statesWithActions(final StateAction.Initialize initializeAction,
        final StateAction.ConfigureAgent configureAgentAction,
        final StateAction.ResolveJobSpecification resolveJobSpecificationAction,
        final StateAction.SetUpJob setUpJobAction, final StateAction.LaunchJob launchJobAction,
        final StateAction.MonitorJob monitorJobAction, final StateAction.CleanupJob cleanupJobAction,
        final StateAction.Shutdown shutdownAction, final StateAction.HandleError handleErrorAction) {
    return Arrays.asList(Pair.of(States.INITIALIZE, initializeAction),
            Pair.of(States.CONFIGURE_AGENT, configureAgentAction),
            Pair.of(States.RESOLVE_JOB_SPECIFICATION, resolveJobSpecificationAction),
            Pair.of(States.SETUP_JOB, setUpJobAction), Pair.of(States.LAUNCH_JOB, launchJobAction),
            Pair.of(States.MONITOR_JOB, monitorJobAction), Pair.of(States.CLEANUP_JOB, cleanupJobAction),
            Pair.of(States.SHUTDOWN, shutdownAction), Pair.of(States.HANDLE_ERROR, handleErrorAction));
}

From source file:com.yahoo.bullet.record.AvroBulletRecordTest.java

@Test
public void testEqualsAndHashcodeByteArrays() {
    avroRecord.setMap("4", Pair.of("4.1", false), Pair.of("4.2", true), Pair.of("4.3", null))
            .setString("1", "bar").setLong("2", 42L).setBoolean("3", false)
            .setListOfStringMap("5", singletonList(singletonMap("5.1", "foo")))
            .setStringList("6", singletonList("baz"));
    avroAnother.setMap("4", Pair.of("4.1", false), Pair.of("4.2", true), Pair.of("4.3", null))
            .setString("1", "bar").setLong("2", 42L).setBoolean("3", false)
            .setListOfStringMap("5", singletonList(singletonMap("5.1", "foo")))
            .setStringList("6", singletonList("baz"));

    avroRecord.setSerializedData(getRecordBytes(avroRecord));
    avroRecord.setDeserialized(false);/*from w  w  w. j av  a 2  s  .com*/
    avroAnother.setSerializedData(getRecordBytes(avroAnother));
    avroAnother.setDeserialized(false);

    Assert.assertTrue(avroRecord.equals(avroAnother));
    Assert.assertEquals(avroRecord.hashCode(), avroAnother.hashCode());
}

From source file:com.github.steveash.guavate.GuavateTest.java

@Test
public void test_zip_firstLonger() {
    Stream<String> base1 = Stream.of("a", "b", "c");
    Stream<Integer> base2 = Stream.of(1, 2);
    List<Pair<String, Integer>> test = Guavate.zip(base1, base2).collect(Collectors.toList());
    assertEquals(test, ImmutableList.of(Pair.of("a", 1), Pair.of("b", 2)));
}

From source file:cherry.foundation.querydsl.CustomizingConfigurationFactoryBean.java

private Pair<Integer, Integer> parsePair(String s) {
    Matcher mSingle = Pattern.compile("^(\\d+)$").matcher(s);
    if (mSingle.matches()) {
        return Pair.of(Integer.valueOf(mSingle.group(1)), Integer.valueOf(mSingle.group(1)));
    }// w w w.j a  v  a 2  s  .co m
    Matcher mRange = Pattern.compile("^(\\d+)-(\\d+)$").matcher(s);
    if (mRange.matches()) {
        return Pair.of(Integer.valueOf(mRange.group(1)), Integer.valueOf(mRange.group(2)));
    }
    throw new IllegalArgumentException(
            "numericTypeSpecs must be \"{total},{decimal},{javaType}\" or \"{beginTotal},{endTotal},{beginDecimal},{endDecimal},{javaType}\"");
}

From source file:edu.wpi.checksims.util.PairGeneratorTest.java

@Test
public void TestGenerateFromThreeElementSet() {
    Set<Submission> submissions = setFromElements(a, b, c);
    Set<Pair<Submission, Submission>> expected = setFromElements(Pair.of(a, b), Pair.of(a, c), Pair.of(b, c));
    Set<Pair<Submission, Submission>> results = PairGenerator.generatePairs(submissions);

    checkPairsAreInSet(results, expected);
}

From source file:com.qwazr.utils.json.DirectoryJsonManager.java

private Pair<Long, T> put(String name, long lastModified, T instance) {
    name = name.intern();//from   w  w w. j  a v a2  s . c om
    Pair<Long, T> item = Pair.of(lastModified, instance);
    instancesMap.put(name, item);
    return item;
}

From source file:com.github.steveash.jg2p.util.NestedLoopPairIterableTest.java

@Test
public void shouldWorkIfBothAreOnlyOne() throws Exception {
    ImmutableList<Integer> a = ImmutableList.of(1);
    ImmutableList<String> b = ImmutableList.of("a");
    NestedLoopPairIterable<Integer, String> ible = NestedLoopPairIterable.of(a, b);
    Iterator<Pair<Integer, String>> iter = ible.iterator();

    assertEquals(1, size(ible));//w  ww  . ja va2  s.  co  m
    assertEquals(Pair.of(1, "a"), iter.next());

    assertFalse(iter.hasNext());
}