本文整理了Java中java.util.stream.LongStream.filter()
方法的一些代码示例,展示了LongStream.filter()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。LongStream.filter()
方法的具体详情如下:
包路径:java.util.stream.LongStream
类名称:LongStream
方法名:filter
[英]Returns a stream consisting of the elements of this stream that match the given predicate.
This is an intermediate operation.
[中]返回一个流,该流包含与给定谓词匹配的该流元素。
这是一个intermediate operation。
代码示例来源:origin: speedment/speedment
public LongFilterAction(LongPredicate predicate) {
super(s -> s.filter(requireNonNull(predicate)), LongStream.class, FILTER);
}
代码示例来源:origin: speedment/speedment
@Override
public LongStream filter(LongPredicate predicate) {
requireNonNull(predicate);
if (STRICT) {
return toStream().filter(predicate);
}
return predicate.test(element) ? this : empty();
}
代码示例来源:origin: speedment/speedment
@Override
public LongStream build(boolean parallel) {
return previous().build(parallel).filter(predicate);
}
}
代码示例来源:origin: speedment/speedment
@Override
public LongStream filter(LongPredicate predicate) {
return wrap(stream().filter(predicate));
}
代码示例来源:origin: jooby-project/jooby
private void onChange(final Kind<?> kind, final Path path) {
try {
debug("OnChange: %s(%s)", path, kind);
Path candidate = relativePath(path);
if (candidate == null || !includes.matches(candidate) || excludes.matches(candidate)) {
debug("Ignoring change: %s", path);
return;
}
// weak hash check: avoid change on conf/* that are propagated to target/classs by maven.
File f = candidate.toFile();
// len and lastModified reports 0 on external paths, we hack and use now as millis
long l = LongStream.of(f.length(), f.lastModified(), System.currentTimeMillis())
.filter(it -> it > 0)
.findFirst()
.getAsLong();
String h = f.getName() + ":" + l;
debug("hash %s > new hash %s", hash.get(), h);
if (!hash.getAndSet(h).equals(h)) {
debug("File change detected: %s", path);
// reload
startApp(args);
} else {
debug("Ignoring change: %s", path);
}
} catch (Exception ex) {
ex.printStackTrace();
}
}
代码示例来源:origin: prestodb/presto
.filter(x -> bucketIds.contains(toIntExact(x % bucketCount)))
.boxed()
.collect(toImmutableSet());
代码示例来源:origin: apache/incubator-druid
dataSource)
.filter(stat -> stat == expectedRemainingSegments)
.count();
Assert.assertEquals(i + 1, numDataSourceOfExpectedRemainingSegments);
代码示例来源:origin: aol/cyclops
public static Function<? super ReactiveSeq<Long>, ? extends ReactiveSeq<Long>> filterLongs(LongPredicate b){
return a->a.longs(i->i,s->s.filter(b));
}
/*
代码示例来源:origin: aol/cyclops
@Deprecated //moved to cyclops.companion.Functions
public static Function<? super ReactiveSeq<Long>, ? extends ReactiveSeq<Long>> filterLongs(LongPredicate b){
return a->a.longs(i->i,s->s.filter(b));
}
/*
代码示例来源:origin: org.elasticsearch/elasticsearch
private static long inSyncCheckpointStates(
final Map<String, CheckpointState> checkpoints,
ToLongFunction<CheckpointState> function,
Function<LongStream, OptionalLong> reducer) {
final OptionalLong value =
reducer.apply(
checkpoints
.values()
.stream()
.filter(cps -> cps.inSync)
.mapToLong(function)
.filter(v -> v != SequenceNumbers.PRE_60_NODE_CHECKPOINT && v != SequenceNumbers.UNASSIGNED_SEQ_NO));
return value.isPresent() ? value.getAsLong() : SequenceNumbers.UNASSIGNED_SEQ_NO;
}
代码示例来源:origin: palantir/atlasdb
@VisibleForTesting
Long getOutcomeCount(BackgroundCompactor.CompactionOutcome outcome) {
if (outcome == BackgroundCompactor.CompactionOutcome.SHUTDOWN) {
return shutdown ? 1L : 0L;
}
return Arrays.stream(reservoir.getSnapshot().getValues())
.filter(l -> l == outcome.ordinal())
.count();
}
代码示例来源:origin: palantir/atlasdb
private Long getOutcomeCount(SweepOutcome outcome) {
if (outcome == SweepOutcome.SHUTDOWN) {
return shutdown ? 1L : 0L;
}
if (outcome == SweepOutcome.FATAL) {
return fatal ? 1L : 0L;
}
return Arrays.stream(reservoir.getSnapshot().getValues())
.filter(l -> l == outcome.ordinal())
.count();
}
代码示例来源:origin: DV8FromTheWorld/JDA
/**
* The average time in milliseconds between all shards that discord took to respond to our last heartbeat.
* This roughly represents the WebSocket ping of this session. If there is no shard running this wil return {@code -1}.
*
* <p><b>{@link net.dv8tion.jda.core.requests.RestAction RestAction} request times do not
* correlate to this value!</b>
*
* @return The average time in milliseconds between heartbeat and the heartbeat ack response
*/
default double getAveragePing()
{
return this.getShardCache()
.stream()
.mapToLong(JDA::getPing)
.filter(ping -> ping != -1)
.average()
.orElse(-1D);
}
代码示例来源:origin: lenskit/lenskit
private LongList recommendWithPredicate(int n, LongPredicate filter) {
LongList items = statistics.getItemsByPopularity();
LongList list = new LongArrayList(items.size());
LongStream str = IntStream.range(0, items.size()).mapToLong(items::getLong);
if (filter != null) {
str = str.filter(filter);
}
if (n > 0) {
str = str.limit(n);
}
str.forEachOrdered(list::add);
return list;
}
代码示例来源:origin: aol/cyclops
@Test
public void longs(){
assertThat(ReactiveSeq.rangeLong(1, 1000).longs(i->i,s->s.map(i->i*2).filter(i->i<500))
.size(),equalTo(249));
}
代码示例来源:origin: BruceEckel/OnJava8-Examples
public LongStream numbers() {
return iterate(2, i -> i + 1)
.filter(Prime::isPrime);
}
public static void main(String[] args) {
代码示例来源:origin: stackoverflow.com
private void applyManyFilters(long[] initialData, LongPredicate... filters) {
long[] dataToUse = Arrays.stream(initialData)
.filter(combine(filters))
.toArray();
// Use filtered data
}
public static LongPredicate combine(LongPredicate... filters) {
return Arrays.stream(filters)
.reduce(LongPredicate::and)
.orElse(x -> true);
}
代码示例来源:origin: stackoverflow.com
//prints 6
public static void main(String[] args) {
applyManyFilters(new long[]{1, 2, 3, 4, 5, 6}, l -> l % 2 == 0, l -> l % 3 == 0);
}
private static void applyManyFilters(long[] initialData, LongPredicate... filters) {
Arrays.stream(initialData).filter(
Arrays.stream(filters).reduce(l -> true, LongPredicate::and)
).forEach(System.out::println);
}
代码示例来源:origin: com.palantir.atlasdb/atlasdb-impl-shared
@VisibleForTesting
Long getOutcomeCount(BackgroundCompactor.CompactionOutcome outcome) {
if (outcome == BackgroundCompactor.CompactionOutcome.SHUTDOWN) {
return shutdown ? 1L : 0L;
}
return Arrays.stream(reservoir.getSnapshot().getValues())
.filter(l -> l == outcome.ordinal())
.count();
}
代码示例来源:origin: org.neo4j/graph-algorithms-algo
public Stream<SCCAlgorithm.StreamResult> resultStream() {
return LongStream.range(0, nodeCount)
.filter(i -> connectedComponents.get(i) != -1)
.mapToObj(i -> new SCCAlgorithm.StreamResult(graph.toOriginalNodeId(i), connectedComponents.get(i)));
}
内容来源于网络,如有侵权,请联系作者删除!