本文整理了Java中java.util.stream.DoubleStream.limit()
方法的一些代码示例,展示了DoubleStream.limit()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。DoubleStream.limit()
方法的具体详情如下:
包路径:java.util.stream.DoubleStream
类名称:DoubleStream
方法名: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 DoubleLimitAction(long maxSize) {
super(s -> s.limit(maxSize), DoubleStream.class, LIMIT);
this.limit = maxSize;
}
代码示例来源:origin: speedment/speedment
@Override
public DoubleStream 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: aol/cyclops
@Deprecated //moved to cyclops.companion.Functions
public static Function<? super ReactiveSeq<Double>, ? extends ReactiveSeq<Double>> limitDouble(long maxSize){
return a->a.doubles(i->i,s->s.limit(maxSize));
}
/*
代码示例来源:origin: aol/cyclops
public static Function<? super ReactiveSeq<Double>, ? extends ReactiveSeq<Double>> limitDouble(long maxSize){
return a->a.doubles(i->i,s->s.limit(maxSize));
}
/*
代码示例来源:origin: stackoverflow.com
double[] array = new Random().doubles()
.distinct()
.limit(500) // How many you want.
.toArray();
代码示例来源:origin: spinnaker/kayenta
public static TimeseriesData dummy(String type, long count) {
List<Double> values = DoubleStream.iterate(1.0, d -> d + 1.0).limit(count).boxed().collect(Collectors.toList());
return TimeseriesData.builder().type(type).values(values).build();
}
}
代码示例来源:origin: spinnaker/kayenta
DoubleStream
.generate(() -> Double.NaN)
.limit(offset)
.boxed()
.collect(Collectors.toList());
代码示例来源:origin: jenetics/jenetics
@Test
public void acceptReverseMinMax() {
final Random random = RandomRegistry.getRandom();
final double[] numbers = random.doubles().limit(1000).toArray();
final MinMax<Double> minMax = MinMax.of((a, b) -> b.compareTo(a));
Arrays.stream(numbers)
.mapToObj(Double::valueOf)
.forEach(minMax);
Assert.assertEquals(minMax.getMin(), StatUtils.max(numbers));
Assert.assertEquals(minMax.getMax(), StatUtils.min(numbers));
}
代码示例来源:origin: jenetics/jenetics
@Test
public void acceptNormalMinMax() {
final Random random = RandomRegistry.getRandom();
final double[] numbers = random.doubles().limit(1000).toArray();
final MinMax<Double> minMax = MinMax.of();
Arrays.stream(numbers)
.mapToObj(Double::valueOf)
.forEach(minMax);
Assert.assertEquals(minMax.getMin(), StatUtils.min(numbers));
Assert.assertEquals(minMax.getMax(), StatUtils.max(numbers));
}
代码示例来源:origin: jenetics/jenetics
@Test
public void toMinMaxNormal() {
final Random random = RandomRegistry.getRandom();
final double[] numbers = random.doubles().limit(1000).toArray();
final MinMax<Double> minMax = Arrays.stream(numbers)
.mapToObj(Double::valueOf)
.collect(MinMax.toMinMax());
Assert.assertEquals(minMax.getMin(), StatUtils.min(numbers));
Assert.assertEquals(minMax.getMax(), StatUtils.max(numbers));
}
代码示例来源:origin: org.infinispan/infinispan-core
public void testDoubleSortedIterator() {
Cache<Double, String> cache = getCache(0);
int range = 10;
// First populate the cache with a bunch of values
DoubleStream.iterate(0.0, d -> d + .5).limit(10).boxed().forEach(i -> cache.put(i, i + "-value"));
assertEquals(range, cache.size());
CacheSet<Map.Entry<Double, String>> entrySet = cache.entrySet();
PrimitiveIterator.OfDouble iterator = createStream(entrySet).mapToDouble(toDouble).sorted().iterator();
AtomicInteger i = new AtomicInteger();
iterator.forEachRemaining((double e) -> assertEquals((double) i.getAndIncrement() / 2, e));
}
代码示例来源:origin: org.infinispan/infinispan-core
public void testDoubleMax() {
Cache<Double, String> cache = getCache(0);
int range = 10;
// First populate the cache with a bunch of values
DoubleStream.iterate(0.0, d -> d + .5).limit(10).boxed().forEach(i -> cache.put(i, i + "-value"));
assertEquals(range, cache.size());
CacheSet<Map.Entry<Double, String>> entrySet = cache.entrySet();
assertEquals(4.5, createStream(entrySet).mapToDouble(toDouble).max().getAsDouble());
}
代码示例来源:origin: org.infinispan/infinispan-core
public void testDoubleCollect() {
Cache<Double, String> cache = getCache(0);
int range = 10;
// First populate the cache with a bunch of values
DoubleStream.iterate(0.0, d -> d + .5).limit(10).boxed().forEach(i -> cache.put(i, i + "-value"));
assertEquals(range, cache.size());
CacheSet<Map.Entry<Double, String>> entrySet = cache.entrySet();
HashSet<Double> set = createStream(entrySet).mapToDouble(toDouble).collect(HashSet::new,
Set::add, Set::addAll);
assertEquals(10, set.size());
}
代码示例来源:origin: org.infinispan/infinispan-core
public void testDoubleFindFirst() {
Cache<Double, String> cache = getCache(0);
int range = 10;
// First populate the cache with a bunch of values
DoubleStream.iterate(0.0, d -> d + .5).limit(10).boxed().forEach(i -> cache.put(i, i + "-value"));
assertEquals(range, cache.size());
CacheSet<Map.Entry<Double, String>> entrySet = cache.entrySet();
assertEquals(0.0, createStream(entrySet).mapToDouble(toDouble).sorted().findFirst().getAsDouble());
}
代码示例来源:origin: org.infinispan/infinispan-core
public void testDoubleSum() {
Cache<Double, String> cache = getCache(0);
int range = 10;
// First populate the cache with a bunch of values
DoubleStream.iterate(0.0, d -> d + .5).limit(10).boxed().forEach(i -> cache.put(i, i + "-value"));
assertEquals(range, cache.size());
CacheSet<Map.Entry<Double, String>> entrySet = cache.entrySet();
// This isn't the best usage of this, but should be a usable example
double result = createStream(entrySet).mapToDouble(toDouble).sum();
assertEquals((double) (range - 1) * (range / 2) / 2, result);
}
代码示例来源:origin: org.infinispan/infinispan-core
public void testDoubleCount() {
Cache<Double, String> cache = getCache(0);
int range = 10;
// First populate the cache with a bunch of values
DoubleStream.iterate(0.0, d -> d + .5).limit(10).boxed().forEach(i -> cache.put(i, i + "-value"));
assertEquals(range, cache.size());
CacheSet<Map.Entry<Double, String>> entrySet = cache.entrySet();
assertEquals(10, createStream(entrySet).mapToDouble(toDouble).count());
}
代码示例来源:origin: org.infinispan/infinispan-core
public void testDoubleAnyMatch() {
Cache<Double, String> cache = getCache(0);
int range = 10;
// First populate the cache with a bunch of values
DoubleStream.iterate(0.0, d -> d + .5).limit(10).boxed().forEach(i -> cache.put(i, i + "-value"));
assertEquals(range, cache.size());
CacheSet<Map.Entry<Double, String>> entrySet = cache.entrySet();
assertTrue(createStream(entrySet).mapToDouble(toDouble).anyMatch(i -> i % 2 == 0));
assertFalse(createStream(entrySet).mapToDouble(toDouble).anyMatch(i -> i > 5 && i < 0));
assertTrue(createStream(entrySet).mapToDouble(toDouble).anyMatch(i -> i < 5));
assertTrue(createStream(entrySet).mapToDouble(toDouble).anyMatch(i -> Math.floor(i) == i));
}
代码示例来源:origin: org.infinispan/infinispan-core
public void testDoubleToArray() {
Cache<Double, String> cache = getCache(0);
int range = 10;
// First populate the cache with a bunch of values
DoubleStream.iterate(0.0, d -> d + .5).limit(10).boxed().forEach(i -> cache.put(i, i + "-value"));
assertEquals(range, cache.size());
CacheSet<Map.Entry<Double, String>> entrySet = cache.entrySet();
double[] array = createStream(entrySet).mapToDouble(toDouble).toArray();
assertEquals(cache.size(), array.length);
Spliterator.OfDouble spliterator = Spliterators.spliterator(array, Spliterator.DISTINCT);
StreamSupport.doubleStream(spliterator, true).forEach(e -> assertTrue(cache.containsKey(e)));
}
代码示例来源:origin: org.infinispan/infinispan-core
public void testDoubleAllMatch() {
Cache<Double, String> cache = getCache(0);
int range = 10;
// First populate the cache with a bunch of values
DoubleStream.iterate(0.0, d -> d + .5).limit(10).boxed().forEach(i -> cache.put(i, i + "-value"));
assertEquals(range, cache.size());
CacheSet<Map.Entry<Double, String>> entrySet = cache.entrySet();
assertFalse(createStream(entrySet).mapToDouble(toDouble).allMatch(i -> i % 2 == 0));
assertFalse(createStream(entrySet).mapToDouble(toDouble).allMatch(i -> i > 5 && i < 0));
assertTrue(createStream(entrySet).mapToDouble(toDouble).allMatch(i -> i < 5));
assertFalse(createStream(entrySet).mapToDouble(toDouble).allMatch(i -> Math.floor(i) == i));
}
内容来源于网络,如有侵权,请联系作者删除!