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:com.vmware.identity.openidconnect.server.LogoutRequestProcessor.java
public HttpResponse process() { ClientID clientId;//from www .j a v a 2 s.co m URI postLogoutRedirectUri; LogoutErrorResponse parseErrorResponse; try { this.logoutRequest = LogoutRequest.parse(this.httpRequest); clientId = this.logoutRequest.getClientID(); postLogoutRedirectUri = this.logoutRequest.getPostLogoutRedirectURI(); parseErrorResponse = null; } catch (LogoutRequest.ParseException e) { if (e.getClientID() != null && e.getPostLogoutRedirectURI() != null && e.createLogoutErrorResponse() != null) { clientId = e.getClientID(); postLogoutRedirectUri = e.getPostLogoutRedirectURI(); parseErrorResponse = e.createLogoutErrorResponse(); } else { LoggerUtils.logFailedRequest(logger, e.getErrorObject(), e); return HttpResponse.createErrorResponse(e.getErrorObject()); } } try { if (this.tenant == null) { this.tenant = this.tenantInfoRetriever.getDefaultTenantName(); } this.tenantInfo = this.tenantInfoRetriever.retrieveTenantInfo(this.tenant); this.clientInfo = this.clientInfoRetriever.retrieveClientInfo(this.tenant, clientId); if (!this.clientInfo.getPostLogoutRedirectURIs().contains(postLogoutRedirectUri)) { throw new ServerException(ErrorObject.invalidRequest("unregistered post_logout_redirect_uri")); } } catch (ServerException e) { LoggerUtils.logFailedRequest(logger, e); return HttpResponse.createErrorResponse(e.getErrorObject()); } if (parseErrorResponse != null) { LoggerUtils.logFailedRequest(logger, parseErrorResponse.getErrorObject()); return parseErrorResponse.toHttpResponse(); } try { authenticateClient(); Pair<LogoutSuccessResponse, Cookie> result = processInternal(); LogoutSuccessResponse logoutSuccessResponse = result.getLeft(); Cookie personUserCertificateLoggedOutCookie = result.getRight(); HttpResponse httpResponse = logoutSuccessResponse.toHttpResponse(); httpResponse.addCookie(loggedOutSessionCookie()); if (personUserCertificateLoggedOutCookie != null) { httpResponse.addCookie(personUserCertificateLoggedOutCookie); } return httpResponse; } catch (ServerException e) { LoggerUtils.logFailedRequest(logger, e); LogoutErrorResponse logoutErrorResponse = new LogoutErrorResponse( this.logoutRequest.getPostLogoutRedirectURI(), this.logoutRequest.getState(), e.getErrorObject()); return logoutErrorResponse.toHttpResponse(); } }
From source file:com.cisco.oss.foundation.message.HornetQMessageProducer.java
private ClientProducer getProducer(String groupIdentifier) { try {/*w ww . ja va 2s. co m*/ if (producer.get() == null) { String realQueueName = createQueueIfNeeded(); List<ClientProducer> producers = new ArrayList<>(); for (Pair<ClientSession, SessionFailureListener> clientSession : HornetQMessagingFactory .getSession()) { ClientProducer clientProducer = clientSession.getLeft().createProducer(realQueueName); producersSet.add(clientProducer); producers.add(clientProducer); } producer.set(producers); } ClientProducer clientProducer = null; if (groupIdentifier != null) { clientProducer = producer.get().get(groupIdentifier.hashCode() % producer.get().size()); } else { clientProducer = producer.get().get(nextNode(producer.get().size())); } return clientProducer; } catch (Exception e) { LOGGER.error("can't create queue producer: {}", e, e); throw new QueueException(e); } }
From source file:de.tuberlin.uebb.jbop.optimizer.var.LocalVarInliner.java
private AbstractInsnNode skipVars(final AbstractInsnNode currentNode, final Map<Integer, Object> knownValues) { final Pair<AbstractInsnNode, AbstractInsnNode> loopBounds = LoopMatcher.getLoopBounds(currentNode); final Collection<Integer> vars = getVarsInRange(loopBounds.getLeft(), loopBounds.getRight()); for (final Integer varInLoop : vars) { knownValues.remove(varInLoop);//from w w w . j a v a 2s .c o m } return loopBounds.getRight().getNext(); }
From source file:name.martingeisse.phunky.runtime.code.expression.array.ArrayElementExpression.java
@Override public Variable resolveOrCreateVariable(final Environment environment) { Pair<Variable, String> variableArrayAndKey = obtainArrayVariableAndKey(environment); if (variableArrayAndKey == null) { return null; } else {// ww w . j a v a 2s .c o m PhpVariableArray variableArray = variableArrayAndKey.getLeft() .getVariableArray(environment.getRuntime(), getLocation()); String key = variableArrayAndKey.getRight(); return variableArray.getOrCreateVariable(key); } }
From source file:com.romeikat.datamessie.core.processing.service.stemming.text.TextStemmer.java
private String replaceNamedEntity(final SharedSessionContract ssc, final String textUnderStemming, final String namedEntityName) { // Determine replacement final Pair<String, String> replacingAndReplacement = getReplacingAndReplacement(ssc, namedEntityName); if (replacingAndReplacement == null) { return textUnderStemming; }/*from w w w . j a v a 2s. co m*/ final String replacing = replacingAndReplacement.getLeft(); final String replacement = replacingAndReplacement.getRight(); // Do the replacement (to whole words only) final String result = textUtil.replaceAllAsWholeWord(textUnderStemming, replacing, replacement); // Done return result; }
From source file:com.tussle.motion.MotionSystem.java
public CollisionTriad ecbHit(Map<StageElement<CollisionStadium>, CollisionStadium> beforeBoxes, Map<StageElement<CollisionStadium>, CollisionStadium> afterBoxes, Map<StageElement, CollisionShape> beforeSurfaces, Map<StageElement, CollisionShape> afterSurfaces, CollisionMap fores) {//from w w w . j av a 2 s . co m if (fores.isEmpty()) return null; //Split the given surfaces into two groups: those which are not worth timestep subdividing, //and those which are Predicate<Pair<StageElement<CollisionStadium>, StageElement>> splitHeuristic = ( Pair<StageElement<CollisionStadium>, StageElement> m) -> { StageElement<CollisionStadium> c = m.getLeft(); StageElement s = m.getRight(); double[] velocity = Utility.displacementDiff(beforeSurfaces.get(s), afterSurfaces.get(s), beforeBoxes.get(c), afterBoxes.get(c)); return FastMath.hypot(velocity[0], velocity[1]) >= PIXEL_STEP; }; if (fores.keySet().stream().anyMatch(splitHeuristic)) { //Split in half, and run Map<StageElement<CollisionStadium>, CollisionStadium> middleBoxes = LazyMap.lazyMap(new HashMap<>(), (StageElement<CollisionStadium> c) -> beforeBoxes.get(c).interpolate(afterBoxes.get(c))); Map<StageElement, CollisionShape> middleSurfaces = LazyMap.lazyMap(new HashMap<>(), (StageElement s) -> beforeSurfaces.get(s).interpolate(afterSurfaces.get(s))); CollisionTriad latestHit = ecbHit(beforeBoxes, middleBoxes, beforeSurfaces, middleSurfaces, fores); Map<StageElement<CollisionStadium>, CollisionStadium> postMiddleBoxes; Map<StageElement<CollisionStadium>, CollisionStadium> postAfterBoxes; Map<StageElement, CollisionShape> postMiddleSurfaces; Map<StageElement, CollisionShape> postAfterSurfaces; if (latestHit != null) { double xDisp = latestHit.cumulativeX; double yDisp = latestHit.cumulativeY; postMiddleBoxes = LazyMap.lazyMap(new HashMap<>(), (StageElement<CollisionStadium> c) -> middleBoxes.get(c).displacementBy(xDisp, yDisp)); postAfterBoxes = LazyMap.lazyMap(new HashMap<>(), (StageElement<CollisionStadium> c) -> afterBoxes.get(c).displacementBy(xDisp, yDisp)); postMiddleSurfaces = LazyMap.lazyMap(new HashMap<>(), (StageElement s) -> middleSurfaces.get(s).displacementBy(xDisp, yDisp)); postAfterSurfaces = LazyMap.lazyMap(new HashMap<>(), (StageElement s) -> afterSurfaces.get(s).displacementBy(xDisp, yDisp)); } else { postMiddleBoxes = middleBoxes; postAfterBoxes = afterBoxes; postMiddleSurfaces = middleSurfaces; postAfterSurfaces = afterSurfaces; } //Populate a new collision map for the second half CollisionMap mids = new CollisionMap(); for (Map.Entry<Pair<StageElement<CollisionStadium>, StageElement>, ProjectionVector> foreEntry : fores .entrySet()) { StageElement<CollisionStadium> c = foreEntry.getKey().getLeft(); StageElement s = foreEntry.getKey().getRight(); mids.put(c, s, s.getBefore().interpolate(s.getAfter()).depth(postMiddleBoxes.get(c))); } CollisionTriad secondHalfHit = ecbHit(postMiddleBoxes, postAfterBoxes, postMiddleSurfaces, postAfterSurfaces, mids); if (secondHalfHit != null) latestHit = latestHit == null ? secondHalfHit : new CollisionTriad(latestHit, secondHalfHit); return latestHit; } else { //Take the whole step at once CollisionMap afts = new CollisionMap(); for (Pair<StageElement<CollisionStadium>, StageElement> foreKey : fores.keySet()) { if (foreKey.getRight().getBefore().collidesWith(beforeBoxes.get(foreKey.getLeft())) || foreKey.getRight().getAfter().collidesWith(afterBoxes.get(foreKey.getLeft()))) { afts.put(foreKey, foreKey.getRight().getAfter().depth(afterBoxes.get(foreKey.getLeft()))); } } ProjectionVector combinedVectors = Utility.combineProjections(Utility.prunedProjections(afts.values())); return combinedVectors == null ? null : new CollisionTriad(combinedVectors); } }
From source file:im.dadoo.cedar.SelectCriteria.java
private String makeConditionSql(Condition condition) { StringBuilder sb = new StringBuilder(); if (condition != null && condition.getField() != null && condition.getOp() != null && condition.getValue() != null) { switch (condition.getOp()) { case EQ:/*from www. j ava2 s . c o m*/ case GT: case LT: sb.append(condition.getField()).append(" ").append(condition.getOp().getWord()).append(" ") .append(condition.getValue()); break; case IN: String temp = null; //?? if (condition.getValue() instanceof String) { temp = (String) condition.getValue(); } else if (condition.getValue() instanceof SelectCriteria) { temp = ((SelectCriteria) condition.getValue()).sql(); } sb.append(condition.getField()).append(" ").append(condition.getOp().getWord()).append(" ") .append("( ").append(temp).append(" )"); break; case BETWEEN: Pair<String, String> pair = (Pair<String, String>) condition.getValue(); sb.append(condition.getField()).append(" ").append(condition.getOp().getWord()).append(" ") .append(pair.getLeft()).append(" ").append("AND").append(" ").append(pair.getRight()); break; } } return sb.toString(); }
From source file:mase.spec.BasicHybridExchangerDunn.java
@Override protected void mergeProcess(EvolutionState state) { List<BehaviourResult>[] mpBehavs = new List[metaPops.size()]; for (int i = 0; i < metaPops.size(); i++) { MetaPopulation mp = metaPops.get(i); Individual[] inds = getElitePortion(mp.inds, (int) Math.ceil(elitePortion * popSize)); mpBehavs[i] = new ArrayList<BehaviourResult>(mp.agents.size() * inds.length); for (Individual ind : inds) { for (Integer a : mp.agents) { mpBehavs[i].add(getAgentBR(ind, a)); }// www .j a va2 s . c o m } } distanceMatrix = distanceMatrix(mpBehavs, state); Pair<MetaPopulation, MetaPopulation> nextMerge = metaPops.size() >= 3 ? findNextMerge(distanceMatrix, state) : null; // Merge if they are similar if (nextMerge != null) { state.output.message("*************************** Merging " + nextMerge.getLeft() + " with " + nextMerge.getRight() + " ***************************"); merges++; MetaPopulation mpNew = mergePopulations(nextMerge.getLeft(), nextMerge.getRight(), state); metaPops.remove(nextMerge.getLeft()); metaPops.remove(nextMerge.getRight()); metaPops.add(mpNew); } }
From source file:it.polimi.diceH2020.SPACE4CloudWS.solvers.solversImpl.QNSolver.QNSolver.java
@Override protected Pair<Double, Boolean> run(Pair<List<File>, List<File>> pFiles, String remoteName, String remoteDirectory) throws Exception { File jmtFile = pFiles.getLeft().stream().filter(s -> s.getName().contains(".jsimg")).findFirst().get(); String jmtFileName = jmtFile.getName(); String remotePath = remoteDirectory + File.separator + jmtFileName; boolean stillNotOk = true; for (int i = 0; stillNotOk && i < MAX_ITERATIONS; ++i) { logger.info(remoteName + "-> Starting Queuing Net resolution on the server"); cleanRemoteSubDirectory(remoteDirectory); sendFiles(remoteDirectory, pFiles.getLeft()); sendFiles(remoteDirectory, pFiles.getRight()); logger.debug(remoteName + "-> Working files sent"); String command = connSettings.getMaxDuration() == Integer.MIN_VALUE ? String.format("java -cp %s jmt.commandline.Jmt sim %s ", connSettings.getSolverPath(), remotePath)/* w ww . ja v a 2s .c o m*/ : String.format("java -cp %s jmt.commandline.Jmt sim %s -maxtime %d", connSettings.getSolverPath(), remotePath, connSettings.getMaxDuration()); logger.debug(remoteName + "-> Starting JMT model..."); List<String> remoteMsg = connector.exec(command, getClass()); if (remoteMsg.contains("exit-status: 0")) { stillNotOk = false; logger.info(remoteName + "-> The remote optimization process completed correctly"); } else { logger.debug(remoteName + "-> Remote exit status: " + remoteMsg); } } if (stillNotOk) { logger.info(remoteName + "-> Error in remote optimization"); throw new Exception("Error in the QN server"); } else { File solFile = fileUtility.provideTemporaryFile(jmtFileName + "-result", ".jsim"); connector.receiveFile(solFile.getAbsolutePath(), remotePath + "-result" + ".jsim", getClass()); SolutionsWrapper resultObject = SolutionsWrapper.unMarshal(solFile); if (fileUtility.delete(solFile)) logger.debug(solFile + " deleted"); Double throughput = resultObject.getMeanValue(); /* This is a workaround for the crazy behavior of the PNML transformation * that converts milliseconds to seconds. * Here we turn hertz into kilohertz to obtain results consistent * with our input. */ if (usingInputModel) throughput /= 1000; boolean failure = resultObject.isFailed(); return Pair.of(throughput, failure); } }
From source file:alfio.manager.WaitingQueueProcessorIntegrationTest.java
@Test public void testSoldOut() throws InterruptedException { Pair<String, Event> pair = initSoldOutEvent(true); Event event = pair.getRight(); String reservationId = pair.getLeft(); Ticket firstTicket = ticketRepository.findTicketsInReservation(reservationId).get(0); ticketRepository.releaseTicket(reservationId, UUID.randomUUID().toString(), event.getId(), firstTicket.getId());/* www .j a v a 2s .co m*/ waitingQueueSubscriptionProcessor.distributeAvailableSeats(event); List<WaitingQueueSubscription> subscriptions = waitingQueueRepository.loadAll(event.getId()); assertEquals(1, subscriptions.stream().filter(w -> StringUtils.isNotBlank(w.getReservationId())).count()); Optional<WaitingQueueSubscription> first = subscriptions.stream() .filter(w -> w.getStatus().equals(WaitingQueueSubscription.Status.PENDING)).findFirst(); assertTrue(first.isPresent()); assertEquals("Giuseppe Garibaldi", first.get().getFullName()); }