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();
}
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));
}
}
Aggregations