Java Code Examples for java.util.function.LongPredicate#test()

The following examples show how to use java.util.function.LongPredicate#test() . 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: LongPipeline.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
@Override
public final LongStream filter(LongPredicate predicate) {
    Objects.requireNonNull(predicate);
    return new StatelessOp<Long>(this, StreamShape.LONG_VALUE,
                                 StreamOpFlag.NOT_SIZED) {
        @Override
        Sink<Long> opWrapSink(int flags, Sink<Long> sink) {
            return new Sink.ChainedLong<Long>(sink) {
                @Override
                public void begin(long size) {
                    downstream.begin(-1);
                }

                @Override
                public void accept(long t) {
                    if (predicate.test(t))
                        downstream.accept(t);
                }
            };
        }
    };
}
 
Example 2
Source File: LongPipeline.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
@Override
public final LongStream filter(LongPredicate predicate) {
    Objects.requireNonNull(predicate);
    return new StatelessOp<Long>(this, StreamShape.LONG_VALUE,
                                 StreamOpFlag.NOT_SIZED) {
        @Override
        Sink<Long> opWrapSink(int flags, Sink<Long> sink) {
            return new Sink.ChainedLong<Long>(sink) {
                @Override
                public void begin(long size) {
                    downstream.begin(-1);
                }

                @Override
                public void accept(long t) {
                    if (predicate.test(t))
                        downstream.accept(t);
                }
            };
        }
    };
}
 
Example 3
Source File: MatchOps.java    From desugar_jdk_libs with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Constructs a quantified predicate matcher for a {@code LongStream}.
 *
 * @param predicate the {@code Predicate} to apply to stream elements
 * @param matchKind the kind of quantified match (all, any, none)
 * @return a {@code TerminalOp} implementing the desired quantified match
 *         criteria
 */
public static TerminalOp<Long, Boolean> makeLong(LongPredicate predicate,
                                                 MatchKind matchKind) {
    Objects.requireNonNull(predicate);
    Objects.requireNonNull(matchKind);
    class MatchSink extends BooleanTerminalSink<Long> implements Sink.OfLong {

        MatchSink() {
            super(matchKind);
        }

        @Override
        public void accept(long t) {
            if (!stop && predicate.test(t) == matchKind.stopOnPredicateMatches) {
                stop = true;
                value = matchKind.shortCircuitResult;
            }
        }
    }

    return new MatchOp<>(StreamShape.LONG_VALUE, matchKind, MatchSink::new);
}
 
Example 4
Source File: LongPipeline.java    From desugar_jdk_libs with GNU General Public License v2.0 6 votes vote down vote up
@Override
public final LongStream filter(LongPredicate predicate) {
    Objects.requireNonNull(predicate);
    return new StatelessOp<Long>(this, StreamShape.LONG_VALUE,
                                 StreamOpFlag.NOT_SIZED) {
        @Override
        Sink<Long> opWrapSink(int flags, Sink<Long> sink) {
            return new Sink.ChainedLong<Long>(sink) {
                @Override
                public void begin(long size) {
                    downstream.begin(-1);
                }

                @Override
                public void accept(long t) {
                    if (predicate.test(t))
                        downstream.accept(t);
                }
            };
        }
    };
}
 
Example 5
Source File: KolobokeLongEntityMap.java    From catnip with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public boolean forEachWhile(LongPredicate predicate) {
    if (predicate == null)
        throw new NullPointerException();
    
    if (KolobokeLongEntityMap.this.isEmpty())
        return true;
    
    boolean terminated = false;
    long free = freeValue;
    long[] keys = set;
    for (int i = (keys.length) - 1; i >= 0; i--) {
        long key;
        if ((key = keys[i]) != free) {
            if (!(predicate.test(key))) {
                terminated = true;
                break;
            }
        }
    }
    return !terminated;
}
 
Example 6
Source File: MatchOps.java    From JDKSourceCode1.8 with MIT License 6 votes vote down vote up
/**
 * Constructs a quantified predicate matcher for a {@code LongStream}.
 *
 * @param predicate the {@code Predicate} to apply to stream elements
 * @param matchKind the kind of quantified match (all, any, none)
 * @return a {@code TerminalOp} implementing the desired quantified match
 *         criteria
 */
public static TerminalOp<Long, Boolean> makeLong(LongPredicate predicate,
                                                 MatchKind matchKind) {
    Objects.requireNonNull(predicate);
    Objects.requireNonNull(matchKind);
    class MatchSink extends BooleanTerminalSink<Long> implements Sink.OfLong {

        MatchSink() {
            super(matchKind);
        }

        @Override
        public void accept(long t) {
            if (!stop && predicate.test(t) == matchKind.stopOnPredicateMatches) {
                stop = true;
                value = matchKind.shortCircuitResult;
            }
        }
    }

    return new MatchOp<>(StreamShape.LONG_VALUE, matchKind, MatchSink::new);
}
 
Example 7
Source File: LongPipeline.java    From JDKSourceCode1.8 with MIT License 6 votes vote down vote up
@Override
public final LongStream filter(LongPredicate predicate) {
    Objects.requireNonNull(predicate);
    return new StatelessOp<Long>(this, StreamShape.LONG_VALUE,
                                 StreamOpFlag.NOT_SIZED) {
        @Override
        Sink<Long> opWrapSink(int flags, Sink<Long> sink) {
            return new Sink.ChainedLong<Long>(sink) {
                @Override
                public void begin(long size) {
                    downstream.begin(-1);
                }

                @Override
                public void accept(long t) {
                    if (predicate.test(t))
                        downstream.accept(t);
                }
            };
        }
    };
}
 
Example 8
Source File: MatchOps.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Constructs a quantified predicate matcher for a {@code LongStream}.
 *
 * @param predicate the {@code Predicate} to apply to stream elements
 * @param matchKind the kind of quantified match (all, any, none)
 * @return a {@code TerminalOp} implementing the desired quantified match
 *         criteria
 */
public static TerminalOp<Long, Boolean> makeLong(LongPredicate predicate,
                                                 MatchKind matchKind) {
    Objects.requireNonNull(predicate);
    Objects.requireNonNull(matchKind);
    class MatchSink extends BooleanTerminalSink<Long> implements Sink.OfLong {

        MatchSink() {
            super(matchKind);
        }

        @Override
        public void accept(long t) {
            if (!stop && predicate.test(t) == matchKind.stopOnPredicateMatches) {
                stop = true;
                value = matchKind.shortCircuitResult;
            }
        }
    }

    return new MatchOp<>(StreamShape.LONG_VALUE, matchKind, MatchSink::new);
}
 
Example 9
Source File: TestOrcPageSourceFactory.java    From presto with Apache License 2.0 6 votes vote down vote up
private static void assertRead(Set<NationColumn> columns, OptionalLong nationKeyPredicate, Optional<AcidInfo> acidInfo, LongPredicate deletedRows)
        throws Exception
{
    TupleDomain<HiveColumnHandle> tupleDomain = TupleDomain.all();
    if (nationKeyPredicate.isPresent()) {
        tupleDomain = TupleDomain.withColumnDomains(ImmutableMap.of(toHiveColumnHandle(NATION_KEY), Domain.singleValue(BIGINT, nationKeyPredicate.getAsLong())));
    }

    List<Nation> actual = readFile(columns, tupleDomain, acidInfo);

    List<Nation> expected = new ArrayList<>();
    for (Nation nation : ImmutableList.copyOf(new NationGenerator().iterator())) {
        if (nationKeyPredicate.isPresent() && nationKeyPredicate.getAsLong() != nation.getNationKey()) {
            continue;
        }
        if (deletedRows.test(nation.getNationKey())) {
            continue;
        }
        expected.addAll(nCopies(1000, nation));
    }

    assertEqualsByColumns(columns, actual, expected);
}
 
Example 10
Source File: MatchOps.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Constructs a quantified predicate matcher for a {@code LongStream}.
 *
 * @param predicate the {@code Predicate} to apply to stream elements
 * @param matchKind the kind of quantified match (all, any, none)
 * @return a {@code TerminalOp} implementing the desired quantified match
 *         criteria
 */
public static TerminalOp<Long, Boolean> makeLong(LongPredicate predicate,
                                                 MatchKind matchKind) {
    Objects.requireNonNull(predicate);
    Objects.requireNonNull(matchKind);
    class MatchSink extends BooleanTerminalSink<Long> implements Sink.OfLong {

        MatchSink() {
            super(matchKind);
        }

        @Override
        public void accept(long t) {
            if (!stop && predicate.test(t) == matchKind.stopOnPredicateMatches) {
                stop = true;
                value = matchKind.shortCircuitResult;
            }
        }
    }

    return new MatchOp<>(StreamShape.LONG_VALUE, matchKind, MatchSink::new);
}
 
Example 11
Source File: LongPipeline.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
@Override
public final LongStream filter(LongPredicate predicate) {
    Objects.requireNonNull(predicate);
    return new StatelessOp<Long>(this, StreamShape.LONG_VALUE,
                                 StreamOpFlag.NOT_SIZED) {
        @Override
        Sink<Long> opWrapSink(int flags, Sink<Long> sink) {
            return new Sink.ChainedLong<Long>(sink) {
                @Override
                public void begin(long size) {
                    downstream.begin(-1);
                }

                @Override
                public void accept(long t) {
                    if (predicate.test(t))
                        downstream.accept(t);
                }
            };
        }
    };
}
 
Example 12
Source File: MatchOps.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Constructs a quantified predicate matcher for a {@code LongStream}.
 *
 * @param predicate the {@code Predicate} to apply to stream elements
 * @param matchKind the kind of quantified match (all, any, none)
 * @return a {@code TerminalOp} implementing the desired quantified match
 *         criteria
 */
public static TerminalOp<Long, Boolean> makeLong(LongPredicate predicate,
                                                 MatchKind matchKind) {
    Objects.requireNonNull(predicate);
    Objects.requireNonNull(matchKind);
    class MatchSink extends BooleanTerminalSink<Long> implements Sink.OfLong {

        MatchSink() {
            super(matchKind);
        }

        @Override
        public void accept(long t) {
            if (!stop && predicate.test(t) == matchKind.stopOnPredicateMatches) {
                stop = true;
                value = matchKind.shortCircuitResult;
            }
        }
    }

    return new MatchOp<>(StreamShape.LONG_VALUE, matchKind, MatchSink::new);
}
 
Example 13
Source File: LongPipeline.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
@Override
public final LongStream filter(LongPredicate predicate) {
    Objects.requireNonNull(predicate);
    return new StatelessOp<Long>(this, StreamShape.LONG_VALUE,
                                 StreamOpFlag.NOT_SIZED) {
        @Override
        Sink<Long> opWrapSink(int flags, Sink<Long> sink) {
            return new Sink.ChainedLong<Long>(sink) {
                @Override
                public void begin(long size) {
                    downstream.begin(-1);
                }

                @Override
                public void accept(long t) {
                    if (predicate.test(t))
                        downstream.accept(t);
                }
            };
        }
    };
}
 
Example 14
Source File: TaskLocalStateStoreImpl.java    From flink with Apache License 2.0 6 votes vote down vote up
/**
 * Pruning the useless checkpoints, it should be called only when holding the {@link #lock}.
 */
private void pruneCheckpoints(LongPredicate pruningChecker, boolean breakOnceCheckerFalse) {

	final List<Map.Entry<Long, TaskStateSnapshot>> toRemove = new ArrayList<>();

	synchronized (lock) {

		Iterator<Map.Entry<Long, TaskStateSnapshot>> entryIterator =
			storedTaskStateByCheckpointID.entrySet().iterator();

		while (entryIterator.hasNext()) {

			Map.Entry<Long, TaskStateSnapshot> snapshotEntry = entryIterator.next();
			long entryCheckpointId = snapshotEntry.getKey();

			if (pruningChecker.test(entryCheckpointId)) {
				toRemove.add(snapshotEntry);
				entryIterator.remove();
			} else if (breakOnceCheckerFalse) {
				break;
			}
		}
	}

	asyncDiscardLocalStateForCollection(toRemove);
}
 
Example 15
Source File: MatchOps.java    From jdk1.8-source-analysis with Apache License 2.0 6 votes vote down vote up
/**
 * Constructs a quantified predicate matcher for a {@code LongStream}.
 *
 * @param predicate the {@code Predicate} to apply to stream elements
 * @param matchKind the kind of quantified match (all, any, none)
 * @return a {@code TerminalOp} implementing the desired quantified match
 *         criteria
 */
public static TerminalOp<Long, Boolean> makeLong(LongPredicate predicate,
                                                 MatchKind matchKind) {
    Objects.requireNonNull(predicate);
    Objects.requireNonNull(matchKind);
    class MatchSink extends BooleanTerminalSink<Long> implements Sink.OfLong {

        MatchSink() {
            super(matchKind);
        }

        @Override
        public void accept(long t) {
            if (!stop && predicate.test(t) == matchKind.stopOnPredicateMatches) {
                stop = true;
                value = matchKind.shortCircuitResult;
            }
        }
    }

    return new MatchOp<>(StreamShape.LONG_VALUE, matchKind, MatchSink::new);
}
 
Example 16
Source File: LongPipeline.java    From jdk1.8-source-analysis with Apache License 2.0 6 votes vote down vote up
@Override
public final LongStream filter(LongPredicate predicate) {
    Objects.requireNonNull(predicate);
    return new StatelessOp<Long>(this, StreamShape.LONG_VALUE,
                                 StreamOpFlag.NOT_SIZED) {
        @Override
        Sink<Long> opWrapSink(int flags, Sink<Long> sink) {
            return new Sink.ChainedLong<Long>(sink) {
                @Override
                public void begin(long size) {
                    downstream.begin(-1);
                }

                @Override
                public void accept(long t) {
                    if (predicate.test(t))
                        downstream.accept(t);
                }
            };
        }
    };
}
 
Example 17
Source File: MatchOps.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Constructs a quantified predicate matcher for a {@code LongStream}.
 *
 * @param predicate the {@code Predicate} to apply to stream elements
 * @param matchKind the kind of quantified match (all, any, none)
 * @return a {@code TerminalOp} implementing the desired quantified match
 *         criteria
 */
public static TerminalOp<Long, Boolean> makeLong(LongPredicate predicate,
                                                 MatchKind matchKind) {
    Objects.requireNonNull(predicate);
    Objects.requireNonNull(matchKind);
    class MatchSink extends BooleanTerminalSink<Long> implements Sink.OfLong {

        MatchSink() {
            super(matchKind);
        }

        @Override
        public void accept(long t) {
            if (!stop && predicate.test(t) == matchKind.stopOnPredicateMatches) {
                stop = true;
                value = matchKind.shortCircuitResult;
            }
        }
    }

    return new MatchOp<>(StreamShape.LONG_VALUE, matchKind, MatchSink::new);
}
 
Example 18
Source File: FastCollectionsUtils.java    From fastjgame with Apache License 2.0 6 votes vote down vote up
/**
 * 移除map中符合条件的元素,并对删除的元素执行后续的操作。
 *
 * @param collection 必须是可修改的集合
 * @param predicate  过滤条件,为真的删除
 * @param then       元素删除之后执行的逻辑
 * @return 删除的元素数量
 */
public static int removeIfAndThen(LongCollection collection, LongPredicate predicate, LongConsumer then) {
    if (collection.size() == 0) {
        return 0;
    }
    final LongIterator itr = collection.iterator();
    long value;
    int removeNum = 0;
    while (itr.hasNext()) {
        value = itr.nextLong();
        if (predicate.test(value)) {
            itr.remove();
            removeNum++;
            then.accept(value);
        }
    }
    return removeNum;
}
 
Example 19
Source File: VerifyHelper.java    From Launcher with GNU General Public License v3.0 4 votes vote down vote up
public static long verifyLong(long l, LongPredicate predicate, String error) {
    if (predicate.test(l))
        return l;
    throw new IllegalArgumentException(error);
}
 
Example 20
Source File: KolobokeLongEntityMap.java    From catnip with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public boolean removeIf(LongPredicate filter) {
    if (filter == null)
        throw new NullPointerException();
    
    if (KolobokeLongEntityMap.this.isEmpty())
        return false;
    
    boolean changed = false;
    long free = freeValue;
    long[] keys = set;
    int capacityMask = (keys.length) - 1;
    int firstDelayedRemoved = -1;
    long delayedRemoved = 0L;
    T[] vals = values;
    for (int i = (keys.length) - 1; i >= 0; i--) {
        long key;
        if ((key = keys[i]) != free) {
            if (filter.test(key)) {
                closeDeletion : if (firstDelayedRemoved < 0) {
                    int indexToRemove = i;
                    int indexToShift = indexToRemove;
                    int shiftDistance = 1;
                    while (true) {
                        indexToShift = (indexToShift - 1) & capacityMask;
                        long keyToShift;
                        if ((keyToShift = keys[indexToShift]) == free) {
                            break;
                        }
                        if ((((LHash.SeparateKVLongKeyMixing.mix(keyToShift)) - indexToShift) & capacityMask) >= shiftDistance) {
                            if (indexToShift > indexToRemove) {
                                firstDelayedRemoved = i;
                                delayedRemoved = key;
                                keys[indexToRemove] = key;
                                break closeDeletion;
                            }
                            if (indexToRemove == i) {
                                i++;
                            }
                            keys[indexToRemove] = keyToShift;
                            vals[indexToRemove] = vals[indexToShift];
                            indexToRemove = indexToShift;
                            shiftDistance = 1;
                        } else {
                            shiftDistance++;
                            if (indexToShift == (1 + i)) {
                                throw new ConcurrentModificationException();
                            }
                        }
                    }
                    keys[indexToRemove] = free;
                    vals[indexToRemove] = null;
                    postRemoveHook();
                } else {
                    keys[i] = delayedRemoved;
                }
                changed = true;
            }
        }
    }
    if (firstDelayedRemoved >= 0) {
        closeDelayedRemoved(firstDelayedRemoved, delayedRemoved);
    }
    return changed;
}