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:cherry.goods.telno.SoumuExcelParserTest.java

@Test
public void testParse3() throws Exception {
    Map<String, Pair<String, String>> map;
    try (InputStream in = getClass().getResourceAsStream("soumu/000124072.xls")) {
        map = parser.parse(in);/*from w ww  .  ja va  2 s . c  o m*/
    }
    assertEquals(3400, map.size());
    assertEquals(Pair.of("03", "3000"), map.get("033000"));
    assertEquals(Pair.of("03", "6999"), map.get("036999"));
}

From source file:cc.kave.commons.model.groum.GroumBuilder.java

public void removeEdge(Node source, Node target) {
    edges.remove(Pair.of(source, target));
}

From source file:ca.uhn.fhir.util.BundleUtil.java

@SuppressWarnings("unchecked")
public static List<Pair<String, IBaseResource>> getBundleEntryUrlsAndResources(FhirContext theContext,
        IBaseBundle theBundle) {/*from  w  w  w .  j a v  a 2  s .co  m*/
    RuntimeResourceDefinition def = theContext.getResourceDefinition(theBundle);
    BaseRuntimeChildDefinition entryChild = def.getChildByName("entry");
    List<IBase> entries = entryChild.getAccessor().getValues(theBundle);

    BaseRuntimeElementCompositeDefinition<?> entryChildElem = (BaseRuntimeElementCompositeDefinition<?>) entryChild
            .getChildByName("entry");
    BaseRuntimeChildDefinition resourceChild = entryChildElem.getChildByName("resource");

    BaseRuntimeChildDefinition requestChild = entryChildElem.getChildByName("request");
    BaseRuntimeElementCompositeDefinition<?> requestDef = (BaseRuntimeElementCompositeDefinition<?>) requestChild
            .getChildByName("request");

    BaseRuntimeChildDefinition urlChild = requestDef.getChildByName("url");

    List<Pair<String, IBaseResource>> retVal = new ArrayList<Pair<String, IBaseResource>>(entries.size());
    for (IBase nextEntry : entries) {

        String url = null;
        IBaseResource resource = null;

        for (IBase nextEntryValue : requestChild.getAccessor().getValues(nextEntry)) {
            for (IBase nextUrlValue : urlChild.getAccessor().getValues(nextEntryValue)) {
                url = ((IPrimitiveType<String>) nextUrlValue).getValue();
            }
        }

        // Should return 0..1 only
        for (IBase nextValue : resourceChild.getAccessor().getValues(nextEntry)) {
            resource = (IBaseResource) nextValue;
        }

        retVal.add(Pair.of(url, resource));
    }

    return retVal;
}

From source file:eu.transkribus.swt_canvas.util.GeomUtils.java

/**
 * Returns the distance and the closest segment of a point (x,y) to a polygon given as a series of points
 * @param isClosedShape True if this is a closes polygon or false if its a polyline
 *///w w w . ja va2 s .  co  m
public static Pair<Double, java.awt.geom.Line2D.Double> getDistToPolygonAndClosestSegment(List<Point> pts,
        double x, double y, boolean isClosedShape) {
    double minDist = Integer.MAX_VALUE;
    java.awt.geom.Line2D.Double minLine = new java.awt.geom.Line2D.Double(0, 0, 0, 0);

    int N = isClosedShape ? pts.size() : pts.size() - 1;

    for (int i = 0; i < N; ++i) {
        java.awt.geom.Line2D.Double line = new java.awt.geom.Line2D.Double(pts.get(i),
                pts.get((i + 1) % pts.size()));
        double d = line.ptSegDistSq(x, y);
        //         logger.debug("d = "+d);
        if (d < minDist) {
            minDist = d;
            minLine = line;
        }
    }

    return Pair.of(minDist, minLine);
}

From source file:li.klass.fhem.service.room.RoomListHolderServiceTest.java

@DataProvider
public static Object[][] FHEMWEB_DEVICE_NAMES() {
    return new Object[][] { { // find device with exact name
            ImmutableList.of(Pair.of("myDevice", 80), Pair.of("someDevice", 80)), 80, "myDevice", "myDevice" },
            { // finds device containing the qualifier
                    ImmutableList.of(Pair.of("FHEMWEB_myDevice", 80), Pair.of("someDevice", 80)), 80,
                    "myDevice", "FHEMWEB_myDevice" },
            { // takes the first device it finds (containing the qualifier)
                    ImmutableList.of(Pair.of("FHEMWEB_myDevice", 80), Pair.of("myDevice", 80)), 80, "myDevice",
                    "FHEMWEB_myDevice" },
            { // takes the first device if no device contains the qualifier
                    ImmutableList.of(Pair.of("FHEMWEB_myDevice", 80), Pair.of("someDevice", 80)), 80, "",
                    "FHEMWEB_myDevice" },
            { // defaults to andFHEM as qualifier if port is not found
                    ImmutableList.of(Pair.of("andFHEM_myDevice", 80), Pair.of("someDevice", 80)), 80, "",
                    "andFHEM_myDevice" },
            { // defaults to port if qualifier is unset
                    ImmutableList.of(Pair.of("andFHEM_myDevice", 80), Pair.of("someDevice", 8084)), 8084, "",
                    "someDevice" },
            { // defaults to andFHEM as qualifier, as no device matches the selected device's port
                    ImmutableList.of(Pair.of("andFHEM_myDevice", 80), Pair.of("someDevice", 8084)), 8083, "",
                    "andFHEM_myDevice" }, };
}

From source file:cn.lambdalib.util.mc.Raytrace.java

public static Pair<Vec3, MovingObjectPosition> getLookingPos(Entity living, double dist, Predicate<Entity> esel,
        IBlockSelector bsel) {/*w w w.  j  a v  a2s  . com*/
    MovingObjectPosition pos = traceLiving(living, dist, esel, bsel);
    Vec3 end = null;
    if (pos != null) {
        end = pos.hitVec;
        if (pos.entityHit != null)
            end.yCoord += pos.entityHit.getEyeHeight() * 0.6;
    }
    if (end == null)
        end = new Motion3D(living, true).move(dist).getPosVec();

    return Pair.of(end, pos);
}

From source file:hu.ppke.itk.nlpg.purepos.common.lemma.SuffixLemmaTransformation.java

@Override
protected Pair<String, Integer> encode(String word, Pair<String, Integer> representation) {
    int tagCode = representation.getRight() / SHIFT;
    int cutSize = representation.getRight() % SHIFT;
    String add = representation.getLeft();
    String lemma = word.substring(0, word.length() - cutSize) + add;
    return Pair.of(lemma, tagCode);
}

From source file:com.netflix.genie.web.data.services.jpa.JpaAgentConnectionPersistenceServiceImplIntegrationTest.java

/**
 * Perform assorted operations on persisted connections.
 *///www .j a  v a 2s  .  c  o  m
@Test
public void createUpdateDelete() {
    // Check empty
    verifyExpectedConnections();
    Assert.assertThat(this.agentConnectionRepository.count(), Matchers.is(0L));

    // Create two connections for two jobs on different servers
    this.agentConnectionPersistenceService.saveAgentConnection(JOB1, HOST1);
    this.agentConnectionPersistenceService.saveAgentConnection(JOB2, HOST2);
    verifyExpectedConnections(Pair.of(JOB1, HOST1), Pair.of(JOB2, HOST2));
    Assert.assertThat(this.agentConnectionPersistenceService.getNumAgentConnectionsOnServer(HOST1),
            Matchers.is(1L));
    Assert.assertThat(this.agentConnectionPersistenceService.getNumAgentConnectionsOnServer(HOST2),
            Matchers.is(1L));

    // Migrate a connection, with delete before update
    this.agentConnectionPersistenceService.removeAgentConnection(JOB1, HOST1);
    this.agentConnectionPersistenceService.saveAgentConnection(JOB1, HOST2);
    verifyExpectedConnections(Pair.of(JOB1, HOST2), Pair.of(JOB2, HOST2));
    Assert.assertThat(this.agentConnectionPersistenceService.getNumAgentConnectionsOnServer(HOST1),
            Matchers.is(0L));
    Assert.assertThat(this.agentConnectionPersistenceService.getNumAgentConnectionsOnServer(HOST2),
            Matchers.is(2L));

    // Migrate a connection with update before delete
    this.agentConnectionPersistenceService.saveAgentConnection(JOB1, HOST1);
    this.agentConnectionPersistenceService.removeAgentConnection(JOB1, HOST2);
    verifyExpectedConnections(Pair.of(JOB1, HOST1), Pair.of(JOB2, HOST2));
    Assert.assertThat(this.agentConnectionPersistenceService.getNumAgentConnectionsOnServer(HOST1),
            Matchers.is(1L));
    Assert.assertThat(this.agentConnectionPersistenceService.getNumAgentConnectionsOnServer(HOST2),
            Matchers.is(1L));

    // Migrate a connection, landing on the same server with deletion
    this.agentConnectionPersistenceService.removeAgentConnection(JOB1, HOST1);
    this.agentConnectionPersistenceService.saveAgentConnection(JOB1, HOST1);
    verifyExpectedConnections(Pair.of(JOB1, HOST1), Pair.of(JOB2, HOST2));
    Assert.assertThat(this.agentConnectionPersistenceService.getNumAgentConnectionsOnServer(HOST1),
            Matchers.is(1L));
    Assert.assertThat(this.agentConnectionPersistenceService.getNumAgentConnectionsOnServer(HOST2),
            Matchers.is(1L));

    // Migrate a connection, landing on the same server without deletion (unexpected in practice)
    this.agentConnectionPersistenceService.saveAgentConnection(JOB1, HOST1);
    this.agentConnectionPersistenceService.saveAgentConnection(JOB1, HOST1);
    verifyExpectedConnections(Pair.of(JOB1, HOST1), Pair.of(JOB2, HOST2));
    Assert.assertThat(this.agentConnectionPersistenceService.getNumAgentConnectionsOnServer(HOST1),
            Matchers.is(1L));
    Assert.assertThat(this.agentConnectionPersistenceService.getNumAgentConnectionsOnServer(HOST2),
            Matchers.is(1L));

    // Delete all
    this.agentConnectionPersistenceService.removeAgentConnection(JOB1, HOST1);
    this.agentConnectionPersistenceService.removeAgentConnection(JOB2, HOST2);
    verifyExpectedConnections();
    Assert.assertThat(this.agentConnectionPersistenceService.getNumAgentConnectionsOnServer(HOST1),
            Matchers.is(0L));
    Assert.assertThat(this.agentConnectionPersistenceService.getNumAgentConnectionsOnServer(HOST2),
            Matchers.is(0L));
}

From source file:io.cloudslang.lang.runtime.navigations.Navigations.java

/**
 * Returns the next step position to navigate to.
 * In case an error key was set in the runtime services, throw an error event and return null.
 *
 * @param runEnv                   the run environment
 * @param executionRuntimeServices the runtime services
 * @return the step id the score engine needs to navigate to the next step
 *///from   w  w  w  .  ja va  2s .  com
public Long navigate(@Param(ScoreLangConstants.RUN_ENV) RunEnvironment runEnv,
        @Param(EXECUTION_RUNTIME_SERVICES) ExecutionRuntimeServices executionRuntimeServices) {

    // If we have an error key stored, we fire an error event and return null as the next position
    if (executionRuntimeServices.hasStepErrorKey()) {
        AbstractExecutionData.fireEvent(executionRuntimeServices, runEnv,
                ScoreLangConstants.SLANG_EXECUTION_EXCEPTION, "Error detected during step",
                LanguageEventData.StepType.NAVIGATION, null, extractContext(runEnv),
                Pair.of(LanguageEventData.EXCEPTION, executionRuntimeServices.getStepErrorKey()));
        throw new RuntimeException(executionRuntimeServices.getStepErrorKey());
    }

    // return the next step position from the run env
    return runEnv.removeNextStepPosition();

}

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

public Pair<PageSet, ResultSet> search(SqlClauseForm form) {
    String databaseName = form.getDatabaseName();
    QueryBuilder builder = getQueryBuilder(form);
    Map<String, ?> paramMap = paramParser.parseMap(form.getParamMap());

    if (form.getPno() <= 0L) {
        form.setPno(0L);//  ww w  . ja v  a 2  s. c  o m
    }
    if (form.getPsz() <= 0L) {
        form.setPsz(config.getPaginatorDefaultPageSize());
    }

    ResultSet resultSet = new ResultSet();
    PageSet ps = execQueryService.query(databaseName, builder, paramMap, form.getPno(), form.getPsz(),
            resultSet);

    return Pair.of(ps, resultSet);
}