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.github.helenusdriver.driver.tools.Tool.java
/** * Finds object creators with their dependencies based on the provided set of * package names./*ww w. java 2s . c om*/ * * @author paouelle * * @param classes the graph where to record creator classes * @param pkgs the set of packages to for creator objects * @param no_dependents if dependents creators should not be considered * @throws LinkageError if the linkage fails for one entity class * @throws ExceptionInInitializerError if the initialization provoked by one * of one the entity class fails */ private static void findCreatorsFromPackages(DirectedGraph<Class<?>> classes, String[] pkgs, boolean no_dependents) { for (final String pkg : pkgs) { if (pkg == null) { continue; } // search for all object creator classes for (final Class<?> clazz : new Reflections(pkg) .getTypesAnnotatedWith(com.github.helenusdriver.persistence.InitialObjects.class, true)) { final Pair<Method, Class<?>[]> initial = Tool.findInitial(clazz); if (initial == null) { System.out.println(Tool.class.getSimpleName() + ": no objects found using " + clazz.getName()); continue; } classes.add(clazz); final DirectedGraph.Node<Class<?>> node = classes.get(clazz); if (!no_dependents) { for (final Class<?> c : initial.getRight()) { node.add(c); } } } } }
From source file:com.spotify.heroic.shell.task.DeleteKeys.java
private AsyncFuture<Void> doDelete(final ShellIO io, final Parameters params, final MetricBackendGroup group, final QueryOptions options, final Stream<BackendKey> keys) { final StreamCollector<Pair<BackendKey, Long>, Void> collector = new StreamCollector<Pair<BackendKey, Long>, Void>() { @Override//from w w w .j a v a 2 s. c o m public void resolved(Pair<BackendKey, Long> result) throws Exception { if (params.verbose) { synchronized (io) { io.out().println("Deleted: " + result.getLeft() + " (" + result.getRight() + ")"); io.out().flush(); } } } @Override public void failed(Throwable cause) throws Exception { synchronized (io) { io.out().println("Delete Failed: " + cause); cause.printStackTrace(io.out()); io.out().flush(); } } @Override public void cancelled() throws Exception { } @Override public Void end(int resolved, int failed, int cancelled) throws Exception { io.out().println("Finished (resolved: " + resolved + ", failed: " + failed + ", " + "cancelled: " + cancelled + ")"); io.out().flush(); return null; } }; final AtomicInteger outstanding = new AtomicInteger(params.parallelism); final Object lock = new Object(); final ResolvableFuture<Void> future = async.future(); final Iterator<BackendKey> it = keys.iterator(); for (int i = 0; i < params.parallelism; i++) { async.call(new Callable<Void>() { @Override public Void call() throws Exception { final BackendKey k; synchronized (lock) { k = it.hasNext() ? it.next() : null; } if (k == null) { if (outstanding.decrementAndGet() == 0) { future.resolve(null); } return null; } deleteKey(group, k, options).onDone(new FutureDone<Pair<BackendKey, Long>>() { @Override public void failed(Throwable cause) throws Exception { collector.failed(cause); } @Override public void resolved(Pair<BackendKey, Long> result) throws Exception { collector.resolved(result); } @Override public void cancelled() throws Exception { collector.cancelled(); } }).onFinished(this::call); return null; } }); } return future.onFinished(keys::close); }
From source file:com.epam.catgenome.manager.externaldb.ncbi.NCBIGeneManager.java
/** * Retrieves XML gene info from NCBI's gene database * * @param id gene id// w w w. j a v a2 s. co m * @return NCBIGeneVO * @throws ExternalDbUnavailableException */ public NCBIGeneVO fetchGeneById(final String id) throws ExternalDbUnavailableException { String realID = id; NCBIGeneVO ncbiGeneVO = null; if (StringUtils.isNotBlank(id)) { // if ID contains literals then we consider this external ID and perform search if (!id.matches("\\d+")) { String ncbiId = ncbiAuxiliaryManager.searchDbForId(NCBIDatabase.GENE.name(), realID); realID = StringUtils.isNotBlank(ncbiId) ? ncbiId : id; } String geneInfoXml = ncbiAuxiliaryManager.fetchXmlById(NCBIDatabase.GENE.name(), realID, null); ncbiGeneVO = geneInfoParser.parseGeneInfo(geneInfoXml); ncbiGeneVO.setLinkToCitations(String.format(NCBI_PUBMED_FULL_URL, ncbiGeneVO.getGeneId())); ncbiGeneVO.setGeneLink(String.format(NCBI_GENE_LINK, ncbiGeneVO.getGeneId())); String pubmedQueryXml = ncbiAuxiliaryManager.link(realID, NCBIDatabase.GENE.name(), NCBIDatabase.PUBMED.name(), "gene_pubmed"); Pair<String, String> stringStringPair = geneInfoParser.parseHistoryResponse(pubmedQueryXml, NCBIUtility.NCBI_LINK); String pubmedHistoryQuery = stringStringPair.getLeft(); String pubmedHistoryWebenv = stringStringPair.getRight(); JsonNode pubmedEntries = ncbiAuxiliaryManager.summaryWithHistory(pubmedHistoryQuery, pubmedHistoryWebenv); JsonNode pubmedResultRoot = pubmedEntries.path(RESULT_PATH).path(UIDS); try { parseJsonFromPubmed(pubmedResultRoot, pubmedEntries, ncbiGeneVO); } catch (JsonProcessingException e) { throw new ExternalDbUnavailableException( MessageHelper.getMessage(MessagesConstants.ERROR_NO_RESULT_BY_EXTERNAL_DB), e); } String biosystemsQueryXml = ncbiAuxiliaryManager.link(realID, NCBIDatabase.GENE.name(), NCBIDatabase.BIOSYSTEMS.name(), "gene_biosystems"); Pair<String, String> biosystemsParams = geneInfoParser.parseHistoryResponse(biosystemsQueryXml, NCBIUtility.NCBI_LINK); String biosystemsHistoryQuery = biosystemsParams.getLeft(); String biosystemsHistoryWebenv = biosystemsParams.getRight(); JsonNode biosystemsEntries = ncbiAuxiliaryManager.summaryWithHistory(biosystemsHistoryQuery, biosystemsHistoryWebenv); JsonNode biosystemsResultRoot = biosystemsEntries.path(RESULT_PATH).path(UIDS); try { parseJsonFromBio(biosystemsResultRoot, biosystemsEntries, ncbiGeneVO); } catch (JsonProcessingException e) { throw new ExternalDbUnavailableException( MessageHelper.getMessage(MessagesConstants.ERROR_NO_RESULT_BY_EXTERNAL_DB), e); } String homologsQueryXml = ncbiAuxiliaryManager.link(realID, NCBIDatabase.GENE.name(), NCBIDatabase.HOMOLOGENE.name(), "gene_homologene"); Pair<String, String> homologsParams = geneInfoParser.parseHistoryResponse(homologsQueryXml, NCBIUtility.NCBI_LINK); String homologsQuery = homologsParams.getLeft(); String homologsWebenv = homologsParams.getRight(); JsonNode homologEntries = ncbiAuxiliaryManager.summaryWithHistory(homologsQuery, homologsWebenv); JsonNode homologsResultRoot = homologEntries.path(RESULT_PATH).path(UIDS); try { parseJsonFromHomolog(homologsResultRoot, homologEntries, ncbiGeneVO); } catch (JsonProcessingException e) { throw new ExternalDbUnavailableException( MessageHelper.getMessage(MessagesConstants.ERROR_NO_RESULT_BY_EXTERNAL_DB), e); } } return ncbiGeneVO; }
From source file:com.twitter.distributedlog.service.balancer.ClusterBalancer.java
ClusterBalancer(DistributedLogClientBuilder clientBuilder, Pair<DistributedLogClient, MonitorServiceClient> clientPair) { this.clientBuilder = clientBuilder; this.client = clientPair.getLeft(); this.monitor = clientPair.getRight(); }
From source file:com.quancheng.saluki.boot.runner.GrpcReferenceRunner.java
private String getVersion(SalukiReference reference, String serviceName, Class<?> referenceClass) { Pair<String, String> groupVersion = findGroupAndVersionByServiceName(serviceName); if (StringUtils.isNoneBlank(reference.version())) { return reference.version(); } else if (StringUtils.isNoneBlank(groupVersion.getRight())) { String replaceVersion = groupVersion.getRight(); Matcher matcher = REPLACE_PATTERN.matcher(replaceVersion); if (matcher.find()) { String replace = matcher.group().substring(2, matcher.group().length() - 1).trim(); String[] replaces = StringUtils.split(replace, ":"); if (replaces.length == 2) { String realVersion = env.getProperty(replaces[0], replaces[1]); return realVersion; } else { throw new IllegalArgumentException("replaces formater is #{XXXservice:1.0.0}"); }//from www .j a va 2s . co m } else { return replaceVersion; } } else if (this.isGenericClient(referenceClass)) { return StringUtils.EMPTY; } else { throw new java.lang.IllegalArgumentException("reference version can not be null or empty"); } }
From source file:eu.crydee.alignment.aligner.ae.MetricsOneVsOneC.java
@Override public void collectionProcessComplete() throws AnalysisEngineProcessException { try {// w w w . java 2 s . c o m String template = IOUtils.toString(getClass() .getResourceAsStream("/eu/crydee/alignment/aligner/ae/" + "metrics-one-vs-one-template.html")); template = template.replace("@@TITLE@@", "Metrics comparator" + LocalDateTime.now().format(DateTimeFormatter.ISO_DATE_TIME)); template = template.replace("@@LEFTALGO@@", leftAlgoName); template = template.replace("@@RIGHTALGO@@", rightAlgoName); StringBuilder sb = new StringBuilder(); sb.append("<table class=\"table table-condensed\">\n").append(" <thead>\n") .append(" <tr>\n").append(" <th>Document\\Metric</th>\n"); for (String key : keys) { sb.append(" <th colspan=\"2\">").append(methodsMetadata.get(key).getRight()) .append("</th>\n"); } sb.append(" <tr>\n").append(" </thead>\n").append(" <tbody>\n") .append(" <tr>\n").append(" <td>\n") .append(" <strong>Total</strong>\n") .append(" </td>\n"); for (String key : keys) { SummaryStatistics ss1 = new SummaryStatistics(), ss2 = new SummaryStatistics(); List<Pair<Double, Double>> column = results.column(key).values().stream().peek(p -> { ss1.addValue(p.getLeft()); ss2.addValue(p.getRight()); }).collect(Collectors.toList()); boolean significant = TestUtils.pairedTTest(column.stream().mapToDouble(p -> p.getLeft()).toArray(), column.stream().mapToDouble(p -> p.getRight()).toArray(), 0.05); double mean1 = ss1.getMean(), mean2 = ss2.getMean(); boolean above = mean1 > mean2; String summary1 = String.format("%.3f", mean1) + "<small class=\"text-muted\">" + "" + String.format("%.3f", ss1.getStandardDeviation()) + "</small>", summary2 = String.format("%.3f", mean2) + "<small class=\"text-muted\">" + "" + String.format("%.3f", ss2.getStandardDeviation()) + "</small>"; sb.append(" <td class=\"") .append(significant ? (above ? "success" : "danger") : "warning").append("\">") .append(summary1).append("</td>\n"); sb.append(" <td class=\"") .append(significant ? (!above ? "success" : "danger") : "warning").append("\">") .append(summary2).append("</td>\n"); } sb.append(" </tr>\n"); SortedSet<String> rows = new TreeSet<>(results.rowKeySet()); for (String row : rows) { sb.append(" <tr>\n").append(" <td>").append(row) .append("</td>\n"); for (String key : keys) { Pair<Double, Double> r = results.get(row, key); sb.append(" <td>").append(String.format("%.3f", r.getLeft())) .append("</td>\n").append(" <td>") .append(String.format("%.3f", r.getRight())).append("</td>\n"); } sb.append(" </tr>\n"); } sb.append(" </tbody>\n").append(" </table>"); FileUtils.write(new File(htmlFilepath), template.replace("@@TABLE@@", sb.toString()), StandardCharsets.UTF_8); } catch (IOException ex) { logger.error("IO problem with the HTML output."); throw new AnalysisEngineProcessException(ex); } }
From source file:at.beris.virtualfile.shell.Shell.java
private void processCommand(Pair<Command, List<String>> cmd) throws IOException { switch (cmd.getLeft()) { case CD:/*from ww w. j a va 2 s. c o m*/ change(cmd.getRight().get(0), false); break; case CON: connect(new URL(cmd.getRight().get(0))); break; case DIS: disconnect(); break; case GET: get(cmd.getRight().get(0)); break; case HELP: displayHelp(); break; case LCD: change(cmd.getRight().get(0), true); break; case LPWD: System.out.println(localFile.getPath()); break; case LLS: list(true); break; case LRM: remove(true, cmd.getRight().get(0)); break; case LS: list(false); break; case PUT: put(cmd.getRight().get(0)); break; case PWD: System.out.println(workingFile != null ? maskedUrlString(workingFile.getUrl()) : NOT_CONNECTED_MSG); break; case RM: remove(false, cmd.getRight().get(0)); break; case STAT: displayStatistics(); break; case QUIT: quit(); break; default: System.out.println("Unknown command."); } }
From source file:com.norconex.importer.handler.transformer.impl.StripBetweenTransformer.java
@Override protected void saveHandlerToXML(EnhancedXMLStreamWriter writer) throws XMLStreamException { writer.writeAttribute("caseSensitive", Boolean.toString(isCaseSensitive())); writer.writeAttribute("inclusive", Boolean.toString(isInclusive())); for (Pair<String, String> pair : stripPairs) { writer.writeStartElement("stripBetween"); writer.writeStartElement("start"); writer.writeCharacters(pair.getLeft()); writer.writeEndElement();//from w ww . ja va 2 s .com writer.writeStartElement("end"); writer.writeCharacters(pair.getRight()); writer.writeEndElement(); writer.writeEndElement(); } }
From source file:fredboat.audio.GuildPlayer.java
public Pair<Boolean, String> skipTracksForMemberPerms(TextChannel channel, Member member, List<AudioTrackContext> list) { Pair<Boolean, String> pair = canMemberSkipTracks(member, list); if (pair.getLeft()) { skipTracks(list);// w w w .j a va2 s . c om } else { TextUtils.replyWithName(channel, member, pair.getRight()); } return pair; }
From source file:com.epam.catgenome.manager.externaldb.ncbi.NCBIShortVarManager.java
/** * Retrieves variations from snp database in given region * * @param organism -- organism name/*from w w w .j a va2s .c o m*/ * @param start -- start position * @param finish -- end position * @param chromosome -- chromosome number * @return list of found variations * @throws ExternalDbUnavailableException */ public List<Variation> fetchVariationsOnRegion(String organism, String start, String finish, String chromosome) throws ExternalDbUnavailableException { String term = String.format("%s:%s[Base Position] AND \"%s\"[CHR] AND \"%s\"[ORGN]", start, finish, chromosome, organism); String searchResultXml = ncbiAuxiliaryManager.searchWithHistory(NCBIDatabase.SNP.name(), term, MAX_RESULT); Pair<String, String> stringStringPair = ncbiGeneInfoParser.parseHistoryResponse(searchResultXml, NCBIUtility.NCBI_SEARCH); String queryKey = stringStringPair.getLeft(); String webEnv = stringStringPair.getRight(); String dataXml = ncbiAuxiliaryManager.fetchWithHistory(queryKey, webEnv, NCBIDatabase.SNP); ExchangeSet snpResultJaxb = null; try { JAXBContext jaxbContext = JAXBContext .newInstance("com.epam.catgenome.manager.externaldb.bindings.dbsnp"); Unmarshaller unmarshaller = jaxbContext.createUnmarshaller(); StringReader reader = new StringReader(dataXml); Object uniprotObject = unmarshaller.unmarshal(reader); if (uniprotObject instanceof ExchangeSet) { snpResultJaxb = (ExchangeSet) uniprotObject; } } catch (JAXBException e) { throw new ExternalDbUnavailableException("Error parsing ncbi snp response", e); } return getResultList(snpResultJaxb); }