public DoubleLimitAction(long maxSize) { super(s -> s.limit(maxSize), DoubleStream.class, LIMIT); this.limit = maxSize; }
@Override public DoubleStream limit(long maxSize) { return wrap(stream().limit(maxSize)); }
@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." ); } } }
@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)); } /*
public static Function<? super ReactiveSeq<Double>, ? extends ReactiveSeq<Double>> limitDouble(long maxSize){ return a->a.doubles(i->i,s->s.limit(maxSize)); } /*
double[] array = new Random().doubles() .distinct() .limit(500) // How many you want. .toArray();
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(); } }
DoubleStream .generate(() -> Double.NaN) .limit(offset) .boxed() .collect(Collectors.toList());
@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)); }
@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)); }
@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)); }
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)); }
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()); }
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()); }
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()); }
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); }
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()); }
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)); }
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))); }
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)); }