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.streamsets.pipeline.lib.salesforce.PushTopicRecordCreator.java
@Override @SuppressWarnings("unchecked") public Record createRecord(String sourceId, Object source) throws StageException { Pair<PartnerConnection, Map<String, Object>> pair = (Pair<PartnerConnection, Map<String, Object>>) source; Map<String, Object> data = pair.getRight(); Map<String, Object> event = (Map<String, Object>) data.get("event"); Map<String, Object> sobject = (Map<String, Object>) data.get("sobject"); Record rec = context.createRecord(sourceId); // sobject data becomes fields LinkedHashMap<String, Field> map = new LinkedHashMap<>(); for (Map.Entry<String, Object> entry : sobject.entrySet()) { String key = entry.getKey(); Object val = entry.getValue(); com.sforce.soap.partner.Field sfdcField = getFieldMetadata(sobjectType, key); Field field = createField(val, sfdcField); if (conf.createSalesforceNsHeaders) { setHeadersOnField(field, getFieldMetadata(sobjectType, key)); }/*from ww w .ja va2 s . c o m*/ map.put(key, field); } rec.set(Field.createListMap(map)); // event data becomes header attributes // of the form salesforce.cdc.createdDate, // salesforce.cdc.type Record.Header recordHeader = rec.getHeader(); for (Map.Entry<String, Object> entry : event.entrySet()) { recordHeader.setAttribute(HEADER_ATTRIBUTE_PREFIX + entry.getKey(), entry.getValue().toString()); if ("type".equals(entry.getKey())) { int operationCode = SFDC_TO_SDC_OPERATION.get(entry.getValue().toString()); recordHeader.setAttribute(OperationType.SDC_OPERATION_TYPE, String.valueOf(operationCode)); } } recordHeader.setAttribute(SOBJECT_TYPE_ATTRIBUTE, sobjectType); return rec; }
From source file:com.muk.ext.core.jackson.PairSerializer.java
@Override public void serialize(Pair value, JsonGenerator gen, SerializerProvider serializers) throws IOException, JsonProcessingException { gen.writeStartArray(2);/* w ww .j a va 2 s . com*/ gen.writeObject(value.getLeft()); gen.writeObject(value.getRight()); gen.writeEndArray(); }
From source file:com.romeikat.datamessie.core.statistics.cache.MergeNumberOfDocumentsFunction.java
@Override public DocumentsPerState apply(final Pair<DocumentsPerState, DocumentsPerState> documentsPerStatePair) { final DocumentsPerState documentsPerState1 = documentsPerStatePair.getLeft(); final DocumentsPerState documentsPerState2 = documentsPerStatePair.getRight(); final DocumentsPerState documentsPerStateMerged = new DocumentsPerState(); documentsPerStateMerged.addAll(documentsPerState1); documentsPerStateMerged.addAll(documentsPerState2); return documentsPerStateMerged; }
From source file:com.twitter.distributedlog.subscription.ZKSubscriptionsStore.java
private void getLastCommitPositions(final Promise<Map<String, DLSN>> result, List<String> subscribers) { List<Future<Pair<String, DLSN>>> futures = new ArrayList<Future<Pair<String, DLSN>>>(subscribers.size()); for (String s : subscribers) { final String subscriber = s; Future<Pair<String, DLSN>> future = // Get the last commit position from zookeeper getSubscriber(subscriber).getLastCommitPositionFromZK() .map(new AbstractFunction1<DLSN, Pair<String, DLSN>>() { @Override public Pair<String, DLSN> apply(DLSN dlsn) { return Pair.of(subscriber, dlsn); }/* w w w .j a v a 2 s.co m*/ }); futures.add(future); } Future.collect(futures).foreach(new AbstractFunction1<List<Pair<String, DLSN>>, BoxedUnit>() { @Override public BoxedUnit apply(List<Pair<String, DLSN>> subscriptions) { Map<String, DLSN> subscriptionMap = new HashMap<String, DLSN>(); for (Pair<String, DLSN> pair : subscriptions) { subscriptionMap.put(pair.getLeft(), pair.getRight()); } result.setValue(subscriptionMap); return BoxedUnit.UNIT; } }); }
From source file:com.act.lcms.CompareTwoNetCDFAroundMass.java
private double extractMZ(double mzWanted, List<Pair<Double, Double>> intensities, double time) { double intensityFound = 0; int numWithinPrecision = 0; double mzLowRange = mzWanted - mzTolerance; double mzHighRange = mzWanted + mzTolerance; // we expect there to be pretty much only one intensity value in the precision // range we are looking at. But if a lot of masses show up then complain for (Pair<Double, Double> mz_int : intensities) { double mz = mz_int.getLeft(); double intensity = mz_int.getRight(); if (mz > mzLowRange && mz < mzHighRange) { intensityFound += intensity; numWithinPrecision++;/*from w w w . ja v a2s .c o m*/ if (intensity > 100000) System.out.format("time: %f\tmz: %f\t intensity: %f\n", time, mz, intensity); } } if (numWithinPrecision > maxNumMzTolerated) { System.out.format("Only expected %d, but found %d in the mz range [%f, %f]\n", maxNumMzTolerated, numWithinPrecision, mzLowRange, mzHighRange); } return intensityFound; }
From source file:com.qwazr.utils.json.DirectoryJsonManager.java
protected T delete(String name) throws ServerException, IOException { if (StringUtils.isEmpty(name)) return null; name = name.intern();//from w w w . java 2 s . c o m rwl.writeLock().lock(); try { getFile(name).delete(); Pair<Long, T> instance = instancesMap.remove(name); buildCache(); return instance.getRight(); } finally { rwl.writeLock().unlock(); } }
From source file:com.lithium.flow.filer.CachedReadFiler.java
@Override @Nonnull// ww w. j av a2 s.co m public InputStream readFile(@Nonnull String path) throws IOException { checkNotNull(path); Pair<Long, byte[]> pair = cache.getIfPresent(path); if (pair != null && pair.getLeft().equals(super.getRecord(path).getTime())) { return new ByteArrayInputStream(pair.getRight()); } try { return new ByteArrayInputStream(cache.get(path).getRight()); } catch (ExecutionException e) { if (e.getCause() instanceof IOException) { throw (IOException) e.getCause(); } else { throw new IOException(e); } } }
From source file:edu.wpi.checksims.util.threading.SimilarityDetectionWorker.java
/** * Construct a Callable to perform pairwise similarity detection for one pair of assignments. * * @param algorithm Algorithm to use/*from w w w. j ava 2s . com*/ * @param submissions Assignments to compare */ public SimilarityDetectionWorker(SimilarityDetector algorithm, Pair<Submission, Submission> submissions) { checkNotNull(algorithm); checkNotNull(submissions); checkNotNull(submissions.getLeft()); checkNotNull(submissions.getRight()); this.algorithm = algorithm; this.submissions = submissions; }
From source file:io.github.autsia.crowly.services.social.impl.TwitterSocialEndpoint.java
@Override public List<Mention> gatherMentions(Campaign campaign) { List<Mention> result = new ArrayList<>(); String language = campaign.getLanguages().iterator().next(); GeoCode geoCode = geoLocationService .convertCoordinatesToGeoCode(campaign.getLocations().values().iterator().next()); SearchParameters searchParameters = new SearchParameters( StringUtils.join(campaign.getKeywords().toArray(), SEPARATOR)).lang(language).geoCode(geoCode); SearchResults searchResults = twitter.searchOperations().search(searchParameters); for (Tweet tweet : searchResults.getTweets()) { String text = tweet.getText(); Pair<Sentiment, Float> sentiment = sentimentAnalyzer.analyze(text); if (sentiment.getLeft().equals(campaign.getSentiment()) && sentiment.getRight() > campaign.getThreshold()) { result.add(buildMention(campaign, tweet, text)); }/* w ww . java 2 s .c o m*/ } return result; }
From source file:fr.lirmm.graphik.graal.forward_chaining.ChaseWithGRDAndUnfiers.java
@Override public void next() throws ChaseException { Rule rule, unifiedRule;/*from w w w .j a v a 2s. c o m*/ Substitution unificator; try { Pair<Rule, Substitution> pair = queue.poll(); if (pair != null) { unificator = pair.getRight(); rule = pair.getLeft(); unifiedRule = Unifier.computeInitialAtomSetTermsSubstitution(rule.getBody()).createImageOf(rule); unifiedRule = unificator.createImageOf(unifiedRule); if (LOGGER.isDebugEnabled()) { LOGGER.debug("Execute rule: " + rule + " with unificator " + unificator); } if (this.getRuleApplier().apply(unifiedRule, this.atomSet)) { for (Integer e : this.grd.getOutgoingEdgesOf(rule)) { Rule triggeredRule = this.grd.getEdgeTarget(e); for (Substitution u : this.grd.getUnifiers(e)) { if (LOGGER.isDebugEnabled()) { LOGGER.debug("-- -- Dependency: " + triggeredRule + " with " + u); LOGGER.debug("-- -- Unificator: " + u); } if (u != null) { this.queue.add(new ImmutablePair<Rule, Substitution>(triggeredRule, u)); } } } } } } catch (Exception e) { throw new ChaseException("An error occur pending saturation step.", e); } }