本文整理了Java中java.util.stream.DoubleStream.sorted()
方法的一些代码示例,展示了DoubleStream.sorted()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。DoubleStream.sorted()
方法的具体详情如下:
包路径:java.util.stream.DoubleStream
类名称:DoubleStream
方法名:sorted
[英]Returns a stream consisting of the elements of this stream in sorted order. The elements are compared for equality according to java.lang.Double#compare(double,double).
This is a stateful intermediate operation.
[中]返回由该流的元素按排序顺序组成的流。根据java比较元素是否相等。比较(双重,双重)。
这是一个stateful intermediate operation。
代码示例来源:origin: speedment/speedment
public DoubleSortedAction() {
super(s -> s.sorted(), DoubleStream.class, SORTED);
}
代码示例来源:origin: speedment/speedment
@Override
public DoubleStream sorted() {
return wrap(stream().sorted());
}
代码示例来源:origin: speedment/speedment
@Override
@SuppressWarnings("unchecked")
public TS build(boolean parallel) {
final TS built = previous().build(parallel);
if (built instanceof Stream<?>) {
if (comparator == null) {
return (TS) ((Stream<T>) built).sorted();
} else {
return (TS) ((Stream<T>) built).sorted(comparator);
}
} else if (built instanceof IntStream) {
return (TS) ((IntStream) built).sorted();
} else if (built instanceof LongStream) {
return (TS) ((LongStream) built).sorted();
} else if (built instanceof DoubleStream) {
return (TS) ((DoubleStream) built).sorted();
} else {
throw new UnsupportedOperationException(
"Built stream did not match any known stream interface."
);
}
}
}
代码示例来源:origin: prestodb/presto
private void testAggregationDoubles(InternalAggregationFunction function, Page page, double maxError, double... inputs)
{
assertAggregation(function,
QDIGEST_EQUALITY,
"test multiple positions",
page,
getExpectedValueDoubles(maxError, inputs));
// test scalars
List<Double> rows = Arrays.stream(inputs).sorted().boxed().collect(Collectors.toList());
SqlVarbinary returned = (SqlVarbinary) AggregationTestUtils.aggregation(function, page);
assertPercentileWithinError(StandardTypes.DOUBLE, returned, maxError, rows, 0.1, 0.5, 0.9, 0.99);
}
代码示例来源:origin: prestodb/presto
private void assertPercentilesWithinError(String type, SqlVarbinary binary, double error, List<? extends Number> rows, double[] percentiles)
{
List<Double> boxedPercentiles = Arrays.stream(percentiles).sorted().boxed().collect(toImmutableList());
List<Number> lowerBounds = boxedPercentiles.stream().map(percentile -> getLowerBound(error, rows, percentile)).collect(toImmutableList());
List<Number> upperBounds = boxedPercentiles.stream().map(percentile -> getUpperBound(error, rows, percentile)).collect(toImmutableList());
// Ensure that the lower bound of each item in the distribution is not greater than the chosen quantiles
functionAssertions.assertFunction(
format(
"zip_with(values_at_quantiles(CAST(X'%s' AS qdigest(%s)), ARRAY[%s]), ARRAY[%s], (value, lowerbound) -> value >= lowerbound)",
binary.toString().replaceAll("\\s+", " "),
type,
ARRAY_JOINER.join(boxedPercentiles),
ARRAY_JOINER.join(lowerBounds)),
METADATA.getType(parseTypeSignature("array(boolean)")),
Collections.nCopies(percentiles.length, true));
// Ensure that the upper bound of each item in the distribution is not less than the chosen quantiles
functionAssertions.assertFunction(
format(
"zip_with(values_at_quantiles(CAST(X'%s' AS qdigest(%s)), ARRAY[%s]), ARRAY[%s], (value, upperbound) -> value <= upperbound)",
binary.toString().replaceAll("\\s+", " "),
type,
ARRAY_JOINER.join(boxedPercentiles),
ARRAY_JOINER.join(upperBounds)),
METADATA.getType(parseTypeSignature("array(boolean)")),
Collections.nCopies(percentiles.length, true));
}
代码示例来源:origin: com.speedment.runtime/runtime-core
public DoubleSortedAction() {
super(s -> s.sorted(), DoubleStream.class, SORTED);
}
代码示例来源:origin: net.dongliu/commons-lang
@Override
public ExDoubleStream sorted() {
return ExDoubleStream.of(stream.sorted());
}
代码示例来源:origin: se.ugli.ugli-commons/ugli-commons
@Override
public DoubleStream sorted() {
return new DoubleResourceStream(stream.sorted(), closeOnTerminalOperation, resources);
}
代码示例来源:origin: stanford-futuredata/macrobase
/**
* @param inputCol The column values to convert to percentiles, remains unmodified
* @param outputCol The percentile value that corresponds to the given column value
*/
@Override
protected void applyFunction(final double[] inputCol, final double[] outputCol) {
// sort the column, and, for each value in the column, store the *min* position in the sorted array
final double[] sortedInputCol = Arrays.stream(inputCol).sorted().toArray();
final Map<Double, Integer> map = new HashMap<>();
for (int i = sortedInputCol.length - 1; i >= 0; --i) {
// increment by one so that the max value has 100th percentile
map.put(sortedInputCol[i], i + 1);
}
// normalize the position for each value by the size of the column
final double norm = inputCol.length;
for (int i = 0; i < inputCol.length; ++i) {
outputCol[i] = map.get(inputCol[i]) / norm;
}
}
}
代码示例来源:origin: com.davidbracewell/mango
@Override
public MDoubleStream sorted(boolean ascending) {
if (ascending) {
return new LocalDoubleStream(stream.sorted());
}
return new LocalDoubleStream(stream.mapToObj(Double::valueOf)
.sorted((d1, d2) -> -Double.compare(d1, d2))
.mapToDouble(d -> d));
}
代码示例来源:origin: org.apache.solr/solr-solrj
@Override
public Object doWork(Object value) throws IOException {
if(!(value instanceof List<?>)){
throw new StreamEvaluatorException("List value expected but found type %s for value %s", value.getClass().getName(), value.toString());
}
EmpiricalDistribution empiricalDistribution = new EmpiricalDistribution();
double[] backingValues = ((List<?>)value).stream().mapToDouble(innerValue -> ((Number)innerValue).doubleValue()).sorted().toArray();
empiricalDistribution.load(backingValues);
return empiricalDistribution;
}
}
代码示例来源:origin: com.simiacryptus/mindseye
/**
* Normalize distribution tensor.
*
* @return the tensor
*/
public Tensor normalizeDistribution() {
double[] sortedValues = Arrays.stream(getData()).sorted().toArray();
Tensor result = map(v -> Math.abs(((double) Arrays.binarySearch(sortedValues, v)) / ((double) sortedValues.length)));
return result;
}
代码示例来源:origin: com.simiacryptus/java-util
/**
* Gets percentile.
*
* @param percentile the percentile
* @return the percentile
*/
public synchronized Double getPercentile(final double percentile) {
if (null == values) return Double.NaN;
return values.parallelStream().flatMapToDouble(x -> Arrays.stream(x)).sorted().skip((int) (percentile * values.size())).findFirst().orElse(Double.NaN);
}
代码示例来源:origin: com.speedment.runtime/runtime-core
@Override
public DoubleStream sorted() {
return wrap(stream().sorted());
}
代码示例来源:origin: one.util/streamex
@Override
public DoubleStreamEx sorted() {
return new DoubleStreamEx(stream().sorted(), context);
}
代码示例来源:origin: stackoverflow.com
double[] monthsArray = Random.doubles(12, 0, 100).sorted().toArray();
代码示例来源:origin: io.prestosql/presto-main
private void testAggregationDoubles(InternalAggregationFunction function, Page page, double maxError, double... inputs)
{
assertAggregation(function,
QDIGEST_EQUALITY,
"test multiple positions",
page,
getExpectedValueDoubles(maxError, inputs));
// test scalars
List<Double> rows = Arrays.stream(inputs).sorted().boxed().collect(Collectors.toList());
SqlVarbinary returned = (SqlVarbinary) AggregationTestUtils.aggregation(function, page);
assertPercentileWithinError(StandardTypes.DOUBLE, returned, maxError, rows, 0.1, 0.5, 0.9, 0.99);
}
代码示例来源:origin: prestosql/presto
private void testAggregationDoubles(InternalAggregationFunction function, Page page, double maxError, double... inputs)
{
assertAggregation(function,
QDIGEST_EQUALITY,
"test multiple positions",
page,
getExpectedValueDoubles(maxError, inputs));
// test scalars
List<Double> rows = Arrays.stream(inputs).sorted().boxed().collect(Collectors.toList());
SqlVarbinary returned = (SqlVarbinary) AggregationTestUtils.aggregation(function, page);
assertPercentileWithinError(StandardTypes.DOUBLE, returned, maxError, rows, 0.1, 0.5, 0.9, 0.99);
}
代码示例来源:origin: prestosql/presto
private void assertPercentilesWithinError(String type, SqlVarbinary binary, double error, List<? extends Number> rows, double[] percentiles)
{
List<Double> boxedPercentiles = Arrays.stream(percentiles).sorted().boxed().collect(toImmutableList());
List<Number> lowerBounds = boxedPercentiles.stream().map(percentile -> getLowerBound(error, rows, percentile)).collect(toImmutableList());
List<Number> upperBounds = boxedPercentiles.stream().map(percentile -> getUpperBound(error, rows, percentile)).collect(toImmutableList());
// Ensure that the lower bound of each item in the distribution is not greater than the chosen quantiles
functionAssertions.assertFunction(
format(
"zip_with(values_at_quantiles(CAST(X'%s' AS qdigest(%s)), ARRAY[%s]), ARRAY[%s], (value, lowerbound) -> value >= lowerbound)",
binary.toString().replaceAll("\\s+", " "),
type,
ARRAY_JOINER.join(boxedPercentiles),
ARRAY_JOINER.join(lowerBounds)),
METADATA.getType(parseTypeSignature("array(boolean)")),
Collections.nCopies(percentiles.length, true));
// Ensure that the upper bound of each item in the distribution is not less than the chosen quantiles
functionAssertions.assertFunction(
format(
"zip_with(values_at_quantiles(CAST(X'%s' AS qdigest(%s)), ARRAY[%s]), ARRAY[%s], (value, upperbound) -> value <= upperbound)",
binary.toString().replaceAll("\\s+", " "),
type,
ARRAY_JOINER.join(boxedPercentiles),
ARRAY_JOINER.join(upperBounds)),
METADATA.getType(parseTypeSignature("array(boolean)")),
Collections.nCopies(percentiles.length, true));
}
代码示例来源:origin: io.prestosql/presto-main
private void assertPercentilesWithinError(String type, SqlVarbinary binary, double error, List<? extends Number> rows, double[] percentiles)
{
List<Double> boxedPercentiles = Arrays.stream(percentiles).sorted().boxed().collect(toImmutableList());
List<Number> lowerBounds = boxedPercentiles.stream().map(percentile -> getLowerBound(error, rows, percentile)).collect(toImmutableList());
List<Number> upperBounds = boxedPercentiles.stream().map(percentile -> getUpperBound(error, rows, percentile)).collect(toImmutableList());
// Ensure that the lower bound of each item in the distribution is not greater than the chosen quantiles
functionAssertions.assertFunction(
format(
"zip_with(values_at_quantiles(CAST(X'%s' AS qdigest(%s)), ARRAY[%s]), ARRAY[%s], (value, lowerbound) -> value >= lowerbound)",
binary.toString().replaceAll("\\s+", " "),
type,
ARRAY_JOINER.join(boxedPercentiles),
ARRAY_JOINER.join(lowerBounds)),
METADATA.getType(parseTypeSignature("array(boolean)")),
Collections.nCopies(percentiles.length, true));
// Ensure that the upper bound of each item in the distribution is not less than the chosen quantiles
functionAssertions.assertFunction(
format(
"zip_with(values_at_quantiles(CAST(X'%s' AS qdigest(%s)), ARRAY[%s]), ARRAY[%s], (value, upperbound) -> value <= upperbound)",
binary.toString().replaceAll("\\s+", " "),
type,
ARRAY_JOINER.join(boxedPercentiles),
ARRAY_JOINER.join(upperBounds)),
METADATA.getType(parseTypeSignature("array(boolean)")),
Collections.nCopies(percentiles.length, true));
}
内容来源于网络,如有侵权,请联系作者删除!