下面列出了java.util.function.DoubleSupplier#getAsDouble ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/** 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));
}
}
@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());
}
}
}
/**
* 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;
}
private double poll(DoubleSupplier maxSupplier) {
rotate();
synchronized (this) {
return maxSupplier.getAsDouble();
}
}
/**
* 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();
}
/**
* 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();
}
/**
* 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();
}
/**
* 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();
}
/**
* 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();
}
/**
* 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();
}
/**
* 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();
}
/**
* 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();
}
/**
* 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();
}
/**
* 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();
}
/**
* 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();
}
/**
* 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();
}
/**
* 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();
}
/**
* 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();
}
/**
* 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();
}
/**
* 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();
}