Java Code Examples for java.util.stream.Stream#noneMatch()

The following examples show how to use java.util.stream.Stream#noneMatch() . 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: StackUtils.java    From healenium-web with Apache License 2.0 5 votes vote down vote up
/**
 *
 * @return
 */
private Predicate<StackTraceElement> redundantPackages() {
    return value -> {
        Stream<String> skippingPackageStream = Stream.of("java.base","sun.reflect", "java.lang", "org.gradle", "org.junit", "java.util", "com.sun", "com.google","jdk.internal","org.openqa");
        return skippingPackageStream.noneMatch(s -> value.getClassName().startsWith(s));
    };
}
 
Example 2
Source File: ServerWorld_onePlayerSleepingMixin.java    From fabric-carpet with MIT License 5 votes vote down vote up
@Redirect(method = "tick", at = @At(
        value = "INVOKE",
        target = "Ljava/util/stream/Stream;noneMatch(Ljava/util/function/Predicate;)Z"
))
private boolean noneMatchSleep(Stream<ServerPlayerEntity> stream, Predicate<ServerPlayerEntity> predicate)
{
    if (CarpetSettings.onePlayerSleeping)
        return stream.anyMatch((p) -> !p.isSpectator() && p.isSleepingLongEnough());
    return stream.noneMatch(predicate);
}
 
Example 3
Source File: MatchRelationshipPartExecutionStep.java    From vertexium with Apache License 2.0 5 votes vote down vote up
private boolean doLabelNamesMatch(VertexiumCypherQueryContext ctx, Edge edge) {
    if (relTypesNames.size() > 0) {
        Stream<String> labelNames = relTypesNames.stream()
            .map(ctx::normalizeLabelName);
        if (labelNames.noneMatch(ln -> edge.getLabel().equals(ln))) {
            return false;
        }
    }
    return true;
}
 
Example 4
Source File: Streams5.java    From java8-tutorial with MIT License 5 votes vote down vote up
private static void test7(List<String> stringCollection) {
    Stream<String> stream = stringCollection
        .stream()
        .filter(s -> s.startsWith("a"));

    stream.anyMatch(s -> true);
    stream.noneMatch(s -> true);
}
 
Example 5
Source File: Streams5.java    From javacore with Creative Commons Attribution Share Alike 4.0 International 4 votes vote down vote up
private static void test7(List<String> stringCollection) {
    Stream<String> stream = stringCollection.stream().filter(s -> s.startsWith("a"));

    stream.anyMatch(s -> true);
    stream.noneMatch(s -> true);
}
 
Example 6
Source File: ExpressionInterpreter.java    From immutables with Apache License 2.0 4 votes vote down vote up
private static Object binaryCall(Call call, Object left, Object right) {
  Preconditions.checkArgument(call.operator().arity() == Operator.Arity.BINARY, "Expected binary call got %s", call);
  final Operator op = call.operator();

  if (op == Operators.EQUAL || op == Operators.NOT_EQUAL) {
    final boolean equals = Objects.equals(left, right);
    return (op == Operators.EQUAL) == equals;
  }

  if (op == Operators.IN || op == Operators.NOT_IN) {
    Preconditions.checkArgument(right instanceof Iterable, "%s is not iterable", left.getClass());
    @SuppressWarnings("unchecked")
    final Iterable<Object> rightValue = (Iterable<Object>) right;
    final Stream<Object> stream = StreamSupport.stream(rightValue.spliterator(), false);
    return op == Operators.IN ? stream.anyMatch(r -> Objects.equals(left, r)) : stream.noneMatch(r -> Objects.equals(left, r));
  }

  if (op == IterableOperators.HAS_SIZE) {
    Preconditions.checkArgument(left instanceof Iterable, "%s is not iterable", left);
    Preconditions.checkArgument(right instanceof Number, "%s is not a number", left);
    final Iterable<?> iter = (Iterable<?>) left;
    final int size = ((Number) right).intValue();
    return Iterables.size(iter) == size;
  }

  if (op == IterableOperators.CONTAINS) {
    Preconditions.checkArgument(left instanceof Iterable, "%s is not iterable", left);
    return Iterables.contains((Iterable<?>) left, right);
  }

  // comparables
  if (ComparableOperators.isComparable(call.operator())) {
    Preconditions.checkArgument(left instanceof Comparable, "%s is not comparable", left);
    @SuppressWarnings("unchecked")
    final Comparable<Object> leftComparable = (Comparable<Object>) left;

    Preconditions.checkArgument(right instanceof Comparable, "%s is not comparable", right);
    @SuppressWarnings("unchecked")
    final Comparable<Object> rightComparable = (Comparable<Object>) right;

    final int compare = leftComparable.compareTo(rightComparable);

    if (op == ComparableOperators.GREATER_THAN) {
      return compare > 0;
    } else if (op == ComparableOperators.GREATER_THAN_OR_EQUAL) {
      return compare >= 0;
    } else if (op == ComparableOperators.LESS_THAN) {
      return compare < 0;
    } else if (op == ComparableOperators.LESS_THAN_OR_EQUAL) {
      return compare <= 0;
    }
  }

  if (op == StringOperators.HAS_LENGTH) {
    Preconditions.checkArgument(left instanceof CharSequence, "%s is not CharSequence", left);
    Preconditions.checkArgument(right instanceof Number, "%s is not Number", right);
    int length = ((Number) right).intValue();
    return left.toString().length() == length;
  }

  if (op == StringOperators.MATCHES) {
    Preconditions.checkArgument(left instanceof CharSequence, "%s is not string (or CharSequence)", left);
    Preconditions.checkArgument(right instanceof Pattern, "%s is not regex pattern", right);
    return ((Pattern) right).asPredicate().test(left.toString());
  }

  if (op == StringOperators.STARTS_WITH || op == StringOperators.ENDS_WITH || op == StringOperators.CONTAINS) {
    Preconditions.checkArgument(left instanceof CharSequence, "%s is not string (or CharSequence)", left);
    Preconditions.checkArgument(right instanceof CharSequence, "%s is not string (or CharSequence)", right);

    if (op == StringOperators.CONTAINS) {
      return left.toString().contains(right.toString());
    }

    return op == StringOperators.STARTS_WITH ? left.toString().startsWith(right.toString()) : left.toString().endsWith(right.toString());
  }

  throw new UnsupportedOperationException("Unsupported binary call " + call);
}
 
Example 7
Source File: CollectionUtils.java    From freecol with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Implementation of none().
 *
 * @param <T> The stream member type.
 * @param stream The {@code Stream} to test.
 * @param predicate The {@code Predicate} to test with.
 * @return True if no member passes the predicate test.
 */
private static <T> boolean none_internal(Stream<T> stream,
                                         Predicate<? super T> predicate) {
    return stream.noneMatch(predicate);
}