List of usage examples for com.google.common.collect Lists reverse
@CheckReturnValue public static <T> List<T> reverse(List<T> list)
From source file:net.hydromatic.optiq.Schemas.java
/** Returns the path of a schema, appending the name of a table if not * null. *///from w w w .j a v a2 s .com public static List<String> path(Schema schema, String name) { final List<String> list = new ArrayList<String>(); if (name != null) { list.add(name); } for (Schema s = schema; s != null; s = s.getParentSchema()) { if (s.getParentSchema() != null || !s.getName().equals("")) { // Omit the root schema's name from the path if it's the empty string, // which it usually is. list.add(s.getName()); } } return ImmutableList.copyOf(Lists.reverse(list)); }
From source file:org.eclipse.elk.alg.layered.p4nodes.bk.BKCompactor.java
/** * In this step, actual coordinates are calculated for blocks and its nodes. * /*from w w w . ja v a 2s . co m*/ * <p>First, all blocks are placed, trying to avoid any crossing of the blocks. Then, the blocks are * shifted towards each other if there is any space for compaction.</p> * * @param bal One of the four layouts which shall be used in this step */ public void horizontalCompaction(final BKAlignedLayout bal) { // Initialize fields with basic values, partially depending on the direction for (Layer layer : layeredGraph.getLayers()) { for (LNode node : layer.getNodes()) { bal.sink[node.id] = node; bal.shift[node.id] = bal.vdir == VDirection.UP ? Double.NEGATIVE_INFINITY : Double.POSITIVE_INFINITY; } } // clear any previous sinks sinkNodes.clear(); // If the horizontal direction is LEFT, the layers are traversed from right to left, thus // a reverse iterator is needed (note that this does not change the original list of layers) List<Layer> layers = layeredGraph.getLayers(); if (bal.hdir == HDirection.LEFT) { layers = Lists.reverse(layers); } // init threshold strategy threshStrategy.init(bal, ni); // mark all blocks as unplaced Arrays.fill(bal.y, null); for (Layer layer : layers) { // As with layers, we need a reversed iterator for blocks for different directions List<LNode> nodes = layer.getNodes(); if (bal.vdir == VDirection.UP) { nodes = Lists.reverse(nodes); } // Do an initial placement for all blocks for (LNode v : nodes) { if (bal.root[v.id].equals(v)) { placeBlock(v, bal); } } } // Try to compact classes by shifting them towards each other if there is space between them. // Other than the original algorithm we use a "class graph" here in conjunction with a longest // path layering based on previously calculated separations between any pair of adjacent classes. // This allows to have different node sizes and disconnected graphs. placeClasses(bal); // apply final coordinates for (Layer layer : layers) { for (LNode v : layer.getNodes()) { bal.y[v.id] = bal.y[bal.root[v.id].id]; // If this is the root node of the block, check if the whole block can be shifted to // further compact the drawing (the block's non-root nodes will be processed later by // this loop and will thus use the updated y position calculated here) if (v.equals(bal.root[v.id])) { double sinkShift = bal.shift[bal.sink[v.id].id]; if ((bal.vdir == VDirection.UP && sinkShift > Double.NEGATIVE_INFINITY) || (bal.vdir == VDirection.DOWN && sinkShift < Double.POSITIVE_INFINITY)) { bal.y[v.id] = bal.y[v.id] + sinkShift; } } } } // all blocks were placed, shift latecomers threshStrategy.postProcess(); }
From source file:co.cask.tigon.internal.app.runtime.distributed.AbstractServiceTwillRunnable.java
@Override public void run() { runThread = Thread.currentThread(); LOG.info("Starting runnable {}", name); List<ListenableFuture<Service.State>> completions = Lists.newArrayList(); for (Service service : services) { SettableFuture<Service.State> completion = SettableFuture.create(); service.addListener(createServiceListener(completion), Threads.SAME_THREAD_EXECUTOR); completions.add(completion);/* w ww . j a v a 2 s . c o m*/ } Services.chainStart(services.get(0), services.subList(1, services.size()).toArray(new Service[0])); LOG.info("Runnable started {}", name); try { Futures.allAsList(completions).get(); } catch (InterruptedException e) { LOG.debug("Waiting on latch interrupted {}", name); Thread.currentThread().interrupt(); } catch (ExecutionException e) { LOG.error("Exception in service.", e); throw Throwables.propagate(e); } List<Service> reverse = Lists.reverse(services); Services.chainStop(reverse.get(0), reverse.subList(1, reverse.size()).toArray(new Service[0])); LOG.info("Runnable stopped {}", name); }
From source file:com.synflow.models.graph.visit.ReversePostOrder.java
@Override public Iterator<Vertex> iterator() { return Lists.reverse(vertices).iterator(); }
From source file:org.jboss.hal.core.finder.FinderPath.java
/** @return a reversed copy of this path. The current path is not modified. */ FinderPath reversed() { return new FinderPath(Lists.reverse(segments)); }
From source file:minium.actions.internal.AbstractInteraction.java
/** * Trigger reverse.//from ww w . j a va 2 s . co m * * @param type * the type */ protected boolean triggerReverse(Type type, Throwable e) { return trigger(Lists.reverse(getAllListeners()), type, e); }
From source file:com.ning.billing.analytics.BusinessOverdueStatusDao.java
private void overdueStatusChangedForBundle(final UUID bundleId, final InternalCallContext context) { final SubscriptionBundle bundle; try {//from w ww . j a v a2 s . c o m bundle = entitlementApi.getBundleFromId(bundleId, context); } catch (EntitlementUserApiException e) { log.warn("Ignoring update for bundle {}: bundle does not exist", bundleId); return; } final Account account; try { account = accountApi.getAccountById(bundle.getAccountId(), context); } catch (AccountApiException e) { log.warn("Ignoring update for bundle {}: account {} does not exist", bundleId, bundle.getAccountId()); return; } final String accountKey = account.getExternalKey(); final String externalKey = bundle.getExternalKey(); overdueStatusSqlDao.inTransaction(new Transaction<Void, BusinessOverdueStatusSqlDao>() { @Override public Void inTransaction(final BusinessOverdueStatusSqlDao transactional, final TransactionStatus status) throws Exception { log.info("Started rebuilding overdue statuses for bundle id {}", bundleId); transactional.deleteOverdueStatusesForBundle(bundleId.toString(), context); final List<BlockingState> blockingHistory = junctionApi.getBlockingHistory(bundleId, context.toTenantContext()); if (blockingHistory != null && blockingHistory.size() > 0) { final List<BlockingState> overdueStates = ImmutableList.<BlockingState>copyOf(blockingHistory); final List<BlockingState> overdueStatesReversed = Lists.reverse(overdueStates); DateTime previousStartDate = null; for (final BlockingState state : overdueStatesReversed) { final BusinessOverdueStatusModelDao overdueStatus = new BusinessOverdueStatusModelDao( accountKey, bundleId, previousStartDate, externalKey, state.getTimestamp(), state.getStateName()); log.info("Adding overdue state {}", overdueStatus); overdueStatusSqlDao.createOverdueStatus(overdueStatus, context); previousStartDate = state.getTimestamp(); } } log.info("Finished rebuilding overdue statuses for bundle id {}", bundleId); return null; } }); }
From source file:org.opendaylight.controller.sal.connect.netconf.NetconfMapping.java
static Node<?> toFilterStructure(InstanceIdentifier identifier) { Node<?> previous = null; if (identifier.getPath().isEmpty()) { return null; }//from w w w . j a va2s . co m for (org.opendaylight.yangtools.yang.data.api.InstanceIdentifier.PathArgument component : Lists .reverse(identifier.getPath())) { previous = toNode(component, previous); } return filter("subtree", previous); }
From source file:com.jvms.i18neditor.Editor.java
public void importResources(Path dir) { if (!closeCurrentSession()) { return;/*from w w w. j a v a 2 s. c o m*/ } if (Files.isDirectory(dir, LinkOption.NOFOLLOW_LINKS)) { reset(); resourcesDir = dir; } else { showError(MessageBundle.get("resources.open.error.multiple")); return; } try { Files.walk(resourcesDir, 1).filter(path -> Resources.isResource(path)).forEach(path -> { try { Resource resource = Resources.read(path); setupResource(resource); } catch (Exception e) { e.printStackTrace(); showError(MessageBundle.get("resources.open.error.single", path.toString())); } }); List<String> recentDirs = settings.getListProperty("history"); recentDirs.remove(resourcesDir); recentDirs.add(resourcesDir.toString()); if (recentDirs.size() > 5) { recentDirs.remove(0); } settings.setProperty("history", recentDirs); editorMenu.setRecentItems(Lists.reverse(recentDirs)); Map<String, String> keys = Maps.newTreeMap(); resources.forEach(resource -> keys.putAll(resource.getTranslations())); List<String> keyList = Lists.newArrayList(keys.keySet()); translationTree.setModel(new TranslationTreeModel(keyList)); updateUI(); } catch (IOException e) { e.printStackTrace(); showError(MessageBundle.get("resources.open.error.multiple")); } }
From source file:de.cau.cs.kieler.klay.layered.p4nodes.bk.BKCompactor.java
/** * In this step, actual coordinates are calculated for blocks and its nodes. * /*from w ww. ja va 2 s . c om*/ * <p>First, all blocks are placed, trying to avoid any crossing of the blocks. Then, the blocks are * shifted towards each other if there is any space for compaction.</p> * * @param bal One of the four layouts which shall be used in this step */ public void horizontalCompaction(final BKAlignedLayout bal) { // Initialize fields with basic values, partially depending on the direction for (Layer layer : layeredGraph.getLayers()) { for (LNode node : layer.getNodes()) { bal.sink[node.id] = node; bal.shift[node.id] = bal.vdir == VDirection.UP ? Double.NEGATIVE_INFINITY : Double.POSITIVE_INFINITY; } } // If the horizontal direction is LEFT, the layers are traversed from right to left, thus // a reverse iterator is needed (note that this does not change the original list of layers) List<Layer> layers = layeredGraph.getLayers(); if (bal.hdir == HDirection.LEFT) { layers = Lists.reverse(layers); } // init threshold strategy threshStrategy.init(bal); // mark all blocks as unplaced Arrays.fill(bal.y, null); for (Layer layer : layers) { // As with layers, we need a reversed iterator for blocks for different directions List<LNode> nodes = layer.getNodes(); if (bal.vdir == VDirection.UP) { nodes = Lists.reverse(nodes); } // Do an initial placement for all blocks for (LNode v : nodes) { if (bal.root[v.id].equals(v)) { placeBlock(v, bal); } } } // Try to compact blocks by shifting them towards each other if there is space between them. // It's important to traverse top-bottom or bottom-top here too // This is where 'classes' are compacted?! for (Layer layer : layers) { for (LNode v : layer.getNodes()) { bal.y[v.id] = bal.y[bal.root[v.id].id]; // If this is the root node of the block, check if the whole block can be shifted to // further compact the drawing (the block's non-root nodes will be processed later by // this loop and will thus use the updated y position calculated here) if (v.equals(bal.root[v.id])) { double sinkShift = bal.shift[bal.sink[v.id].id]; if ((bal.vdir == VDirection.UP && sinkShift > Double.NEGATIVE_INFINITY) || (bal.vdir == VDirection.DOWN && sinkShift < Double.POSITIVE_INFINITY)) { bal.y[v.id] = bal.y[v.id] + sinkShift; } } } } // all blocks were placed, shift latecomers threshStrategy.postProcess(); }