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.ijuru.kwibuka.WordListWordifier.java
/** * Recursively tries sequences of words// w w w . ja v a2 s. c o m * @param completed the completed sequences * @param current the current sequence * @param remainder the input remainder */ protected void trySequence(List<WordSequence> completed, WordSequence current, String remainder) { if (remainder.length() == 0) { completed.add(current); return; } List<Pair<Set<String>, String>> splits = splitInput(remainder); for (Pair<Set<String>, String> split : splits) { for (String token : split.getLeft()) { WordSequence tokensCopy = current.clone(); tokensCopy.add(token); trySequence(completed, tokensCopy, split.getRight()); } } }
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 . co 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:hu.ppke.itk.nlpg.purepos.common.AnalysisQueue.java
public void addWord(String input, Integer position) { Pair<String, List<String>> res = parse(input); String word = res.getLeft(); List<String> analsList = res.getRight(); words.set(position, word);//www . j av a 2s . co m anals.set(position, new HashMap<String, Double>()); for (String anal : analsList) { int indexOfValSep = anal.indexOf("$$"); String lemmaTag = anal; double prob = 1; if (indexOfValSep > -1) { useProb.set(position, true); prob = Double.parseDouble(anal.substring(indexOfValSep + 2)); lemmaTag = anal.substring(0, indexOfValSep); } anals.get(position).put(lemmaTag, prob); } }
From source file:net.malisis.blocks.item.MixedBlockBlockItem.java
@Override public void addInformation(ItemStack itemStack, EntityPlayer player, List list, boolean advancedTooltip) { if (itemStack.getTagCompound() == null) return;/*from w ww .j a va2 s . c om*/ Pair<IBlockState, IBlockState> pair = readNBT(itemStack.getTagCompound()); Item item = itemsAllowed.inverse().get(pair.getLeft()); ItemStack is1 = item != null ? new ItemStack(item) : ItemUtils.getItemStackFromState(pair.getLeft()); item = itemsAllowed.inverse().get(pair.getRight()); ItemStack is2 = item != null ? new ItemStack(item) : ItemUtils.getItemStackFromState(pair.getRight()); list.addAll(is1.getTooltip(player, advancedTooltip)); list.addAll(is2.getTooltip(player, advancedTooltip)); }
From source file:cn.liutils.vis.animation.CubicSplineCurve.java
@Override public double valueAt(double x) { // Find last point whose value <= x int index = 0; for (; index < pts.size() && pts.get(index).getLeft() < x; ++index) ;// w w w. j av a 2s. co m if (index > 0) --index; if (index >= pts.size() - 1) index = pts.size() - 2; // Generate 4 refpoints' vals Pair<Double, Double> pt1 = pts.get(index), pt2 = pts.get(index + 1), pt0 = index == 0 ? pt1 : pts.get(index - 1); double dist = pt2.getLeft() - pt1.getLeft(), ldist = pt0 == pt1 ? dist : pt1.getRight() - pt0.getLeft(); double p0 = pt1.getRight(), p1 = pt2.getRight(), m0 = kval(index) * ldist, m1 = kval(index + 1) * dist; double u = (x - pt1.getLeft()) / dist, u2 = u * u, u3 = u2 * u; // Apply calculation return (2 * u3 - 3 * u2 + 1) * p0 + (u3 - 2 * u2 + u) * m0 + (-2 * u3 + 3 * u2) * p1 + (u3 - u2) * m1; }
From source file:com.twosigma.beakerx.scala.serializers.ScalaTableDeSerializer.java
@SuppressWarnings("unchecked") @Override// w w w . ja v a 2 s . c om public Object deserialize(JsonNode n, ObjectMapper mapper) { org.apache.commons.lang3.tuple.Pair<String, Object> deserializeObject = TableDisplayDeSerializer .getDeserializeObject(parent, n, mapper); String subtype = deserializeObject.getLeft(); if (subtype != null && subtype.equals(TableDisplay.DICTIONARY_SUBTYPE)) { return JavaConverters.mapAsScalaMapConverter((Map<String, Object>) deserializeObject.getRight()) .asScala().toMap(Predef.<Tuple2<String, Object>>conforms()); } else if (subtype != null && subtype.equals(TableDisplay.LIST_OF_MAPS_SUBTYPE)) { List<Map<String, Object>> rows = (List<Map<String, Object>>) deserializeObject.getRight(); List<Object> oo = new ArrayList<Object>(); for (Map<String, Object> row : rows) { oo.add(JavaConverters.mapAsScalaMapConverter(row).asScala() .toMap(Predef.<Tuple2<String, Object>>conforms())); } return scala.collection.JavaConversions.collectionAsScalaIterable(oo); } else if (subtype != null && subtype.equals(TableDisplay.MATRIX_SUBTYPE)) { List<List<?>> matrix = (List<List<?>>) deserializeObject.getRight(); ArrayList<Object> ll = new ArrayList<Object>(); for (List<?> ob : matrix) { ll.add(scala.collection.JavaConversions.asScalaBuffer(ob).toList()); } return scala.collection.JavaConversions.asScalaBuffer(ll).toList(); } return deserializeObject.getRight(); }
From source file:de.johni0702.minecraft.gui.layout.CustomLayout.java
@Override @SuppressWarnings("unchecked") public Map<GuiElement, Pair<ReadablePoint, ReadableDimension>> layOut(GuiContainer container, ReadableDimension size) {/*from ww w.j av a2 s .c om*/ result.clear(); if (parent == null) { Collection<GuiElement> elements = container.getChildren(); for (GuiElement element : elements) { result.put(element, Pair.of(new Point(0, 0), new Dimension(element.getMinSize()))); } } else { Map<GuiElement, Pair<ReadablePoint, ReadableDimension>> elements = parent.layOut(container, size); for (Map.Entry<GuiElement, Pair<ReadablePoint, ReadableDimension>> entry : elements.entrySet()) { Pair<ReadablePoint, ReadableDimension> pair = entry.getValue(); result.put(entry.getKey(), Pair.of(new Point(pair.getLeft()), new Dimension(pair.getRight()))); } } layout((T) container, size.getWidth(), size.getHeight()); return (Map) result; }
From source file:net.malisis.doors.door.tileentity.FenceGateTileEntity.java
public void updateAll() { if (!worldObj.isRemote) return;//from w w w . jav a 2 s . co m Pair<BlockState, Integer> pair = updateCamo(); camoState = pair.getLeft(); camoColor = pair.getRight(); isWall = updateWall(); worldObj.markBlockForUpdate(xCoord, yCoord, zCoord); }
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 */// w w w. ja v a 2 s. co m @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:com.act.lcms.v2.MassChargeCalculatorTest.java
@Test public void testComputeMass() throws Exception { List<Pair<MassChargeCalculator.MZSource, Double>> testCases = Arrays.asList( Pair.of(new MassChargeCalculator.MZSource( "InChI=1S/C8H9NO2/c1-6(10)9-7-2-4-8(11)5-3-7/h2-5,11H,1H3,(H,9,10)"), 151.063329), Pair.of(new MassChargeCalculator.MZSource(151.063329), 151.063329), Pair.of(new MassChargeCalculator.MZSource(Pair.of("APAP", 151.063329)), 151.063329)); for (Pair<MassChargeCalculator.MZSource, Double> testCase : testCases) { Double actualMass = MassChargeCalculator.computeMass(testCase.getLeft()); assertEquals(// ww w. j av a2 s . c om String.format("(Case %d) Actual mass is within bounds: %.6f ~ %.6f", testCase.getLeft().getId(), testCase.getRight(), actualMass), testCase.getRight(), actualMass, MASS_ERROR_TOLERANCE); } }