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.tussle.motion.CollisionMap.java

public ProjectionVector get(StageElement<CollisionStadium> c, StageElement s) {
    //Ah well, looks like I'm going to have to use a transient pair
    return get(Pair.of(c, s));
}

From source file:com.yahoo.bullet.tracing.FilterRuleTest.java

@Test
public void testFilteringProjection() {
    FilterRule rule = getFilterRule(makeProjectionFilterRule("map_field.id", Arrays.asList("1", "23"),
            FilterType.EQUALS, Pair.of("map_field.id", "mid")), emptyMap());
    RecordBox boxA = RecordBox.get().addMap("map_field", Pair.of("id", "3"));
    Assert.assertFalse(rule.consume(boxA.getRecord()));
    Assert.assertNull(rule.getData());//w  ww. j  av a 2 s.  com

    RecordBox boxB = RecordBox.get().addMap("map_field", Pair.of("id", "23"));
    RecordBox expected = RecordBox.get().add("mid", "23");
    Assert.assertTrue(rule.consume(boxB.getRecord()));
    Assert.assertEquals(rule.getData(), getListBytes(expected.getRecord()));
}

From source file:materialisticbiomesop.handler.FurnaceFuelHandler.java

public void addFuel(Item item, int metadata, int value) {
    itemMetaFuelList.put(Pair.of(item, metadata), value);
}

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

/**
 * Generate all possible unique, unordered pairs of submissions.
 *
 * @param submissions Submissions to generate pairs from
 * @return Set of all unique, unordered pairs of submissions
 *///www.j  ava 2s  .  c o m
public static Set<Pair<Submission, Submission>> generatePairs(Set<Submission> submissions) {
    checkNotNull(submissions);
    checkArgument(submissions.size() >= 2, "Cannot generate pairs with less than 2 submissions!");

    Set<Pair<Submission, Submission>> pairs = new HashSet<>();

    List<Submission> remaining = new ArrayList<>();
    remaining.addAll(submissions);

    while (remaining.size() >= 2) {
        // Get the first submission in the list and remove it
        Submission first = remaining.get(0);
        remaining.remove(0);

        // Form a pair for every remaining submission by pairing with the first, removed submission
        for (Submission submission : remaining) {
            Pair<Submission, Submission> pair = Pair.of(first, submission);
            Pair<Submission, Submission> reversed = Pair.of(submission, first);

            // Something's wrong, we've made a duplicate pair (but reversed)
            // Should never happen
            if (pairs.contains(reversed)) {
                throw new RuntimeException("Internal error in pair generation: duplicate pair produced!");
            }

            // Add the newly-generated pair to our return
            pairs.add(pair);
        }
    }

    return pairs;
}

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

public static void checkPairsAreInSet(Set<Pair<Submission, Submission>> toCheck,
        Set<Pair<Submission, Submission>> expected) {
    assertNotNull(toCheck);// ww w .ja v a2  s .c  o  m
    assertNotNull(expected);

    assertEquals(expected.size(), toCheck.size());

    expected.stream().forEach((pair) -> assertTrue(
            toCheck.contains(pair) || toCheck.contains(Pair.of(pair.getRight(), pair.getLeft()))));
}

From source file:com.nesscomputing.jackson.datatype.CommonsLang3SerializerTest.java

@Test
public void testPair() throws IOException {
    Pair<String, Boolean> pair = Pair.of("foo", true);
    Pair<String, Boolean> newPair = mapper.readValue(mapper.writeValueAsBytes(pair),
            new TypeReference<Pair<String, Boolean>>() {
            });//  w  w w  .j  a va  2 s.  c  o m
    assertEquals(pair, newPair);
}

From source file:ivorius.ivtoolkit.tools.Pairs.java

public static <L, R> Iterable<Pair<L, R>> pairLeft(final L left, Iterable<R> right) {
    return Iterables.transform(right, new Function<R, Pair<L, R>>() {
        @Nullable//from w  w w .  j  av  a 2 s.  com
        @Override
        public Pair<L, R> apply(R input) {
            return Pair.of(left, input);
        }
    });
}

From source file:com.github.steveash.jg2p.align.InputRecord.java

public Pair<Word, Word> xyWordPair() {
    return Pair.of(xWord, yWord);
}

From source file:com.yahoo.bullet.result.ClipTest.java

@Test
public void testNullValueInRecord() {
    BulletRecord record = new RecordBox().addMap("map_field", Pair.of("bar", true), Pair.of("foo", null))
            .getRecord();// ww w  .  j  a va  2  s  . c  om
    assertJSONEquals(Clip.of(record).asJSON(), makeJSON("[{'map_field':{'bar':true,'foo':null}}]"));
}

From source file:fr.landel.utils.commons.function.BiSupplierTest.java

/**
 * Test method for {@link BiSupplier#get()}.
 *///from  w  w  w . j a va2  s . co  m
@Test
public void testGet() {
    boolean test = false;
    final String error = "error";

    final BiSupplier<String, String> s1 = () -> Pair.of("l", "r");
    final BiSupplier<String, String> s2 = () -> {
        if (test) {
            return Pair.of("l", "r");
        }
        throw new IllegalArgumentException(error);
    };

    try {
        assertEquals("(l,r)", s1.get().toString());
    } catch (FunctionException e) {
        fail("Supplier failed");
    }

    try {
        s2.get();
        fail("Supplier has to fail");
    } catch (IllegalArgumentException e) {
        assertNotNull(e);
        assertEquals(error, e.getMessage());
    }
}