Java Code Examples for java.util.function.DoubleSupplier#getAsDouble()
The following examples show how to use
java.util.function.DoubleSupplier#getAsDouble() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: VectorPerformance.java From commons-geometry with Apache License 2.0 | 6 votes |
/** Set up the instance for the benchmark. */ @Setup(Level.Iteration) public void setup() { vectors = new ArrayList<>(size); final double[] values = new double[dimension]; final DoubleSupplier doubleSupplier = createDoubleSupplier(getType(), RandomSource.create(RandomSource.XO_RO_SHI_RO_128_PP)); for (int i = 0; i < size; ++i) { for (int j = 0; j < dimension; ++j) { values[j] = doubleSupplier.getAsDouble(); } vectors.add(vectorFactory.apply(values)); } }
Example 2
Source File: SphereTest.java From commons-geometry with Apache License 2.0 | 5 votes |
@Test public void testToTree_randomSpheres() { // arrange UniformRandomProvider rand = RandomSource.create(RandomSource.XO_RO_SHI_RO_128_PP, 1L); DoublePrecisionContext precision = new EpsilonDoublePrecisionContext(1e-10); double min = 1e-1; double max = 1e2; DoubleSupplier randDouble = () -> (rand.nextDouble() * (max - min)) + min; int count = 10; for (int i = 0; i < count; ++i) { Vector3D center = Vector3D.of( randDouble.getAsDouble(), randDouble.getAsDouble(), randDouble.getAsDouble()); double radius = randDouble.getAsDouble(); Sphere sphere = Sphere.from(center, radius, precision); for (int s = 0; s < 7; ++s) { // act RegionBSPTree3D tree = sphere.toTree(s); // assert Assert.assertEquals((int)(8 * Math.pow(4, s)), tree.getBoundaries().size()); Assert.assertTrue(tree.isFinite()); Assert.assertFalse(tree.isEmpty()); Assert.assertTrue(tree.getSize() < sphere.getSize()); } } }
Example 3
Source File: PostgreSQLDatabaseMetrics.java From micrometer with Apache License 2.0 | 5 votes |
/** * Function that makes sure functional counter values survive pg_stat_reset calls. */ Double resettableFunctionalCounter(String functionalCounterKey, DoubleSupplier function) { Double result = function.getAsDouble(); Double previousResult = previousValueCacheMap.getOrDefault(functionalCounterKey, 0D); Double beforeResetValue = beforeResetValuesCacheMap.getOrDefault(functionalCounterKey, 0D); Double correctedValue = result + beforeResetValue; if (correctedValue < previousResult) { beforeResetValuesCacheMap.put(functionalCounterKey, previousResult); correctedValue = previousResult + result; } previousValueCacheMap.put(functionalCounterKey, correctedValue); return correctedValue; }
Example 4
Source File: TimeWindowMax.java From micrometer with Apache License 2.0 | 4 votes |
private double poll(DoubleSupplier maxSupplier) { rotate(); synchronized (this) { return maxSupplier.getAsDouble(); } }
Example 5
Source File: TomlTable.java From cava with Apache License 2.0 | 3 votes |
/** * Get a double from the TOML document, or return a default. * * @param path The key path. * @param defaultValue A supplier for the default value. * @return The value, or the default. * @throws TomlInvalidTypeException If the value is present but not a double, or any element of the path preceding the * final key is not a table. */ default double getDouble(List<String> path, DoubleSupplier defaultValue) { requireNonNull(defaultValue); Double value = getDouble(path); if (value != null) { return value; } return defaultValue.getAsDouble(); }
Example 6
Source File: TomlTable.java From incubator-tuweni with Apache License 2.0 | 3 votes |
/** * Get a double from the TOML document, or return a default. * * @param path The key path. * @param defaultValue A supplier for the default value. * @return The value, or the default. * @throws TomlInvalidTypeException If the value is present but not a double, or any element of the path preceding the * final key is not a table. */ default double getDouble(List<String> path, DoubleSupplier defaultValue) { requireNonNull(defaultValue); Double value = getDouble(path); if (value != null) { return value; } return defaultValue.getAsDouble(); }
Example 7
Source File: OptionalDouble.java From desugar_jdk_libs with GNU General Public License v2.0 | 2 votes |
/** * Return the value if present, otherwise invoke {@code other} and return * the result of that invocation. * * @param other a {@code DoubleSupplier} whose result is returned if no value * is present * @return the value if present otherwise the result of {@code other.getAsDouble()} * @throws NullPointerException if value is not present and {@code other} is * null */ public double orElseGet(DoubleSupplier other) { return isPresent ? value : other.getAsDouble(); }
Example 8
Source File: OptionalDouble.java From hottub with GNU General Public License v2.0 | 2 votes |
/** * Return the value if present, otherwise invoke {@code other} and return * the result of that invocation. * * @param other a {@code DoubleSupplier} whose result is returned if no value * is present * @return the value if present otherwise the result of {@code other.getAsDouble()} * @throws NullPointerException if value is not present and {@code other} is * null */ public double orElseGet(DoubleSupplier other) { return isPresent ? value : other.getAsDouble(); }
Example 9
Source File: OptionalDouble.java From Java8CN with Apache License 2.0 | 2 votes |
/** * Return the value if present, otherwise invoke {@code other} and return * the result of that invocation. * * @param other a {@code DoubleSupplier} whose result is returned if no value * is present * @return the value if present otherwise the result of {@code other.getAsDouble()} * @throws NullPointerException if value is not present and {@code other} is * null */ public double orElseGet(DoubleSupplier other) { return isPresent ? value : other.getAsDouble(); }
Example 10
Source File: OptionalDouble.java From jdk8u_jdk with GNU General Public License v2.0 | 2 votes |
/** * Return the value if present, otherwise invoke {@code other} and return * the result of that invocation. * * @param other a {@code DoubleSupplier} whose result is returned if no value * is present * @return the value if present otherwise the result of {@code other.getAsDouble()} * @throws NullPointerException if value is not present and {@code other} is * null */ public double orElseGet(DoubleSupplier other) { return isPresent ? value : other.getAsDouble(); }
Example 11
Source File: OptionalDouble.java From openjdk-8-source with GNU General Public License v2.0 | 2 votes |
/** * Return the value if present, otherwise invoke {@code other} and return * the result of that invocation. * * @param other a {@code DoubleSupplier} whose result is returned if no value * is present * @return the value if present otherwise the result of {@code other.getAsDouble()} * @throws NullPointerException if value is not present and {@code other} is * null */ public double orElseGet(DoubleSupplier other) { return isPresent ? value : other.getAsDouble(); }
Example 12
Source File: OptionalDouble.java From Bytecoder with Apache License 2.0 | 2 votes |
/** * If a value is present, returns the value, otherwise returns the result * produced by the supplying function. * * @param supplier the supplying function that produces a value to be returned * @return the value, if present, otherwise the result produced by the * supplying function * @throws NullPointerException if no value is present and the supplying * function is {@code null} */ public double orElseGet(DoubleSupplier supplier) { return isPresent ? value : supplier.getAsDouble(); }
Example 13
Source File: OptionalDouble.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 2 votes |
/** * Return the value if present, otherwise invoke {@code other} and return * the result of that invocation. * * @param other a {@code DoubleSupplier} whose result is returned if no value * is present * @return the value if present otherwise the result of {@code other.getAsDouble()} * @throws NullPointerException if value is not present and {@code other} is * null */ public double orElseGet(DoubleSupplier other) { return isPresent ? value : other.getAsDouble(); }
Example 14
Source File: OptionalDouble.java From openjdk-jdk8u with GNU General Public License v2.0 | 2 votes |
/** * Return the value if present, otherwise invoke {@code other} and return * the result of that invocation. * * @param other a {@code DoubleSupplier} whose result is returned if no value * is present * @return the value if present otherwise the result of {@code other.getAsDouble()} * @throws NullPointerException if value is not present and {@code other} is * null */ public double orElseGet(DoubleSupplier other) { return isPresent ? value : other.getAsDouble(); }
Example 15
Source File: OptionalDouble.java From JDKSourceCode1.8 with MIT License | 2 votes |
/** * Return the value if present, otherwise invoke {@code other} and return * the result of that invocation. * * @param other a {@code DoubleSupplier} whose result is returned if no value * is present * @return the value if present otherwise the result of {@code other.getAsDouble()} * @throws NullPointerException if value is not present and {@code other} is * null */ public double orElseGet(DoubleSupplier other) { return isPresent ? value : other.getAsDouble(); }
Example 16
Source File: OptionalDouble.java From jdk8u60 with GNU General Public License v2.0 | 2 votes |
/** * Return the value if present, otherwise invoke {@code other} and return * the result of that invocation. * * @param other a {@code DoubleSupplier} whose result is returned if no value * is present * @return the value if present otherwise the result of {@code other.getAsDouble()} * @throws NullPointerException if value is not present and {@code other} is * null */ public double orElseGet(DoubleSupplier other) { return isPresent ? value : other.getAsDouble(); }
Example 17
Source File: OptionalDouble.java From TencentKona-8 with GNU General Public License v2.0 | 2 votes |
/** * Return the value if present, otherwise invoke {@code other} and return * the result of that invocation. * * @param other a {@code DoubleSupplier} whose result is returned if no value * is present * @return the value if present otherwise the result of {@code other.getAsDouble()} * @throws NullPointerException if value is not present and {@code other} is * null */ public double orElseGet(DoubleSupplier other) { return isPresent ? value : other.getAsDouble(); }
Example 18
Source File: OptionalDouble.java From dragonwell8_jdk with GNU General Public License v2.0 | 2 votes |
/** * Return the value if present, otherwise invoke {@code other} and return * the result of that invocation. * * @param other a {@code DoubleSupplier} whose result is returned if no value * is present * @return the value if present otherwise the result of {@code other.getAsDouble()} * @throws NullPointerException if value is not present and {@code other} is * null */ public double orElseGet(DoubleSupplier other) { return isPresent ? value : other.getAsDouble(); }
Example 19
Source File: OptionalDouble.java From jdk1.8-source-analysis with Apache License 2.0 | 2 votes |
/** * Return the value if present, otherwise invoke {@code other} and return * the result of that invocation. * * @param other a {@code DoubleSupplier} whose result is returned if no value * is present * @return the value if present otherwise the result of {@code other.getAsDouble()} * @throws NullPointerException if value is not present and {@code other} is * null */ public double orElseGet(DoubleSupplier other) { return isPresent ? value : other.getAsDouble(); }
Example 20
Source File: OptionalDouble.java From openjdk-8 with GNU General Public License v2.0 | 2 votes |
/** * Return the value if present, otherwise invoke {@code other} and return * the result of that invocation. * * @param other a {@code DoubleSupplier} whose result is returned if no value * is present * @return the value if present otherwise the result of {@code other.getAsDouble()} * @throws NullPointerException if value is not present and {@code other} is * null */ public double orElseGet(DoubleSupplier other) { return isPresent ? value : other.getAsDouble(); }