Java Code Examples for com.google.common.collect.ImmutableList#equals()

The following examples show how to use com.google.common.collect.ImmutableList#equals() . 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: AddPathAbstractRouteEntry.java    From bgpcep with Eclipse Public License 1.0 6 votes vote down vote up
private boolean isBestPathNew(final ImmutableList<AddPathBestPath> newBestPathList) {
    this.isNonAddPathBestPathNew = !isNonAddPathBestPathTheSame(newBestPathList);
    filterRemovedPaths(newBestPathList);
    if (this.bestPathRemoved != null && !this.bestPathRemoved.isEmpty()
            || newBestPathList != null
            && !newBestPathList.equals(this.bestPath)) {
        if (this.bestPath != null) {
            this.newBestPathToBeAdvertised = new ArrayList<>(newBestPathList);
            this.newBestPathToBeAdvertised.removeAll(this.bestPath);
        } else {
            this.newBestPathToBeAdvertised = newBestPathList;
        }
        this.bestPath = newBestPathList;
        LOG.trace("Actual Best {}, removed best {}", this.bestPath, this.bestPathRemoved);
        return true;
    }
    return false;
}
 
Example 2
Source File: RelBuilder.java    From Quicksql with MIT License 5 votes vote down vote up
public AggCall sort(Iterable<RexNode> orderKeys) {
  final ImmutableList<RexNode> orderKeyList =
      ImmutableList.copyOf(orderKeys);
  return orderKeyList.equals(this.orderKeys)
      ? this
      : new AggCallImpl(aggFunction, distinct, approximate, ignoreNulls,
          filter, alias, operands, orderKeyList);
}
 
Example 3
Source File: VictoryMatchModule.java    From ProjectAres with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Re-sort all {@link Competitor}s from scratch, according to the current {@link VictoryCondition}.
 * This should be called when the state of the match changes in a way that affects the
 * rank of any competitors.
 */
public void invalidateCompetitorRanking() {
    final ImmutableList<Competitor> before = ImmutableList.copyOf(calculator().rankedCompetitors());
    calculator().invalidateRanking();
    final ImmutableList<Competitor> after = ImmutableList.copyOf(calculator().rankedCompetitors());

    if(!before.equals(after)) {
        eventBus.callEvent(new RankingsChangeEvent(match, before, after));
    }
}
 
Example 4
Source File: GenericMethodType.java    From ProjectAres with GNU Affero General Public License v3.0 5 votes vote down vote up
public GenericMethodType<? extends T> resolveIn(TypeToken<?> context) {
    final TypeToken<? extends T> returnType = (TypeToken<? extends T>) context.resolveType(this.returnType.getType());
    final ImmutableList<TypeToken<?>> parameterTypes = this.parameterTypes.stream()
                                                                          .map(t -> context.resolveType(t.getType()))
                                                                          .collect(Collectors.toImmutableList());
    return returnType.equals(this.returnType) && parameterTypes.equals(this.parameterTypes)
           ? this
           : new GenericMethodType<>(returnType, parameterTypes);
}
 
Example 5
Source File: AbstractScriptBuilder.java    From balzac with Apache License 2.0 5 votes vote down vote up
private static ImmutableList<ScriptChunk> iterateOptimize(ImmutableList<ScriptChunk> scriptChunks) {
    ImmutableList<ScriptChunk> value = scriptChunks;
    ImmutableList<ScriptChunk> newValue = optimize(scriptChunks);

    while (!newValue.equals(value)) {
        value = newValue;
        newValue = optimize(value);
    }
    ;

    return newValue;
}
 
Example 6
Source File: TextDiffSubject.java    From nomulus with Apache License 2.0 5 votes vote down vote up
public void hasSameContentAs(List<String> expectedContent) {
  checkNotNull(expectedContent, "expectedContent");
  ImmutableList<String> expected = ImmutableList.copyOf(expectedContent);
  if (expected.equals(actual)) {
    return;
  }
  String diffString = diffFormat.generateDiff(expected, actual);
  failWithoutActual(
      Fact.simpleFact(
          Joiner.on('\n')
              .join(
                  "Files differ in content. Displaying " + Ascii.toLowerCase(diffFormat.name()),
                  diffString)));
}
 
Example 7
Source File: BuilderSpec.java    From RetroFacebook with Apache License 2.0 5 votes vote down vote up
/**
 * Finds any methods in the set that return the builder type. If the builder has type parameters
 * {@code <A, B>}, then the return type of the method must be {@code Builder<A, B>} with
 * the same parameter names. We enforce elsewhere that the names and bounds of the builder
 * parameters must be the same as those of the @RetroFacebook class. Here's a correct example:
 * <pre>
 * {@code @RetroFacebook abstract class Foo<A extends Number, B> {
 *   abstract int someProperty();
 *
 *   abstract Builder<A, B> toBuilder();
 *
 *   interface Builder<A extends Number, B> {...}
 * }}
 * </pre>
 * <p/>
 * <p>We currently impose that there cannot be more than one such method.</p>
 */
ImmutableSet<ExecutableElement> toBuilderMethods(
    Types typeUtils, Set<ExecutableElement> abstractMethods) {

  ImmutableList<String> builderTypeParamNames =
      FluentIterable.from(builderTypeElement.getTypeParameters())
          .transform(SimpleNameFunction.INSTANCE)
          .toList();

  ImmutableSet.Builder<ExecutableElement> methods = ImmutableSet.builder();
  for (ExecutableElement method : abstractMethods) {
    if (builderTypeElement.equals(typeUtils.asElement(method.getReturnType()))) {
      methods.add(method);
      DeclaredType returnType = MoreTypes.asDeclared(method.getReturnType());
      ImmutableList.Builder<String> typeArguments = ImmutableList.builder();
      for (TypeMirror typeArgument : returnType.getTypeArguments()) {
        if (typeArgument.getKind().equals(TypeKind.TYPEVAR)) {
          typeArguments.add(typeUtils.asElement(typeArgument).getSimpleName().toString());
        }
      }
      if (!builderTypeParamNames.equals(typeArguments.build())) {
        errorReporter.reportError(
            "Builder converter method should return "
                + builderTypeElement
                + TypeSimplifier.actualTypeParametersString(builderTypeElement),
            method);
      }
    }
  }
  ImmutableSet<ExecutableElement> builderMethods = methods.build();
  if (builderMethods.size() > 1) {
    errorReporter.reportError(
        "There can be at most one builder converter method", builderMethods.iterator().next());
  }
  return builderMethods;
}
 
Example 8
Source File: BuilderSpec.java    From RetroFacebook with Apache License 2.0 5 votes vote down vote up
/**
 * Finds any methods in the set that return the builder type. If the builder has type parameters
 * {@code <A, B>}, then the return type of the method must be {@code Builder<A, B>} with
 * the same parameter names. We enforce elsewhere that the names and bounds of the builder
 * parameters must be the same as those of the @RetroFacebook class. Here's a correct example:
 * <pre>
 * {@code @RetroFacebook abstract class Foo<A extends Number, B> {
 *   abstract int someProperty();
 *
 *   abstract Builder<A, B> toBuilder();
 *
 *   interface Builder<A extends Number, B> {...}
 * }}
 * </pre>
 * <p/>
 * <p>We currently impose that there cannot be more than one such method.</p>
 */
ImmutableSet<ExecutableElement> toBuilderMethods(
    Types typeUtils, Set<ExecutableElement> abstractMethods) {

  ImmutableList<String> builderTypeParamNames =
      FluentIterable.from(builderTypeElement.getTypeParameters())
          .transform(SimpleNameFunction.INSTANCE)
          .toList();

  ImmutableSet.Builder<ExecutableElement> methods = ImmutableSet.builder();
  for (ExecutableElement method : abstractMethods) {
    if (builderTypeElement.equals(typeUtils.asElement(method.getReturnType()))) {
      methods.add(method);
      DeclaredType returnType = MoreTypes.asDeclared(method.getReturnType());
      ImmutableList.Builder<String> typeArguments = ImmutableList.builder();
      for (TypeMirror typeArgument : returnType.getTypeArguments()) {
        if (typeArgument.getKind().equals(TypeKind.TYPEVAR)) {
          typeArguments.add(typeUtils.asElement(typeArgument).getSimpleName().toString());
        }
      }
      if (!builderTypeParamNames.equals(typeArguments.build())) {
        errorReporter.reportError(
            "Builder converter method should return "
                + builderTypeElement
                + TypeSimplifier.actualTypeParametersString(builderTypeElement),
            method);
      }
    }
  }
  ImmutableSet<ExecutableElement> builderMethods = methods.build();
  if (builderMethods.size() > 1) {
    errorReporter.reportError(
        "There can be at most one builder converter method", builderMethods.iterator().next());
  }
  return builderMethods;
}
 
Example 9
Source File: BuilderSpec.java    From SimpleWeibo with Apache License 2.0 5 votes vote down vote up
/**
 * Finds any methods in the set that return the builder type. If the builder has type parameters
 * {@code <A, B>}, then the return type of the method must be {@code Builder<A, B>} with
 * the same parameter names. We enforce elsewhere that the names and bounds of the builder
 * parameters must be the same as those of the @RetroWeibo class. Here's a correct example:
 * <pre>
 * {@code @RetroWeibo abstract class Foo<A extends Number, B> {
 *   abstract int someProperty();
 *
 *   abstract Builder<A, B> toBuilder();
 *
 *   interface Builder<A extends Number, B> {...}
 * }}
 * </pre>
 * <p/>
 * <p>We currently impose that there cannot be more than one such method.</p>
 */
ImmutableSet<ExecutableElement> toBuilderMethods(
    Types typeUtils, Set<ExecutableElement> abstractMethods) {

  ImmutableList<String> builderTypeParamNames =
      FluentIterable.from(builderTypeElement.getTypeParameters())
          .transform(SimpleNameFunction.INSTANCE)
          .toList();

  ImmutableSet.Builder<ExecutableElement> methods = ImmutableSet.builder();
  for (ExecutableElement method : abstractMethods) {
    if (builderTypeElement.equals(typeUtils.asElement(method.getReturnType()))) {
      methods.add(method);
      DeclaredType returnType = MoreTypes.asDeclared(method.getReturnType());
      ImmutableList.Builder<String> typeArguments = ImmutableList.builder();
      for (TypeMirror typeArgument : returnType.getTypeArguments()) {
        if (typeArgument.getKind().equals(TypeKind.TYPEVAR)) {
          typeArguments.add(typeUtils.asElement(typeArgument).getSimpleName().toString());
        }
      }
      if (!builderTypeParamNames.equals(typeArguments.build())) {
        errorReporter.reportError(
            "Builder converter method should return "
                + builderTypeElement
                + TypeSimplifier.actualTypeParametersString(builderTypeElement),
            method);
      }
    }
  }
  ImmutableSet<ExecutableElement> builderMethods = methods.build();
  if (builderMethods.size() > 1) {
    errorReporter.reportError(
        "There can be at most one builder converter method", builderMethods.iterator().next());
  }
  return builderMethods;
}
 
Example 10
Source File: RelBuilder.java    From calcite with Apache License 2.0 5 votes vote down vote up
public AggCall sort(Iterable<RexNode> orderKeys) {
  final ImmutableList<RexNode> orderKeyList =
      ImmutableList.copyOf(orderKeys);
  return orderKeyList.equals(this.orderKeys)
      ? this
      : new AggCallImpl(aggFunction, distinct, approximate, ignoreNulls,
          filter, alias, operands, orderKeyList);
}
 
Example 11
Source File: AndroidResourcesTest.java    From bazel with Apache License 2.0 5 votes vote down vote up
private Optional<? extends AndroidResources> assertFilter(
    AndroidResources unfiltered, ImmutableList<Artifact> filteredResources, boolean isDependency)
    throws Exception {

  ImmutableList.Builder<Artifact> filteredDepsBuilder = ImmutableList.builder();

  ResourceFilter fakeFilter =
      ResourceFilter.of(ImmutableSet.copyOf(filteredResources), filteredDepsBuilder::add);

  Optional<? extends AndroidResources> filtered =
      unfiltered.maybeFilter(errorConsumer, fakeFilter, isDependency);

  if (filteredResources.equals(unfiltered.getResources())) {
    // We expect filtering to have been a no-op
    assertThat(filtered.isPresent()).isFalse();
  } else {
    // The resources and their roots should be filtered
    assertThat(filtered.get().getResources())
        .containsExactlyElementsIn(filteredResources)
        .inOrder();
    assertThat(filtered.get().getResourceRoots())
        .containsExactlyElementsIn(getResourceRoots(filteredResources))
        .inOrder();
  }

  if (!isDependency) {
    // The filter should not record any filtered dependencies
    assertThat(filteredDepsBuilder.build()).isEmpty();
  } else {
    // The filtered dependencies should be exactly the list of filtered resources
    assertThat(unfiltered.getResources())
        .containsExactlyElementsIn(
            Iterables.concat(filteredDepsBuilder.build(), filteredResources));
  }

  return filtered;
}
 
Example 12
Source File: RelBuilder.java    From Bats with Apache License 2.0 4 votes vote down vote up
@Override
public AggCall sort(Iterable<RexNode> orderKeys) {
    final ImmutableList<RexNode> orderKeyList = ImmutableList.copyOf(orderKeys);
    return orderKeyList.equals(this.orderKeys) ? this
            : new AggCallImpl(aggFunction, distinct, approximate, filter, alias, operands, orderKeyList);
}
 
Example 13
Source File: LinkageMonitor.java    From cloud-opensource-java with Apache License 2.0 4 votes vote down vote up
/**
 * Returns new problems in the BOM specified by {@code groupId} and {@code artifactId}. This
 * method compares the latest release of the BOM and its snapshot version which uses artifacts in
 * {@link #localArtifacts}.
 */
private ImmutableSet<SymbolProblem> run(String groupId, String artifactId)
    throws RepositoryException, IOException, MavenRepositoryException, ModelBuildingException {
  String latestBomCoordinates =
      RepositoryUtility.findLatestCoordinates(repositorySystem, groupId, artifactId);
  logger.info("BOM Coordinates: " + latestBomCoordinates);
  Bom baseline = Bom.readBom(latestBomCoordinates);
  ImmutableSet<SymbolProblem> problemsInBaseline =
      LinkageChecker.create(baseline, null).findSymbolProblems().keySet();
  Bom snapshot = copyWithSnapshot(repositorySystem, session, baseline, localArtifacts);

  // Comparing coordinates because DefaultArtifact does not override equals
  ImmutableList<String> baselineCoordinates = coordinatesList(baseline.getManagedDependencies());
  ImmutableList<String> snapshotCoordinates = coordinatesList(snapshot.getManagedDependencies());
  if (baselineCoordinates.equals(snapshotCoordinates)) {
    logger.info(
        "Snapshot is same as baseline. Not running comparison.");
    logger.info(
        "Baseline coordinates: " + Joiner.on(";").join(baselineCoordinates));
    return ImmutableSet.of();
  }

  ImmutableList<Artifact> snapshotManagedDependencies = snapshot.getManagedDependencies();
  ClassPathResult classPathResult = (new ClassPathBuilder()).resolve(snapshotManagedDependencies);
  ImmutableList<ClassPathEntry> classpath = classPathResult.getClassPath();
  List<ClassPathEntry> entryPointJars = classpath.subList(0, snapshotManagedDependencies.size());

  ImmutableSetMultimap<SymbolProblem, ClassFile> snapshotSymbolProblems =
      LinkageChecker.create(classpath, ImmutableSet.copyOf(entryPointJars), null)
          .findSymbolProblems();
  ImmutableSet<SymbolProblem> problemsInSnapshot = snapshotSymbolProblems.keySet();

  if (problemsInBaseline.equals(problemsInSnapshot)) {
    logger.info(
        "Snapshot versions have the same " + problemsInBaseline.size() + " errors as baseline");
    return ImmutableSet.of();
  }

  Set<SymbolProblem> fixedProblems = Sets.difference(problemsInBaseline, problemsInSnapshot);
  if (!fixedProblems.isEmpty()) {
    logger.info(messageForFixedErrors(fixedProblems));
  }

  Set<SymbolProblem> newProblems = Sets.difference(problemsInSnapshot, problemsInBaseline);
  if (!newProblems.isEmpty()) {
    logger.severe(
        messageForNewErrors(snapshotSymbolProblems, problemsInBaseline, classPathResult));
  }
  return ImmutableSet.copyOf(newProblems);
}