@Override public DoubleStream asDoubleStream() { return DoubleStream.of(element); }
@Override public DoubleStream asDoubleStream() { return DoubleStream.of(element); }
public static double min(double... values) { return DoubleStream.of(values) .min() .getAsDouble(); }
public static double max(double... values) { return DoubleStream.of(values) .max() .getAsDouble(); }
/** * If a value is present in {@code optional}, returns a stream containing only that element, * otherwise returns an empty stream. * * <p><b>Java 9 users:</b> use {@code optional.stream()} instead. */ public static DoubleStream stream(OptionalDouble optional) { return optional.isPresent() ? DoubleStream.of(optional.getAsDouble()) : DoubleStream.empty(); }
double totalCost = DoubleStream.of(targetTermDeletionCosts).sum(); for (int sourceTermIndex = 0; sourceTermIndex < assignments.length; sourceTermIndex++) { int targetTermIndex = assignments[sourceTermIndex];
/** * If a value is present in {@code optional}, returns a stream containing only that element, * otherwise returns an empty stream. * * <p><b>Java 9 users:</b> use {@code optional.stream()} instead. */ public static DoubleStream stream(OptionalDouble optional) { return optional.isPresent() ? DoubleStream.of(optional.getAsDouble()) : DoubleStream.empty(); }
/** * If a value is present in {@code optional}, returns a stream containing only that element, * otherwise returns an empty stream. * * <p><b>Java 9 users:</b> use {@code optional.stream()} instead. */ public static DoubleStream stream(OptionalDouble optional) { return optional.isPresent() ? DoubleStream.of(optional.getAsDouble()) : DoubleStream.empty(); }
@SuppressWarnings( "unchecked" ) public static DoubleStream toDoubleStream( Object list ) { if ( list == null ) { return DoubleStream.empty(); } else if ( list instanceof SequenceValue ) { throw new IllegalArgumentException( "Need to implement support for SequenceValue in CompiledConversionUtils.toDoubleStream" ); } else if ( list instanceof List ) { return ((List) list).stream().mapToDouble( n -> ((Number) n).doubleValue() ); } else if ( Object[].class.isAssignableFrom( list.getClass() ) ) { return Arrays.stream( (Object[]) list ).mapToDouble( n -> ((Number) n).doubleValue() ); } else if ( list instanceof float[] ) { float[] array = (float[]) list; return IntStream.range( 0, array.length ).mapToDouble( i -> array[i] ); } else if ( list instanceof double[] ) { return DoubleStream.of( (double[]) list ); } throw new IllegalArgumentException( format( "Can not be converted to stream: %s", list.getClass().getName() ) ); }
public void testMapWithIndex_doubleStream_closeIsPropagated_sized() { testMapWithIndex_doubleStream_closeIsPropagated(DoubleStream.of(1, 2, 3)); }
/** * Create new {@link Weights} given {@code weights} as {@code double}. * * @param weights must not be {@literal null}. * @return the {@link Weights} for {@code weights}. */ public static Weights of(double... weights) { Assert.notNull(weights, "Weights must not be null!"); return new Weights(DoubleStream.of(weights).boxed().collect(Collectors.toList())); }
/** * If a value is present in {@code optional}, returns a stream containing only that element, * otherwise returns an empty stream. * * <p><b>Java 9 users:</b> use {@code optional.stream()} instead. */ public static DoubleStream stream(OptionalDouble optional) { return optional.isPresent() ? DoubleStream.of(optional.getAsDouble()) : DoubleStream.empty(); }
private Double[] box(double[] values) { return DoubleStream.of(values).boxed().toArray(Double[]::new); } }
/** * Verifies that {@link DoublePredicate} evaluates all the given values to {@code false}. * <p> * Example : * <pre><code class='java'> DoublePredicate tallSize = size -> size > 1.90; * * // assertion succeeds: * assertThat(tallSize).rejects(1.75, 1.80, 1.85); * * // assertion fails because of 1.90 size: * assertThat(tallSize).rejects(1.80, 1.85, 1.90);</code></pre> * * @param values values that the actual {@code Predicate} should reject. * @return this assertion object. * @throws AssertionError if the actual {@code Predicate} accepts one of the given values. */ public DoublePredicateAssert rejects(double... values) { if (values.length == 1) return rejectsInternal(values[0]); return rejectsAllInternal(DoubleStream.of(values).boxed().collect(Collectors.toList())); } }
/** * Verifies that {@link DoublePredicate} evaluates all the given values to {@code true}. * <p> * Example : * <pre><code class='java'> DoublePredicate tallSize = size -> size > 1.90; * * // assertion succeeds: * assertThat(tallSize).accepts(1.95, 2.00, 2.05); * * // assertion fails: * assertThat(tallSize).accepts(1.85, 1.95, 2.05);</code></pre> * * @param values values that the actual {@code Predicate} should accept. * @return this assertion object. * @throws AssertionError if the actual {@code Predicate} does not accept all given values. */ public DoublePredicateAssert accepts(double... values) { if (values.length == 1) return acceptsInternal(values[0]); return acceptsAllInternal(DoubleStream.of(values).boxed().collect(Collectors.toList())); }
private SymbolStatsEstimate buildSymbolStatistics(List<Object> values, Session session, Type type) { List<Object> nonNullValues = values.stream() .filter(Objects::nonNull) .collect(toImmutableList()); if (nonNullValues.isEmpty()) { return SymbolStatsEstimate.zero(); } double[] valuesAsDoubles = nonNullValues.stream() .map(value -> toStatsRepresentation(metadata, session, type, value)) .filter(OptionalDouble::isPresent) .mapToDouble(OptionalDouble::getAsDouble) .toArray(); double lowValue = DoubleStream.of(valuesAsDoubles).min().orElse(Double.NEGATIVE_INFINITY); double highValue = DoubleStream.of(valuesAsDoubles).max().orElse(Double.POSITIVE_INFINITY); double valuesCount = values.size(); double nonNullValuesCount = nonNullValues.size(); long distinctValuesCount = nonNullValues.stream().distinct().count(); return SymbolStatsEstimate.builder() .setNullsFraction((valuesCount - nonNullValuesCount) / valuesCount) .setLowValue(lowValue) .setHighValue(highValue) .setDistinctValuesCount(distinctValuesCount) .build(); } }
public void testCopyOf_stream() { assertThat(ImmutableDoubleArray.copyOf(DoubleStream.empty())) .isSameAs(ImmutableDoubleArray.of()); assertThat(ImmutableDoubleArray.copyOf(DoubleStream.of(0, 1, 3)).asList()) .containsExactly(0.0, 1.0, 3.0) .inOrder(); }
@GwtIncompatible // TODO(b/38490623): reenable after GWT double-to-string conversion is fixed public void testMapWithIndex_doubleStream() { SpliteratorTester.of( () -> Streams.mapWithIndex(DoubleStream.of(0, 1, 2), (x, i) -> x + ":" + i).spliterator()) .expect("0.0:0", "1.0:1", "2.0:2"); }