當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。