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.eclipse.elk.layered.p4nodes.bk.BKAligner.java
/** * The graph is traversed in the given directions and nodes a grouped into blocks. The nodes in these * blocks will later be placed such that the edges connecting them will be straight lines. * //from ww w. j a va 2 s . c o m * <p>Type 1 conflicts are resolved, so that the dummy nodes of a long edge share the same block if * possible, such that the long edge is drawn straightly.</p> * * @param bal One of the four layouts which shall be used in this step * @param markedEdges List with all edges that were marked as type 1 conflicts */ public void verticalAlignment(final BKAlignedLayout bal, final Set<LEdge> markedEdges) { // Initialize root and align maps for (Layer layer : layeredGraph.getLayers()) { for (LNode v : layer.getNodes()) { bal.root[v.id] = v; bal.align[v.id] = v; bal.innerShift[v.id] = 0.0; } } List<Layer> layers = layeredGraph.getLayers(); // If the horizontal direction is LEFT, the layers are traversed from // right to left, thus a reverse iterator is needed if (bal.hdir == HDirection.LEFT) { layers = Lists.reverse(layers); } for (Layer layer : layers) { // r denotes the position in layer order where the last block was found // It is initialized with -1, since nothing is found and the ordering starts with 0 int r = -1; List<LNode> nodes = layer.getNodes(); if (bal.vdir == VDirection.UP) { // If the alignment direction is UP, the nodes in a layer are traversed // reversely, thus we start at INT_MAX and with the reversed list of nodes. r = Integer.MAX_VALUE; nodes = Lists.reverse(nodes); } // Variable names here are again taken from the paper mentioned above. // i denotes the index of the layer and k the position of the node within the layer. // m denotes the position of a neighbor in the neighbor list of a node. // CHECKSTYLEOFF Local Variable Names for (LNode v_i_k : nodes) { List<Pair<LNode, LEdge>> neighbors = null; if (bal.hdir == HDirection.LEFT) { neighbors = ni.rightNeighbors.get(v_i_k.id); } else { neighbors = ni.leftNeighbors.get(v_i_k.id); } if (neighbors.size() > 0) { // When a node has many upper neighbors, consider only the (two) nodes in the // middle. int d = neighbors.size(); int low = ((int) Math.floor(((d + 1.0) / 2.0))) - 1; int high = ((int) Math.ceil(((d + 1.0) / 2.0))) - 1; if (bal.vdir == VDirection.UP) { // Check, whether v_i_k can be added to a block of its upper/lower neighbor(s) for (int m = high; m >= low; m--) { if (bal.align[v_i_k.id].equals(v_i_k)) { Pair<LNode, LEdge> u_m_pair = neighbors.get(m); LNode u_m = u_m_pair.getFirst(); // Again, getEdge won't return null because the neighbor relationship // ensures that at least one edge exists if (!markedEdges.contains(u_m_pair.getSecond()) && r > ni.nodeIndex[u_m.id]) { bal.align[u_m.id] = v_i_k; bal.root[v_i_k.id] = bal.root[u_m.id]; bal.align[v_i_k.id] = bal.root[v_i_k.id]; r = ni.nodeIndex[u_m.id]; } } } } else { // Check, whether vik can be added to a block of its upper/lower neighbor(s) for (int m = low; m <= high; m++) { if (bal.align[v_i_k.id].equals(v_i_k)) { Pair<LNode, LEdge> um_pair = neighbors.get(m); LNode um = um_pair.getFirst(); if (!markedEdges.contains(um_pair.getSecond()) && r < ni.nodeIndex[um.id]) { bal.align[um.id] = v_i_k; bal.root[v_i_k.id] = bal.root[um.id]; bal.align[v_i_k.id] = bal.root[v_i_k.id]; r = ni.nodeIndex[um.id]; } } } } } } // CHECKSTYLEON Local Variable Names } }
From source file:com.codebullets.sagalib.processing.invocation.ModulesInvoker.java
/** * Call finishers on all started modules. */ public void finish() { Lists.reverse(finishers).forEach(Runnable::run); }
From source file:org.eclipse.elk.alg.layered.p3order.GreedyPortDistributor.java
/** * Distribute ports greedily on a single node. *///w ww. j a va 2 s.c o m private boolean distributePortsOnNode(final LNode node, final PortSide side, final boolean useHierarchicalCrosscounter) { List<LPort> ports = node.getPortSideView(side); if (side == PortSide.SOUTH || side == PortSide.WEST) { ports = Lists.reverse(ports); } boolean improved = false; boolean continueSwitching; do { continueSwitching = false; for (int i = 0; i < ports.size() - 1; i++) { LPort upperPort = ports.get(i); LPort lowerPort = ports.get(i + 1); if (switchingDecreasesCrossings(upperPort, lowerPort, node, useHierarchicalCrosscounter)) { improved = true; switchPorts(ports, node, i, i + 1); continueSwitching = true; } } } while (continueSwitching); return improved; }
From source file:com.pressassociation.pr.ast.visitor.FindFieldsVisitor.java
private Iterable<Field> getFields() { if (result.isEmpty()) { checkState(last != null, "Cannot get the result if the visitor hasn't been used"); return ImmutableList.of(last); }//from ww w .j a v a2s. c om List<Field> allButLast = Lists.transform(result, new Function<Fields, Field>() { @Override public Field apply(Fields input) { return input.getField(); } }); return Iterables.concat(ImmutableList.of(getEnd()), Lists.reverse(allButLast)); }
From source file:c5db.log.InRamLog.java
@Override public synchronized QuorumConfiguration getLastConfiguration() { for (LogEntry entry : Lists.reverse(log)) { if (entry.getQuorumConfiguration() != null) { return QuorumConfiguration.fromProtostuff(entry.getQuorumConfiguration()); }//from w w w . jav a 2 s .co m } return QuorumConfiguration.EMPTY; }
From source file:org.ros.android.view.visualization.VisualizationView.java
@Override public boolean onTouchEvent(MotionEvent event) { for (Layer layer : Lists.reverse(layers)) { if (layer.onTouchEvent(this, event)) { return true; }/*from ww w . j av a 2 s . c om*/ } return super.onTouchEvent(event); }
From source file:org.tymoonnext.bot.module.misc.Syslog.java
public void onCommand(CommandEvent evt) { if (evt.getCommand().equals("syslog")) { CommandInstance ci = ((CommandInstanceEvent) evt).get(); int n = Integer.parseInt(ci.getValue("n")); int l = 0; if (ci.getValue("filter").equals("NONE")) l = Level.OFF.intValue(); else if (ci.getValue("filter").equals("SEVERE")) l = Level.SEVERE.intValue(); else if (ci.getValue("filter").equals("WARNING")) l = Level.WARNING.intValue(); else if (ci.getValue("filter").equals("INFO")) l = Level.INFO.intValue(); else if (ci.getValue("filter").equals("FINE")) l = Level.FINE.intValue(); else if (ci.getValue("filter").equals("FINER")) l = Level.FINER.intValue(); else if (ci.getValue("filter").equals("FINEST")) l = Level.FINEST.intValue(); else if (ci.getValue("filter").equals("ALL")) l = Level.ALL.intValue(); if (ci.getValue("action").equalsIgnoreCase("print") || ci.getValue("action").equalsIgnoreCase("write")) { List<String> list = new ArrayList<String>(); for (int i = 0, c = 0; i < lvlstack.size() && c < n; i++) { if (lvlstack.get(i).intValue() >= l) { list.add(logstack.get(i)); c++;/*from w w w . j a v a2 s . c o m*/ } } list = Lists.reverse(list); if (ci.getValue("action").equalsIgnoreCase("print")) { evt.getStream().send(toString() + " Last " + n + " available log messages, filtered to " + ci.getValue("filter") + ": ", evt.getChannel()); for (String s : list) { evt.getStream().send(s, evt.getChannel()); } } else { Toolkit.saveStringToFile(StringUtils.implode(list.toArray(), "\n"), new File(Commons.f_BASEDIR, "syslog.out.log")); evt.getStream().send(toString() + " Last " + n + " available log messages, filtered to " + ci.getValue("filter") + " saved to syslog.out.log", evt.getChannel()); } } else if (ci.getValue("action").equalsIgnoreCase("clear")) { logstack.clear(); lvlstack.clear(); evt.getStream().send(toString() + " Log cleared.", evt.getChannel()); } } }
From source file:com.mycelium.wallet.activity.ConnectionLogsActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.show_logs_activity); final MbwManager mbwManager = MbwManager.getInstance(this); // get the log entries in a new list and show them in reverse order ArrayList<LogEntry> logEntries = Lists.newArrayList(mbwManager.getWapiLogs()); final String logs = Joiner.on("\n").join(Lists.reverse(logEntries)); TextView tvLogDisplay = (TextView) findViewById(R.id.tvLogDisplay); tvLogDisplay.setText(logs);//ww w . java 2s . c o m tvLogDisplay.setHorizontallyScrolling(true); tvLogDisplay.setMovementMethod(new ScrollingMovementMethod()); tvLogDisplay.setOnLongClickListener(new View.OnLongClickListener() { @Override public boolean onLongClick(View view) { Utils.setClipboardString(logs, ConnectionLogsActivity.this); Toast.makeText(ConnectionLogsActivity.this, R.string.copied_to_clipboard, Toast.LENGTH_SHORT) .show(); return true; } }); }
From source file:com.viadeo.kasper.core.interceptor.CompositeInterceptorFactory.java
public Optional<InterceptorChain<INPUT, OUTPUT>> create(final TypeToken<?> type, final InterceptorChain<INPUT, OUTPUT> givenTail) { checkNotNull(type);/*from w w w .ja va 2s .c o m*/ if (factories.size() == 0) { return Optional.absent(); } InterceptorChain<INPUT, OUTPUT> tail = givenTail; for (final InterceptorFactory<INPUT, OUTPUT> factory : Lists.reverse(factories)) { final Optional<InterceptorChain<INPUT, OUTPUT>> optChain = factory.create(type); if (optChain.isPresent()) { if (null == tail) { tail = optChain.get(); } else { tail = optChain.get().withNextChain(tail); } } } return Optional.fromNullable(tail); }
From source file:org.gradle.model.internal.manage.schema.extract.ModelSchemaExtractor.java
public <T> ModelSchema<T> extract(ModelType<T> type, ModelSchemaCache cache) { ModelSchemaExtractionContext<T> context = ModelSchemaExtractionContext.root(type); List<ModelSchemaExtractionContext<?>> validations = Lists.newLinkedList(); Queue<ModelSchemaExtractionContext<?>> unsatisfiedDependencies = Lists.newLinkedList(); ModelSchemaExtractionContext<?> extractionContext = context; validations.add(extractionContext);// w w w .j a v a 2 s . c o m while (extractionContext != null) { extractSchema(extractionContext, cache); Iterable<? extends ModelSchemaExtractionContext<?>> dependencies = extractionContext.getChildren(); Iterables.addAll(validations, dependencies); pushUnsatisfiedDependencies(dependencies, unsatisfiedDependencies, cache); extractionContext = unsatisfiedDependencies.poll(); } for (ModelSchemaExtractionContext<?> validationContext : Lists.reverse(validations)) { // TODO - this will leave invalid types in the cache when it fails validate(validationContext, cache); } return context.getResult(); }