List of usage examples for com.google.common.collect Lists reverse
@CheckReturnValue public static <T> List<T> reverse(List<T> list)
From source file:com.google.gerrit.server.change.RelatedChangesSorter.java
public List<PatchSetData> sort(List<ChangeData> in, PatchSet startPs) throws OrmException, IOException { checkArgument(!in.isEmpty(), "Input may not be empty"); // Map of all patch sets, keyed by commit SHA-1. Map<String, PatchSetData> byId = collectById(in); PatchSetData start = byId.get(startPs.getRevision().get()); checkArgument(start != null, "%s not found in %s", startPs, in); ProjectControl ctl = start.data().changeControl().getProjectControl(); // Map of patch set -> immediate parent. ListMultimap<PatchSetData, PatchSetData> parents = MultimapBuilder.hashKeys(in.size()).arrayListValues(3) .build();// w ww . j a v a 2 s . c om // Map of patch set -> immediate children. ListMultimap<PatchSetData, PatchSetData> children = MultimapBuilder.hashKeys(in.size()).arrayListValues(3) .build(); // All other patch sets of the same change as startPs. List<PatchSetData> otherPatchSetsOfStart = new ArrayList<>(); for (ChangeData cd : in) { for (PatchSet ps : cd.patchSets()) { PatchSetData thisPsd = checkNotNull(byId.get(ps.getRevision().get())); if (cd.getId().equals(start.id()) && !ps.getId().equals(start.psId())) { otherPatchSetsOfStart.add(thisPsd); } for (RevCommit p : thisPsd.commit().getParents()) { PatchSetData parentPsd = byId.get(p.name()); if (parentPsd != null) { parents.put(thisPsd, parentPsd); children.put(parentPsd, thisPsd); } } } } Collection<PatchSetData> ancestors = walkAncestors(ctl, parents, start); List<PatchSetData> descendants = walkDescendants(ctl, children, start, otherPatchSetsOfStart, ancestors); List<PatchSetData> result = new ArrayList<>(ancestors.size() + descendants.size() - 1); result.addAll(Lists.reverse(descendants)); result.addAll(ancestors); return result; }
From source file:org.eclipse.elk.alg.layered.intermediate.wrapping.BreakingPointRemover.java
private void remove(final LGraph graph, final BPInfo bpi) { // assemble the new edge route KVectorChain newBends = new KVectorChain(); // System.out.println("NS: " + bpi.nodeStartEdge.getBendPoints()); // System.out.println("EN: " + bpi.originalEdge.getBendPoints()); // depending on the edge routing style we have to act differently switch (edgeRouting) { // for splines it should be enough to add the bpi.start and bpi.end // once to the overall list of bend points, since they will be // control points through which the bezier curve runs case SPLINES: newBends.addAll(bpi.nodeStartEdge.getBendPoints()); newBends.add(bpi.start.getPosition()); newBends.addAll(Lists.reverse(bpi.startEndEdge.getBendPoints())); newBends.add(bpi.end.getPosition()); newBends.addAll(bpi.originalEdge.getBendPoints()); break;//from ww w. j a v a 2 s . c om // after executing the polyline router the edge segments are simply joined, // note that the positions of bpi.start and bpi.end must be added as bend points case POLYLINE: newBends.addAll(bpi.nodeStartEdge.getBendPoints()); newBends.add(bpi.start.getPosition()); newBends.addAll(Lists.reverse(bpi.startEndEdge.getBendPoints())); newBends.add(bpi.end.getPosition()); newBends.addAll(bpi.originalEdge.getBendPoints()); break; // for orthogonal edge routing it is guaranteed, that incident edges of a node // enter the node parallel to the x axis. Thus, the positions // of bpi.start and bpi.end can be dropped since they lie on a straight line default: // ORTHOGONAL newBends.addAll(bpi.nodeStartEdge.getBendPoints()); newBends.addAll(Lists.reverse(bpi.startEndEdge.getBendPoints())); newBends.addAll(bpi.originalEdge.getBendPoints()); } // restore original edge bpi.originalEdge.getBendPoints().clear(); bpi.originalEdge.getBendPoints().addAll(newBends); bpi.originalEdge.setSource(bpi.nodeStartEdge.getSource()); // collect any created junction points (order can be arbitrary) KVectorChain junctionPointsOne = bpi.nodeStartEdge.getProperty(LayeredOptions.JUNCTION_POINTS); KVectorChain junctionPointsTwo = bpi.startEndEdge.getProperty(LayeredOptions.JUNCTION_POINTS); KVectorChain junctionPointsThree = bpi.originalEdge.getProperty(LayeredOptions.JUNCTION_POINTS); if (junctionPointsOne != null || junctionPointsTwo != null || junctionPointsThree != null) { KVectorChain newJunctionPoints = new KVectorChain(); addNullSafe(newJunctionPoints, junctionPointsThree); addNullSafe(newJunctionPoints, junctionPointsTwo); addNullSafe(newJunctionPoints, junctionPointsOne); bpi.originalEdge.setProperty(LayeredOptions.JUNCTION_POINTS, newJunctionPoints); } // remove all the dummy stuff bpi.startEndEdge.setSource(null); bpi.startEndEdge.setTarget(null); bpi.nodeStartEdge.setSource(null); bpi.nodeStartEdge.setTarget(null); bpi.end.setLayer(null); bpi.start.setLayer(null); if (bpi.prev != null) { remove(graph, bpi.prev); } }
From source file:eu.interedition.collatex.lab.VariantGraphLayout.java
/** * @return movements/* w w w . ja va 2s. c o m*/ */ private int solveEdgeCrosses(boolean down, int level) { // Get the current level final List<Cell> cells = grid.get(level); // remember the old sort final List<Cell> levelSortBefore = Lists.newArrayList(cells); // new sort Collections.sort(cells); // test for movements int movements = 0; for (int j = 0; j < levelSortBefore.size(); j++) { if (levelSortBefore.get(j).avgWeight() != cells.get(j).avgWeight()) { movements++; } } // Collections Sort sorts the highest value to the first value for (Cell cell : Lists.reverse(cells)) { final VariantGraph.Vertex vertex = cell.vertex; for (VariantGraph.Edge edge : (down ? vertex.outgoing() : vertex.incoming())) { final Cell neighborCell = vertexToCell.get((down ? edge.to() : edge.from())); // do it only if the edge is a forward edge to a deeper level if (down && neighborCell.y > level) { neighborCell.addWeight(cell.avgWeight()); } if (!down && neighborCell.y < level) { neighborCell.addWeight(cell.avgWeight()); } } } return movements; }
From source file:com.bc.fiduceo.reader.BoundingPolygonCreator.java
public Geometry createBoundingGeometryClockwise(Array longitudes, Array latitudes) { final List<Point> coordinates = extractBoundaryCoordinates(longitudes, latitudes); closePolygon(coordinates);/*from w w w. j a v a 2 s. co m*/ final List<Point> reverse = Lists.reverse(coordinates); return geometryFactory.createPolygon(reverse); }
From source file:org.apache.avro.compiler.schema.Schemas.java
/** * depth first visit.//from w ww . j a v a2 s . com * * @param start * @param visitor */ public static <T> T visit(final Schema start, final SchemaVisitor<T> visitor) { // Set of Visited Schemas IdentityHashMap<Schema, Schema> visited = new IdentityHashMap<>(); // Stack that contains the Schams to process and afterVisitNonTerminal functions. // Deque<Either<Schema, Supplier<SchemaVisitorAction>>> // Using either has a cost which we want to avoid... Deque<Object> dq = new ArrayDeque<>(); dq.addLast(start); Object current; while ((current = dq.pollLast()) != null) { if (current instanceof Supplier) { // we are executing a non terminal post visit. SchemaVisitorAction action = ((Supplier<SchemaVisitorAction>) current).get(); switch (action) { case CONTINUE: break; case SKIP_SUBTREE: throw new UnsupportedOperationException(); case SKIP_SIBLINGS: while (dq.getLast() instanceof Schema) { dq.removeLast(); } break; case TERMINATE: return visitor.get(); default: throw new UnsupportedOperationException("Invalid action " + action); } } else { Schema schema = (Schema) current; boolean terminate; if (!visited.containsKey(schema)) { Schema.Type type = schema.getType(); switch (type) { case ARRAY: terminate = visitNonTerminal(visitor, schema, dq, Arrays.asList(schema.getElementType())); visited.put(schema, schema); break; case RECORD: terminate = visitNonTerminal(visitor, schema, dq, Lists.transform(Lists.reverse(schema.getFields()), new Function<Field, Schema>() { @Override public Schema apply(Field f) { return f.schema(); } })); visited.put(schema, schema); break; case UNION: terminate = visitNonTerminal(visitor, schema, dq, schema.getTypes()); visited.put(schema, schema); break; case MAP: terminate = visitNonTerminal(visitor, schema, dq, Arrays.asList(schema.getValueType())); visited.put(schema, schema); break; case NULL: case BOOLEAN: case BYTES: case DOUBLE: case ENUM: case FIXED: case FLOAT: case INT: case LONG: case STRING: terminate = visitTerminal(visitor, schema, dq); break; default: throw new UnsupportedOperationException("Invalid type " + type); } } else { terminate = visitTerminal(visitor, schema, dq); } if (terminate) { return visitor.get(); } } } return visitor.get(); }
From source file:net.sf.qualitytest.blueprint.configuration.ImmutableBlueprintConfiguration.java
@Nullable @Override// w ww . j av a 2 s . c o m @Throws(IllegalNullArgumentException.class) public CreationStrategy<?> findCreationStrategyForField(@Nonnull final Field field) { Check.notNull(field, "field"); for (final StrategyPair entry : Lists.reverse(mapping)) { if (entry.getKey().matchesByField(field)) { return entry.getValue(); } } return null; }
From source file:com.jivesoftware.os.tasmo.test.Expectations.java
private void walkTree(IdTreeNode parent, List<Id[]> allBranches) { if (parent.children().isEmpty()) { List<Id> ids = new ArrayList<>(); while (true) { ids.add(parent.value());/*from ww w . j a v a 2 s . co m*/ parent = parent.parent(); if (parent == null) { break; } } ids = Lists.reverse(ids); allBranches.add(ids.toArray(new Id[ids.size()])); } else { for (IdTreeNode child : parent.children()) { walkTree(child, allBranches); } } }
From source file:co.paralleluniverse.strands.queues.SingleConsumerArrayQueue.java
@Override public List<E> snapshot() { final long t = tail; final ArrayList<E> list = new ArrayList<E>((int) (t - head)); for (long p = tail; p != head; p--) list.add(value((int) p & mask)); return Lists.reverse(list); }
From source file:org.opendaylight.netconf.cli.reader.custom.ConfigReader.java
@Override protected List<NormalizedNode<?, ?>> readWithContext(final DataSchemaNode schemaNode) throws IOException, ReadingException { console.writeLn("Config " + schemaNode.getQName().getLocalName()); console.writeLn("Submit path of the data to edit. Use TAB for autocomplete"); final String rawValue = console.read(); // FIXME isSkip check should be somewhere in abstractReader if (isSkipInput(rawValue) || Strings.isNullOrEmpty(rawValue)) { return Collections.emptyList(); }//from www . j a v a2 s . c o m final List<QName> filterPartsQNames = Lists.newArrayList(); for (final String part : rawValue.split(SEPARATOR)) { final QName qName = IOUtil.qNameFromKeyString(part, mappedModules); filterPartsQNames.add(qName); } List<? extends NormalizedNode<?, ?>> previous = readInnerNode(rawValue); for (final QName qName : Lists.reverse(filterPartsQNames).subList(1, filterPartsQNames.size())) { previous = Collections.<NormalizedNode<?, ?>>singletonList( ImmutableContainerNodeBuilder.create().withNodeIdentifier(new NodeIdentifier(qName)) .withValue(previous == null ? Collections.<DataContainerChild<?, ?>>emptyList() : (Collection) previous) .build()); } if (previous == null) { return Collections.singletonList(null); } final DataContainerNodeAttrBuilder<NodeIdentifier, ContainerNode> builder = ImmutableContainerNodeBuilder .create(); builder.withNodeIdentifier(new NodeIdentifier(schemaNode.getQName())); builder.withValue((Collection<DataContainerChild<?, ?>>) previous); return Collections.<NormalizedNode<?, ?>>singletonList(builder.build()); }
From source file:org.caleydo.view.bicluster.sorting.FuzzyClustering.java
public List<IntFloat> filter(float threshold, int maxElements, EThresholdMode mode) { if (threshold == 0 && maxElements == UNBOUND_NUMBER) { switch (mode) { case ABS: return memberships.asList(); case NEGATIVE_ONLY: return negatives(0, UNBOUND_NUMBER); case POSITVE_ONLY: return positives(0, UNBOUND_NUMBER); }/*from w ww . j a va2s . c o m*/ } ImmutableList<IntFloat> negatives = mode.includeNegatives() ? negatives(threshold, maxElements) : ImmutableList.<IntFloat>of(); ImmutableList<IntFloat> positives = mode.includePositives() ? positives(threshold, maxElements) : ImmutableList.<IntFloat>of(); if (maxElements == UNBOUND_NUMBER || (negatives.size() + positives.size()) <= maxElements) //just add negatives and positives return ConcatedList.concat(negatives, positives); if (negatives.isEmpty()) { return positives.subList(Math.max(0, positives.size() - maxElements), positives.size()); } if (positives.isEmpty()) return negatives.subList(0, Math.min(negatives.size(), maxElements)); // take the abs top X elements Iterator<IntFloat> negIt = negatives.iterator(); Iterator<IntFloat> posIt = Lists.reverse(positives).iterator(); IntFloat negEnd = null; IntFloat negAct = negIt.next(); IntFloat posStart = null; IntFloat posAct = posIt.next(); for (int i = 0; i < maxElements; ++i) { if (negAct == null || (posAct != null && posAct.getMembership() > -negAct.getMembership())) { posStart = posAct; posAct = posIt.hasNext() ? posIt.next() : null; } else { negEnd = negAct; negAct = negIt.hasNext() ? negIt.next() : null; } } ImmutableSortedSet<IntFloat> headSet = negEnd == null ? ImmutableSortedSet.<IntFloat>of() : memberships.headSet(negEnd, true); ImmutableSortedSet<IntFloat> tailSet = posStart == null ? ImmutableSortedSet.<IntFloat>of() : memberships.tailSet(posStart, true); return ConcatedList.concat(headSet.asList(), tailSet.asList()); }