List of usage examples for com.google.common.collect ImmutableList reverse
public ImmutableList<E> reverse()
From source file:org.openqa.selenium.grid.web.Routes.java
public static CombinedRoute combine(Routes atLeastOne, Routes... optionalOthers) { ImmutableList<Routes> queue = Stream.concat(Stream.of(atLeastOne), Arrays.stream(optionalOthers)) .collect(ImmutableList.toImmutableList()); return new CombinedRoute(queue.reverse()); }
From source file:com.google.errorprone.bugpatterns.AssignmentToMock.java
private static SuggestedFix createFix(VariableTree tree, VisitorState state) { if (MOCK_FACTORY.matches(tree.getInitializer(), state) && !classContainsInitializer(state.findEnclosing(ClassTree.class), state)) { AnnotationTree anno = ASTHelpers.getAnnotationWithSimpleName(tree.getModifiers().getAnnotations(), "Mock"); return SuggestedFix.delete(anno); }//from w ww . ja v a 2 s . c o m int startPos = ((JCTree) tree).getStartPosition(); ImmutableList<ErrorProneToken> tokens = ErrorProneTokens.getTokens(state.getSourceCode() .subSequence(startPos, ((JCTree) tree.getInitializer()).getStartPosition()).toString(), state.context); for (ErrorProneToken token : tokens.reverse()) { if (token.kind() == TokenKind.EQ) { return SuggestedFix.replace(startPos + token.pos(), state.getEndPosition(tree.getInitializer()), ""); } } return SuggestedFix.builder().build(); }
From source file:cc.shanruifeng.functions.udfs.presto.json.JsonExtract.java
public static <T> JsonExtractor<T> generateExtractor(String path, JsonExtractor<T> rootExtractor, boolean exceptionOnOutOfBounds) { ImmutableList<String> tokens = ImmutableList.copyOf(new JsonPathTokenizer(path)); JsonExtractor<T> jsonExtractor = rootExtractor; for (String token : tokens.reverse()) { jsonExtractor = new ObjectFieldJsonExtractor<>(token, jsonExtractor, exceptionOnOutOfBounds); }//from ww w. java 2s .c om return jsonExtractor; }
From source file:com.facebook.buck.android.UberRDotJavaUtil.java
/** * Finds the transitive set of {@code rules}' {@link AndroidResource} dependencies with * non-null {@code res} directories, which can also include any of the {@code rules} themselves. * This set will be returned as an {@link ImmutableList} with the rules topologically sorted. * Rules will be ordered from least dependent to most dependent. */// ww w . jav a 2s. c o m public static ImmutableList<HasAndroidResourceDeps> getAndroidResourceDeps(Collection<BuildRule> rules, final boolean includeAssetOnlyRules) { // This visitor finds all AndroidResourceRules that are reachable from the specified rules via // rules with types in the TRAVERSABLE_TYPES collection. It also builds up the dependency graph // that was traversed to find the AndroidResourceRules. final MutableDirectedGraph<BuildRule> mutableGraph = new MutableDirectedGraph<>(); final ImmutableSet.Builder<HasAndroidResourceDeps> androidResources = ImmutableSet.builder(); AbstractDependencyVisitor visitor = new AbstractDependencyVisitor(rules) { @Override public ImmutableSet<BuildRule> visit(BuildRule rule) { HasAndroidResourceDeps androidResourceRule = null; if (rule instanceof HasAndroidResourceDeps) { androidResourceRule = (HasAndroidResourceDeps) rule; } else if (rule.getBuildable() instanceof HasAndroidResourceDeps) { androidResourceRule = (HasAndroidResourceDeps) rule.getBuildable(); } if (androidResourceRule != null && (androidResourceRule.getRes() != null || (includeAssetOnlyRules && androidResourceRule.getAssets() != null))) { androidResources.add(androidResourceRule); } // Only certain types of rules should be considered as part of this traversal. BuildRuleType type = rule.getType(); ImmutableSet<BuildRule> depsToVisit = maybeVisitAllDeps(rule, TRAVERSABLE_TYPES.contains(type)); mutableGraph.addNode(rule); for (BuildRule dep : depsToVisit) { mutableGraph.addEdge(rule, dep); } return depsToVisit; } }; visitor.start(); final Set<HasAndroidResourceDeps> allAndroidResourceRules = androidResources.build(); // Now that we have the transitive set of AndroidResourceRules, we need to return them in // topologically sorted order. This is critical because the order in which -S flags are passed // to aapt is significant and must be consistent. Predicate<BuildRule> inclusionPredicate = new Predicate<BuildRule>() { @Override public boolean apply(BuildRule rule) { return allAndroidResourceRules.contains(rule) || allAndroidResourceRules.contains(rule.getBuildable()); } }; ImmutableList<BuildRule> sortedAndroidResourceRules = TopologicalSort.sort(mutableGraph, inclusionPredicate); // TopologicalSort.sort() returns rules in leaves-first order, which is the opposite of what we // want, so we must reverse the list and cast BuildRules to AndroidResourceRules. return ImmutableList .copyOf(Iterables.transform(sortedAndroidResourceRules.reverse(), CAST_TO_ANDROID_RESOURCE_RULE)); }
From source file:com.facebook.buck.rules.AndroidResourceRule.java
/** * Finds the transitive set of {@code rule}'s {@link AndroidResourceRule} dependencies with * non-null {@code res} directories, which can also include {@code rule} itself. * This set will be returned as an {@link ImmutableList} with the rules topologically sorted as * determined by {@code graph}. Rules will be ordered from least dependent to most dependent. *//*from www . ja v a2 s . co m*/ public static ImmutableList<AndroidResourceRule> getAndroidResourceDeps(BuildRule rule, DependencyGraph graph) { final Set<AndroidResourceRule> allAndroidResourceRules = findAllAndroidResourceDeps(rule); // Now that we have the transitive set of AndroidResourceRules, we need to return them in // topologically sorted order. This is critical because the order in which -S flags are passed // to aapt is significant and must be consistent. Predicate<BuildRule> inclusionPredicate = new Predicate<BuildRule>() { @Override public boolean apply(BuildRule rule) { return allAndroidResourceRules.contains(rule); } }; ImmutableList<BuildRule> sortedAndroidResourceRules = TopologicalSort.sort(graph, inclusionPredicate); // TopologicalSort.sort() returns rules in leaves-first order, which is the opposite of what we // want, so we must reverse the list and cast BuildRules to AndroidResourceRules. return ImmutableList .copyOf(Iterables.transform(sortedAndroidResourceRules.reverse(), CAST_TO_ANDROID_RESOURCE_RULE)); }
From source file:ratpack.registry.internal.DefaultRegistryBuilder.java
@Override public Registry build() { ImmutableList<RegistryEntry<?>> entries = builder.build(); if (entries.size() == 1) { return new SingleEntryRegistry(entries.get(0)); } else {// w ww . j av a2s . co m return CachingRegistry.of(new MultiEntryRegistry(entries.reverse())); } }
From source file:org.opennms.newts.cassandra.search.CassandraResourceTreeWalker.java
/** * Visits all nodes in the resource tree bellow the given resource using * depth-first search./* ww w . j a v a2 s . co m*/ */ public void depthFirstSearch(Context context, SearchResultVisitor visitor, Resource root) { ArrayDeque<SearchResults.Result> stack = Queues.newArrayDeque(); // Build an instance of a SearchResult for the root resource // but don't invoke the visitor with it boolean skipFirstVisit = true; SearchResults initialResults = new SearchResults(); initialResults.addResult(root, new ArrayList<String>(0)); stack.add(initialResults.iterator().next()); while (!stack.isEmpty()) { SearchResults.Result r = stack.pop(); if (skipFirstVisit) { skipFirstVisit = false; } else { if (!visitor.visit(r)) { return; } } // Reverse the order of the results so we walk the left-most // branches first ImmutableList<SearchResults.Result> results = ImmutableList.copyOf(m_searcher.search(context, matchKeyAndValue(Constants.PARENT_TERM_FIELD, r.getResource().getId()))); for (SearchResults.Result result : results.reverse()) { stack.push(result); } } }
From source file:com.facebook.buck.android.relinker.NativeRelinker.java
/** * Creates a map from every BuildRule to the set of transitive dependents of that BuildRule that * are in the linkableRules set./*from w w w . j a va2s . c om*/ */ private ImmutableMap<BuildRule, ImmutableSet<BuildRule>> getAllDependentsMap(Set<BuildRule> linkableRules, DirectedAcyclicGraph<BuildRule> graph, ImmutableList<BuildRule> sortedRules) { final Map<BuildRule, ImmutableSet<BuildRule>> allDependentsMap = new HashMap<>(); // Using the sorted list of rules makes this calculation much simpler. We can just assume that // we already know all the dependents of a rules incoming nodes when we are processing that // rule. for (BuildRule rule : sortedRules.reverse()) { ImmutableSet.Builder<BuildRule> transitiveDependents = ImmutableSet.builder(); for (BuildRule dependent : graph.getIncomingNodesFor(rule)) { transitiveDependents.addAll(allDependentsMap.get(dependent)); if (linkableRules.contains(dependent)) { transitiveDependents.add(dependent); } } allDependentsMap.put(rule, transitiveDependents.build()); } return ImmutableMap.copyOf(allDependentsMap); }
From source file:msi.gaml.factories.ModelAssembler.java
public ModelDescription assemble(final String projectPath, final String modelPath, final Iterable<ISyntacticElement> allModels, final ValidationContext collector, final boolean document, final Map<String, ModelDescription> mm) { final ImmutableList<ISyntacticElement> models = ImmutableList.copyOf(allModels); final TOrderedHashMap<String, ISyntacticElement> speciesNodes = new TOrderedHashMap(); final TOrderedHashMap<String, TOrderedHashMap<String, ISyntacticElement>>[] experimentNodes = new TOrderedHashMap[1]; final ISyntacticElement globalNodes = SyntacticFactory.create(GLOBAL, (EObject) null, true); final ISyntacticElement source = models.get(0); Facets globalFacets = null;//www .j a v a2 s. c o m if (source.hasFacet(IKeyword.PRAGMA)) { final Facets facets = source.copyFacets(null); final List<String> pragmas = (List<String>) facets.get(IKeyword.PRAGMA).getExpression().getConstValue(); collector.resetInfoAndWarning(); if (pragmas != null) { if (pragmas.contains(IKeyword.NO_INFO)) { collector.setNoInfo(); } if (pragmas.contains(IKeyword.NO_WARNING)) { collector.setNoWarning(); } if (pragmas.contains(IKeyword.NO_EXPERIMENT)) { collector.setNoExperiment(); } } } final Map<String, SpeciesDescription> tempSpeciesCache = new THashMap<>(); for (final ISyntacticElement cm : models.reverse()) { final SyntacticModelElement currentModel = (SyntacticModelElement) cm; if (currentModel != null) { if (currentModel.hasFacets()) { if (globalFacets == null) { globalFacets = new Facets(currentModel.copyFacets(null)); } else { globalFacets.putAll(currentModel.copyFacets(null)); } } currentModel.visitChildren(element -> globalNodes.addChild(element)); SyntacticVisitor visitor = element -> addSpeciesNode(element, speciesNodes, collector); currentModel.visitSpecies(visitor); // We input the species so that grids are always the last ones // (see DiffusionStatement) currentModel.visitGrids(visitor); visitor = element -> { if (experimentNodes[0] == null) { experimentNodes[0] = new TOrderedHashMap(); } addExperimentNode(element, currentModel.getName(), experimentNodes[0], collector); }; currentModel.visitExperiments(visitor); } } final String modelName = buildModelName(source.getName()); // We build a list of working paths from which the composite model will // be able to look for resources. These working paths come from the // imported models Set<String> absoluteAlternatePathAsStrings = models.isEmpty() ? null : ImmutableSet.copyOf( Iterables.transform(models.reverse(), each -> ((SyntacticModelElement) each).getPath())); if (mm != null) { for (final ModelDescription m1 : mm.values()) { for (final String im : m1.getAlternatePaths()) { absoluteAlternatePathAsStrings = Sets.union(absoluteAlternatePathAsStrings, Collections.singleton(im)); } } } final ModelDescription model = new ModelDescription(modelName, null, projectPath, modelPath, source.getElement(), null, ModelDescription.ROOT, null, globalFacets, collector, absoluteAlternatePathAsStrings); final Collection<String> allModelNames = models.size() == 1 ? null : ImmutableSet.copyOf( Iterables.transform(Iterables.skip(models, 1), each -> buildModelName(each.getName()))); model.setImportedModelNames(allModelNames); model.isDocumenting(document); // hqnghi add micro-models if (mm != null) { // model.setMicroModels(mm); model.addChildren(mm.values()); } // end-hqnghi // recursively add user-defined species to world and down on to the // hierarchy speciesNodes.forEachValue(speciesNode -> { addMicroSpecies(model, speciesNode, tempSpeciesCache); return true; }); if (experimentNodes[0] != null) { experimentNodes[0].forEachEntry((s, b) -> { b.forEachValue(experimentNode -> { addExperiment(s, model, experimentNode, tempSpeciesCache); return true; }); return true; }); } // Parent the species and the experiments of the model (all are now // known). speciesNodes.forEachValue(speciesNode -> { parentSpecies(model, speciesNode, model, tempSpeciesCache); return true; }); if (experimentNodes[0] != null) { experimentNodes[0].forEachEntry((s, b) -> { b.forEachValue(experimentNode -> { parentExperiment(model, experimentNode); return true; }); return true; }); } // Initialize the hierarchy of types model.buildTypes(); // hqnghi build micro-models as types if (mm != null) { for (final Entry<String, ModelDescription> entry : mm.entrySet()) { model.getTypesManager().alias(entry.getValue().getName(), entry.getKey()); } // end-hqnghi } // Make species and experiments recursively create their attributes, // actions.... complementSpecies(model, globalNodes); speciesNodes.forEachValue(speciesNode -> { complementSpecies(model.getMicroSpecies(speciesNode.getName()), speciesNode); return true; }); if (experimentNodes[0] != null) { experimentNodes[0].forEachEntry((s, b) -> { b.forEachValue(experimentNode -> { complementSpecies(model.getExperiment(experimentNode.getName()), experimentNode); return true; }); return true; }); } // Complement recursively the different species (incl. the world). The // recursion is hierarchical model.inheritFromParent(); for (final SpeciesDescription sd : getSpeciesInHierarchicalOrder(model)) { sd.inheritFromParent(); if (sd.isExperiment()) { if (!sd.finalizeDescription()) { return null; } } } // Issue #1708 (put before the finalization) if (model.hasFacet(SCHEDULES) || model.hasFacet(FREQUENCY)) { createSchedulerSpecies(model); } if (!model.finalizeDescription()) { return null; } if (document) { collector.document(model); } return model; }
From source file:org.eclipse.elk.core.util.nodespacing.LabelAndNodeSizeProcessor.java
/** * Places the labels of the given port on the inside of the port's node. * * @param port//from www .ja v a2 s . co m * the port whose labels to place. * @param compoundNodeMode * {@code true} if the node contains further nodes in the original graph. In this * case, port labels are not placed next to ports, but a little down as well to avoid * edge-label-crossings if the port has edges connected to the node's insides. * @param labelSpacing * spacing between labels and other objects. */ private void placePortLabelsInside(final PortAdapter<?> port, final boolean compoundNodeMode, final double labelSpacing) { ImmutableList<LabelAdapter<?>> labels = ImmutableList.copyOf(port.getLabels()); if (labels.isEmpty()) { return; } // The initial y position we'll be starting from depends on the port side double y = 0; switch (port.getSide()) { case WEST: case EAST: // We need the first label's size here and we know that there is at least one label y = compoundNodeMode && port.hasCompoundConnections() ? port.getSize().y : (port.getSize().y - labels.get(0).getSize().y) / 2.0 - labelSpacing; break; case NORTH: y = port.getSize().y; break; case SOUTH: y = 0.0; break; } // In the usual case, we simply start at a given y position and place the labels downwards. // For southern ports, however, we actually need to start with the last label and place them // upwards. We thus first add all labels to a list that we may need to reverse if (port.getSide() == PortSide.SOUTH) { labels = labels.reverse(); } // Place da labels! for (final LabelAdapter<?> label : port.getLabels()) { final KVector position = new KVector(port.getPosition()); switch (port.getSide()) { case WEST: position.x = port.getSize().x + labelSpacing; position.y = y + labelSpacing; y += labelSpacing + label.getSize().y; break; case EAST: position.x = -label.getSize().x - labelSpacing; position.y = y + labelSpacing; y += labelSpacing + label.getSize().y; break; case NORTH: position.x = (port.getSize().x - label.getSize().x) / 2; position.y = y + labelSpacing; y += labelSpacing + label.getSize().y; break; case SOUTH: position.x = (port.getSize().x - label.getSize().x) / 2; position.y = y - labelSpacing - label.getSize().y; y -= labelSpacing + label.getSize().y; break; } label.setPosition(position); } }