com.google.common.collect.ImmutableList#reverse ( )源码实例Demo

下面列出了com.google.common.collect.ImmutableList#reverse ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: intellij   文件: TargetExpressionList.java
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;
}
 
源代码2 项目: bazel   文件: CpuProfiler.java
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;
    }
  }
}
 
源代码3 项目: buck   文件: NativeRelinker.java
/**
 * 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);
}
 
源代码4 项目: presto   文件: 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);
    }
    return jsonExtractor;
}
 
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();
}
 
源代码6 项目: hive-third-functions   文件: 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);
    }
    return jsonExtractor;
}
 
源代码7 项目: c5-replicator   文件: GraphTest.java
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);
  }
}
 
源代码8 项目: docker-client   文件: CompressedDirectory.java
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;
}
 
源代码9 项目: newts   文件: CassandraResourceTreeWalker.java
/**
 * 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);
        }
    }
}
 
源代码10 项目: bazel   文件: NestedSet.java
/**
 * 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;
}
 
源代码11 项目: closure-stylesheets   文件: DelegatingVisitor.java
/**
 * 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();
          }
        }
      });
}
 
源代码12 项目: buck   文件: NdkCxxPlatformTest.java
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;
    }
  }
}
 
源代码13 项目: Signals   文件: RailEdge.java
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();
}