本文整理匯總了Java中java.util.function.DoubleUnaryOperator.applyAsDouble方法的典型用法代碼示例。如果您正苦於以下問題:Java DoubleUnaryOperator.applyAsDouble方法的具體用法?Java DoubleUnaryOperator.applyAsDouble怎麽用?Java DoubleUnaryOperator.applyAsDouble使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.util.function.DoubleUnaryOperator
的用法示例。
在下文中一共展示了DoubleUnaryOperator.applyAsDouble方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: integrate
import java.util.function.DoubleUnaryOperator; //導入方法依賴的package包/類
static double integrate(DoubleUnaryOperator f, double a, double b) {
double dx = (b - a);
double sum0;
double sum1 = f.applyAsDouble(a) * (b - a);
int it = 1;
do {
dx /= 2.;
it *= 2;
sum0 = sum1;
sum1 = .0;
for (double x = a, eps = dx / 2.; x + eps < b; x += dx) {
sum1 += dx * f.applyAsDouble(x);
}
} while (Math.abs(sum0 - sum1) > 1e-7 && it < 100000000);
return sum1;
}
示例2: iterate
import java.util.function.DoubleUnaryOperator; //導入方法依賴的package包/類
/**
* Returns an infinite sequential ordered {@code DoubleStream} produced by iterative
* application of a function {@code f} to an initial element {@code seed},
* producing a {@code Stream} consisting of {@code seed}, {@code f(seed)},
* {@code f(f(seed))}, etc.
*
* <p>The first element (position {@code 0}) in the {@code DoubleStream}
* will be the provided {@code seed}. For {@code n > 0}, the element at
* position {@code n}, will be the result of applying the function {@code f}
* to the element at position {@code n - 1}.
*
* @param seed the initial element
* @param f a function to be applied to to the previous element to produce
* a new element
* @return a new sequential {@code DoubleStream}
*/
public static DoubleStream iterate(final double seed, final DoubleUnaryOperator f) {
Objects.requireNonNull(f);
final PrimitiveIterator.OfDouble iterator = new PrimitiveIterator.OfDouble() {
double t = seed;
@Override
public boolean hasNext() {
return true;
}
@Override
public double nextDouble() {
double v = t;
t = f.applyAsDouble(t);
return v;
}
};
return StreamSupport.doubleStream(Spliterators.spliteratorUnknownSize(
iterator,
Spliterator.ORDERED | Spliterator.IMMUTABLE | Spliterator.NONNULL), false);
}
示例3: iterate
import java.util.function.DoubleUnaryOperator; //導入方法依賴的package包/類
/**
* Returns an infinite sequential ordered {@code DoubleStream} produced by iterative
* application of a function {@code f} to an initial element {@code seed},
* producing a {@code Stream} consisting of {@code seed}, {@code f(seed)},
* {@code f(f(seed))}, etc.
*
* <p>The first element (position {@code 0}) in the {@code DoubleStream}
* will be the provided {@code seed}. For {@code n > 0}, the element at
* position {@code n}, will be the result of applying the function {@code f}
* to the element at position {@code n - 1}.
*
* <p>The action of applying {@code f} for one element
* <a href="../concurrent/package-summary.html#MemoryVisibility"><i>happens-before</i></a>
* the action of applying {@code f} for subsequent elements. For any given
* element the action may be performed in whatever thread the library
* chooses.
*
* @param seed the initial element
* @param f a function to be applied to the previous element to produce
* a new element
* @return a new sequential {@code DoubleStream}
*/
public static DoubleStream iterate(final double seed, final DoubleUnaryOperator f) {
Objects.requireNonNull(f);
Spliterator.OfDouble spliterator = new Spliterators.AbstractDoubleSpliterator(Long.MAX_VALUE,
Spliterator.ORDERED | Spliterator.IMMUTABLE | Spliterator.NONNULL) {
double prev;
boolean started;
@Override
public boolean tryAdvance(DoubleConsumer action) {
Objects.requireNonNull(action);
double t;
if (started)
t = f.applyAsDouble(prev);
else {
t = seed;
started = true;
}
action.accept(prev = t);
return true;
}
};
return StreamSupport.doubleStream(spliterator, false);
}
示例4: iterate
import java.util.function.DoubleUnaryOperator; //導入方法依賴的package包/類
/**
* Returns an infinite sequential ordered {@code DoubleStream} produced by iterative
* application of a function {@code f} to an initial element {@code seed},
* producing a {@code Stream} consisting of {@code seed}, {@code f(seed)},
* {@code f(f(seed))}, etc.
*
* <p>The first element (position {@code 0}) in the {@code DoubleStream}
* will be the provided {@code seed}. For {@code n > 0}, the element at
* position {@code n}, will be the result of applying the function {@code f}
* to the element at position {@code n - 1}.
*
* @param seed the initial element
* @param f a function to be applied to the previous element to produce
* a new element
* @return a new sequential {@code DoubleStream}
*/
public static DoubleStream iterate(final double seed, final DoubleUnaryOperator f) {
Objects.requireNonNull(f);
Spliterator.OfDouble spliterator = new Spliterators.AbstractDoubleSpliterator(Long.MAX_VALUE,
Spliterator.ORDERED | Spliterator.IMMUTABLE | Spliterator.NONNULL) {
double prev;
boolean started;
@Override
public boolean tryAdvance(DoubleConsumer action) {
Objects.requireNonNull(action);
double t;
if (started)
t = f.applyAsDouble(prev);
else {
t = seed;
started = true;
}
action.accept(prev = t);
return true;
}
};
return StreamSupport.doubleStream(spliterator, false);
}
示例5: map
import java.util.function.DoubleUnaryOperator; //導入方法依賴的package包/類
@NonNull
@Override
public MuVector2d map(@NonNull final DoubleUnaryOperator operator) {
this.x = operator.applyAsDouble(this.x);
this.y = operator.applyAsDouble(this.y);
return this;
}
示例6: map
import java.util.function.DoubleUnaryOperator; //導入方法依賴的package包/類
@NonNull
@Override
public MuVector3d map(@NonNull final DoubleUnaryOperator operator) {
this.x = operator.applyAsDouble(this.x);
this.y = operator.applyAsDouble(this.y);
this.z = operator.applyAsDouble(this.z);
return this;
}
示例7: map
import java.util.function.DoubleUnaryOperator; //導入方法依賴的package包/類
@NonNull
@Override
public MuVector4d map(@NonNull final DoubleUnaryOperator operator) {
this.x = operator.applyAsDouble(this.x);
this.y = operator.applyAsDouble(this.y);
this.z = operator.applyAsDouble(this.z);
this.w = operator.applyAsDouble(this.w);
return this;
}
示例8: map
import java.util.function.DoubleUnaryOperator; //導入方法依賴的package包/類
@NonNull
@Override
public MuVector4f map(@NonNull final DoubleUnaryOperator operator) {
this.x = (float) operator.applyAsDouble(this.x);
this.y = (float) operator.applyAsDouble(this.y);
this.z = (float) operator.applyAsDouble(this.z);
this.w = (float) operator.applyAsDouble(this.w);
return this;
}
示例9: map
import java.util.function.DoubleUnaryOperator; //導入方法依賴的package包/類
@NonNull
@Override
public MuVector3f map(@NonNull final DoubleUnaryOperator operator) {
this.x = (float) operator.applyAsDouble(this.x);
this.y = (float) operator.applyAsDouble(this.y);
this.z = (float) operator.applyAsDouble(this.z);
return this;
}
示例10: map
import java.util.function.DoubleUnaryOperator; //導入方法依賴的package包/類
@NonNull
@Override
public MuVector2f map(@NonNull final DoubleUnaryOperator operator) {
this.x = (float) operator.applyAsDouble(this.x);
this.y = (float) operator.applyAsDouble(this.y);
return this;
}
示例11: updateAndGet
import java.util.function.DoubleUnaryOperator; //導入方法依賴的package包/類
public final double updateAndGet( DoubleUnaryOperator updateFunction ) {
double prev, next;
do {
prev = get();
next = updateFunction.applyAsDouble( prev );
} while ( !compareAndSet( prev, next ) );
return next;
}
示例12: getAndUpdate
import java.util.function.DoubleUnaryOperator; //導入方法依賴的package包/類
public final double getAndUpdate( DoubleUnaryOperator updateFunction ) {
double prev, next;
do {
prev = get();
next = updateFunction.applyAsDouble( prev );
} while ( !compareAndSet( prev, next ) );
return prev;
}
示例13: applyToArray
import java.util.function.DoubleUnaryOperator; //導入方法依賴的package包/類
public static double[] applyToArray(final double[] array, final DoubleUnaryOperator func) {
Utils.nonNull(func, "function may not be null");
Utils.nonNull(array, "array may not be null");
final double[] result = new double[array.length];
for (int m = 0; m < result.length; m++) {
result[m] = func.applyAsDouble(array[m]);
}
return result;
}
示例14: applyToArrayInPlace
import java.util.function.DoubleUnaryOperator; //導入方法依賴的package包/類
public static double[] applyToArrayInPlace(final double[] array, final DoubleUnaryOperator func) {
Utils.nonNull(array, "array may not be null");
Utils.nonNull(func, "function may not be null");
for (int m = 0; m < array.length; m++) {
array[m] = func.applyAsDouble(array[m]);
}
return array;
}
示例15: applyToArray
import java.util.function.DoubleUnaryOperator; //導入方法依賴的package包/類
public static double[] applyToArray(final double[] array, final DoubleUnaryOperator func) {
JointCallingUtils.nonNull(func, "function may not be null");
JointCallingUtils.nonNull(array, "array may not be null");
final double[] result = new double[array.length];
for (int m = 0; m < result.length; m++) {
result[m] = func.applyAsDouble(array[m]);
}
return result;
}