Search in sources :

Example 1 with DoubleArrayList

use of com.carrotsearch.hppc.DoubleArrayList in project anomaly-detection by opensearch-project.

the class ParseUtils method parseDoubleArray.

public static double[] parseDoubleArray(XContentParser parser) throws IOException {
    DoubleArrayList oldValList = new DoubleArrayList();
    ensureExpectedToken(XContentParser.Token.START_ARRAY, parser.currentToken(), parser);
    while (parser.nextToken() != XContentParser.Token.END_ARRAY) {
        oldValList.add(parser.doubleValue());
    }
    return oldValList.toArray();
}
Also used : DoubleArrayList(com.carrotsearch.hppc.DoubleArrayList)

Example 2 with DoubleArrayList

use of com.carrotsearch.hppc.DoubleArrayList in project teavm by konsoletyper.

the class Helper method testDoubleStream.

static void testDoubleStream(Supplier<DoubleStream> streamSupplier, double... expected) {
    StringBuilder sb = new StringBuilder();
    for (double e : expected) {
        sb.append(e).append(';');
    }
    String expectedText = sb.toString();
    sb.setLength(0);
    streamSupplier.get().forEach(appendDoubleNumbersTo(sb));
    assertEquals(expectedText, sb.toString());
    sb.setLength(0);
    PrimitiveIterator.OfDouble iter = streamSupplier.get().iterator();
    while (iter.hasNext()) {
        sb.append(iter.next()).append(';');
    }
    assertEquals(expectedText, sb.toString());
    sb.setLength(0);
    DoubleArrayList list = streamSupplier.get().collect(DoubleArrayList::new, DoubleArrayList::add, DoubleArrayList::addAll);
    for (DoubleCursor cursor : list) {
        sb.append(cursor.value).append(';');
    }
    assertEquals(expectedText, sb.toString());
    assertEquals(expected.length, streamSupplier.get().count());
    if (expected.length > 0) {
        double max = expected[0];
        for (double e : expected) {
            max = Math.max(max, e);
        }
        double notInCollection = max + 1;
        double inCollection = expected[0];
        assertTrue(streamSupplier.get().allMatch(e -> e < notInCollection));
        assertFalse(streamSupplier.get().allMatch(e -> e < inCollection));
        assertTrue(streamSupplier.get().anyMatch(e -> e == inCollection));
        assertFalse(streamSupplier.get().anyMatch(e -> e == notInCollection));
    } else {
        assertTrue(streamSupplier.get().allMatch(e -> false));
        assertTrue(streamSupplier.get().allMatch(e -> true));
        assertFalse(streamSupplier.get().anyMatch(e -> true));
        assertFalse(streamSupplier.get().anyMatch(e -> false));
    }
}
Also used : LongArrayList(com.carrotsearch.hppc.LongArrayList) IntStream(java.util.stream.IntStream) LongStream(java.util.stream.LongStream) Iterator(java.util.Iterator) DoubleCursor(com.carrotsearch.hppc.cursors.DoubleCursor) IntCursor(com.carrotsearch.hppc.cursors.IntCursor) DoubleArrayList(com.carrotsearch.hppc.DoubleArrayList) IntConsumer(java.util.function.IntConsumer) Assert.assertTrue(org.junit.Assert.assertTrue) DoubleConsumer(java.util.function.DoubleConsumer) Supplier(java.util.function.Supplier) Collectors(java.util.stream.Collectors) LongConsumer(java.util.function.LongConsumer) DoubleStream(java.util.stream.DoubleStream) PrimitiveIterator(java.util.PrimitiveIterator) Consumer(java.util.function.Consumer) List(java.util.List) Stream(java.util.stream.Stream) LongCursor(com.carrotsearch.hppc.cursors.LongCursor) Assert.assertFalse(org.junit.Assert.assertFalse) IntArrayList(com.carrotsearch.hppc.IntArrayList) Assert.assertEquals(org.junit.Assert.assertEquals) PrimitiveIterator(java.util.PrimitiveIterator) DoubleArrayList(com.carrotsearch.hppc.DoubleArrayList) DoubleCursor(com.carrotsearch.hppc.cursors.DoubleCursor)

Aggregations

DoubleArrayList (com.carrotsearch.hppc.DoubleArrayList)2 IntArrayList (com.carrotsearch.hppc.IntArrayList)1 LongArrayList (com.carrotsearch.hppc.LongArrayList)1 DoubleCursor (com.carrotsearch.hppc.cursors.DoubleCursor)1 IntCursor (com.carrotsearch.hppc.cursors.IntCursor)1 LongCursor (com.carrotsearch.hppc.cursors.LongCursor)1 Iterator (java.util.Iterator)1 List (java.util.List)1 PrimitiveIterator (java.util.PrimitiveIterator)1 Consumer (java.util.function.Consumer)1 DoubleConsumer (java.util.function.DoubleConsumer)1 IntConsumer (java.util.function.IntConsumer)1 LongConsumer (java.util.function.LongConsumer)1 Supplier (java.util.function.Supplier)1 Collectors (java.util.stream.Collectors)1 DoubleStream (java.util.stream.DoubleStream)1 IntStream (java.util.stream.IntStream)1 LongStream (java.util.stream.LongStream)1 Stream (java.util.stream.Stream)1 Assert.assertEquals (org.junit.Assert.assertEquals)1