public LongFilterAction(LongPredicate predicate) { super(s -> s.filter(requireNonNull(predicate)), LongStream.class, FILTER); }
@Override public LongStream filter(LongPredicate predicate) { requireNonNull(predicate); if (STRICT) { return toStream().filter(predicate); } return predicate.test(element) ? this : empty(); }
@Override public LongStream build(boolean parallel) { return previous().build(parallel).filter(predicate); } }
@Override public LongStream filter(LongPredicate predicate) { return wrap(stream().filter(predicate)); }
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(); } }
.filter(x -> bucketIds.contains(toIntExact(x % bucketCount))) .boxed() .collect(toImmutableSet());
dataSource) .filter(stat -> stat == expectedRemainingSegments) .count(); Assert.assertEquals(i + 1, numDataSourceOfExpectedRemainingSegments);
public static Function<? super ReactiveSeq<Long>, ? extends ReactiveSeq<Long>> filterLongs(LongPredicate b){ return a->a.longs(i->i,s->s.filter(b)); } /*
@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)); } /*
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; }
@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(); }
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(); }
/** * 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); }
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; }
@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)); }
public LongStream numbers() { return iterate(2, i -> i + 1) .filter(Prime::isPrime); } public static void main(String[] args) {
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); }
//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); }
@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(); }
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))); }