本文整理了Java中java.util.stream.LongStream.limit()
方法的一些代码示例,展示了LongStream.limit()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。LongStream.limit()
方法的具体详情如下:
包路径:java.util.stream.LongStream
类名称:LongStream
方法名:limit
[英]Returns a stream consisting of the elements of this stream, truncated to be no longer than maxSize in length.
This is a short-circuiting stateful intermediate operation.
[中]返回由此流的元素组成的流,该流被截断为长度不超过maxSize。
这是一个short-circuiting stateful intermediate operation。
代码示例来源:origin: speedment/speedment
public LongLimitAction(long maxSize) {
super(s -> s.limit(maxSize), LongStream.class, LIMIT);
this.limit = maxSize;
}
代码示例来源:origin: apache/hbase
long getNumAtOrBelow(long val) {
return Arrays.stream(counts).mapToLong(c -> c.sum()).limit(getIndex(val) + 1).sum();
}
代码示例来源:origin: apache/ignite
/**
* Generates pseudorandom discrete distribution.
*
* @param numOfValues Number of distinct values of pseudorandom variable.
* @param seed Seed.
* @return Probabilities array.
*/
public static double[] randomDistribution(int numOfValues, long seed) {
A.ensure(numOfValues > 0, "numberOfValues > 0");
Random random = new Random(seed);
long[] rnd = IntStream.range(0, numOfValues)
.mapToLong(i -> random.nextInt(Integer.MAX_VALUE))
.limit(numOfValues)
.toArray();
long sum = Arrays.stream(rnd).sum();
double[] res = new double[numOfValues];
for (int i = 0; i < res.length; i++)
res[i] = rnd[i] / Math.max(1.0, sum);
return res;
}
代码示例来源:origin: speedment/speedment
@Override
public LongStream limit(long maxSize) {
return wrap(stream().limit(maxSize));
}
代码示例来源:origin: speedment/speedment
@Override
@SuppressWarnings("unchecked")
public TS build(boolean parallel) {
final TS built = previous().build(parallel);
if (built instanceof Stream<?>) {
return (TS) ((Stream<T>) built).limit(limit);
} else if (built instanceof IntStream) {
return (TS) ((IntStream) built).limit(limit);
} else if (built instanceof LongStream) {
return (TS) ((LongStream) built).limit(limit);
} else if (built instanceof DoubleStream) {
return (TS) ((DoubleStream) built).limit(limit);
} else {
throw new UnsupportedOperationException(
"Built stream did not match any known stream interface."
);
}
}
}
代码示例来源:origin: goldmansachs/gs-collections
long[] randomLongsGet = new Random(0x123456789ABCDL).longs().limit(this.mapSizeDividedBy16000).toArray();
代码示例来源:origin: ehcache/ehcache3
Map<Long, BlobValue> map = random.longs().limit(JOB_SIZE).collect(HashMap::new, (hashMap, x) -> hashMap.put(x, new BlobValue()), HashMap::putAll);
futures.add(executorService.submit(() -> {
cache.putAll(map);
代码示例来源:origin: ehcache/ehcache3
futures.add(executorService.submit(() -> random.longs().limit(JOB_SIZE).forEach(x -> {
cache.put(x, new BlobValue());
universalSet.add(x);
代码示例来源:origin: ehcache/ehcache3
@Ignore("This is currently unstable as if the clear does not complete before the failover," +
"there is no future operation that will trigger the code in ClusterTierActiveEntity.invokeServerStoreOperation" +
"dealing with in-flight invalidation reconstructed from reconnect data")
@Test(timeout=180000)
public void testClear() throws Exception {
List<Future<?>> futures = new ArrayList<>();
Set<Long> universalSet = ConcurrentHashMap.newKeySet();
caches.forEach(cache -> {
for (int i = 0; i < NUM_OF_THREADS; i++) {
Map<Long, BlobValue> map = random.longs().limit(JOB_SIZE).collect(HashMap::new, (hashMap, x) -> hashMap.put(x, new BlobValue()), HashMap::putAll);
futures.add(executorService.submit(() -> {
cache.putAll(map);
universalSet.addAll(map.keySet());
}));
}
});
drainTasks(futures);
universalSet.forEach(x -> {
CACHE1.get(x);
CACHE2.get(x);
});
Future<?> clearFuture = executorService.submit(() -> CACHE1.clear());
CLUSTER.getClusterControl().terminateActive();
clearFuture.get();
universalSet.forEach(x -> assertThat(CACHE2.get(x), nullValue()));
}
代码示例来源:origin: aol/cyclops
@Deprecated //moved to cyclops.companion.Functions
public static Function<? super ReactiveSeq<Long>, ? extends ReactiveSeq<Long>> limitLongs(long maxSize){
return a->a.longs(i->i,s->s.limit(maxSize));
}
/*
代码示例来源:origin: aol/cyclops
public static Function<? super ReactiveSeq<Long>, ? extends ReactiveSeq<Long>> limitLongs(long maxSize){
return a->a.longs(i->i,s->s.limit(maxSize));
}
/*
代码示例来源:origin: biezhi/learn-java8
public static void main(String[] args) {
long[] arrayOfLong = new long[20000];
Arrays.parallelSetAll(arrayOfLong,
index -> ThreadLocalRandom.current().nextInt(1000000));
Arrays.stream(arrayOfLong).limit(10).forEach(
i -> System.out.print(i + " "));
System.out.println();
Arrays.parallelSort(arrayOfLong);
Arrays.stream(arrayOfLong).limit(10).forEach(
i -> System.out.print(i + " "));
System.out.println();
}
}
代码示例来源: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: net.dongliu/commons-lang
@Override
public ExLongStream limit(long maxSize) {
return ExLongStream.of(stream.limit(maxSize));
}
代码示例来源:origin: BruceEckel/OnJava8-Examples
public static void main(String[] args) {
new Prime().numbers()
.limit(10)
.forEach(n -> System.out.format("%d ", n));
System.out.println();
new Prime().numbers()
.skip(90)
.limit(10)
.forEach(n -> System.out.format("%d ", n));
}
}
代码示例来源:origin: hazelcast/hazelcast-jet
/**
* Returns a stream of {@code long}s:
* {@code for (long i = start; i <= end; i += step) yield i;}
*/
private static LongStream range(long start, long end, long step) {
return start > end
? LongStream.empty()
: LongStream.iterate(start, n -> n + step).limit(1 + (end - start) / step);
}
代码示例来源:origin: BruceEckel/OnJava8-Examples
static long[] fillCounted(int size) {
return LongStream.iterate(0, i -> i + 1)
.limit(size).toArray();
}
public static void main(String[] args) {
代码示例来源:origin: com.aol.cyclops/cyclops-core
public LongStream asLongRange(){
long start = ((Number)t3.v1()).longValue();
long end = ((Number)t3.v2()).longValue();
long step = ((Number)t3.v3()).longValue();
return LongStream.iterate(start, i -> i + step)
.limit((end-start)/step);
}
}
代码示例来源:origin: apache/incubator-ratis
@Test(timeout = 1000)
public void testMinMax() {
runTestMinMax(LongStream.empty());
runTestMinMax(LongStream.iterate(0, n -> n).limit(10));
for(int count = 1; count < 10; count++) {
runTestMinMax(LongStream.iterate(1, n -> n + 1).limit(count));
}
for(int count = 1; count < 10; count++) {
runTestMinMax(LongStream.iterate(0, _dummy -> ThreadLocalRandom.current().nextLong()).limit(count));
}
}
代码示例来源:origin: imglib/imglib2
@Test
public void constantRandomAccessibleInterval()
{
final int nDim = 5;
final Random rng = new Random( 100 );
final long[] dims = LongStream.generate( () -> rng.nextInt( 5 ) + 1 ).limit( nDim ).toArray();
final IntType constVal = new IntType( 123 );
final RandomAccessibleInterval< IntType > randomAccessibleInterval = ConstantUtils.constantRandomAccessibleInterval( constVal, new FinalInterval( dims ) );
Assert.assertArrayEquals( dims, Intervals.dimensionsAsLongArray( randomAccessibleInterval ) );
Assert.assertArrayEquals( new long[ nDim ], Intervals.minAsLongArray( randomAccessibleInterval ) );
Views.iterable( randomAccessibleInterval ).forEach( p -> Assert.assertTrue( constVal.valueEquals( constVal ) ) );
}
内容来源于网络,如有侵权,请联系作者删除!