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

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

Introduction

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

Prototype

public abstract R getRight();

Source Link

Document

Gets the right element from this pair.

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

Usage

From source file:com.act.lcms.MassCalculator2Test.java

@Test
public void testMC2MatchesMC1WithinMeaningfulTolerance() throws Exception {
    List<Map<String, String>> rows;
    try (InputStream is = MassCalculator2Test.class.getResourceAsStream(TEST_CASE_RESOURCE)) {
        TSVParser parser = new TSVParser();
        parser.parse(is);//from  w w  w .  j  av  a  2 s  .c  o m
        rows = parser.getResults();
    }

    int testCase = 1;
    for (Map<String, String> row : rows) {
        String inchi = row.get("InChI");
        Double expectedMass = Double.valueOf(row.get("Mass"));
        Integer expectedCharge = Integer.valueOf(row.get("Charge"));

        Pair<Double, Integer> actualMassAndCharge = MassCalculator2.calculateMassAndCharge(inchi);

        Double threshold = ACCEPTABLE_MASS_DELTA_THRESHOLD;
        if (actualMassAndCharge.getRight() < 0) {
            // Widen the window for added electrons' masses included in Chemaxon's calculations for negative ions.
            threshold += ACCEPTABLE_MASS_DELTA_THRESHOLD * -1.0 * actualMassAndCharge.getRight().doubleValue();
        } else if (actualMassAndCharge.getRight() > 0) {
            // Positively charged molecules have the missing electrons' masses subtracted
            threshold += ACCEPTABLE_MASS_DELTA_THRESHOLD * actualMassAndCharge.getRight().doubleValue();
        }

        assertEquals(
                String.format("Case %d: mass for %s is within delta threshold: %.6f vs. %.6f", testCase, inchi,
                        expectedMass, actualMassAndCharge.getLeft()),
                expectedMass, actualMassAndCharge.getLeft(), threshold);
        assertEquals(String.format("Case %d: charge %s matches expected", testCase, inchi), expectedCharge,
                actualMassAndCharge.getRight());
        testCase++;
    }
}

From source file:com.bitranger.parknshop.common.recommend.vectors.similarity.PearsonCorrelation.java

@Override
public double similarity(ArrayList<Long> vec1, ArrayList<Long> vec2) {
    if (vec1.isEmpty() || vec2.isEmpty()) {
        return 0;
    }//from www  .j  a  v  a 2s.co  m

    // first compute means of common items
    double sum1 = 0;
    double sum2 = 0;
    int n = 0;
    for (Pair<VectorEntry, VectorEntry> pair : Vectors.fastIntersect(vec1, vec2)) {
        sum1 += pair.getLeft().getValue();
        sum2 += pair.getRight().getValue();
        n += 1;
    }

    if (n == 0) {
        return 0;
    }

    final double mu1 = sum1 / n;
    final double mu2 = sum2 / n;

    double var1 = 0;
    double var2 = 0;
    double dot = 0;
    int nCoratings = 0;

    for (Pair pair : Vectors.fastIntersect(vec1, vec2)) {
        final double v1 = (double) pair.getLeft();
        final double v2 = (double) pair.getRight();
        var1 += v1 * v1;
        var2 += v2 * v2;
        dot += v1 * v2;
        nCoratings += 1;
    }

    if (nCoratings == 0) {
        return 0;
    } else {
        return dot / (sqrt(var1 * var2) + shrink_age);
    }
}

From source file:com.muk.services.processor.api.IntentApiProcessor.java

@Override
protected Map<String, Object> applyDiff(PatchRequest body, Exchange exchange,
        UriComponents redirectComponents) {
    Map<String, Object> response = super.applyDiff(body, exchange, redirectComponents);

    /* Paypal centric for now since this is the first */
    //TODO generalize
    final String paymentId = exchange.getIn().getHeader("rId", String.class);

    if ("execute".equals(body.getStateChange())) {
        final StringBuilder jqBuilder = new StringBuilder();

        body.getPathChanges().add(Pair.of(".paymentId", "\"" + paymentId + "\""));

        for (final Pair<String, Object> jqStatement : body.getPathChanges()) {
            jqBuilder.append(jqStatement.getLeft()).append("|=").append(jqStatement.getRight()).append(" | ");
        }//from  w w w.  ja  v a  2s .com

        jqBuilder.append(".");
        final String jqString = jqBuilder.toString();
        //jqString = StringUtils.chop(jqString);

        try {
            final JsonQuery jq = JsonQuery.compile(jqString);
            final JsonNode node = getMapper().valueToTree(new PaymentRequest());
            final List<JsonNode> patched = jq.apply(node);

            response = paymentFacade.commitPayment(
                    getMapper().treeToValue(patched.get(0), PaymentRequest.class), redirectComponents);
        } catch (final JsonProcessingException jsonEx) {
            LOG.error("Failed in json processing", jsonEx);
            response.put("error", "internal error");
        }
    }

    return response;
}

From source file:com.netflix.spinnaker.clouddriver.kubernetes.v2.description.manifest.KubernetesMultiManifestOperationDescription.java

@JsonIgnore
@Deprecated/* w  w  w.jav a  2  s  .  c  o m*/
public KubernetesCoordinates getPointCoordinates() {
    Pair<KubernetesKind, String> parsedName = KubernetesManifest.fromFullResourceName(manifestName);

    return KubernetesCoordinates.builder().namespace(location).kind(parsedName.getLeft())
            .name(parsedName.getRight()).build();
}

From source file:com.qq.tars.service.PatchService.java

private String md5(String path) {
    String command = "md5sum " + path;
    Pair<Integer, Pair<String, String>> result = SystemUtils.exec(command);
    if (result.getLeft() == -1) {
        return null;
    }//from  w  w  w  . ja  v  a 2 s.  c  om
    String stdout = result.getRight().getLeft();
    if (stdout.contains(" ")) {
        stdout = stdout.substring(0, stdout.indexOf(" "));
    }

    return StringUtils.trimToNull(stdout);
}

From source file:com.vmware.identity.openidconnect.server.AuthenticationController.java

@RequestMapping(value = "/oidc/authorize/{tenant:.*}", method = { RequestMethod.GET, RequestMethod.POST })
public ModelAndView authenticate(Model model, Locale locale, HttpServletRequest request,
        HttpServletResponse response, @PathVariable("tenant") String tenant) throws IOException {
    ModelAndView page;/*w w  w.  j a v a2 s  .  co m*/
    HttpResponse httpResponse;
    IDiagnosticsContextScope context = null;

    try {
        HttpRequest httpRequest = HttpRequest.from(request);
        context = DiagnosticsContextFactory.createContext(LoggerUtils.getCorrelationID(httpRequest).getValue(),
                tenant);

        AuthenticationRequestProcessor p = new AuthenticationRequestProcessor(this.idmClient,
                this.authzCodeManager, this.sessionManager, this.messageSource, model, locale, httpRequest,
                tenant);
        Pair<ModelAndView, HttpResponse> result = p.process();
        page = result.getLeft();
        httpResponse = result.getRight();
    } catch (Exception e) {
        ErrorObject errorObject = ErrorObject
                .serverError(String.format("unhandled %s: %s", e.getClass().getName(), e.getMessage()));
        LoggerUtils.logFailedRequest(logger, errorObject, e);
        page = null;
        httpResponse = HttpResponse.createErrorResponse(errorObject);
    } finally {
        if (context != null) {
            context.close();
        }
    }

    if (httpResponse != null) {
        httpResponse.applyTo(response);
    }
    return page;
}

From source file:edu.uci.ics.pregelix.dataflow.ConnectorPolicyAssignmentPolicy.java

@Override
public IConnectorPolicy getConnectorPolicyAssignment(IConnectorDescriptor c, int nProducers, int nConsumers,
        int[] fanouts) {
    if (c instanceof MToNPartitioningMergingConnectorDescriptor) {
        return senderSideMatPipPolicy;
    } else {/*from ww  w  . j  a v a2s  .com*/
        Pair<Pair<IOperatorDescriptor, Integer>, Pair<IOperatorDescriptor, Integer>> endPoints = spec
                .getConnectorOperatorMap().get(c.getConnectorId());
        IOperatorDescriptor consumer = endPoints.getRight().getLeft();
        if (consumer instanceof TreeIndexInsertUpdateDeleteOperatorDescriptor) {
            return senderSideMatBlkPolicy;
        } else {
            return pipeliningPolicy;
        }
    }
}

From source file:com.intuit.karate.Script.java

public static ScriptValue eval(String text, ScriptContext context) {
    text = StringUtils.trimToEmpty(text);
    if (text.isEmpty()) {
        logger.trace("script is empty");
        return ScriptValue.NULL;
    }/*from w  ww  .ja  v  a  2s .  c om*/
    if (isCallSyntax(text)) { // special case in form "call foo arg"
        text = text.substring(5);
        int pos = text.indexOf(' '); // TODO handle read('file with spaces in the name')
        String arg;
        if (pos != -1) {
            arg = text.substring(pos);
            text = text.substring(0, pos);
        } else {
            arg = null;
        }
        return call(text, arg, context);
    } else if (isGetSyntax(text)) { // special case in form
        // get json[*].path
        // get /xml/path
        // get xpath-function(expression)
        text = text.substring(4);
        String left;
        String right;
        if (isVariableAndSpaceAndPath(text)) {
            int pos = text.indexOf(' ');
            right = text.substring(pos + 1);
            left = text.substring(0, pos);
        } else {
            Pair<String, String> pair = parseVariableAndPath(text);
            left = pair.getLeft();
            right = pair.getRight();
        }
        if (isXmlPath(right) || isXmlPathFunction(right)) {
            return evalXmlPathOnVarByName(left, right, context);
        } else {
            return evalJsonPathOnVarByName(left, right, context);
        }
    } else if (isJsonPath(text)) {
        return evalJsonPathOnVarByName(ScriptValueMap.VAR_RESPONSE, text, context);
    } else if (isJson(text)) {
        DocumentContext doc = JsonUtils.toJsonDoc(text);
        evalJsonEmbeddedExpressions(doc, context);
        return new ScriptValue(doc);
    } else if (isBson(text)) {
        text = text.substring(1);
        DocumentContext doc = JsonUtils.toJsonDoc(text);
        evalJsonEmbeddedExpressions(doc, context);
        JSONObject json = JSONValue.parse(doc.jsonString(), JSONObject.class);
        BsonDocument bson = BsonUtils.jsonToBson(json);
        return new ScriptValue(bson);
    } else if (isXml(text)) {
        Document doc = XmlUtils.toXmlDoc(text);
        evalXmlEmbeddedExpressions(doc, context);
        return new ScriptValue(doc);
    } else if (isXmlPath(text)) {
        return evalXmlPathOnVarByName(ScriptValueMap.VAR_RESPONSE, text, context);
    } else if (isStringExpression(text)) { // has to be above variableAndXml/JsonPath because of / in URL-s etc
        return evalInNashorn(text, context);
    } else if (isVariableAndJsonPath(text)) {
        Pair<String, String> pair = parseVariableAndPath(text);
        return evalJsonPathOnVarByName(pair.getLeft(), pair.getRight(), context);
    } else if (isVariableAndXmlPath(text)) {
        Pair<String, String> pair = parseVariableAndPath(text);
        return evalXmlPathOnVarByName(pair.getLeft(), pair.getRight(), context);
    } else {
        // js expressions e.g. foo, foo(bar), foo.bar, foo + bar, 5, true
        // including function declarations e.g. function() { }
        return evalInNashorn(text, context);
    }
}

From source file:com.vmware.identity.openidconnect.server.AuthorizationController.java

@RequestMapping(value = "/oidc/authorize/{tenant:.*}", method = { RequestMethod.GET, RequestMethod.POST })
public ModelAndView authorize(Model model, Locale locale, HttpServletRequest request,
        HttpServletResponse response, @PathVariable("tenant") String tenant) throws IOException {
    ModelAndView page = null;//from  w w  w .  j  a  v a 2 s.c om

    IDiagnosticsContextScope context = null;

    try {
        HttpRequest httpRequest = HttpRequest.create(request);
        context = DiagnosticsContextFactory.createContext(CorrelationID.get(httpRequest).getValue(), tenant);

        AuthenticationRequestProcessor p = new AuthenticationRequestProcessor(this.idmClient,
                this.authzCodeManager, this.sessionManager, this.messageSource, model, locale, httpRequest,
                tenant);
        Pair<ModelAndView, HttpResponse> result = p.process();
        page = result.getLeft();
        HttpResponse httpResponse = result.getRight();
        if (httpResponse != null) {
            httpResponse.applyTo(response);
        }
    } catch (Exception e) {
        logger.error("unhandled exception", e);
        response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
                "unhandled exception: " + e.getClass().getName());
    } finally {
        if (context != null) {
            context.close();
        }
    }

    return page;
}

From source file:net.community.chest.gitcloud.facade.AbstractEnvironmentInitializer.java

protected void extractConfigFiles(File confDir, Collection<Pair<String, Collection<String>>> filesList) {
    for (Pair<String, Collection<String>> p : filesList) {
        extractConfigFiles(confDir, p.getLeft(), p.getRight());
    }/*from  w  w w .  jav a 2  s.  c o  m*/
}