java.util.function.LongPredicate Java Examples

The following examples show how to use java.util.function.LongPredicate. 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: 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 #2
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 #3
Source File: TaskLocalStateStoreImpl.java    From Flink-CEPplus 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 #4
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 #5
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 #6
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 #7
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 #8
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 #9
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 #10
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 #11
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 #12
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 #13
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 #14
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 #15
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 #16
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 #17
Source File: MatchOpTest.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
@Test(dataProvider = "LongStreamTestData", dataProviderClass = LongStreamTestDataProvider.class)
public void testLongStream(String name, TestData.OfLong data) {
    for (LongPredicate p : LONG_PREDICATES) {
        setContext("p", p);
        for (Kind kind : Kind.values()) {
            setContext("kind", kind);
            exerciseTerminalOps(data, longKinds.get(kind).apply(p));
            exerciseTerminalOps(data, s -> s.filter(lpFalse), longKinds.get(kind).apply(p));
            exerciseTerminalOps(data, s -> s.filter(lpEven), longKinds.get(kind).apply(p));
        }
    }
}
 
Example #18
Source File: MatchOpTest.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
@Test(dataProvider = "LongStreamTestData", dataProviderClass = LongStreamTestDataProvider.class)
public void testLongStream(String name, TestData.OfLong data) {
    for (LongPredicate p : LONG_PREDICATES) {
        setContext("p", p);
        for (Kind kind : Kind.values()) {
            setContext("kind", kind);
            exerciseTerminalOps(data, longKinds.get(kind).apply(p));
            exerciseTerminalOps(data, s -> s.filter(lpFalse), longKinds.get(kind).apply(p));
            exerciseTerminalOps(data, s -> s.filter(lpEven), longKinds.get(kind).apply(p));
        }
    }
}
 
Example #19
Source File: IdSelector.java    From paintera with GNU General Public License v2.0 5 votes vote down vote up
public IdSelector(
		final DataSource<? extends IntegerType<?>, ?> source,
		final SelectedIds selectedIds,
		final ViewerPanelFX viewer,
		final LongPredicate foregroundCheck)
{
	super();
	this.source = source;
	this.selectedIds = selectedIds;
	this.viewer = viewer;
	this.foregroundCheck = foregroundCheck;
}
 
Example #20
Source File: MatchOpTest.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
private void assertLongPredicates(Supplier<LongStream> source, Kind kind, LongPredicate[] predicates, boolean... answers) {
    for (int i = 0; i < predicates.length; i++) {
        setContext("i", i);
        boolean match = longKinds.get(kind).apply(predicates[i]).apply(source.get());
        assertEquals(answers[i], match, kind.toString() + predicates[i].toString());
    }
}
 
Example #21
Source File: TaskLocalStateStoreImpl.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public void pruneMatchingCheckpoints(@Nonnull LongPredicate matcher) {

	pruneCheckpoints(
		matcher,
		false);
}
 
Example #22
Source File: MatchOpTest.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
@Test(dataProvider = "LongStreamTestData", dataProviderClass = LongStreamTestDataProvider.class)
public void testLongStream(String name, TestData.OfLong data) {
    for (LongPredicate p : LONG_PREDICATES) {
        setContext("p", p);
        for (Kind kind : Kind.values()) {
            setContext("kind", kind);
            exerciseTerminalOps(data, longKinds.get(kind).apply(p));
            exerciseTerminalOps(data, s -> s.filter(lpFalse), longKinds.get(kind).apply(p));
            exerciseTerminalOps(data, s -> s.filter(lpEven), longKinds.get(kind).apply(p));
        }
    }
}
 
Example #23
Source File: MatchOpTest.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
private void assertLongPredicates(Supplier<LongStream> source, Kind kind, LongPredicate[] predicates, boolean... answers) {
    for (int i = 0; i < predicates.length; i++) {
        setContext("i", i);
        boolean match = longKinds.get(kind).apply(predicates[i]).apply(source.get());
        assertEquals(answers[i], match, kind.toString() + predicates[i].toString());
    }
}
 
Example #24
Source File: MatchOpTest.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
@Test(dataProvider = "LongStreamTestData", dataProviderClass = LongStreamTestDataProvider.class)
public void testLongStream(String name, TestData.OfLong data) {
    for (LongPredicate p : LONG_PREDICATES) {
        setContext("p", p);
        for (Kind kind : Kind.values()) {
            setContext("kind", kind);
            exerciseTerminalOps(data, longKinds.get(kind).apply(p));
            exerciseTerminalOps(data, s -> s.filter(lpFalse), longKinds.get(kind).apply(p));
            exerciseTerminalOps(data, s -> s.filter(lpEven), longKinds.get(kind).apply(p));
        }
    }
}
 
Example #25
Source File: MatchOpTest.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
private void assertLongPredicates(Supplier<LongStream> source, Kind kind, LongPredicate[] predicates, boolean... answers) {
    for (int i = 0; i < predicates.length; i++) {
        setContext("i", i);
        boolean match = longKinds.get(kind).apply(predicates[i]).apply(source.get());
        assertEquals(answers[i], match, kind.toString() + predicates[i].toString());
    }
}
 
Example #26
Source File: TaskLocalStateStoreImpl.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Override
public void pruneMatchingCheckpoints(@Nonnull LongPredicate matcher) {

	pruneCheckpoints(
		matcher,
		false);
}
 
Example #27
Source File: LongPipeline.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
@Override
public final boolean allMatch(LongPredicate predicate) {
    return evaluate(MatchOps.makeLong(predicate, MatchOps.MatchKind.ALL));
}
 
Example #28
Source File: Utils.java    From catnip with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public static void removeIf(@Nonnull final Map<Long, ?> map, @Nonnull final LongPredicate predicate) {
    map.keySet().removeIf(predicate::test);
}
 
Example #29
Source File: LongPipeline.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
@Override
public final boolean allMatch(LongPredicate predicate) {
    return evaluate(MatchOps.makeLong(predicate, MatchOps.MatchKind.ALL));
}
 
Example #30
Source File: LongPipeline.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
@Override
public final boolean noneMatch(LongPredicate predicate) {
    return evaluate(MatchOps.makeLong(predicate, MatchOps.MatchKind.NONE));
}