本文整理匯總了Java中java.util.function.DoubleUnaryOperator類的典型用法代碼示例。如果您正苦於以下問題:Java DoubleUnaryOperator類的具體用法?Java DoubleUnaryOperator怎麽用?Java DoubleUnaryOperator使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
DoubleUnaryOperator類屬於java.util.function包,在下文中一共展示了DoubleUnaryOperator類的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: map
import java.util.function.DoubleUnaryOperator; //導入依賴的package包/類
@Override
public final DoubleStream map(DoubleUnaryOperator mapper) {
Objects.requireNonNull(mapper);
return new StatelessOp<Double>(this, StreamShape.DOUBLE_VALUE,
StreamOpFlag.NOT_SORTED | StreamOpFlag.NOT_DISTINCT) {
@Override
Sink<Double> opWrapSink(int flags, Sink<Double> sink) {
return new Sink.ChainedDouble<Double>(sink) {
@Override
public void accept(double t) {
downstream.accept(mapper.applyAsDouble(t));
}
};
}
};
}
示例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}.
*
* @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);
}
示例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}.
*
* <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);
}
示例5: 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);
}
示例6: shouldRequireNonNullCache
import java.util.function.DoubleUnaryOperator; //導入依賴的package包/類
/**
*
*/
@Test
@SuppressWarnings(CompilerWarnings.UNUSED)
public void shouldRequireNonNullCache() {
// given
final ConcurrentMap<Double, Double> cache = null;
final DoubleUnaryOperator operator = input -> input;
final DoubleFunction<Double> keyFunction = Double::valueOf;
// when
thrown.expect(NullPointerException.class);
thrown.expectMessage("Provide an empty map instead of NULL.");
// then
new ConcurrentMapBasedDoubleUnaryOperatorMemoizer<>(cache, keyFunction, operator);
}
開發者ID:sebhoss,項目名稱:memoization.java,代碼行數:19,代碼來源:ConcurrentMapBasedDoubleUnaryOperatorMemoizerTest.java
示例7: shouldRequireNonNullOperator
import java.util.function.DoubleUnaryOperator; //導入依賴的package包/類
/**
*
*/
@Test
@SuppressWarnings(CompilerWarnings.UNUSED)
public void shouldRequireNonNullOperator() {
// given
final ConcurrentMap<Double, Double> cache = new ConcurrentHashMap<>();
final DoubleUnaryOperator operator = null;
final DoubleFunction<Double> keyFunction = Double::valueOf;
// when
thrown.expect(NullPointerException.class);
thrown.expectMessage(
"Cannot memoize a NULL DoubleUnaryOperator - provide an actual DoubleUnaryOperator to fix this.");
// then
new ConcurrentMapBasedDoubleUnaryOperatorMemoizer<>(cache, keyFunction, operator);
}
開發者ID:sebhoss,項目名稱:memoization.java,代碼行數:20,代碼來源:ConcurrentMapBasedDoubleUnaryOperatorMemoizerTest.java
示例8: shouldUseSetCacheKeyAndValue
import java.util.function.DoubleUnaryOperator; //導入依賴的package包/類
/**
*
*/
@Test
public void shouldUseSetCacheKeyAndValue() {
// given
final ConcurrentMap<Double, Double> cache = new ConcurrentHashMap<>();
final DoubleUnaryOperator operator = input -> input;
final DoubleFunction<Double> keyFunction = Double::valueOf;
// when
final ConcurrentMapBasedDoubleUnaryOperatorMemoizer<Double> memoizer = new ConcurrentMapBasedDoubleUnaryOperatorMemoizer<>(
cache, keyFunction, operator);
// then
memoizer.applyAsDouble(123D);
Assert.assertFalse("Cache is still empty after memoization", memoizer.viewCacheForTest().isEmpty());
Assert.assertEquals("Memoization key does not match expectations", 123D,
memoizer.viewCacheForTest().keySet().iterator().next().doubleValue(), 0.0D);
Assert.assertEquals("Memoization value does not match expectations", 123D,
memoizer.viewCacheForTest().values().iterator().next().doubleValue(), 0.0D);
}
開發者ID:sebhoss,項目名稱:memoization.java,代碼行數:23,代碼來源:ConcurrentMapBasedDoubleUnaryOperatorMemoizerTest.java
示例9: shouldUseCallWrappedOperator
import java.util.function.DoubleUnaryOperator; //導入依賴的package包/類
/**
*
*/
@Test
public void shouldUseCallWrappedOperator() {
// given
final ConcurrentMap<Double, Double> cache = new ConcurrentHashMap<>();
final DoubleUnaryOperator operator = Mockito.mock(DoubleUnaryOperator.class);
final DoubleFunction<Double> keyFunction = Double::valueOf;
// when
final ConcurrentMapBasedDoubleUnaryOperatorMemoizer<Double> memoizer = new ConcurrentMapBasedDoubleUnaryOperatorMemoizer<>(
cache, keyFunction, operator);
// then
memoizer.applyAsDouble(123D);
Mockito.verify(operator).applyAsDouble(123D);
}
開發者ID:sebhoss,項目名稱:memoization.java,代碼行數:19,代碼來源:ConcurrentMapBasedDoubleUnaryOperatorMemoizerTest.java
示例10: NewtonRaphson
import java.util.function.DoubleUnaryOperator; //導入依賴的package包/類
/**
* Construct an instance of the NewtonRaphson method for masochists who
* do not want to use {@link #builder()}.
* @param func the function
* @param derivative the derivative of the function
* @param tolerance the tolerance
* @param iterations maximum number of iterations
*/
public NewtonRaphson(
DoubleUnaryOperator func,
DoubleUnaryOperator derivative,
double tolerance,
long iterations) {
this.func = func;
this.derivative = derivative;
this.tolerance = tolerance;
this.iterations = iterations;
}
示例11: 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;
}
示例12: 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;
}
示例13: 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;
}
示例14: 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;
}
示例15: 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;
}