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

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

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

Predicate.or介绍

[英]Returns a composed predicate that represents a short-circuiting logical OR of this predicate and another. When evaluating the composed predicate, if this predicate is true, then the otherpredicate is not evaluated.

Any exceptions thrown during evaluation of either predicate are relayed to the caller; if evaluation of this predicate throws an exception, the other predicate will not be evaluated.
[中]返回一个组合谓词,该谓词表示该谓词和另一个谓词的短路逻辑OR。在计算组合谓词时,如果该谓词为true,则不计算otherpredicate。
在对任一谓词求值期间抛出的任何异常都会转发给调用方;如果对该谓词的求值引发异常,则不会对另一个谓词求值。

代码示例

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

/**
 * Include the tables that the given predicate tests as true for.
 * Tables previously included will still be included.
 * @param tables the tables to be included.
 * @return this
 */
public Builder includeTables(Predicate<TableId> tables) {
  this.tableFilter = this.tableFilter.or(tables);
  return this;
}

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

/**
 * Include all the databases that the given predicate tests as true for.
 * All databases previously included will still be included.
 * @param databases the databases to be included
 * @return
 */
public Builder includeDatabases(Predicate<String> databases) {
  this.dbFilter = this.dbFilter.or(databases);
  return this;
}

代码示例来源:origin: spring-projects/spring-framework

@Override
public Predicate<T> or(Predicate<? super T> other) {
  return this.delegate.or(other);
}

代码示例来源:origin: spring-projects/spring-framework

@Override
public Predicate<T> or(Predicate<? super T> other) {
  return this.delegate.or(other);
}

代码示例来源:origin: spring-cloud/spring-cloud-gateway

public Builder or(Predicate<ServerWebExchange> predicate) {
  Assert.notNull(this.predicate, "can not call or() on null predicate");
  this.predicate = this.predicate.or(predicate);
  return this;
}

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

public static boolean containsType(Type type, Predicate<Type> predicate, Predicate<Type>... orPredicates)
  {
    for (Predicate<Type> orPredicate : orPredicates) {
      predicate = predicate.or(orPredicate);
    }
    if (predicate.test(type)) {
      return true;
    }

    return type.getTypeParameters().stream().anyMatch(predicate);
  }
}

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

public static <T> Predicate<T> isInstanceOfAny(Class... classes)
  {
    Predicate<T> predicate = alwaysFalse();
    for (Class clazz : classes) {
      predicate = predicate.or(clazz::isInstance);
    }
    return predicate;
  }
}

代码示例来源:origin: KronicDeth/intellij-elixir

/**
 * Wehther the decompiler accepts the {@code macroNameArity}.
 *
 * @return {@code true} if {@link #append(StringBuilder, org.elixir_lang.beam.MacroNameArity)} should be called with
 *   {@code macroNameArity}.
 */
@Override
public boolean accept(@NotNull org.elixir_lang.beam.MacroNameArity macroNameArity) {
  return BARE_ATOM_PREDICATE.or(NOT_IDENTIFIER_OR_PREFIX_OPERATOR_PREDICATE).test(macroNameArity.name);
}

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

private Predicate<Throwable> getRecordingPredicate() {
  return buildRecordExceptionsPredicate()
      .map(predicate -> recordFailurePredicate != null ? predicate.or(recordFailurePredicate) : predicate)
      .orElseGet(() -> recordFailurePredicate != null ? recordFailurePredicate : DEFAULT_RECORD_FAILURE_PREDICATE);
}

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

private Predicate<Throwable> getRetryPredicate() {
  return buildRetryExceptionsPredicate()
      .map(predicate -> retryExceptionPredicate != null ? predicate.or(retryExceptionPredicate) : predicate)
      .orElseGet(() -> retryExceptionPredicate != null ? retryExceptionPredicate : DEFAULT_RECORD_FAILURE_PREDICATE);
}

代码示例来源:origin: twosigma/beakerx

public void setBase(List<Object> base) {
 Predicate<Object> number = o -> o instanceof Number;
 Predicate<Object> listOfNumber = o -> o instanceof List<?> &&
   ((List<?>)o).stream().allMatch(number);
 if (base.stream().allMatch(number.or(listOfNumber))) {
  setBases(base);
 } else {
  throw new IllegalArgumentException("List of bases must consist of Numbers or Lists of Numbers");
 }
}

代码示例来源:origin: jooby-project/jooby

static Type messageType(final Class handler) {
 return Arrays.asList(handler.getGenericInterfaces())
   .stream()
   .filter(rawTypeIs(WebSocket.Handler.class).or(rawTypeIs(WebSocket.OnMessage.class)))
   .findFirst()
   .filter(ParameterizedType.class::isInstance)
   .map(it -> ((ParameterizedType) it).getActualTypeArguments()[0])
   .orElseThrow(() -> new IllegalArgumentException(
     "Can't extract message type from: " + handler.getName()));
}

代码示例来源:origin: apache/flink

private static Predicate<Throwable> isConnectionProblemOrServiceUnavailable() {
  return isConnectionProblemException().or(isServiceUnavailable());
}

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

private static Predicate<? super Throwable> createAbortedExecutionPredicate() {
  Predicate<Throwable> otaPredicate = TestAbortedException.class::isInstance;
  // Additionally support JUnit 4's AssumptionViolatedException?
  Class<?> clazz = ReflectionUtils.tryToLoadClass(
    "org.junit.internal.AssumptionViolatedException").toOptional().orElse(null);
  if (clazz != null) {
    return otaPredicate.or(clazz::isInstance);
  }
  // Else just OTA's TestAbortedException
  return otaPredicate;
}

代码示例来源:origin: jooby-project/jooby

public static Predicate<MethodInsnNode> joobyRun(final ClassLoader loader) {
 return call(loader, "org.jooby.JoobyKt", "run", "kotlin.jvm.functions.Function0",
   String.class.getName() + "[]").or(
   call(loader, "org.jooby.Jooby", "run", Supplier.class, String.class.getName() + "[]"));
}

代码示例来源:origin: jooby-project/jooby

private List<Object> kotlinLambda(final ClassLoader loader, final ClassNode owner) {
 List<Object> result = new ArrayList<>();
 log.debug("visiting lambda class: {}", owner.name);
 List<MethodNode> methods = owner.methods;
 methods.stream()
   .filter(method("invoke", "org.jooby.Jooby")
     .or(method("invoke", "org.jooby.Kooby")))
   .findFirst()
   .ifPresent(method -> {
    log.debug("  invoke: {}", method.desc);
    result.addAll(kotlinLambda(loader, owner, method));
   });
 return result;
}

代码示例来源:origin: jooby-project/jooby

@SuppressWarnings({"rawtypes", "unchecked"})
public static Predicate<Path> noneOf(final String... names) {
 Predicate predicate = fname(names[0]);
 for (int i = 1; i < names.length; i++) {
  predicate = predicate.or(fname(names[i]));
 }
 return predicate.negate();
}

代码示例来源: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: jooby-project/jooby

private static List<Signature> params() {
 Predicate<Method> args = argument(String.class)
   .or(argument(String.class, String[].class))
   .or(argument(Class.class));
 List<Signature> signatures = signatures(Request.class, m -> {
  String name = m.getName();
  switch (name) {
   case "param":
   case "header":
   case "file":
   case "files":
   case "params":
   case "form":
    return args.test(m);
   case "body":
    return m.getParameterCount() == 0 || args.test(m);
  }
  return false;
 });
 return signatures;
}

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

private AuthenticationConfiguration(final AuthenticationConfiguration original, final AuthenticationConfiguration other) {
  this.capturedAccessContext = getOrDefault(other.capturedAccessContext, original.capturedAccessContext);
  this.principal = other.principal instanceof AnonymousPrincipal ? original.principal : other.principal;
  this.setHost = getOrDefault(other.setHost, original.setHost);
  this.setProtocol = getOrDefault(other.setProtocol, original.setProtocol);
  this.setRealm = getOrDefault(other.setRealm, original.setRealm);
  this.setAuthzPrincipal = getOrDefault(other.setAuthzPrincipal, original.setAuthzPrincipal);
  this.authenticationNameForwardSecurityDomain = getOrDefault(other.authenticationNameForwardSecurityDomain, original.authenticationNameForwardSecurityDomain);
  this.authenticationCredentialsForwardSecurityDomain = getOrDefault(other.authenticationCredentialsForwardSecurityDomain, original.authenticationCredentialsForwardSecurityDomain);
  this.authorizationNameForwardSecurityDomain = getOrDefault(other.authorizationNameForwardSecurityDomain, original.authorizationNameForwardSecurityDomain);
  this.userCallbackHandler = getOrDefault(other.userCallbackHandler, original.userCallbackHandler);
  this.userCallbackKinds = getOrDefault(other.userCallbackKinds, original.userCallbackKinds).clone();
  this.credentialSource = other.credentialSource == IdentityCredentials.NONE ? original.credentialSource : other.credentialSource;
  this.setPort = getOrDefault(other.setPort, original.setPort);
  this.providerSupplier = getOrDefault(other.providerSupplier, original.providerSupplier);
  this.keyManagerFactory = getOrDefault(other.keyManagerFactory, original.keyManagerFactory);
  this.saslMechanismSelector = getOrDefault(other.saslMechanismSelector, original.saslMechanismSelector);
  this.principalRewriter = getOrDefault(other.principalRewriter, original.principalRewriter);
  this.saslClientFactorySupplier = getOrDefault(other.saslClientFactorySupplier, original.saslClientFactorySupplier);
  this.parameterSpecs = getOrDefault(other.parameterSpecs, original.parameterSpecs);
  this.trustManagerFactory = getOrDefault(other.trustManagerFactory, original.trustManagerFactory);
  this.saslMechanismProperties = getOrDefault(other.saslMechanismProperties, original.saslMechanismProperties);
  this.callbackIntercept = other.callbackIntercept == null ? original.callbackIntercept : original.callbackIntercept == null ? other.callbackIntercept : other.callbackIntercept.or(original.callbackIntercept);
  this.saslProtocol =  getOrDefault(other.saslProtocol, original.saslProtocol);
  sanitazeOnMutation(SET_USER_CBH);
}

相关文章