java.util.function.Predicate.isEqual()方法的使用及代码示例

x33g5p2x  于2022-01-25 转载在 其他  
字(8.0k)|赞(0)|评价(0)|浏览(294)

本文整理了Java中java.util.function.Predicate.isEqual()方法的一些代码示例,展示了Predicate.isEqual()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Predicate.isEqual()方法的具体详情如下:
包路径:java.util.function.Predicate
类名称:Predicate
方法名:isEqual

Predicate.isEqual介绍

[英]Returns a predicate that tests if two arguments are equal according to Objects#equals(Object,Object).
[中]返回一个谓词,根据Objects#equals(Object,Object)测试两个参数是否相等。

代码示例

代码示例来源:origin: org.apache.ant/ant

/**
 * Does the tokenized pattern contain the given string?
 *
 * @param pat String
 * @return boolean
 */
public boolean containsPattern(String pat) {
  return Stream.of(tokenizedPattern).anyMatch(Predicate.isEqual(pat));
}

代码示例来源:origin: org.apache.ant/ant

/**
 *  Find out whether one particular include pattern is more powerful
 *  than all the excludes.
 *  Note:  the power comparison is based on the length of the include pattern
 *  and of the exclude patterns without the wildcards.
 *  Ideally the comparison should be done based on the depth
 *  of the match; that is to say how many file separators have been matched
 *  before the first ** or the end of the pattern.
 *
 *  IMPORTANT : this function should return false "with care".
 *
 *  @param name the relative path to test.
 *  @return true if there is no exclude pattern more powerful than
 *  this include pattern.
 *  @since Ant 1.6
 */
private boolean isMorePowerfulThanExcludes(final String name) {
  final String soughtexclude = name + File.separatorChar + SelectorUtils.DEEP_TREE_MATCH;
  return Stream.of(excludePatterns).map(Object::toString)
    .noneMatch(Predicate.isEqual(soughtexclude));
}

代码示例来源:origin: google/guava

@CollectionFeature.Require({SUPPORTS_ITERATOR_REMOVE, FAILS_FAST_ON_CONCURRENT_MODIFICATION})
@CollectionSize.Require(SEVERAL)
public void testRemoveIfSomeMatchesConcurrentWithIteration() {
 try {
  Iterator<E> iterator = collection.iterator();
  assertTrue(collection.removeIf(Predicate.isEqual(samples.e0())));
  iterator.next();
  fail("Expected ConcurrentModificationException");
 } catch (ConcurrentModificationException expected) {
  // success
 }
}

代码示例来源:origin: org.apache.ant/ant

/**
   * A method to test if an object responds to a given
   * message (method call)
   * @param o the object
   * @param methodName the method to check for
   * @return true if the object has the method.
   * @throws BuildException if there is a problem.
   */
  public static boolean respondsTo(Object o, String methodName)
    throws BuildException {
    try {
      return Stream.of(o.getClass().getMethods()).map(Method::getName)
        .anyMatch(Predicate.isEqual(methodName));
    } catch (Exception t) {
      throw toBuildException(t);
    }
  }
}

代码示例来源:origin: org.junit.vintage/junit-vintage-engine

void pruneDescriptorsForObsoleteDescriptions(List<Description> newSiblingDescriptions) {
  Optional<Description> newDescription = newSiblingDescriptions.stream().filter(isEqual(description)).findAny();
  if (newDescription.isPresent()) {
    List<Description> newChildren = newDescription.get().getChildren();
    new ArrayList<>(children).stream().map(VintageTestDescriptor.class::cast).forEach(
      childDescriptor -> childDescriptor.pruneDescriptorsForObsoleteDescriptions(newChildren));
  }
  else {
    super.removeFromHierarchy();
  }
}

代码示例来源:origin: atomix/atomix

@Override
public CompletableFuture<Boolean> containsValue(byte[] value) {
 return getProxyClient().applyAll(service -> service.containsValue(value))
   .thenApply(results -> results.filter(Predicate.isEqual(true)).findFirst().orElse(false));
}

代码示例来源:origin: org.apache.ant/ant

/**
 * Find the source file for a given class
 *
 * @param classname the classname in slash format.
 * @param sourceFileKnownToExist if not null, a file already known to exist
 *                               (saves call to .exists())
 */
private File findSourceFile(String classname, File sourceFileKnownToExist) {
  String sourceFilename;
  int innerIndex = classname.indexOf('$');
  if (innerIndex != -1) {
    sourceFilename = classname.substring(0, innerIndex) + ".java";
  } else {
    sourceFilename = classname + ".java";
  }
  // search the various source path entries
  return directories(srcPath)
    .map(d -> new File(d, sourceFilename)).filter(Predicate
      .<File> isEqual(sourceFileKnownToExist).or(File::exists))
    .findFirst().orElse(null);
}

代码示例来源:origin: atomix/atomix

@Override
public CompletableFuture<Boolean> isEmpty() {
 return getProxyClient().applyAll(service -> service.isEmpty())
   .thenApply(results -> results.allMatch(Predicate.isEqual(true)));
}

代码示例来源:origin: atomix/atomix

@Override
public CompletableFuture<Boolean> isEmpty() {
 return getProxyClient().applyAll(service -> service.isEmpty())
   .thenApply(results -> results.allMatch(Predicate.isEqual(true)));
}

代码示例来源:origin: atomix/atomix

@Override
public CompletableFuture<Boolean> containsValue(byte[] value) {
 return getProxyClient().applyAll(service -> service.containsValue(value))
   .thenApply(results -> results.anyMatch(Predicate.isEqual(true)));
}

代码示例来源:origin: google/guava

@CollectionFeature.Require(SUPPORTS_ITERATOR_REMOVE)
@CollectionSize.Require(absent = ZERO)
public void testRemoveIf_sometimesTrue() {
 assertTrue(
   "removeIf(isEqual(present)) should return true",
   collection.removeIf(Predicate.isEqual(samples.e0())));
 expectMissing(samples.e0());
}

代码示例来源:origin: neo4j/neo4j

static <KEY> boolean contains( List<KEY> expectedKeys, KEY key, Comparator<KEY> comparator )
{
  return expectedKeys.stream()
      .map( bind( comparator::compare, key ) )
      .anyMatch( Predicate.isEqual( 0 ) );
}

代码示例来源:origin: neo4j/neo4j

/**
 * Add an expected response header. If the heading is missing in the
 * response the test will fail. The header and its value are also included
 * in the documentation.
 *
 * @param expectedHeaderField the expected header
 * @param expectedValue the expected header value
 */
public RESTRequestGenerator expectedHeader( final String expectedHeaderField, String expectedValue )
{
  this.expectedHeaderFields.add( Pair.of(expectedHeaderField, Predicate.isEqual( expectedValue )) );
  return this;
}

代码示例来源:origin: org.junit.vintage/junit-vintage-engine

private static MethodSource toMethodSource(Class<?> testClass, String methodName) {
  if (methodName.contains("[") && methodName.endsWith("]")) {
    // special case for parameterized tests
    return toMethodSource(testClass, methodName.substring(0, methodName.indexOf("[")));
  }
  else {
    List<Method> methods = findMethods(testClass, where(Method::getName, isEqual(methodName)));
    return (methods.size() == 1) ? MethodSource.from(testClass, getOnlyElement(methods)) : null;
  }
}

代码示例来源:origin: facebook/litho

.filter(Predicate.isEqual(null).negate())
.collect(Collectors.toList());

代码示例来源:origin: prestodb/presto

match.getSchedulingPolicy().ifPresent(group::setSchedulingPolicy);
match.getSchedulingWeight().ifPresent(group::setSchedulingWeight);
match.getJmxExport().filter(isEqual(group.getJmxExport()).negate()).ifPresent(group::setJmxExport);
match.getSoftCpuLimit().ifPresent(group::setSoftCpuLimit);
match.getHardCpuLimit().ifPresent(group::setHardCpuLimit);

代码示例来源:origin: google/bundletool

/** Returns whether the given namespace {@code prefix} is used currently in the scope. */
private boolean isNamespacePrefixInScope(String prefix) {
 return namespaceUriToPrefix.values().stream()
   .flatMap(queue -> Streams.stream(queue.iterator()))
   .anyMatch(Predicate.isEqual(prefix));
}

代码示例来源:origin: google/bundletool

@Override
public boolean matchesTargeting(ScreenDensityTargeting targeting) {
 ImmutableList<ScreenDensity> allDensities =
   ImmutableList.<ScreenDensity>builder()
     .addAll(targeting.getValueList())
     .addAll(targeting.getAlternativesList())
     .build();
 if (allDensities.isEmpty()) {
  return true;
 }
 int bestMatchingDensity =
   new ScreenDensitySelector()
     .selectBestDensity(
       Iterables.transform(allDensities, ResourcesUtils::convertToDpi),
       getDeviceSpec().getScreenDensity());
 return targeting
   .getValueList()
   .stream()
   .map(ResourcesUtils::convertToDpi)
   .anyMatch(isEqual(bestMatchingDensity));
}

代码示例来源:origin: google/bundletool

public void withStringValue(String value) {
 if (actual()
   .getConfigValueList()
   .stream()
   .map(configValue -> configValue.getValue().getItem().getStr().getValue())
   .noneMatch(isEqual(value))) {
  fail("does not contain resource with string value '%s'", value);
 }
}

代码示例来源:origin: google/bundletool

public void withFileReference(String resFilePath) {
  if (actual()
    .getConfigValueList()
    .stream()
    .map(configValue -> configValue.getValue().getItem().getFile().getPath())
    .noneMatch(isEqual(resFilePath))) {
   fail("does not contain resource with file pointing to path '%s'", resFilePath);
  }
 }
}

相关文章