List of usage examples for org.apache.commons.lang3.tuple Pair getRight
public abstract R getRight();
Gets the right element from this pair.
When treated as a key-value pair, this is the value.
From source file:com.cfitzarl.cfjwed.controller.StatsController.java
/** * This returns four different statistics back to the browser: * * <ul>/*w w w . j a v a 2 s .c om*/ * <li>The number of attendants who have accepted</li> * <li>The number of attendants who have declined</li> * <li>The number of attendants who have not yet responded</li> * <li>A breakdown of each meal and how many people have chosen them</li> * </ul> * * @return the stats */ @PreAuthorize("hasRole('ROLE_ADMIN')") @RequestMapping(value = "", method = RequestMethod.GET) public StatsDTO displayStats() { StatsDTO dto = new StatsDTO(); dto.setAcceptedAttendants(attendantService.countByStatus(ResponseStatus.ACCEPTED)); dto.setDeclinedAttendants(attendantService.countByStatus(ResponseStatus.DECLINED)); dto.setPendingAttendants(attendantService.countByStatus(ResponseStatus.PENDING)); for (Pair<MealOption, Long> mealGroupings : mealOptionService.getChosenMealCount()) { dto.addMealStat(mealGroupings.getLeft().getName(), mealGroupings.getRight()); } return dto; }
From source file:com.silverpeas.gallery.dao.MediaDAO.java
/** * Finds media according to the given criteria. * @param con the database connection./*from w w w . j a va 2s . c o m*/ * @param criteria the media criteria. * @return the media list corresponding to the given criteria. */ public static List<Media> findByCriteria(final Connection con, final MediaCriteria criteria) throws SQLException { MediaSQLQueryBuilder queryBuilder = new MediaSQLQueryBuilder(); criteria.processWith(queryBuilder); Pair<String, List<Object>> queryBuild = queryBuilder.result(); final Map<String, Photo> photos = new HashMap<String, Photo>(); final Map<String, Video> videos = new HashMap<String, Video>(); final Map<String, Sound> sounds = new HashMap<String, Sound>(); final Map<String, Streaming> streamings = new HashMap<String, Streaming>(); List<Media> media = select(con, queryBuild.getLeft(), queryBuild.getRight(), new SelectResultRowProcessor<Media>(criteria.getResultLimit()) { @Override protected Media currentRow(final int rowIndex, final ResultSet rs) throws SQLException { String mediaId = rs.getString(1); MediaType mediaType = MediaType.from(rs.getString(2)); String instanceId = rs.getString(3); final Media currentMedia; switch (mediaType) { case Photo: currentMedia = new Photo(); photos.put(mediaId, (Photo) currentMedia); break; case Video: currentMedia = new Video(); videos.put(mediaId, (Video) currentMedia); break; case Sound: currentMedia = new Sound(); sounds.put(mediaId, (Sound) currentMedia); break; case Streaming: currentMedia = new Streaming(); streamings.put(mediaId, (Streaming) currentMedia); break; default: currentMedia = null; } if (currentMedia == null) { // Unknown media ... SilverTrace.warn(GalleryComponentSettings.COMPONENT_NAME, "MediaDAO.findByCriteria()", "root.MSG_GEN_PARAM_VALUE", "unknown media type: " + mediaType); return null; } currentMedia.setMediaPK(new MediaPK(mediaId, instanceId)); currentMedia.setTitle(rs.getString(4)); currentMedia.setDescription(rs.getString(5)); currentMedia.setAuthor(rs.getString(6)); currentMedia.setKeyWord(rs.getString(7)); currentMedia.setVisibilityPeriod( Period.check(Period.from(new Date(rs.getLong(8)), new Date(rs.getLong(9))))); currentMedia.setCreationDate(rs.getTimestamp(10)); currentMedia.setCreatorId(rs.getString(11)); currentMedia.setLastUpdateDate(rs.getTimestamp(12)); currentMedia.setLastUpdatedBy(rs.getString(13)); return currentMedia; } }); decoratePhotos(con, media, photos); decorateVideos(con, media, videos); decorateSounds(con, media, sounds); decorateStreamings(con, media, streamings); return queryBuilder.orderingResult(media); }
From source file:com.garethahealy.quotalimitsgenerator.cli.parsers.CLIOptions.java
public QuotaLimitModel calculate() { Pair<Integer, Integer> instanceTypeLine = lines.get(instanceType); Integer instanceCoreInMillis = instanceTypeLine.getLeft() * 1000; Integer instanceMemoryInMb = instanceTypeLine.getRight() * 1000; QuotaLimitModel quotaLimitModel = new QuotaLimitModel(); quotaLimitModel.setInstanceType(instanceType); quotaLimitModel.setQualityOfService(qualityOfService); quotaLimitModel.setAllocatableNodeCores(instanceCoreInMillis); quotaLimitModel.setAllocatableNodeMemory(instanceMemoryInMb); quotaLimitModel/*from w w w . j a va 2 s . c om*/ .setMaxPods(Double.valueOf(Math.floor((instanceMemoryInMb / 500) * nodeWorkerCount)).intValue()); quotaLimitModel.setTerminatingPodCPU(Double.valueOf(Math.floor(instanceCoreInMillis * 0.5)).intValue()); quotaLimitModel.setTerminatingPodMemory(Double.valueOf(Math.floor(instanceMemoryInMb * 0.5)).intValue()); quotaLimitModel.setMaxOrNotTerminatingPodLimitCPU(instanceCoreInMillis * requestRatio); quotaLimitModel.setMaxOrNotTerminatingPodLimitMemory(instanceMemoryInMb * requestRatio); quotaLimitModel.setMaxOrNotTerminatingPodRequestCPU(instanceCoreInMillis); quotaLimitModel.setMaxOrNotTerminatingPodRequestMemory(instanceMemoryInMb); quotaLimitModel.setIsTeamNamespace(isTeamNamespace); quotaLimitModel.setCpuRequestRatio(requestRatio); quotaLimitModel.setMemoryRequestRatio(requestRatio); quotaLimitModel.setOutputPath(outputPath); return quotaLimitModel; }
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;/*ww w .j av a 2 s .com*/ 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:com.pinterest.terrapin.client.ReplicatedTerrapinClient.java
public Future<TerrapinSingleResponse> getOne(final String fileSet, final ByteBuffer key, RequestOptions options) {//from www.j a v a2 s .co m Pair<TerrapinClient, TerrapinClient> clientPair = getClientTuple(options); final TerrapinClient firstClient = clientPair.getLeft(); final TerrapinClient secondClient = clientPair.getRight(); // We perform the request on the primary cluster with retries to second replica. if (secondClient == null) { return firstClient.getOne(fileSet, key); } return FutureUtil.getSpeculativeFuture(firstClient.getOne(fileSet, key), new Function0<Future<TerrapinSingleResponse>>() { @Override public Future<TerrapinSingleResponse> apply() { return secondClient.getOneNoRetries(fileSet, key); } }, options.speculativeTimeoutMillis, "terrapin-get-one"); }
From source file:com.pinterest.terrapin.client.ReplicatedTerrapinClient.java
public Future<TerrapinResponse> getMany(final String fileSet, final Set<ByteBuffer> keys, RequestOptions options) {/* w w w . j av a2 s .c om*/ Pair<TerrapinClient, TerrapinClient> clientPair = getClientTuple(options); final TerrapinClient firstClient = clientPair.getLeft(); final TerrapinClient secondClient = clientPair.getRight(); // We perform the request on the primary cluster with retries to second replica. if (secondClient == null) { return firstClient.getMany(fileSet, keys); } return FutureUtil.getSpeculativeFuture(firstClient.getMany(fileSet, keys), new Function0<Future<TerrapinResponse>>() { @Override public Future<TerrapinResponse> apply() { return secondClient.getManyNoRetries(fileSet, keys); } }, options.speculativeTimeoutMillis, "terrapin-get-many"); }
From source file:eionet.gdem.web.listeners.JobScheduler.java
/** * @see javax.servlet.ServletContextListener#contextInitialized(javax.servlet.ServletContextEvent) {@inheritDoc} *//* w w w . ja va 2s. c om*/ @Override public void contextInitialized(ServletContextEvent sce) { intervalJobs = new Pair[] { Pair.of(new Integer(Properties.wqCheckInterval), newJob(WQCheckerJob.class) .withIdentity(WQCheckerJob.class.getSimpleName(), WQCheckerJob.class.getName()).build()), Pair.of(new Integer(Properties.wqCleanInterval), newJob(WQCleanerJob.class) .withIdentity(WQCleanerJob.class.getSimpleName(), WQCleanerJob.class.getName()).build()), Pair.of(new Integer(Properties.ddTablesUpdateInterval), newJob(DDTablesCacheUpdater.class).withIdentity(DDTablesCacheUpdater.class.getSimpleName(), DDTablesCacheUpdater.class.getName()).build()) }; // schedule interval jobs for (Pair<Integer, JobDetail> job : intervalJobs) { try { scheduleIntervalJob(job.getLeft(), job.getRight()); LOGGER.debug(job.getRight().getKey().getName() + " scheduled, interval=" + job.getLeft()); } catch (Exception e) { LOGGER.error(Markers.fatal, "Error when scheduling " + job.getRight().getKey().getName(), e); } } WorkqueueManager.resetActiveJobs(); }
From source file:edu.wpi.checksims.algorithm.smithwaterman.SmithWaterman.java
/** * Apply the Smith-Waterman algorithm to determine the similarity between two submissions. * * Token list types of A and B must match * * @param a First submission to apply to * @param b Second submission to apply to * @return Similarity results of comparing submissions A and B * @throws TokenTypeMismatchException Thrown on comparing submissions with mismatched token types * @throws InternalAlgorithmError Thrown on internal error *///from w ww. ja v a 2 s . com @Override public AlgorithmResults detectSimilarity(Submission a, Submission b) throws TokenTypeMismatchException, InternalAlgorithmError { checkNotNull(a); checkNotNull(b); // Test for token type mismatch if (!a.getTokenType().equals(b.getTokenType())) { throw new TokenTypeMismatchException("Token list type mismatch: submission " + a.getName() + " has type " + a.getTokenType().toString() + ", while submission " + b.getName() + " has type " + b.getTokenType().toString()); } // Handle a 0-token submission (no similarity) if (a.getNumTokens() == 0 || b.getNumTokens() == 0) { return new AlgorithmResults(a, b, a.getContentAsTokens(), b.getContentAsTokens()); } else if (a.equals(b)) { // Handle identical submissions TokenList aInval = TokenList.cloneTokenList(a.getContentAsTokens()); aInval.stream().forEach((token) -> token.setValid(false)); return new AlgorithmResults(a, b, aInval, aInval); } // Alright, easy cases taken care of. Generate an instance to perform the actual algorithm SmithWatermanAlgorithm algorithm = new SmithWatermanAlgorithm(a.getContentAsTokens(), b.getContentAsTokens()); Pair<TokenList, TokenList> endLists = algorithm.computeSmithWatermanAlignmentExhaustive(); return new AlgorithmResults(a, b, endLists.getLeft(), endLists.getRight()); }
From source file:mase.app.playground.Playground.java
protected void placeObstacles() { // Add closed polygons of random size. The addition of objects next must ensure no overlaps int nObstacles = par.minObstacles + (par.maxObstacles > par.minObstacles ? random.nextInt(par.maxObstacles - par.minObstacles) : 0); obstacles = new ArrayList<>(nObstacles); while (obstacles.size() < nObstacles) { MultilineObject obs = createObstacle(); Pair<Double2D, Double2D> bb = obs.getPolygon().boundingBox; double w = bb.getRight().x - bb.getLeft().x; double h = bb.getRight().y - bb.getLeft().y; Double2D candidate = new Double2D(random.nextDouble() * (par.arenaSize - w), random.nextDouble() * (par.arenaSize - h)); obs.setLocation(candidate);/*from w w w. j av a 2 s . c o m*/ // overlap with the agent boolean valid = !obs.isInside(agent.getLocation()) && obs.distanceTo(agent.getLocation()) > agent.getRadius(); if (valid) { // overlap with other obstacles for (MultilineObject other : obstacles) { if (obs.getPolygon().boundingBoxOverlap(other.getPolygon())) { valid = false; break; } } } if (valid) { obstacles.add(obs); } else { field.remove(obs); } } }
From source file:com.formkiq.core.controller.user.DesignerController.java
/** * User Workflow Edit page./*from w w w . j ava 2 s .c om*/ * @param request {@link HttpServletRequest} * @param response {@link HttpServletResponse} * @param execution {@link String} * @return {@link ModelAndView} * @throws Exception Exception */ @RequestMapping(value = { "/edit" }, method = RequestMethod.GET) public ModelAndView edit(final HttpServletRequest request, final HttpServletResponse response, final @RequestParam(name = "execution", required = false) String execution) throws Exception { WebFlow flow = FlowManager.get(request); this.flowEventService.processGetRequest(flow, request); try { Object result = this.flowEventService.processRequest(request); if (result != null && result instanceof ModelAndView) { ModelAndView mav = (ModelAndView) result; if (!mav.getModel().containsKey("flow")) { return mav; } } } catch (FlowEventMethodNotFound e) { // ignore } if (!flow.getSessionKey().equals(execution)) { Pair<String, Integer> split = FlowManager.getExecutionSessionKey(execution); Integer eventId = split.getRight(); if (eventId != null) { flow.setEventId(eventId.intValue()); } } return new ModelAndView("user/designer/edit", "flow", flow); }