当前位置: 首页>>代码示例>>Java>>正文


Java DoubleStreamEx类代码示例

本文整理汇总了Java中one.util.streamex.DoubleStreamEx的典型用法代码示例。如果您正苦于以下问题:Java DoubleStreamEx类的具体用法?Java DoubleStreamEx怎么用?Java DoubleStreamEx使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


DoubleStreamEx类属于one.util.streamex包,在下文中一共展示了DoubleStreamEx类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testDoubleStreamEx

import one.util.streamex.DoubleStreamEx; //导入依赖的package包/类
@Test
public void testDoubleStreamEx() {
    LongStreamEx.range(0, 4).asDoubleStream().parallel(pool).forEach(this::checkThread);
    assertEquals(6, IntStreamEx.range(0, 4).parallel(pool).peek(this::checkThread).asDoubleStream().sum(), 0);
    assertEquals(3, IntStreamEx.range(0, 4).parallel(pool).peek(this::checkThread).asDoubleStream().max()
            .getAsDouble(), 0);
    assertEquals(0, IntStreamEx.range(0, 4).parallel(pool).peek(this::checkThread).asDoubleStream().min()
            .getAsDouble(), 0);
    assertEquals(1.5, IntStreamEx.range(0, 4).parallel(pool).peek(this::checkThread).asDoubleStream().average()
            .getAsDouble(), 0.000001);
    assertEquals(4, IntStreamEx.range(0, 4).parallel(pool).peek(this::checkThread).asDoubleStream()
            .summaryStatistics().getCount());
    assertArrayEquals(new double[] { 1, 2, 3 }, IntStreamEx.range(0, 5).asDoubleStream().skip(1).limit(3).parallel(
        pool).peek(this::checkThread).toArray(), 0.0);
    assertEquals(6.0, DoubleStreamEx.of(1.0, 2.0, 3.0).parallel(pool).peek(this::checkThread).reduce(Double::sum)
            .getAsDouble(), 0.0);
    assertTrue(DoubleStreamEx.of(1, 2, 3).parallel(pool).peek(this::checkThread).anyMatch(x -> x == 2));
    assertFalse(DoubleStreamEx.of(1, 2, 3).parallel(pool).peek(this::checkThread).allMatch(x -> x == 2));
    assertFalse(DoubleStreamEx.of(1, 2, 3).parallel(pool).peek(this::checkThread).noneMatch(x -> x == 2));
    assertEquals(6.0, DoubleStreamEx.of(1, 2, 3).parallel(pool).peek(this::checkThread).reduce(1, (a, b) -> a * b),
        0.0);
    assertEquals(2, DoubleStreamEx.of(1, 2, 3).parallel(pool).peek(this::checkThread).atLeast(2.0).count());
    assertEquals(2.0, DoubleStreamEx.of(1, 2, 3).parallel(pool).peek(this::checkThread).findAny(x -> x % 2 == 0)
            .getAsDouble(), 0.0);
    assertEquals(2.0, DoubleStreamEx.of(1, 2, 3).parallel(pool).peek(this::checkThread).findFirst(x -> x % 2 == 0)
            .getAsDouble(), 0.0);
    List<Double> res = new ArrayList<>();
    DoubleStreamEx.of(1.0, 2.0, 3.5, 4.5).parallel(pool).peek(this::checkThread).map(x -> x * 2).forEachOrdered(
        res::add);
    assertEquals(Arrays.asList(2.0, 4.0, 7.0, 9.0), res);
    assertArrayEquals(new double[] { 1, 3, 6, 10 }, DoubleStreamEx.of(1, 2, 3, 4).parallel(pool).peek(
        this::checkThread).scanLeft((a, b) -> {
        checkThread(b);
        return a + b;
    }), 0.0);
}
 
开发者ID:amaembo,项目名称:streamex,代码行数:37,代码来源:CustomPoolTest.java

示例2: testMapping

import one.util.streamex.DoubleStreamEx; //导入依赖的package包/类
@Test
public void testMapping() {
    assertEquals(10100.0, IntStreamEx.rangeClosed(0, 100).asDoubleStream().collect(
        DoubleCollector.mapping(x -> x * 2, DoubleCollector.summing())), 0.0);

    assertArrayEquals(LongStreamEx.of(1, 1, 2, 3).toArray(), DoubleStreamEx.of(0.8, 1.3, 1.7, 2.9).collect(
        DoubleCollector.mappingToObj(Math::round, LongCollector.toArray())));
}
 
开发者ID:amaembo,项目名称:streamex,代码行数:9,代码来源:DoubleCollectorTest.java

示例3: testToBooleanArray

import one.util.streamex.DoubleStreamEx; //导入依赖的package包/类
@Test
public void testToBooleanArray() {
    assertArrayEquals(new boolean[0], DoubleStreamEx.empty().collect(DoubleCollector.toBooleanArray(x -> true)));
    boolean[] expected = new boolean[] { true, false, false, true };
    assertArrayEquals(expected, DoubleStreamEx.of(1.0, 1.5, 2.7, 3.0).collect(
        DoubleCollector.toBooleanArray(x -> Math.floor(x) == x)));
    assertArrayEquals(expected, DoubleStreamEx.of(1.0, 1.5, 2.7, 3.0).parallel().collect(
        DoubleCollector.toBooleanArray(x -> Math.floor(x) == x)));
}
 
开发者ID:amaembo,项目名称:streamex,代码行数:10,代码来源:DoubleCollectorTest.java

示例4: testSpliterator

import one.util.streamex.DoubleStreamEx; //导入依赖的package包/类
@Test
public void testSpliterator() {
    withRandom(r -> {
        int[] ints = IntStreamEx.of(r, 100).toArray();
        long[] longs = LongStreamEx.of(r, 100).toArray();
        double[] doubles = DoubleStreamEx.of(r, 100).toArray();

        checkSpliterator("ref", () -> new PairSpliterator.PSOfRef<>((a, b) -> (a - b), Arrays.spliterator(ints)));
        checkSpliterator("int", () -> new PairSpliterator.PSOfInt((a, b) -> (a - b), null, Arrays.spliterator(ints), PairSpliterator.MODE_PAIRS));
        checkSpliterator("long", () -> new PairSpliterator.PSOfLong((a, b) -> (a - b), null, Arrays.spliterator(longs), PairSpliterator.MODE_PAIRS));
        checkSpliterator("double", () -> new PairSpliterator.PSOfDouble((a, b) -> (a - b), null, Arrays.spliterator(doubles), PairSpliterator.MODE_PAIRS));
        
        // mapFirst
        checkSpliterator("ref", IntStreamEx.of(ints, 1, ints.length).boxed().prepend(ints[0] + 2).toList(),
            () -> new PairSpliterator.PSOfRef<>(a -> a + 2, Arrays.spliterator(ints), true));
        checkSpliterator("int", IntStreamEx.of(ints, 1, ints.length).boxed().prepend(ints[0] + 2).toList(),
            () -> new PairSpliterator.PSOfInt((a, b) -> b, a -> a+2, Arrays.spliterator(ints), PairSpliterator.MODE_MAP_FIRST));
        checkSpliterator("long", LongStreamEx.of(longs, 1, longs.length).boxed().prepend(longs[0] + 2).toList(),
            () -> new PairSpliterator.PSOfLong((a, b) -> b, a -> a+2, Arrays.spliterator(longs), PairSpliterator.MODE_MAP_FIRST));
        checkSpliterator("double", DoubleStreamEx.of(doubles, 1, doubles.length).boxed().prepend(doubles[0] + 2).toList(), 
            () -> new PairSpliterator.PSOfDouble((a, b) -> b, a -> a+2, Arrays.spliterator(doubles), PairSpliterator.MODE_MAP_FIRST));
        
        // mapLast
        checkSpliterator("ref", IntStreamEx.of(ints, 0, ints.length-1).boxed().append(ints[ints.length-1] + 2).toList(),
            () -> new PairSpliterator.PSOfRef<>(a -> a + 2, Arrays.spliterator(ints), false));
        checkSpliterator("int", IntStreamEx.of(ints, 0, ints.length-1).boxed().append(ints[ints.length-1] + 2).toList(),
            () -> new PairSpliterator.PSOfInt((a, b) -> a, a -> a+2, Arrays.spliterator(ints), PairSpliterator.MODE_MAP_LAST));
        checkSpliterator("long", LongStreamEx.of(longs, 0, longs.length-1).boxed().append(longs[longs.length-1] + 2).toList(),
            () -> new PairSpliterator.PSOfLong((a, b) -> a, a -> a+2, Arrays.spliterator(longs), PairSpliterator.MODE_MAP_LAST));
        checkSpliterator("double", DoubleStreamEx.of(doubles, 0, doubles.length-1).boxed().append(doubles[doubles.length-1] + 2).toList(),
            () -> new PairSpliterator.PSOfDouble((a, b) -> a, a -> a+2, Arrays.spliterator(doubles), PairSpliterator.MODE_MAP_LAST));
    });
}
 
开发者ID:amaembo,项目名称:streamex,代码行数:34,代码来源:PairSpliteratorTest.java

示例5: testReducing

import one.util.streamex.DoubleStreamEx; //导入依赖的package包/类
@Test
public void testReducing() {
    assertEquals(7.0, DoubleStreamEx.of(1.0, 2.0, 3.5).collect(DoubleCollector.reducing(1.0, (a, b) -> a * b)), 0.0);
    assertEquals(7.0, DoubleStreamEx.of(1.0, 2.0, 3.5).parallel().collect(
        DoubleCollector.reducing(1.0, (a, b) -> a * b)), 0.0);
}
 
开发者ID:amaembo,项目名称:streamex,代码行数:7,代码来源:DoubleCollectorTest.java

示例6: testAveraging

import one.util.streamex.DoubleStreamEx; //导入依赖的package包/类
@Test
public void testAveraging() {
    assertFalse(DoubleStreamEx.empty().collect(DoubleCollector.averaging()).isPresent());
    assertEquals(1.0,
        DoubleStreamEx.of(0.0, 0.5, 1.0, 1.5, 2.0).collect(DoubleCollector.averaging()).getAsDouble(), 0.0);
}
 
开发者ID:amaembo,项目名称:streamex,代码行数:7,代码来源:DoubleCollectorTest.java

示例7: stream

import one.util.streamex.DoubleStreamEx; //导入依赖的package包/类
@Override
public StreamEx<Double> stream(final IScope scope) {
	return DoubleStreamEx.of(matrix).boxed();
}
 
开发者ID:gama-platform,项目名称:gama,代码行数:5,代码来源:GamaFloatMatrix.java


注:本文中的one.util.streamex.DoubleStreamEx类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。