本文整理汇总了Java中java.util.function.DoubleSupplier.getAsDouble方法的典型用法代码示例。如果您正苦于以下问题:Java DoubleSupplier.getAsDouble方法的具体用法?Java DoubleSupplier.getAsDouble怎么用?Java DoubleSupplier.getAsDouble使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.function.DoubleSupplier
的用法示例。
在下文中一共展示了DoubleSupplier.getAsDouble方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: create
import java.util.function.DoubleSupplier; //导入方法依赖的package包/类
/**
* Create a gyroscope for the given functions that returns the angular displacement and velocity.
*
* @param angleSupplier the function that returns the angle; may not be null
* @param rateSupplier the function that returns the angular acceleration; may not be null
* @return the angle sensor
*/
public static Gyroscope create(DoubleSupplier angleSupplier, DoubleSupplier rateSupplier) {
return new Gyroscope() {
private volatile double zero = 0;
@Override
public double getAngle() {
return angleSupplier.getAsDouble() - zero;
}
@Override
public Gyroscope zero() {
zero = angleSupplier.getAsDouble();
return this;
}
@Override
public double getRate() {
return rateSupplier.getAsDouble();
}
};
}
示例2: create
import java.util.function.DoubleSupplier; //导入方法依赖的package包/类
/**
* Create a distance sensor for the given function that returns the distance.
*
* @param distanceSupplier the function that returns the distance; may not be null
* @return the angle sensor
*/
public static DistanceSensor create(DoubleSupplier distanceSupplier) {
return new DistanceSensor() {
private double zero = 0;
@Override
public double getDistanceInInches() {
return distanceSupplier.getAsDouble() - zero;
}
@Override
public DistanceSensor zero() {
zero = distanceSupplier.getAsDouble();
return this;
}
};
}
示例3: create
import java.util.function.DoubleSupplier; //导入方法依赖的package包/类
/**
* Create an angle sensor around the given function that returns the angle.
*
* @param angleSupplier the function that returns the angle; may not be null
* @return the angle sensor
*/
public static AngleSensor create(DoubleSupplier angleSupplier) {
return new AngleSensor() {
private volatile double zero = 0;
@Override
public double getAngle() {
return angleSupplier.getAsDouble() - zero;
}
@Override
public AngleSensor zero() {
zero = angleSupplier.getAsDouble();
return this;
}
};
}
示例4: create
import java.util.function.DoubleSupplier; //导入方法依赖的package包/类
/**
* Create a angle sensor for the given function that returns the angle.
*
* @param angleSupplier the function that returns the angle; may not be null
* @return the angle sensor
*/
public static Compass create(DoubleSupplier angleSupplier) {
return new Compass() {
private volatile double zero = 0;
@Override
public double getAngle() {
return angleSupplier.getAsDouble() - zero;
}
@Override
public Compass zero() {
zero = angleSupplier.getAsDouble();
return this;
}
};
}
示例5: from
import java.util.function.DoubleSupplier; //导入方法依赖的package包/类
/** Creates a `Box.Dbl` from a `DoubleSupplier` and a `DoubleConsumer`. */
public static Dbl from(DoubleSupplier getter, DoubleConsumer setter) {
return new Dbl() {
@Override
public double getAsDouble() {
return getter.getAsDouble();
}
@Override
public void set(double value) {
setter.accept(value);
}
@Override
public String toString() {
return "Box.Dbl.from[" + get() + "]";
}
};
}
示例6: create
import java.util.function.DoubleSupplier; //导入方法依赖的package包/类
/**
* <p>Creates a binding using the passed supplier and list of dependencies.</p>
*
* <p>Note that this method requires manual implementation of the respective binding logic. For
* most cases, however, the static methods provided by this interface do suffice however and
* require far less manually programmed logic.</p>
*/
@Nonnull
static DoubleBinding create(@Nonnull DoubleSupplier supplier,
ReadOnlyObservable<?>... observables) {
return new AbstractDoubleBinding(new HashSet<>(Arrays.asList(observables))) {
@Override
protected Double compute() {
return supplier.getAsDouble();
}
};
}
示例7: internalNextGaussian
import java.util.function.DoubleSupplier; //导入方法依赖的package包/类
/**
* Core of a reimplementation of {@link #nextGaussian()} whose locking is overridable and doesn't
* happen when a value is already stored.
* @param nextDouble shall return a random number between 0 and 1, like {@link #nextDouble()},
* but shall not debit the entropy count.
* @return a random number that is normally distributed with mean 0 and standard deviation 1.
*/
@SuppressWarnings("LocalVariableHidesMemberVariable") protected double internalNextGaussian(
final DoubleSupplier nextDouble) {
// See Knuth, ACP, Section 3.4.1 Algorithm C.
final double firstTryOut = Double.longBitsToDouble(nextNextGaussian.getAndSet(NAN_LONG_BITS));
if (Double.isNaN(firstTryOut)) {
lockForNextGaussian();
try {
// Another output may have become available while we waited for the lock
final double secondTryOut =
Double.longBitsToDouble(nextNextGaussian.getAndSet(NAN_LONG_BITS));
if (!Double.isNaN(secondTryOut)) {
return secondTryOut;
}
double s;
double v1;
double v2;
do {
v1 = (2 * nextDouble.getAsDouble()) - 1; // between -1 and 1
v2 = (2 * nextDouble.getAsDouble()) - 1; // between -1 and 1
s = (v1 * v1) + (v2 * v2);
} while ((s >= 1) || (s == 0));
final double multiplier = StrictMath.sqrt((-2 * StrictMath.log(s)) / s);
nextNextGaussian.set(Double.doubleToRawLongBits(v2 * multiplier));
return v1 * multiplier;
} finally {
unlockForNextGaussian();
}
} else {
return firstTryOut;
}
}
示例8: ColorGradientSprite
import java.util.function.DoubleSupplier; //导入方法依赖的package包/类
public ColorGradientSprite(Entity e, Color start, Color end, DoubleSupplier variable)
{
this(e, () ->
{
float val = (float) variable.getAsDouble();
if(val > 1)
val = 1;
else if(val < 0)
val = 0;
return new Color(
(1 - val) * start.getRed() / 255 + val * end.getRed() / 255,
(1 - val) * start.getGreen() / 255 + val * end.getGreen() / 255,
(1 - val) * start.getBlue() / 255 + val * end.getBlue() / 255);
});
}
示例9: randomReflection
import java.util.function.DoubleSupplier; //导入方法依赖的package包/类
/**
* Randomly mirrors each plane of the grid to the other side of the centroid.
* Also mirrors the directions of the lines.
*/
public void randomReflection() {
final DoubleSupplier randomSign = () -> rng.nextBoolean() ? -1.0 : 1.0;
xySign = randomSign.getAsDouble();
xzSign = randomSign.getAsDouble();
yzSign = randomSign.getAsDouble();
}
示例10: F
import java.util.function.DoubleSupplier; //导入方法依赖的package包/类
F(DoubleSupplier doubleSupplier) {
this((Supplier<R>) new Supplier<Double>() {
@Override
public Double get() {
return doubleSupplier.getAsDouble();
}
});
}
示例11: readLocked
import java.util.function.DoubleSupplier; //导入方法依赖的package包/类
/**
* Execute the provided callable in a read lock.
*
* @param aSupplier
* Callable to be executed. May not be <code>null</code>.
* @return The return value of the callable. May be <code>null</code>.
*/
public double readLocked (@Nonnull final DoubleSupplier aSupplier)
{
readLock ().lock ();
try
{
return aSupplier.getAsDouble ();
}
finally
{
readLock ().unlock ();
}
}
示例12: writeLocked
import java.util.function.DoubleSupplier; //导入方法依赖的package包/类
/**
* Execute the provided callable in a write lock.
*
* @param aSupplier
* Callable to be executed. May not be <code>null</code>.
* @return The return value of the callable. May be <code>null</code>.
*/
public double writeLocked (@Nonnull final DoubleSupplier aSupplier)
{
writeLock ().lock ();
try
{
return aSupplier.getAsDouble ();
}
finally
{
writeLock ().unlock ();
}
}
示例13: locked
import java.util.function.DoubleSupplier; //导入方法依赖的package包/类
/**
* Execute the provided callable in a read lock.
*
* @param aSupplier
* Callable to be executed. May not be <code>null</code>.
* @return The return value of the callable. May be <code>null</code>.
*/
public double locked (@Nonnull final DoubleSupplier aSupplier)
{
ValueEnforcer.notNull (aSupplier, "Supplier");
lock ();
try
{
return aSupplier.getAsDouble ();
}
finally
{
unlock ();
}
}
示例14: fillAll
import java.util.function.DoubleSupplier; //导入方法依赖的package包/类
public static void fillAll(final double[][] target, final DoubleSupplier supplier) {
final int tmpLength = target.length;
for (int i = 0; i < tmpLength; i++) {
final int tmpInnerLength = target[i].length;
for (int j = 0; j < tmpInnerLength; j++) {
target[i][j] = supplier.getAsDouble();
}
}
}
示例15: fillRange
import java.util.function.DoubleSupplier; //导入方法依赖的package包/类
public static void fillRange(final double[][] target, final int first, final int limit, final DoubleSupplier supplier) {
final int tmpLength = target.length;
for (int index = first; index < limit; index++) {
final int tmpRow = Structure2D.row(index, tmpLength);
final int tmpColumn = Structure2D.column(index, tmpLength);
target[tmpRow][tmpColumn] = supplier.getAsDouble();
}
}