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.github.steveash.jg2p.util.CartesianProductIterable.java

@Override
public Iterator<Pair<T, T>> iterator() {
    return new AbstractIterator<Pair<T, T>>() {

        private Iterator<T> outer = source.iterator();
        private Iterator<T> inner = source.iterator();

        private int nextInnerSkip = 1; // start at one as no self-pairs
        private T lastOuter;

        {/*from w  w  w. j  a  v a  2s .  c om*/
            // setup for the initial state
            if (outer.hasNext()) {
                lastOuter = outer.next();
                positionInnerIterator();
            }
        }

        @Override
        protected Pair<T, T> computeNext() {
            if (!inner.hasNext()) {
                if (!outer.hasNext()) {
                    // this can only happen in the empty input case or if we enhance this to do self-pairs
                    return endOfData();
                }

                lastOuter = outer.next();
                inner = source.iterator();
                positionInnerIterator();
                // because we don't do self refs we will actually skip ahead to the end of the inner before
                // running out in the outer
                if (!inner.hasNext()) {
                    Preconditions.checkState(!outer.hasNext());
                    return endOfData();
                }
            }
            Pair<T, T> result = Pair.of(lastOuter, inner.next());
            return result;
        }

        private void positionInnerIterator() {
            // precondition: inner iterator is right before first element
            int actuallySkipped = advance(inner, this.nextInnerSkip);
            Preconditions.checkState(actuallySkipped == this.nextInnerSkip);
            nextInnerSkip += 1;
        }
    };
}

From source file:edu.uci.ics.hyracks.api.rewriter.OneToOneConnectedActivityCluster.java

/**
 * Set up the mapping of the cluster's input channel to an internal activity and input output channel
 * //w  ww  .j  a v a  2 s  .c  o m
 * @param clusterInputIndex
 *            the input channel index for the cluster
 * @param activityId
 *            the id of the internal activity which consumes the corresponding input
 * @param activityInputIndex
 *            the output channel index of the internal activity which corresponds to the input channel of the cluster of activities
 */
public void setClusterInputIndex(int clusterInputIndex, ActivityId activityId, int activityInputIndex) {
    clusterInputIndexMap.put(clusterInputIndex, Pair.of(activityId, activityInputIndex));
    invertedClusterInputIndexMap.put(Pair.of(activityId, activityInputIndex), clusterInputIndex);
}

From source file:cherry.goods.telno.SoumuExcelParserTest.java

@Test
public void testParse7() throws Exception {
    Map<String, Pair<String, String>> map;
    try (InputStream in = getClass().getResourceAsStream("soumu/000124076.xls")) {
        map = parser.parse(in);//ww  w  .j  a va  2 s .  co  m
    }
    assertEquals(5548, map.size());
    assertEquals(Pair.of("072", "300"), map.get("072300"));
    assertEquals(Pair.of("0799", "89"), map.get("079989"));
}

From source file:com.yahoo.bullet.parsing.SpecificationTest.java

@Test
public void testExtractField() {
    BulletRecord record = RecordBox.get().add("field", "foo").add("map_field.foo", "bar")
            .addMap("map_field", Pair.of("foo", "baz")).addList("list_field", singletonMap("foo", "baz"))
            .getRecord();/*w  w  w .ja v  a 2 s.c o m*/

    Assert.assertNull(Specification.extractField(null, record));
    Assert.assertNull(Specification.extractField("", record));
    Assert.assertNull(Specification.extractField("id", record));
    Assert.assertEquals(Specification.extractField("map_field.foo", record), "baz");
    Assert.assertNull(Specification.extractField("list_field.bar", record));
}

From source file:enumj.StreamComparator.java

private Pair<Function<Stream<T>, Stream<T>>, Function<E, E>> getDistinctFuns() {
    final Function<Stream<T>, Stream<T>> lhs = s -> s.distinct();
    final Function<E, E> rhs = e -> distinct(e);
    if (statistics != null) {
        statistics.distinct();/*from   w  w w . j  a v a  2s  . c  om*/
    }
    return Pair.of(lhs, rhs);
}

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

@Test
public void shouldReturnGoodIterableForNormalInput() throws Exception {
    ImmutableList<Integer> a = ImmutableList.of(1, 2, 3, 4, 5);
    ImmutableList<String> b = ImmutableList.of("a", "b", "c", "d");
    NestedLoopPairIterable<Integer, String> ible = NestedLoopPairIterable.of(a, b);

    Iterator<Pair<Integer, String>> iter = ible.iterator();
    assertEquals(Pair.of(1, "a"), iter.next());
    assertEquals(Pair.of(1, "b"), iter.next());
    assertEquals(Pair.of(1, "c"), iter.next());
    assertEquals(Pair.of(1, "d"), iter.next());

    assertEquals(Pair.of(2, "a"), iter.next());
    assertEquals(Pair.of(2, "b"), iter.next());
    assertEquals(Pair.of(2, "c"), iter.next());
    assertEquals(Pair.of(2, "d"), iter.next());

    assertEquals(Pair.of(3, "a"), iter.next());
    assertEquals(Pair.of(3, "b"), iter.next());
    assertEquals(Pair.of(3, "c"), iter.next());
    assertEquals(Pair.of(3, "d"), iter.next());

    assertEquals(Pair.of(4, "a"), iter.next());
    assertEquals(Pair.of(4, "b"), iter.next());
    assertEquals(Pair.of(4, "c"), iter.next());
    assertEquals(Pair.of(4, "d"), iter.next());

    assertEquals(Pair.of(5, "a"), iter.next());
    assertEquals(Pair.of(5, "b"), iter.next());
    assertEquals(Pair.of(5, "c"), iter.next());
    assertEquals(Pair.of(5, "d"), iter.next());

    assertFalse(iter.hasNext());/*ww w.  j a  va2 s  .co  m*/
}

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

@Override
public Supplier<Pair<Integer, JsonNode>> handlePost(StateContext state) {
    RequestScope requestScope = state.getRequestScope();
    JsonApiMapper mapper = requestScope.getMapper();

    newObject = createObject(requestScope);
    if (parent.isPresent()) {
        parent.get().addRelation(relationName.get(), newObject);
    }//www  .  j ava  2s .c om
    requestScope.getTransaction().save(newObject.getObject());
    return () -> {
        JsonApiDocument returnDoc = new JsonApiDocument();
        returnDoc.setData(new Data(newObject.toResource()));
        JsonNode responseBody = mapper.getObjectMapper().convertValue(returnDoc, JsonNode.class);
        return Pair.of(HttpStatus.SC_CREATED, responseBody);
    };
}

From source file:com.formkiq.core.service.crypto.SecureTokenServiceImpl.java

@Override
public Pair<RSAPublicKey, RSAPrivateKey> initializeToken(final int keysize) throws NoSuchAlgorithmException {

    KeyPairGenerator kpg = KeyPairGenerator.getInstance("RSA");
    kpg.initialize(keysize);//from w  w  w . j  a va2 s.  c  o m

    KeyPair kp = kpg.genKeyPair();
    RSAPublicKey publicKey = (RSAPublicKey) kp.getPublic();
    RSAPrivateKey privateKey = (RSAPrivateKey) kp.getPrivate();

    return Pair.of(publicKey, privateKey);
}

From source file:li.klass.fhem.domain.culhm.ThermostatTest.java

@Test
@SuppressWarnings("unchecked")
public void should_read_weekday_profile_with_weekday_prefixes() {
    CULHMDevice device = getDeviceFor("deviceWithPrefix", CULHMDevice.class);

    assertThat(device).isNotNull();/*w  ww .  ja  va2s.c om*/

    WeekProfile<FilledTemperatureInterval, CULHMConfiguration, CULHMDevice> weekProfile = device
            .getWeekProfile();
    assertThat(weekProfile).isNotNull();

    assertWeekProfileContainsExactly(weekProfile, SATURDAY, Pair.of("08:00", 20.0), Pair.of("23:00", 22.0),
            Pair.of("24:00", 20.0));
    assertWeekProfileContainsExactly(weekProfile, SUNDAY, Pair.of("08:00", 20.0), Pair.of("22:00", 22.0),
            Pair.of("24:00", 20.0));
    assertWeekProfileContainsExactly(weekProfile, MONDAY, Pair.of("04:50", 20.0), Pair.of("22:00", 22.0),
            Pair.of("24:00", 20.0));
    assertWeekProfileContainsExactly(weekProfile, TUESDAY, Pair.of("04:50", 20.0), Pair.of("22:00", 22.0),
            Pair.of("24:00", 20.0));
    assertWeekProfileContainsExactly(weekProfile, WEDNESDAY, Pair.of("04:50", 20.0), Pair.of("22:00", 22.0),
            Pair.of("24:00", 20.0));
    assertWeekProfileContainsExactly(weekProfile, THURSDAY, Pair.of("04:50", 20.0), Pair.of("22:00", 22.0),
            Pair.of("24:00", 20.0));
    assertWeekProfileContainsExactly(weekProfile, FRIDAY, Pair.of("04:50", 20.0), Pair.of("23:00", 22.0),
            Pair.of("24:00", 20.0));
}

From source file:com.teradata.tempto.internal.hadoop.hdfs.WebHDFSClient.java

@Override
public void createDirectory(String path, String username) {
    // TODO: reconsider permission=777
    HttpPut mkdirRequest = new HttpPut(buildUri(path, username, "MKDIRS", Pair.of("permission", "777")));
    try (CloseableHttpResponse response = httpClient.execute(mkdirRequest)) {
        if (response.getStatusLine().getStatusCode() != SC_OK) {
            throw invalidStatusException("MKDIRS", path, username, mkdirRequest, response);
        }//from   w  ww.j  a  v a 2s. c  o  m
        logger.debug("Created directory {} - username: {}", path, username);
    } catch (IOException e) {
        throw new RuntimeException("Could not create directory " + path + " in hdfs, user: " + username, e);
    }
}