List of usage examples for com.google.common.collect Lists reverse
@CheckReturnValue public static <T> List<T> reverse(List<T> list)
From source file:org.sosy_lab.cpachecker.util.predicates.matching.SmtFunctionApplicationPattern.java
public List<SmtAstPatternSelectionElement> getArgumentPatterns(boolean reversed) { if (reversed) { return Lists.reverse(argumentPatterns.getPatterns()); }//from w w w .ja v a2s. c o m return argumentPatterns.getPatterns(); }
From source file:com.netflix.exhibitor.core.activity.ActivityLog.java
/** * Return the current window lines/*from w ww . j av a 2 s. c om*/ * * * @param separator line separator * @param logDirection display direction * @return lines */ public List<String> toDisplayList(final String separator, ExhibitorArguments.LogDirection logDirection) { Iterable<String> transformed = Iterables.transform(queue, new Function<Message, String>() { public String apply(Message message) { return message.date + separator + message.type + separator + message.text; } }); ImmutableList<String> list = ImmutableList.copyOf(transformed); return (logDirection == ExhibitorArguments.LogDirection.NATURAL) ? list : Lists.reverse(list); }
From source file:epiinf.SimulatedTransmissionTree.java
@Override public void initAndValidate() throws Exception { EpidemicTrajectory traj = trajInput.get(); boolean truncateTrajectory = truncateTrajectoryInput.get(); int nSamples = 0; double youngestSamp = 0.0; for (EpidemicEvent event : traj.getEventList()) { if (event.type == EpidemicEvent.Type.SAMPLE) { nSamples += event.multiplicity; youngestSamp = Math.max(event.time, youngestSamp); }/*from w w w .ja v a 2 s . co m*/ } if (nSamples == 0) throw new NoSamplesException(); int nextLeafNr = 0; int nextInternalID = nSamples; List<Node> activeNodes = Lists.newArrayList(); List<EpidemicEvent> revEventList = Lists.reverse(traj.getEventList()); List<EpidemicState> revStateList = Lists.reverse(traj.getStateList()); int samplesSeen = 0; for (int eidx = 0; eidx < revEventList.size(); eidx++) { EpidemicEvent epidemicEvent = revEventList.get(eidx); EpidemicState epidemicState = revStateList.get(eidx); if (epidemicEvent.type == EpidemicEvent.Type.SAMPLE) { for (int i = 0; i < epidemicEvent.multiplicity; i++) { Node leaf = new Node(); leaf.setHeight(youngestSamp - epidemicEvent.time); leaf.setNr(nextLeafNr++); activeNodes.add(leaf); } samplesSeen += epidemicEvent.multiplicity; } else { if (epidemicEvent.type == EpidemicEvent.Type.INFECTION) { int k = activeNodes.size(); double N = epidemicState.I; double pCoalesce = k * (k - 1) / (N * (N - 1)); if (Randomizer.nextDouble() < pCoalesce) { int childIdx = Randomizer.nextInt(k); Node child1 = activeNodes.get(childIdx); activeNodes.remove(childIdx); childIdx = Randomizer.nextInt(k - 1); Node child2 = activeNodes.get(childIdx); activeNodes.remove(childIdx); Node parent = new Node(); parent.addChild(child1); parent.addChild(child2); parent.setHeight(youngestSamp - epidemicEvent.time); parent.setNr(nextInternalID++); activeNodes.add(parent); } } } // Stop when we reach the MRCA of all sampled events. if (samplesSeen == nSamples && activeNodes.size() < 2) break; } // Truncate trajectory at most recent sample if requested: if (truncateTrajectory) { while (revEventList.get(0).time > youngestSamp) { revEventList.remove(0); revStateList.remove(0); } } // Initialise state nodes assignFromWithoutID(new Tree(activeNodes.get(0))); // Write tree to disk if requested: if (fileNameInput.get() != null) { try (PrintStream ps = new PrintStream(fileNameInput.get())) { String newick = toString().concat(";"); ps.println(newick.replace(":0.0;", ":" + (youngestSamp - root.getHeight()) + ";")); } } }
From source file:org.eclipse.xtext.xbase.lib.ListExtensions.java
/** * Provides a reverse view on the given list which is especially useful to traverse a list backwards in a for-each * loop. The list itself is not modified by calling this method. * //from w ww .ja va 2 s. c om * @param list * the list whose elements should be traversed in reverse. May not be <code>null</code>. * @return a list with the same elements as the given list, in reverse */ @Pure public static <T> List<T> reverseView(List<T> list) { return Lists.reverse(list); }
From source file:name.richardson.james.bukkit.banhammer.RecentCommand.java
@Override protected void execute() { int count = this.count.getInteger(); List<BanRecord> bans = banRecordManager.list(count); List<String> messages = new ArrayList<String>(); if (bans.isEmpty()) { messages.add(RECENT_NO_BANS.asInfoMessage()); } else {/*from www . ja va 2 s .c o m*/ // reverse the list so the most recent ban is at the bottom of the list // this makes sense since the console scrolls down. for (BanRecord ban : Lists.reverse(bans)) { BanRecord.BanRecordFormatter formatter = ban.getFormatter(); messages.addAll(formatter.getMessages()); } } getContext().getCommandSender().sendMessage(messages.toArray(new String[messages.size()])); }
From source file:org.apache.james.AggregateJunitExtension.java
@Override public void afterAll(ExtensionContext extensionContext) { Runnables.runParallel(Flux.fromIterable(Lists.reverse(registrableExtensions)) .map(ext -> Throwing.runnable(() -> ext.afterAll(extensionContext)))); }
From source file:edu.isi.karma.modeling.research.approach1.RankedSteinerSet.java
private List<Integer> computeCohesion() { if (nodes == null) return null; List<String> patternIds = new ArrayList<String>(); for (Node n : nodes) for (String s : n.getPatternIds()) patternIds.add(s);//from ww w .ja va2 s . c o m Function<String, String> stringEqualiy = new Function<String, String>() { @Override public String apply(final String s) { return s; } }; Multimap<String, String> index = Multimaps.index(patternIds, stringEqualiy); List<Integer> frequencies = new ArrayList<Integer>(); for (String s : index.keySet()) { frequencies.add(index.get(s).size()); } Collections.sort(frequencies); frequencies = Lists.reverse(frequencies); return frequencies; }
From source file:org.opensingular.form.io.definition.SFormDefinitionPersistenceUtil.java
public static SType<?> fromArchive(SIPersistenceArchive persistenceArchive) { ContextUnarchive ctx = new ContextUnarchive(persistenceArchive); List<SIPersistencePackage> children = persistenceArchive.getPackages().getChildren(); Lists.reverse(children).forEach(ctx::createNewPackage); for (SIPersistencePackage pPackage : Lists.reverse(children)) { PackageBuilder pkg = ctx.getPackage(pPackage.getPackageName()); for (SIPersistenceType pType : Lists.reverse(pPackage.getTypes().getChildren())) { SType<?> superType = resolveSuperType(ctx, pkg.getPackage(), pType); SType<?> newType = pkg.createType(pType.getSimpleName(), superType); readType(ctx, newType, pType); }/*from w ww.j a v a 2s . c o m*/ } return ctx.getDictionary().getType(persistenceArchive.getRootTypeName()); }
From source file:org.apache.jackrabbit.oak.spi.commit.MoveTracker.java
@CheckForNull public String getDestPath(String sourcePath) { for (MoveEntry me : Lists.reverse(entries)) { if (me.sourcePath.equals(sourcePath)) { return me.destPath; }//from w w w .ja v a 2 s. c om } return null; }
From source file:org.eclipse.elk.alg.layered.compaction.recthull.RectilinearConvexHull.java
/** * @param points/*w ww.ja v a2s . co m*/ * a cloud of points for which the rectilinear convex hull should be determined. * @return The {@link RectilinearConvexHull} for the passed points. */ public static RectilinearConvexHull of(final Iterable<Point> points) { RectilinearConvexHull rch = new RectilinearConvexHull(); for (Point p : points) { // equality important since the two extremal points can be equal if (rch.xMax1 == null || p.x >= rch.xMax1.x) { rch.xMax2 = rch.xMax1; rch.xMax1 = p; } if (rch.xMin1 == null || p.x <= rch.xMin1.x) { rch.xMin2 = rch.xMin1; rch.xMin1 = p; } if (rch.yMax1 == null || p.y >= rch.yMax1.y) { rch.yMax2 = rch.yMax1; rch.yMax1 = p; } if (rch.yMin1 == null || p.y <= rch.yMin1.y) { rch.yMin2 = rch.yMin1; rch.yMin1 = p; } } // q1 | q2 // --------- // q4 | q3 // Q1 MaximalElementsEventHandler q1 = new MaximalElementsEventHandler(Quadrant.Q1); Scanline.execute(points, RIGHT_LOW_FIRST, q1); // Q4 MaximalElementsEventHandler q4 = new MaximalElementsEventHandler(Quadrant.Q4); Scanline.execute(points, RIGHT_HIGH_FIRST, q4); // Q2 MaximalElementsEventHandler q2 = new MaximalElementsEventHandler(Quadrant.Q2); Scanline.execute(points, LEFT_LOW_FIRST, q2); // Q3 MaximalElementsEventHandler q3 = new MaximalElementsEventHandler(Quadrant.Q3); Scanline.execute(points, LEFT_HIGH_FIRST, q3); if (DEBUG) { // print clockwise System.out.println("The four stairs (no concaves):"); System.out.println(q1.points); System.out.println(Lists.reverse(q2.points)); System.out.println(q3.points); System.out.println(Lists.reverse(q4.points)); } // the scanline algorithm detected all convex corners, // now we add the concave corners to the lists addConcaveCorners(q1.points, Quadrant.Q1); addConcaveCorners(q2.points, Quadrant.Q2); addConcaveCorners(q3.points, Quadrant.Q3); addConcaveCorners(q4.points, Quadrant.Q4); // print clockwise if (DEBUG) { System.out.println("The four stairs (with concaves):"); System.out.println(q1.points); System.out.println(Lists.reverse(q2.points)); System.out.println(q3.points); System.out.println(Lists.reverse(q4.points)); } // ... and add everything to the hull list // (in clockwise order, q1..q4) rch.getHull().clear(); rch.getHull().addAll(q1.points); rch.getHull().addAll(Lists.reverse(q2.points)); rch.getHull().addAll(q3.points); rch.getHull().addAll(Lists.reverse(q4.points)); return rch; }