List of usage examples for org.apache.commons.lang3.tuple Pair getLeft
public abstract L getLeft();
Gets the left element from this pair.
When treated as a key-value pair, this is the key.
From source file:it.polimi.diceH2020.SPACE4CloudWS.fineGrainedLogicForOptimization.ReactorConsumer.java
public void accept(Event<ContainerGivenHandN> ev) { SolutionPerJob spj = ev.getData().getSpj(); ContainerLogicGivenH containerLogic = ev.getData().getHandler(); logger.info("|Q-STATUS| received spjWrapper" + spj.getId() + "." + spj.getNumberUsers() + " on channel" + id + "\n"); Pair<Boolean, Long> solverResult = runSolver(spj); long exeTime = solverResult.getRight(); if (solverResult.getLeft()) { containerLogic.registerCorrectSolutionPerJob(spj, exeTime); } else {//from www. ja va 2 s.com containerLogic.registerFailedSolutionPerJob(spj, exeTime); } dispatcher.notifyReadyChannel(this); }
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 w ww .j a va 2s . c om*/ // 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.facades.impl.DefaultPaymentFacade.java
@Override public Map<String, Object> startPayment(PaymentRequest paymentRequest, UriComponents redirectComponents) { Map<String, Object> response = new HashMap<String, Object>(); final ObjectNode payload = JsonNodeFactory.instance.objectNode(); if (ServiceConstants.PaymentMethods.paypalExpress.equals(paymentRequest.getPaymentMethod())) { payload.put("intent", "sale"); final ObjectNode redirectUrls = payload.putObject("redirect_urls"); redirectUrls.put("return_url", redirectComponents.toUriString() + "/id/redirect"); redirectUrls.put("cancel_url", redirectComponents.toUriString() + "/id/cancel"); final ObjectNode payer = payload.putObject("payer"); payer.put("payment_method", "paypal"); final ArrayNode transactions = payload.putArray("transactions"); final ObjectNode transaction = transactions.addObject(); transaction.put("description", paymentRequest.getService()); transaction.putObject("amount").put("total", paymentRequest.getPrice()).put("currency", "USD"); response = paypalPaymentService.startPayment(payload); } else if (ServiceConstants.PaymentMethods.stripe.equals(paymentRequest.getPaymentMethod())) { payload.put("amount", (long) Math.floor(paymentRequest.getPrice() * 100d)); payload.put("currency", "usd"); payload.put("description", paymentRequest.getService()); payload.put("source", paymentRequest.getInfo()); if (StringUtils.isNotBlank(paymentRequest.getEmail())) { payload.put("receipt_email", paymentRequest.getEmail()); }/*from w w w . j av a2 s. co m*/ if (paymentRequest.getMetadata() != null) { final ObjectNode mds = payload.putObject("metadata"); for (final Pair<String, String> pair : paymentRequest.getMetadata()) { mds.put(pair.getLeft(), pair.getRight()); } } response = stripePaymentService.startPayment(payload); } return response; }
From source file:com.act.lcms.db.io.report.IonAnalysisInterchangeModel.java
/** * This function takes in a single LCMS result (in the IonAnalysisInterchangeModel format) and extracts all the * molecule hits from the file and applies a filter function on the model. * @param replicateModel The IonAnalysisInterchangeModel to be analyzed * @param hitOrMissFilterAndTransformer This filter function takes in single/multiple HitOrMiss objects from replicates and * performs a transformation operation on them to produce one HitOrMiss object * and a boolean to keep the transformed molecule in the resulting model. * @return A resultant model that contains a list of inchis that are valid molecule hits in the input file and * pass all the thresholds./*from www .j a v a2 s . c om*/ * @throws IOException */ public static IonAnalysisInterchangeModel filterAndOperateOnMoleculesFromModel( IonAnalysisInterchangeModel replicateModel, HitOrMissFilterAndTransformer hitOrMissFilterAndTransformer) throws IOException { List<ResultForMZ> resultsForMZs = new ArrayList<>(); // Iterate through every mass charge // TODO: Consider using a parallel stream here for (int i = 0; i < replicateModel.getResults().size(); i++) { ResultForMZ representativeMZ = replicateModel.getResults().get(i); Double representativeMassCharge = representativeMZ.getMz(); int totalNumberOfMoleculesInMassChargeResult = representativeMZ.getMolecules().size(); ResultForMZ resultForMZ = new ResultForMZ(representativeMassCharge); resultForMZ.setId(representativeMZ.getId()); // TODO: Take out the isValid field since it does not convey useful information for such post processing files. resultForMZ.setIsValid(representativeMZ.getIsValid()); // For each mass charge, iterate through each molecule under the mass charge for (int j = 0; j < totalNumberOfMoleculesInMassChargeResult; j++) { Pair<HitOrMiss, Boolean> transformedAndIsRetainedMolecule; List<HitOrMiss> molecules = replicateModel.getResults().get(i).getMolecules(); HitOrMiss molecule = molecules.get(j); transformedAndIsRetainedMolecule = hitOrMissFilterAndTransformer.apply(molecule); // Check if the filter function wants to throw out the molecule. If not, then add the molecule to the final result. if (transformedAndIsRetainedMolecule.getRight()) { resultForMZ.addMolecule(transformedAndIsRetainedMolecule.getLeft()); } } resultsForMZs.add(resultForMZ); } IonAnalysisInterchangeModel resultModel = new IonAnalysisInterchangeModel(); resultModel.setResults(resultsForMZs); return resultModel; }
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 ww . ja va 2s .c om*/ 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:com.netflix.spinnaker.clouddriver.kubernetes.v2.description.manifest.KubernetesMultiManifestOperationDescription.java
@JsonIgnore @Deprecated// ww w .ja v a 2s.co 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.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 www. jav a2s . c om*/ 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:net.mindengine.galen.specs.reader.page.RuleStandardProcessor.java
@Override public void processRule(ObjectSpecs objectSpecs, String ruleText, VarsContext varsContext, PageSection section, Properties properties, String contextPath, PageSpecReader pageSpecReader) throws IOException { List<Pair<String, Place>> lines = new LinkedList<Pair<String, Place>>(); String indentation = ""; ObjectSpecs temporaryObjectSpecs = null; SpecGroup specGroup = null;/* w w w.j a v a2 s . c om*/ if (objectSpecs != null) { indentation = " "; specGroup = new SpecGroup(); specGroup.setName(ruleText); temporaryObjectSpecs = new ObjectSpecs(objectSpecs.getObjectName()); } else { PageSection subSection = new PageSection(); subSection.setName(ruleText); section.addSubSection(subSection); section = subSection; } for (Pair<String, Place> line : originalLines) { lines.add(new ImmutablePair<String, Place>(indentation + line.getLeft(), line.getRight())); } StateDoingSection stateDoingSection = new StateDoingSection(properties, section, contextPath, pageSpecReader); if (objectSpecs != null) { stateDoingSection.setCurrentObject(temporaryObjectSpecs); } for (Pair<String, Place> line : lines) { stateDoingSection.process(varsContext, line.getLeft(), line.getRight()); } if (objectSpecs != null) { specGroup.getSpecs().addAll(temporaryObjectSpecs.getSpecs()); objectSpecs.getSpecGroups().add(specGroup); } }
From source file:de.vandermeer.skb.interfaces.transformers.textformat.Test_Text_To_WrappedFormat.java
@Test public void test_Simple() { String words = new LoremIpsum().getWords(30); String text = words;//from w w w.j a va 2 s.c o m text = StringUtils.replace(words, "dolor ", "dolor " + LINEBREAK); text = StringUtils.replace(text, "dolore ", "dolore " + LINEBREAK); Pair<ArrayList<String>, ArrayList<String>> textPair; textPair = Text_To_WrappedFormat.convert(text, 20, null); assertEquals(0, textPair.getLeft().size()); assertEquals(11, textPair.getRight().size()); assertEquals(words, StringUtils.join(textPair.getRight(), ' ')); textPair = Text_To_WrappedFormat.convert(text, 30, Pair.of(6, 10)); System.err.println(words); System.err.println(text); System.err.println("\n----[ top ]----"); System.err.println("123456789012345678901234567890"); for (String s : textPair.getLeft()) { System.err.println(s); } System.err.println("\n----[ bottom ]----"); System.err.println("123456789012345678901234567890"); for (String s : textPair.getRight()) { System.err.println(s); } }
From source file:net.lldp.checksims.util.threading.SimilarityDetectionWorker.java
/** * Construct a Callable to perform pairwise similarity detection for one pair of assignments. * * @param algorithm Algorithm to use// ww w. j a va 2 s . c o m * @param submissions Assignments to compare */ public SimilarityDetectionWorker(SimilarityDetector<T> algorithm, Pair<Submission, Submission> submissions) { checkNotNull(algorithm); checkNotNull(submissions); checkNotNull(submissions.getLeft()); checkNotNull(submissions.getRight()); this.algorithm = algorithm; this.submissions = submissions; }