Java Code Examples for com.google.common.collect.ImmutableList#reverse()
The following examples show how to use
com.google.common.collect.ImmutableList#reverse() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TargetExpressionList.java From intellij with Apache License 2.0 | 6 votes |
private TargetExpressionList( ImmutableList<TargetData> projectTargets, @Nullable ProjectDirectoriesHelper directories) { // reverse list, removing trivially-excluded targets List<TargetData> excluded = new ArrayList<>(); ImmutableList.Builder<TargetData> builder = ImmutableList.builder(); for (TargetData target : projectTargets.reverse()) { if (target.isExcluded()) { excluded.add(target); builder.add(target); continue; } boolean drop = excluded.stream().anyMatch(excl -> excl.coversTargetData(target)); if (!drop) { builder.add(target); } } this.reversedTargets = builder.build(); this.directories = directories; }
Example 2
Source File: CpuProfiler.java From bazel with Apache License 2.0 | 6 votes |
synchronized void writeEvent(int ticks, ImmutableList<Debug.Frame> stack) { if (this.error == null) { try { ByteArrayOutputStream sample = new ByteArrayOutputStream(); CodedOutputStream sampleEnc = CodedOutputStream.newInstance(sample); sampleEnc.writeInt64(SAMPLE_VALUE, ticks * period.toNanos() / 1000L); for (Debug.Frame fr : stack.reverse()) { sampleEnc.writeUInt64(SAMPLE_LOCATION_ID, getLocationID(fr)); } sampleEnc.flush(); enc.writeByteArray(PROFILE_SAMPLE, sample.toByteArray()); } catch (IOException ex) { this.error = ex; } } }
Example 3
Source File: NativeRelinker.java From buck with Apache License 2.0 | 6 votes |
/** * Creates a map from every BuildRule to the set of transitive dependents of that BuildRule that * are in the linkableRules set. */ private ImmutableMap<BuildRule, ImmutableSet<BuildRule>> getAllDependentsMap( Set<BuildRule> linkableRules, DirectedAcyclicGraph<BuildRule> graph, ImmutableList<BuildRule> sortedRules) { 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); }
Example 4
Source File: JsonExtract.java From presto with Apache License 2.0 | 5 votes |
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); } return jsonExtractor; }
Example 5
Source File: MaximumLinkageErrorsTest.java From cloud-opensource-java with Apache License 2.0 | 5 votes |
private String findLatestNonSnapshotVersion() throws MavenRepositoryException { ImmutableList<String> versions = RepositoryUtility.findVersions( RepositoryUtility.newRepositorySystem(), "com.google.cloud", "libraries-bom"); ImmutableList<String> versionsLatestFirst = versions.reverse(); Optional<String> highestNonsnapshotVersion = versionsLatestFirst.stream().filter(version -> !version.contains("SNAPSHOT")).findFirst(); if (!highestNonsnapshotVersion.isPresent()) { Assert.fail("Could not find non-snapshot version of the BOM"); } return highestNonsnapshotVersion.get(); }
Example 6
Source File: JsonExtract.java From hive-third-functions with Apache License 2.0 | 5 votes |
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); } return jsonExtractor; }
Example 7
Source File: GraphTest.java From c5-replicator with Apache License 2.0 | 5 votes |
private void validateTopoSort(ImmutableList<NodeType> expected, List<ImmutableList<Node<NodeType>>> result) { // reverse the expected order: ImmutableList<NodeType> reverse = expected.reverse(); Deque<ImmutableList<Node<NodeType>>> q = new LinkedList<>(result); for (NodeType t : reverse) { ImmutableList<Node<NodeType>> topoNode = q.pop(); assertEquals(1, topoNode.size()); assertEquals(t, topoNode.get(0).type); } }
Example 8
Source File: CompressedDirectory.java From docker-client with Apache License 2.0 | 5 votes |
private Visitor(final Path root, ImmutableList<DockerIgnorePathMatcher> ignoreMatchers, final TarArchiveOutputStream tarStream) { this.root = root; // .dockerignore matchers need to be read from the bottom of the file, // so the given list should be reversed before using it. this.ignoreMatchers = ignoreMatchers.reverse(); this.tarStream = tarStream; }
Example 9
Source File: CassandraResourceTreeWalker.java From newts with Apache License 2.0 | 5 votes |
/** * Visits all nodes in the resource tree bellow the given resource using * depth-first search. */ 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); } } }
Example 10
Source File: NestedSet.java From bazel with Apache License 2.0 | 5 votes |
/** * Private implementation of toList which takes the actual children (the deserialized {@code * Object[]} if {@link #children} is a {@link ListenableFuture}). */ private ImmutableList<E> actualChildrenToList(Object actualChildren) { if (actualChildren == EMPTY_CHILDREN) { return ImmutableList.of(); } if (!(actualChildren instanceof Object[])) { return ImmutableList.of((E) actualChildren); } ImmutableList<E> list = expand((Object[]) actualChildren); return getOrder() == Order.LINK_ORDER ? list.reverse() : list; }
Example 11
Source File: DelegatingVisitor.java From closure-stylesheets with Apache License 2.0 | 5 votes |
/** * Creates a {@code DelegatingVisitor} from the given list of visitors. The list must have at * least one element. */ public static CssTreeVisitor from(List<CssTreeVisitor> originalVisitors) { Preconditions.checkArgument(originalVisitors.size() >= 1); if (originalVisitors.size() == 1) { return originalVisitors.get(0); } final ImmutableList<CssTreeVisitor> visitors = ImmutableList.copyOf(originalVisitors); final ImmutableList<CssTreeVisitor> reverseVisitors = visitors.reverse(); return Reflection.newProxy( CssTreeVisitor.class, new InvocationHandler() { @Override public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { try { Object returnValue = null; Iterable<CssTreeVisitor> visitorsInOrderForMethod; if (method.getName().startsWith("enter")) { visitorsInOrderForMethod = visitors; } else { // assume it's a leave* method visitorsInOrderForMethod = reverseVisitors; } for (CssTreeVisitor visitor : visitorsInOrderForMethod) { returnValue = method.invoke(visitor, args); } return returnValue; } catch (InvocationTargetException e) { throw e.getTargetException(); } } }); }
Example 12
Source File: NdkCxxPlatformTest.java From buck with Apache License 2.0 | 5 votes |
private void assertLastMatchingFlagIs( ImmutableList<String> flags, Function<String, Boolean> filter, String expected) { assertThat(flags, hasItems(expected)); for (String flag : flags.reverse()) { if (filter.apply(flag)) { assertThat(flag, is(expected)); return; } } }
Example 13
Source File: RailEdge.java From Signals with GNU General Public License v3.0 | 4 votes |
public RailEdge(RailObjectHolder<TPos> allRailObjects, ImmutableList<NetworkRail<TPos>> edge, List<RailRouteNode<TPos>> intersections){ this.railObjects = allRailObjects.subSelection(edge); //Filter intersections if(intersections != null) { intersections = intersections.stream().filter(i -> railObjects.get(i.pos) != null).collect(Collectors.toList()); } EnumDirectionalityResult rawDirectionality = determineDirectionality(allRailObjects, edge); if(rawDirectionality == EnumDirectionalityResult.UNIDIRECTIONAL_REVERSE) { edge = edge.reverse(); directionality = EnumDirectionalityResult.UNIDIRECTIONAL_NO_CHANGE; } else { directionality = rawDirectionality; } TPos firstPos = edge.get(0).getPos(); TPos lastPos = edge.get(edge.size() - 1).getPos(); //if bidirectional, save in a deterministic form for equals/hashcode purposes if(directionality == EnumDirectionalityResult.BIDIRECTIONAL) { int compareResult = firstPos.compareTo(lastPos); if(compareResult == 0) { //When startPos == endPos (happens in looped tracks), we need to check the other with the neighboring positions compareResult = edge.get(1).getPos().compareTo(edge.get(edge.size() - 2).getPos()); if(compareResult == 0) { throw new IllegalStateException(""); } } if(compareResult > 0) { //Reverse the order edge = edge.reverse(); if(intersections != null) intersections = reverseIntersections(intersections); firstPos = edge.get(0).getPos(); lastPos = edge.get(edge.size() - 1).getPos(); } } this.edge = edge; startPos = firstPos; endPos = lastPos; aabb = new PosAABB<>(edge.stream().map(x -> x.getPos()).collect(Collectors.toSet())); startHeading = startPos.getRelativeHeading(edge.get(1).getPos()); endHeading = endPos.getRelativeHeading(edge.get(edge.size() - 2).getPos()); length = edge.size(); this.intersections = intersections == null ? computeIntersections(allRailObjects) : intersections; intersectionsReversed = reverseIntersections(this.intersections); signals = computeSignals(); }