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: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)); }//from w ww. j a v a2s . c o m } return result; }
From source file:io.codis.nedis.util.AbstractNedisBuilder.java
public final void validateGroupConfig() { if (group == null && channelClass != null) { throw new IllegalArgumentException("group is null but channel is not"); }/*from ww w. j ava 2s. co m*/ if (channelClass == null && group != null) { throw new IllegalArgumentException("channel is null but group is not"); } if (group == null) { Pair<EventLoopGroup, Class<? extends Channel>> defaultEventLoopConfig = defaultEventLoopConfig(); group = defaultEventLoopConfig.getLeft(); channelClass = defaultEventLoopConfig.getRight(); } }
From source file:io.github.karols.hocr4j.Bounds.java
/** * The smallest rectangle containing the first elements of all pairs of the collection. * The collection, all the pairs and all the first elements have to be non-null. * If the collections is empty, returns <code>null</code>. * * @param thingies collection of pairs/*from www.jav a 2 s .c o m*/ * @param <T> type of the second element of the pair * @param <B> type of the first element of the pair * @return union of bounds of all first elements, * or <code>null</code> if the collection was empty * @see Bounds#ofAll(Collection) * @see Bounds#ofAllRight(Collection) */ @Nullable public static <T, B extends Bounded> Bounds ofAllLeft(@Nonnull Collection<Pair<B, T>> thingies) { Bounds acc = null; for (Pair<B, T> thingy : thingies) { acc = nullSafeUnion(acc, thingy.getLeft().getBounds()); } return acc; }
From source file:com.intuit.karate.Script.java
public static AssertionResult matchNamed(MatchType matchType, String name, String path, String expected, ScriptContext context) {//w w w .j a v a 2 s .co m name = StringUtils.trim(name); if (isJsonPath(name) || isXmlPath(name)) { // short-cut for operating on response path = name; name = ScriptValueMap.VAR_RESPONSE; } path = StringUtils.trimToNull(path); if (path == null) { Pair<String, String> pair = parseVariableAndPath(name); name = pair.getLeft(); path = pair.getRight(); } expected = StringUtils.trim(expected); if ("header".equals(name)) { // convenience shortcut for asserting against response header return matchNamed(matchType, ScriptValueMap.VAR_RESPONSE_HEADERS, "$['" + path + "'][0]", expected, context); } else { ScriptValue actual = context.vars.get(name); switch (actual.getType()) { case STRING: case INPUT_STREAM: return matchString(matchType, actual, expected, path, context); case XML: if ("$".equals(path)) { path = "/"; // whole document, also edge case where variable name was 'response' } if (!isJsonPath(path)) { return matchXmlPath(matchType, actual, path, expected, context); } // break; // fall through to JSON. yes, dot notation can be used on XML !! default: return matchJsonPath(matchType, actual, path, expected, context); } } }
From source file:name.martingeisse.phunky.runtime.code.expression.array.ArrayConstructionExpression.java
@Override public Object evaluate(Environment environment) { PhpVariableArray builder = new PhpVariableArray(); for (Pair<Expression, Expression> element : elements) { boolean hasKey = (element.getLeft() != null); Object originalKey = (hasKey ? element.getLeft().evaluate(environment) : null); Object value = element.getRight().evaluate(environment); if (!hasKey) { builder.append().setValue(value); } else {// w w w. j a v a 2s. c o m String key = TypeConversionUtil.convertToArrayKey(originalKey); builder.getOrCreateVariable(key).setValue(value); } } return builder.toValueArray(); }
From source file:io.github.autsia.crowly.tests.SentimentTests.java
@Test public void analyzePositive() throws Exception { Pair<Sentiment, Float> opinion = crowlySentimentAnalyzer.analyze("This movie is great."); Assert.assertEquals(Sentiment.POSITIVE, opinion.getLeft()); }
From source file:com.spotify.heroic.metric.datastax.schema.legacy.MapSerializer.java
@Override public ByteBuffer serialize(final Map<A, B> value) throws IOException { final List<Pair<ByteBuffer, ByteBuffer>> buffers = new ArrayList<>(); short size = 0; for (final Map.Entry<A, B> e : value.entrySet()) { final ByteBuffer key = a.serialize(e.getKey()); final ByteBuffer val = b.serialize(e.getValue()); size += key.limit() + val.limit(); buffers.add(Pair.of(key, val)); }/* ww w . ja va2 s .c o m*/ final ByteBuffer buffer = ByteBuffer.allocate(4 + 8 * value.size() + size); buffer.putShort((short) buffers.size()); for (final Pair<ByteBuffer, ByteBuffer> p : buffers) { buffer.putShort((short) p.getLeft().remaining()); buffer.put(p.getLeft()); buffer.putShort((short) p.getRight().remaining()); buffer.put(p.getRight()); } buffer.flip(); return buffer; }
From source file:io.github.autsia.crowly.tests.SentimentTests.java
@Test public void analyzeNegative() throws Exception { Pair<Sentiment, Float> opinion = crowlySentimentAnalyzer.analyze("This movie is horrible."); Assert.assertEquals(Sentiment.NEGATIVE, opinion.getLeft()); }
From source file:com.act.lcms.ExtractFromNetCDFAroundMass.java
/** * Extracts a window around a particular m/z value within the spectra * @param file The netCDF file with the full LCMS (lockmass corrected) spectra * @param mz The m/z value +- 1 around which to extract data for * @param numTimepointsToExamine Since we stream the netCDF in, we can choose * to look at the first few timepoints or -1 for all *//* w w w . j a v a 2 s. c o m*/ public List<Triple<Double, Double, Double>> get2DWindow(String file, double mz, int numTimepointsToExamine) throws Exception { LCMSParser parser = new LCMSNetCDFParser(); Iterator<LCMSSpectrum> iter = parser.getIterator(file); List<Triple<Double, Double, Double>> window = new ArrayList<>(); int pulled = 0; Double mzTightL = mz - 0.1; Double mzTightR = mz + 0.1; Double mzMinus1Da = mz - 1; Double mzPlus1Da = mz + 1; // iterate through first few, or all if -1 given while (iter.hasNext() && (numTimepointsToExamine == -1 || pulled < numTimepointsToExamine)) { LCMSSpectrum timepoint = iter.next(); List<Pair<Double, Double>> intensities = timepoint.getIntensities(); // this time point is valid to look at if its max intensity is around // the mass we care about. So lets first get the max peak location Pair<Double, Double> max_peak = findMaxPeak(intensities); Double max_mz = max_peak.getLeft(); // If the max_mz value is pretty close to our target mass, ie in [mzTightL, mzTightR] // Then this timepoint is a good timepoint to output... proceed, shall we. if (max_mz >= mzTightL && max_mz <= mzTightR) { // For this timepoint, output a window for (int k = 0; k < intensities.size(); k++) { Double mz_here = intensities.get(k).getLeft(); Double intensity = intensities.get(k).getRight(); // The window not as tight, but +-1 Da around the target mass if (mz_here > mzMinus1Da && mz_here < mzPlus1Da) { window.add(Triple.of(timepoint.getTimeVal(), mz_here, intensity)); } } } pulled++; } return window; }
From source file:com.intuit.karate.Script.java
public static void setValueByPath(String name, String path, String exp, ScriptContext context) { name = StringUtils.trim(name);/* ww w . j av a 2s.co m*/ if ("request".equals(name) || "url".equals(name)) { throw new RuntimeException("'" + name + "' is not a variable," + " use the form '* " + name + " <expression>' to initialize the " + name + ", and <expression> can be a variable"); } path = StringUtils.trimToNull(path); if (path == null) { Pair<String, String> pair = parseVariableAndPath(name); name = pair.getLeft(); path = pair.getRight(); } if (isJsonPath(path)) { ScriptValue target = context.vars.get(name); ScriptValue value = eval(exp, context); switch (target.getType()) { case JSON: DocumentContext dc = target.getValue(DocumentContext.class); JsonUtils.setValueByPath(dc, path, value.getAfterConvertingFromJsonOrXmlIfNeeded()); break; case MAP: Map<String, Object> map = target.getValue(Map.class); DocumentContext fromMap = JsonPath.parse(map); JsonUtils.setValueByPath(fromMap, path, value.getAfterConvertingFromJsonOrXmlIfNeeded()); context.vars.put(name, fromMap); break; default: throw new RuntimeException("cannot set json path on unexpected type: " + target); } } else if (isXmlPath(path)) { Document doc = context.vars.get(name, Document.class); ScriptValue sv = eval(exp, context); switch (sv.getType()) { case XML: Node node = sv.getValue(Node.class); XmlUtils.setByPath(doc, path, node); break; default: XmlUtils.setByPath(doc, path, sv.getAsString()); } } else { throw new RuntimeException("unexpected path: " + path); } }