當前位置: 首頁>>代碼示例>>Java>>正文


Java DoubleStream類代碼示例

本文整理匯總了Java中java.util.stream.DoubleStream的典型用法代碼示例。如果您正苦於以下問題:Java DoubleStream類的具體用法?Java DoubleStream怎麽用?Java DoubleStream使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


DoubleStream類屬於java.util.stream包,在下文中一共展示了DoubleStream類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: testDropWhileMulti

import java.util.stream.DoubleStream; //導入依賴的package包/類
private void testDropWhileMulti(Consumer<Stream<Integer>> mRef,
                                Consumer<IntStream> mInt,
                                Consumer<LongStream> mLong,
                                Consumer<DoubleStream> mDouble) {
    Map<String, Supplier<Stream<Integer>>> sources = new HashMap<>();
    sources.put("IntStream.range().boxed()",
                () -> IntStream.range(0, DROP_SOURCE_SIZE).boxed());
    sources.put("IntStream.range().boxed().unordered()",
                () -> IntStream.range(0, DROP_SOURCE_SIZE).boxed().unordered());
    sources.put("LinkedList.stream()",
                () -> IntStream.range(0, DROP_SOURCE_SIZE).boxed()
                        .collect(toCollection(LinkedList::new))
                        .stream());
    sources.put("LinkedList.stream().unordered()",
                () -> IntStream.range(0, DROP_SOURCE_SIZE).boxed()
                        .collect(toCollection(LinkedList::new))
                        .stream()
                        .unordered());
    testWhileMulti(sources, mRef, mInt, mLong, mDouble);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:21,代碼來源:WhileOpStatefulTest.java

示例2: testWithDoubles

import java.util.stream.DoubleStream; //導入依賴的package包/類
@Test(dataProvider = "sizes")
public void testWithDoubles(int initialSize) {
    final Random random = new Random();
    final ArrayBuilder<Double> builder = ArrayBuilder.of(initialSize);
    final double[] expected = new double[1000];
    for (int i=0; i<expected.length; ++i) {
        expected[i] = random.nextDouble();
        builder.add(expected[i]);
    }
    final Array<Double> actual = builder.toArray();
    Assert.assertEquals(actual.length(), expected.length, "The lengths match");
    Assert.assertEquals(actual.typeCode(), ArrayType.DOUBLE, "The array type is as expected");
    for (int i=0; i<expected.length; ++i) {
        Assert.assertEquals(actual.getDouble(i), expected[i], "The values match at " + i);
    }
    final Array<Double> collected = DoubleStream.of(expected).boxed().collect(ArrayUtils.toArray(expected.length));
    for (int i=0; i<expected.length; ++i) {
        Assert.assertEquals(collected.getDouble(i), expected[i], "The values match at " + i);
    }
}
 
開發者ID:zavtech,項目名稱:morpheus-core,代碼行數:21,代碼來源:ArrayBuilderTests.java

示例3: testClose

import java.util.stream.DoubleStream; //導入依賴的package包/類
@Test
public void testClose() {
    AtomicInteger before = new AtomicInteger();
    AtomicInteger onClose = new AtomicInteger();

    Supplier<Stream<Integer>> s = () -> {
        before.set(0); onClose.set(0);
        return Stream.of(1, 2).peek(e -> before.getAndIncrement());
    };

    s.get().flatMap(i -> Stream.of(i, i).onClose(onClose::getAndIncrement)).count();
    assertEquals(before.get(), onClose.get());

    s.get().flatMapToInt(i -> IntStream.of(i, i).onClose(onClose::getAndIncrement)).count();
    assertEquals(before.get(), onClose.get());

    s.get().flatMapToLong(i -> LongStream.of(i, i).onClose(onClose::getAndIncrement)).count();
    assertEquals(before.get(), onClose.get());

    s.get().flatMapToDouble(i -> DoubleStream.of(i, i).onClose(onClose::getAndIncrement)).count();
    assertEquals(before.get(), onClose.get());
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:23,代碼來源:FlatMapOpTest.java

示例4: getEventRender

import java.util.stream.DoubleStream; //導入依賴的package包/類
@Override
public @NotNull TimeGraphDrawnEventRender getEventRender(TimeGraphTreeRender treeRender, TimeRange timeRange, @Nullable FutureTask<?> task) {
    TimeGraphDrawnEventSeries series = getDrawnEventSeries();

    List<TimeGraphDrawnEvent> events = treeRender.getAllTreeElements().stream()
            .filter(treeElem -> treeElem != StubModelProvider.ROOT_ELEMENT)
            /* Keep only entries (1, 3, 5, 7) */
            .filter(treeElem -> getIndexOfTreeElement(treeElem) < 8)
            .filter(treeElem -> (getIndexOfTreeElement(treeElem) + 1) % 2 == 0)

            /* Draw symbols at positions (.2, .4, .6, .8) */
            .flatMap(treeElem -> DoubleStream.iterate(0.2, i -> i + 0.2).limit(4)
                    .mapToObj(i -> new TimeGraphEvent(ts(timeRange, i), treeElem)))
            .map(event -> new TimeGraphDrawnEvent(event, series, null))
            .collect(ImmutableList.toImmutableList());

    /* There should be 16 symbols total */
    return new TimeGraphDrawnEventRender(timeRange, events);
}
 
開發者ID:lttng,項目名稱:lttng-scope,代碼行數:20,代碼來源:StubDrawnEventProviders.java

示例5: terminationCriteriaMet

import java.util.stream.DoubleStream; //導入依賴的package包/類
private boolean terminationCriteriaMet(int k, double negCoverRatio) {
	if (untilIterationK >= 0 && k >= untilIterationK) {
		System.out.println("Termination criterion met: until iteration k");
		return true;
	}
	
	if (timeout >= 0) {
		long timeDiff = System.currentTimeMillis() - startTime;
		if(timeDiff / 1000 >= timeout) {
			System.out.println("Termination criterion met: timeout");
			return true;
		}
	}
	
	if (negCoverThresh >= 0.0) {
		int index = k % negCoverWindowSize;
		lastNegCoverRatios[index] = negCoverRatio;
		double averageRatio = (DoubleStream.of(lastNegCoverRatios).sum()) / (double)negCoverWindowSize;
		if (averageRatio <= negCoverThresh) {
			System.out.println("Termination criterion met: neg-cover growth ratio");
			return true;
		}
	}

	return false;
}
 
開發者ID:HPI-Information-Systems,項目名稱:metanome-algorithms,代碼行數:27,代碼來源:AIDFD.java

示例6: testDoubleSize

import java.util.stream.DoubleStream; //導入依賴的package包/類
public void testDoubleSize() {
    assertSized(DoubleStream.concat(
            IntStream.range(0, Integer.MAX_VALUE).mapToDouble(i -> i),
            IntStream.range(0, Integer.MAX_VALUE).mapToDouble(i -> i)));

    assertUnsized(DoubleStream.concat(
            LongStream.range(0, Long.MAX_VALUE).mapToDouble(i -> i),
            LongStream.range(0, Long.MAX_VALUE).mapToDouble(i -> i)));

    assertUnsized(DoubleStream.concat(
            LongStream.range(0, Long.MAX_VALUE).mapToDouble(i -> i),
            DoubleStream.iterate(0, i -> i + 1)));

    assertUnsized(DoubleStream.concat(
            DoubleStream.iterate(0, i -> i + 1),
            LongStream.range(0, Long.MAX_VALUE).mapToDouble(i -> i)));
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:18,代碼來源:ConcatOpTest.java

示例7: testWhileMulti

import java.util.stream.DoubleStream; //導入依賴的package包/類
private void testWhileMulti(TestData.OfRef<Integer> data,
                            ResultAsserter<Iterable<Integer>> ra,
                            Function<Stream<Integer>, Stream<Integer>> mRef,
                            Function<IntStream, IntStream> mInt,
                            Function<LongStream, LongStream> mLong,
                            Function<DoubleStream, DoubleStream> mDouble) {
    Map<String, Function<Stream<Integer>, Stream<Integer>>> ms = new HashMap<>();
    ms.put("Ref", mRef);
    ms.put("Int", s -> mInt.apply(s.mapToInt(e -> e)).mapToObj(e -> e));
    ms.put("Long", s -> mLong.apply(s.mapToLong(e -> e)).mapToObj(e -> (int) e));
    ms.put("Double", s -> mDouble.apply(s.mapToDouble(e -> e)).mapToObj(e -> (int) e));
    ms.put("Ref using defaults", s -> mRef.apply(DefaultMethodStreams.delegateTo(s)));
    ms.put("Int using defaults", s -> mInt.apply(DefaultMethodStreams.delegateTo(s.mapToInt(e -> e))).mapToObj(e -> e));
    ms.put("Long using defaults", s -> mLong.apply(DefaultMethodStreams.delegateTo(s.mapToLong(e -> e))).mapToObj(e -> (int) e));
    ms.put("Double using defaults", s -> mDouble.apply(DefaultMethodStreams.delegateTo(s.mapToDouble(e -> e))).mapToObj(e -> (int) e));

    testWhileMulti(data, ra, ms);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:19,代碼來源:WhileOpTest.java

示例8: calculate

import java.util.stream.DoubleStream; //導入依賴的package包/類
public double calculate(int i) {
    //synchronized (calculateLock) {
    this.prop = 2.0 * i;
    DoubleStream.generate(new Random()::nextDouble).limit(10);
    return Math.sqrt(this.prop);
    //}
}
 
開發者ID:PacktPublishing,項目名稱:Java-9-Cookbook,代碼行數:8,代碼來源:Chapter07Concurrency01.java

示例9: demo4_synchronize1

import java.util.stream.DoubleStream; //導入依賴的package包/類
private static void demo4_synchronize1() {
    System.out.println();

    Calculator c = new Calculator();

    Thread thr1 = new Thread(() -> System.out.println(IntStream.range(1, 4)
            .peek(x -> DoubleStream.generate(new Random()::nextDouble).limit(10))
            .mapToDouble(c::calculate).sum()));
    thr1.start();

    Thread thr2 = new Thread(() -> System.out.println(IntStream.range(1, 4)
            .mapToDouble(c::calculate).sum()));
    thr2.start();
}
 
開發者ID:PacktPublishing,項目名稱:Java-9-Cookbook,代碼行數:15,代碼來源:Chapter07Concurrency01.java

示例10: testDoubleStreamBuilder

import java.util.stream.DoubleStream; //導入依賴的package包/類
private void testDoubleStreamBuilder(int size, Function<Integer, DoubleStream> supplier) {
    TestData.OfDouble data = TestData.Factory.ofDoubleSupplier(String.format("[0, %d)", size),
                                                               () -> supplier.apply(size));

    withData(data).
            stream(s -> s).
            expectedResult(IntStream.range(0, size).asDoubleStream().toArray()).
            exercise();

    withData(data).
            stream(s -> s.map(i -> i)).
            expectedResult(IntStream.range(0, size).asDoubleStream().toArray()).
            exercise();
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:15,代碼來源:StreamBuilderTest.java

示例11: testNPE

import java.util.stream.DoubleStream; //導入依賴的package包/類
@Test
public void testNPE() {
    checkNPE(() -> Stream.iterate("", null, x -> x + "a"));
    checkNPE(() -> Stream.iterate("", String::isEmpty, null));
    checkNPE(() -> IntStream.iterate(0, null, x -> x + 1));
    checkNPE(() -> IntStream.iterate(0, x -> x < 10, null));
    checkNPE(() -> LongStream.iterate(0, null, x -> x + 1));
    checkNPE(() -> LongStream.iterate(0, x -> x < 10, null));
    checkNPE(() -> DoubleStream.iterate(0, null, x -> x + 1));
    checkNPE(() -> DoubleStream.iterate(0, x -> x < 10, null));
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:12,代碼來源:IterateTest.java

示例12: testDoubleCollectNull

import java.util.stream.DoubleStream; //導入依賴的package包/類
public void testDoubleCollectNull() {
    checkNPE(() -> DoubleStream.of(1).collect(null,
                                            DoubleSummaryStatistics::accept,
                                            DoubleSummaryStatistics::combine));
    checkNPE(() -> DoubleStream.of(1).collect(DoubleSummaryStatistics::new,
                                            null,
                                            DoubleSummaryStatistics::combine));
    checkNPE(() -> DoubleStream.of(1).collect(DoubleSummaryStatistics::new,
                                              DoubleSummaryStatistics::accept,
                                              null));
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:12,代碼來源:CollectAndSummaryStatisticsTest.java

示例13: scoreGraphToWeightGraph

import java.util.stream.DoubleStream; //導入依賴的package包/類
private double[][] scoreGraphToWeightGraph(double[][] Gs) {
    double[][] Gw = new double[Gs.length][];
    for (int i = 0; i < Gs.length; i++) {
        Gw[i] = DoubleStream.of(Gs[i]).map(Math::exp).toArray();
    }
    return Gw;
}
 
開發者ID:shtechair,項目名稱:CRFAE-Dep-Parser,代碼行數:8,代碼來源:Parameters.java

示例14: testDoubleOps

import java.util.stream.DoubleStream; //導入依賴的package包/類
@Test(dataProvider = "DoubleStreamTestData", dataProviderClass = DoubleStreamTestDataProvider.class)
public void testDoubleOps(String name, TestData.OfDouble data) {
    Collection<Double> result = exerciseOps(data, s -> s.flatMap(i -> Collections.singleton(i).stream().mapToDouble(j -> j)));
    assertEquals(data.size(), result.size());
    assertContents(data, result);

    result = exerciseOps(data, s -> DoubleStream.empty());
    assertEquals(0, result.size());
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:10,代碼來源:FlatMapOpTest.java

示例15: pointsStream

import java.util.stream.DoubleStream; //導入依賴的package包/類
/**
 * MS == -1 -> total
 *
 * @param ms
 * @return
 */
private DoubleStream pointsStream(int ms) {
    ArrayList<Double> points = new ArrayList<>();
    for (Group g : groups) {
        if (ms == -1) {
            points.add(g.getTotalSum(catalogue));
        } else {
            points.add(g.getSumForMilestone(catalogue.getMilestoneByOrdinal(ms), catalogue));
        }
    }
    return points.stream().mapToDouble(Double::valueOf);
}
 
開發者ID:dbisUnibas,項目名稱:ReqMan,代碼行數:18,代碼來源:OverviewSnapshot.java


注:本文中的java.util.stream.DoubleStream類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。