Search in sources :

Example 6 with IntStream

use of java.util.stream.IntStream in project TeeTime by teetime-framework.

the class ThreeStagesGlobalTaskPoolIT method shouldExecutePipelineCorrectlyManyElements.

private void shouldExecutePipelineCorrectlyManyElements(final int numElements, final int numThreads, final int numExecutions) {
    List<Integer> processedElements = new ArrayList<>();
    IntStream inputElements = IntStream.iterate(0, i -> i + 1).limit(numElements);
    Configuration config = new Configuration().from(new StreamProducer<>(inputElements)).to(new Counter<>()).end(new CollectorSink<>(processedElements));
    TeeTimeScheduler scheduling = new GlobalTaskPoolScheduling(numThreads, config, numExecutions);
    Execution<Configuration> execution = new Execution<>(config, true, scheduling);
    execution.executeBlocking();
    for (int i = 0; i < numElements; i++) {
        Integer actualElement = processedElements.get(i);
        assertThat(actualElement, is(i));
    }
    assertThat(processedElements, hasSize(numElements));
}
Also used : IntStream(java.util.stream.IntStream) MethodSorters(org.junit.runners.MethodSorters) StreamProducer(teetime.stage.StreamProducer) Matchers(org.hamcrest.Matchers) Test(org.junit.Test) TeeTimeScheduler(teetime.framework.TeeTimeScheduler) ArrayList(java.util.ArrayList) Configuration(teetime.framework.Configuration) List(java.util.List) CollectorSink(teetime.stage.CollectorSink) Execution(teetime.framework.Execution) Assert(org.junit.Assert) FixMethodOrder(org.junit.FixMethodOrder) Counter(teetime.stage.Counter) Configuration(teetime.framework.Configuration) ArrayList(java.util.ArrayList) Counter(teetime.stage.Counter) Execution(teetime.framework.Execution) TeeTimeScheduler(teetime.framework.TeeTimeScheduler) IntStream(java.util.stream.IntStream)

Example 7 with IntStream

use of java.util.stream.IntStream in project chuidiang-ejemplos by chuidiang.

the class Java8RandomExample method main.

public static void main(String[] args) {
    Random random = new Random();
    // IntStream for values between 1 and 6 both included
    final IntStream ints = random.ints(1, 7);
    // Iterator to get integers
    final PrimitiveIterator.OfInt iterator = ints.iterator();
    // Loop to print 10 integers.
    int counter = 0;
    while (iterator.hasNext() && counter < 10) {
        System.out.println(iterator.next());
        counter++;
    }
    // Close de stream
    ints.close();
}
Also used : Random(java.util.Random) PrimitiveIterator(java.util.PrimitiveIterator) IntStream(java.util.stream.IntStream)

Example 8 with IntStream

use of java.util.stream.IntStream in project ddf by codice.

the class IngestCommand method processBatch.

private boolean processBatch(CatalogFacade catalog, ArrayList<Metacard> metacards) throws SourceUnavailableException {
    CreateResponse createResponse = null;
    try {
        createResponse = createMetacards(catalog, metacards);
    } catch (IngestException e) {
        printErrorMessage("Error executing command: " + e.getMessage());
        if (INGEST_LOGGER.isWarnEnabled()) {
            INGEST_LOGGER.warn("Error ingesting metacard batch {}", buildIngestLog(metacards), e);
        }
    } catch (SourceUnavailableException e) {
        if (INGEST_LOGGER.isWarnEnabled()) {
            INGEST_LOGGER.warn("Error on process batch, local Provider not available. {}" + " metacards failed to ingest. {}", metacards.size(), buildIngestLog(metacards), e);
        }
    } finally {
        IntStream range = IntStream.range(0, metacards.size());
        range.forEach(i -> phaser.arriveAndDeregister());
        range.close();
    }
    if (createResponse != null) {
        ingestCount.getAndAdd(metacards.size());
    }
    return createResponse != null;
}
Also used : SourceUnavailableException(ddf.catalog.source.SourceUnavailableException) CreateResponse(ddf.catalog.operation.CreateResponse) IngestException(ddf.catalog.source.IngestException) IntStream(java.util.stream.IntStream)

Example 9 with IntStream

use of java.util.stream.IntStream in project jdk8u_jdk by JetBrains.

the class StreamSpliteratorTest method testIntSplitting.

//
public void testIntSplitting() {
    List<Consumer<IntStream>> terminalOps = Arrays.asList(s -> s.toArray(), s -> s.forEach(e -> {
    }), s -> s.reduce(Integer::sum));
    List<UnaryOperator<IntStream>> intermediateOps = Arrays.asList(s -> s.parallel(), // The following ensures the wrapping spliterator is tested
    s -> s.map(i -> i).parallel());
    for (int i = 0; i < terminalOps.size(); i++) {
        setContext("termOpIndex", i);
        Consumer<IntStream> terminalOp = terminalOps.get(i);
        for (int j = 0; j < intermediateOps.size(); j++) {
            setContext("intOpIndex", j);
            UnaryOperator<IntStream> intermediateOp = intermediateOps.get(j);
            for (boolean proxyEstimateSize : new boolean[] { false, true }) {
                setContext("proxyEstimateSize", proxyEstimateSize);
                // Size is assumed to be larger than the target size for no splitting
                // @@@ Need way to obtain the target size
                Spliterator.OfInt sp = intermediateOp.apply(IntStream.range(0, 1000)).spliterator();
                ProxyNoExactSizeSpliterator.OfInt psp = new ProxyNoExactSizeSpliterator.OfInt(sp, proxyEstimateSize);
                IntStream s = StreamSupport.intStream(psp, true);
                terminalOp.accept(s);
                Assert.assertTrue(psp.splits > 0, String.format("Number of splits should be greater that zero when proxyEstimateSize is %s", proxyEstimateSize));
                Assert.assertTrue(psp.prefixSplits > 0, String.format("Number of non-null prefix splits should be greater that zero when proxyEstimateSize is %s", proxyEstimateSize));
                Assert.assertTrue(psp.sizeOnTraversal < 1000, String.format("Size on traversal of last split should be less than the size of the list, %d, when proxyEstimateSize is %s", 1000, proxyEstimateSize));
            }
        }
    }
}
Also used : IntStream(java.util.stream.IntStream) Arrays(java.util.Arrays) SpliteratorTestHelper(java.util.stream.SpliteratorTestHelper) IntConsumer(java.util.function.IntConsumer) UnaryOperator(java.util.function.UnaryOperator) Test(org.testng.annotations.Test) DoubleConsumer(java.util.function.DoubleConsumer) Function(java.util.function.Function) Assert(org.testng.Assert) LambdaTestHelpers.dpEven(java.util.stream.LambdaTestHelpers.dpEven) LambdaTestHelpers.irDoubler(java.util.stream.LambdaTestHelpers.irDoubler) StreamSupport(java.util.stream.StreamSupport) IntStreamTestDataProvider(java.util.stream.IntStreamTestDataProvider) LambdaTestHelpers.countTo(java.util.stream.LambdaTestHelpers.countTo) LongStream(java.util.stream.LongStream) LambdaTestHelpers.lpEven(java.util.stream.LambdaTestHelpers.lpEven) DoubleStreamTestDataProvider(java.util.stream.DoubleStreamTestDataProvider) TestData(java.util.stream.TestData) StreamTestDataProvider(java.util.stream.StreamTestDataProvider) LambdaTestHelpers.permuteStreamFunctions(java.util.stream.LambdaTestHelpers.permuteStreamFunctions) LongConsumer(java.util.function.LongConsumer) DoubleStream(java.util.stream.DoubleStream) Consumer(java.util.function.Consumer) List(java.util.List) Stream(java.util.stream.Stream) LambdaTestHelpers(java.util.stream.LambdaTestHelpers) OpTestCase(java.util.stream.OpTestCase) LambdaTestHelpers.mDoubler(java.util.stream.LambdaTestHelpers.mDoubler) LongStreamTestDataProvider(java.util.stream.LongStreamTestDataProvider) LambdaTestHelpers.pEven(java.util.stream.LambdaTestHelpers.pEven) LambdaTestHelpers.ipEven(java.util.stream.LambdaTestHelpers.ipEven) Comparator(java.util.Comparator) Spliterator(java.util.Spliterator) IntConsumer(java.util.function.IntConsumer) DoubleConsumer(java.util.function.DoubleConsumer) LongConsumer(java.util.function.LongConsumer) Consumer(java.util.function.Consumer) UnaryOperator(java.util.function.UnaryOperator) IntStream(java.util.stream.IntStream) Spliterator(java.util.Spliterator)

Example 10 with IntStream

use of java.util.stream.IntStream in project jdk8u_jdk by JetBrains.

the class SplittableRandomTest method intsDataProvider.

@DataProvider(name = "ints")
public static Object[][] intsDataProvider() {
    List<Object[]> data = new ArrayList<>();
    // Function to create a stream using a RandomBoxedSpliterator
    Function<Function<SplittableRandom, Integer>, IntStream> rbsf = sf -> StreamSupport.stream(new RandomBoxedSpliterator<>(new SplittableRandom(), 0, SIZE, sf), false).mapToInt(i -> i);
    // Unbounded
    data.add(new Object[] { TestData.Factory.ofIntSupplier(String.format("new SplittableRandom().ints().limit(%d)", SIZE), () -> new SplittableRandom().ints().limit(SIZE)), randomAsserter(SIZE, Integer.MAX_VALUE, 0) });
    data.add(new Object[] { TestData.Factory.ofIntSupplier(String.format("new SplittableRandom().ints(%d)", SIZE), () -> new SplittableRandom().ints(SIZE)), randomAsserter(SIZE, Integer.MAX_VALUE, 0) });
    data.add(new Object[] { TestData.Factory.ofIntSupplier(String.format("new RandomBoxedSpliterator(0, %d, sr -> sr.nextInt())", SIZE), () -> rbsf.apply(sr -> sr.nextInt())), randomAsserter(SIZE, Integer.MAX_VALUE, 0) });
    for (int b : BOUNDS) {
        for (int o : ORIGINS) {
            final int origin = o;
            final int bound = b;
            data.add(new Object[] { TestData.Factory.ofIntSupplier(String.format("new SplittableRandom().ints(%d, %d).limit(%d)", origin, bound, SIZE), () -> new SplittableRandom().ints(origin, bound).limit(SIZE)), randomAsserter(SIZE, origin, bound) });
            data.add(new Object[] { TestData.Factory.ofIntSupplier(String.format("new SplittableRandom().ints(%d, %d, %d)", SIZE, origin, bound), () -> new SplittableRandom().ints(SIZE, origin, bound)), randomAsserter(SIZE, origin, bound) });
            if (origin == 0) {
                data.add(new Object[] { TestData.Factory.ofIntSupplier(String.format("new RandomBoxedSpliterator(0, %d, sr -> sr.nextInt(%d))", SIZE, bound), () -> rbsf.apply(sr -> sr.nextInt(bound))), randomAsserter(SIZE, origin, bound) });
            }
            data.add(new Object[] { TestData.Factory.ofIntSupplier(String.format("new RandomBoxedSpliterator(0, %d, sr -> sr.nextInt(%d, %d))", SIZE, origin, bound), () -> rbsf.apply(sr -> sr.nextInt(origin, bound))), randomAsserter(SIZE, origin, bound) });
        }
    }
    return data.toArray(new Object[0][]);
}
Also used : IntStream(java.util.stream.IntStream) LongStream(java.util.stream.LongStream) DataProvider(org.testng.annotations.DataProvider) DoubleStreamTestScenario(java.util.stream.DoubleStreamTestScenario) TestData(java.util.stream.TestData) Set(java.util.Set) Test(org.testng.annotations.Test) Function(java.util.function.Function) ArrayList(java.util.ArrayList) DoubleStream(java.util.stream.DoubleStream) HashSet(java.util.HashSet) Consumer(java.util.function.Consumer) List(java.util.List) OpTestCase(java.util.stream.OpTestCase) SplittableRandom(java.util.SplittableRandom) StreamSupport(java.util.stream.StreamSupport) Spliterator(java.util.Spliterator) IntStreamTestScenario(java.util.stream.IntStreamTestScenario) LongStreamTestScenario(java.util.stream.LongStreamTestScenario) Function(java.util.function.Function) ArrayList(java.util.ArrayList) SplittableRandom(java.util.SplittableRandom) IntStream(java.util.stream.IntStream) DataProvider(org.testng.annotations.DataProvider)

Aggregations

IntStream (java.util.stream.IntStream)80 Test (org.junit.Test)20 List (java.util.List)15 ArrayList (java.util.ArrayList)13 Arrays (java.util.Arrays)10 Stream (java.util.stream.Stream)9 Random (java.util.Random)7 Collectors (java.util.stream.Collectors)7 Map (java.util.Map)5 Pattern (java.util.regex.Pattern)5 DoubleStream (java.util.stream.DoubleStream)5 LongStream (java.util.stream.LongStream)5 DecimalBoxFieldDefinition (org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.decimalBox.definition.DecimalBoxFieldDefinition)5 MultipleSubFormFieldDefinition (org.kie.workbench.common.forms.fields.shared.fieldTypes.relations.multipleSubform.definition.MultipleSubFormFieldDefinition)5 SubFormFieldDefinition (org.kie.workbench.common.forms.fields.shared.fieldTypes.relations.subForm.definition.SubFormFieldDefinition)5 FieldDefinition (org.kie.workbench.common.forms.model.FieldDefinition)5 LayoutRow (org.uberfire.ext.layout.editor.api.editor.LayoutRow)5 LayoutTemplate (org.uberfire.ext.layout.editor.api.editor.LayoutTemplate)5 Assert (org.junit.Assert)4 Test (org.junit.jupiter.api.Test)4