本文整理汇总了Java中java.util.function.IntToDoubleFunction类的典型用法代码示例。如果您正苦于以下问题:Java IntToDoubleFunction类的具体用法?Java IntToDoubleFunction怎么用?Java IntToDoubleFunction使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
IntToDoubleFunction类属于java.util.function包,在下文中一共展示了IntToDoubleFunction类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: Spell
import java.util.function.IntToDoubleFunction; //导入依赖的package包/类
public Spell(String name, int manaCost, int maxLevel, int row, int col, String descriptionFormat, IntToDoubleFunction[] functions, Object[] requirements, SpellEffect spellEffect) {
this.name = name;
this.manaCost = manaCost;
this.maxLevel = maxLevel;
this.row = row;
this.col = col;
this.descriptionFormat = descriptionFormat;
this.functions = functions;
this.requirements = new HashMap<Spell, Integer>();
if (requirements != null) {
for (int k = 0; k < requirements.length; k += 2) {
this.requirements.put((Spell) requirements[k], (int) requirements[k + 1]);
}
}
this.spellEffect = spellEffect;
this.spellEffect.functions = functions;
}
示例2: mapToDouble
import java.util.function.IntToDoubleFunction; //导入依赖的package包/类
@Override
public final DoubleStream mapToDouble(IntToDoubleFunction mapper) {
Objects.requireNonNull(mapper);
return new DoublePipeline.StatelessOp<Integer>(this, StreamShape.INT_VALUE,
StreamOpFlag.NOT_SORTED | StreamOpFlag.NOT_DISTINCT) {
@Override
Sink<Integer> opWrapSink(int flags, Sink<Double> sink) {
return new Sink.ChainedInt<Double>(sink) {
@Override
public void accept(int t) {
downstream.accept(mapper.applyAsDouble(t));
}
};
}
};
}
示例3: assign
import java.util.function.IntToDoubleFunction; //导入依赖的package包/类
/** {@inheritDoc} */
@Override public Vector assign(IntToDoubleFunction fun) {
assert fun != null;
if (sto.isArrayBased()) {
ensureReadOnly();
Arrays.setAll(sto.data(), fun);
}
else {
int len = size();
for (int i = 0; i < len; i++)
storageSet(i, fun.applyAsDouble(i));
}
return this;
}
示例4: shouldRequireNonNullCache
import java.util.function.IntToDoubleFunction; //导入依赖的package包/类
/**
*
*/
@Test
@SuppressWarnings(CompilerWarnings.UNUSED)
public void shouldRequireNonNullCache() {
// given
final ConcurrentMap<Integer, Double> cache = null;
final IntToDoubleFunction function = input -> 123;
final IntFunction<Integer> keyFunction = Integer::valueOf;
// when
thrown.expect(NullPointerException.class);
thrown.expectMessage("Provide an empty map instead of NULL.");
// then
new ConcurrentMapBasedIntToDoubleFunctionMemoizer<>(cache, keyFunction, function);
}
开发者ID:sebhoss,项目名称:memoization.java,代码行数:19,代码来源:ConcurrentMapBasedIntToDoubleFunctionMemoizerTest.java
示例5: shouldRequireNonNullFunction
import java.util.function.IntToDoubleFunction; //导入依赖的package包/类
/**
*
*/
@Test
@SuppressWarnings(CompilerWarnings.UNUSED)
public void shouldRequireNonNullFunction() {
// given
final ConcurrentMap<Integer, Double> cache = new ConcurrentHashMap<>();
final IntToDoubleFunction function = null;
final IntFunction<Integer> keyFunction = Integer::valueOf;
// when
thrown.expect(NullPointerException.class);
thrown.expectMessage(
"Cannot memoize a NULL IntToDoubleFunction - provide an actual IntToDoubleFunction to fix this.");
// then
new ConcurrentMapBasedIntToDoubleFunctionMemoizer<>(cache, keyFunction, function);
}
开发者ID:sebhoss,项目名称:memoization.java,代码行数:20,代码来源:ConcurrentMapBasedIntToDoubleFunctionMemoizerTest.java
示例6: shouldUseSetCacheKeyAndValue
import java.util.function.IntToDoubleFunction; //导入依赖的package包/类
/**
*
*/
@Test
public void shouldUseSetCacheKeyAndValue() {
// given
final ConcurrentMap<Integer, Double> cache = new ConcurrentHashMap<>();
final IntToDoubleFunction function = input -> 123;
final IntFunction<Integer> keyFunction = Integer::valueOf;
// when
final ConcurrentMapBasedIntToDoubleFunctionMemoizer<Integer> memoizer = new ConcurrentMapBasedIntToDoubleFunctionMemoizer<>(
cache, keyFunction, function);
// then
memoizer.applyAsDouble(123);
Assert.assertFalse("Cache is still empty after memoization", memoizer.viewCacheForTest().isEmpty());
Assert.assertEquals("Memoization key does not match expectations", 123,
memoizer.viewCacheForTest().keySet().iterator().next().intValue());
Assert.assertEquals("Memoization value does not match expectations", 123D,
memoizer.viewCacheForTest().values().iterator().next().doubleValue(), 0.0D);
}
开发者ID:sebhoss,项目名称:memoization.java,代码行数:23,代码来源:ConcurrentMapBasedIntToDoubleFunctionMemoizerTest.java
示例7: shouldUseCallWrappedFunction
import java.util.function.IntToDoubleFunction; //导入依赖的package包/类
/**
*
*/
@Test
public void shouldUseCallWrappedFunction() {
// given
final ConcurrentMap<Integer, Double> cache = new ConcurrentHashMap<>();
final IntToDoubleFunction function = Mockito.mock(IntToDoubleFunction.class);
final IntFunction<Integer> keyFunction = Integer::valueOf;
// when
final ConcurrentMapBasedIntToDoubleFunctionMemoizer<Integer> memoizer = new ConcurrentMapBasedIntToDoubleFunctionMemoizer<>(
cache, keyFunction, function);
// then
memoizer.applyAsDouble(123);
Mockito.verify(function).applyAsDouble(123);
}
开发者ID:sebhoss,项目名称:memoization.java,代码行数:19,代码来源:ConcurrentMapBasedIntToDoubleFunctionMemoizerTest.java
示例8: create
import java.util.function.IntToDoubleFunction; //导入依赖的package包/类
/**
* Create an input device from the supplied mapping functions.
* @param axisToValue the function that maps an integer to a double value for the axis
* @param buttonNumberToSwitch the function that maps an integer to whether the button is pressed
* @param padToValue the function that maps an integer to the directional axis output
* @return the resulting input device; never null
*/
public static InputDevice create( IntToDoubleFunction axisToValue, IntToBooleanFunction buttonNumberToSwitch, IntToIntFunction padToValue ) {
return new InputDevice() {
@Override
public ContinuousRange getAxis(int axis) {
return ()->axisToValue.applyAsDouble(axis);
}
@Override
public Switch getButton(int button) {
return ()->buttonNumberToSwitch.applyAsBoolean(button);
}
@Override
public DirectionalAxis getDPad(int pad) {
return ()->padToValue.applyAsInt(pad);
}
};
}
示例9: create
import java.util.function.IntToDoubleFunction; //导入依赖的package包/类
/**
* Create a new PowerPanel from functions that supply the current for each channel, total current, voltage, and temperature.
*
* @param currentForChannel the function that returns the current for a given channel; may not be null
* @param totalCurrent the function that returns total current; may not be null
* @param voltage the function that returns voltage; may not be null
* @param temperature the function that returns temperature; may not be null
* @return the power panel; never null
* @see Hardware#powerPanel()
*/
public static PowerPanel create(IntToDoubleFunction currentForChannel, DoubleSupplier totalCurrent, DoubleSupplier voltage,
DoubleSupplier temperature) {
return new PowerPanel() {
@Override
public CurrentSensor getCurrentSensor(int channel) {
return () -> currentForChannel.applyAsDouble(channel);
}
@Override
public CurrentSensor getTotalCurrentSensor() {
return totalCurrent::getAsDouble;
}
@Override
public VoltageSensor getVoltageSensor() {
return voltage::getAsDouble;
}
@Override
public TemperatureSensor getTemperatureSensor() {
return voltage::getAsDouble;
}
};
}
示例10: testSetAllDouble
import java.util.function.IntToDoubleFunction; //导入依赖的package包/类
@Test(dataProvider = "double")
public void testSetAllDouble(String name, int size, IntToDoubleFunction generator, double[] expected) {
double[] result = new double[size];
Arrays.setAll(result, generator);
assertDoubleArrayEquals(result, expected, 0.05, "setAll(double[], IntToDoubleFunction) case " + name + " failed.");
// ensure fresh array
result = new double[size];
Arrays.parallelSetAll(result, generator);
assertDoubleArrayEquals(result, expected, 0.05, "setAll(double[], IntToDoubleFunction) case " + name + " failed.");
}
示例11: mapToDouble
import java.util.function.IntToDoubleFunction; //导入依赖的package包/类
/**
* Apply an int -> double function to this range, producing a double[]
*
* @param lambda the int -> double function
*/
public double[] mapToDouble(final IntToDoubleFunction lambda) {
JointCallingUtils.nonNull(lambda, "the lambda function cannot be null");
final double[] result = new double[size()];
for (int i = from; i < to; i++) {
result[i - from] = lambda.applyAsDouble(i);
}
return result;
}
示例12: sum
import java.util.function.IntToDoubleFunction; //导入依赖的package包/类
/**
* Sums the values of an int -> double function applied to this range
*
* @param lambda the int -> double function
*/
public double sum(final IntToDoubleFunction lambda) {
JointCallingUtils.nonNull(lambda, "the lambda function cannot be null");
double result = 0;
for (int i = from; i < to; i++) {
result += lambda.applyAsDouble(i);
}
return result;
}
示例13: findBestCombinedMatch
import java.util.function.IntToDoubleFunction; //导入依赖的package包/类
/**
* Finds best, in terms of score sum, combined match where each word occurs
* at most once and doesn't overlap with any other
* @param wordMatches - matches of words
* @param distanceCoef - multiplication coefficient applied to score of
* resulting combined submatch, accepting
* distance (in chars) between last two words
*/
static public Seq findBestCombinedMatch(Multimap<Integer, ScoredMatch> wordMatches,
IntToDoubleFunction distanceCoef) {
List<Seq> words = new ArrayList<>();
wordMatches.entries().forEach(e -> words.add(Seq.of(e.getKey(), e.getValue())));
Collections.sort(words, Comparator.comparing(Seq::effectiveStart));
Seq best = null;
List<Seq> seqs = new ArrayList<>();
for (Seq w : words) {
int k = seqs.size();
for (int i = 0; i < k; i++) {
Seq s = seqs.get(i);
Seq ns = s.append(w, distanceCoef.applyAsDouble(w.start - s.end)); // continued sequence
if (ns != null) {
seqs.add(ns);
if (best == null || best.score < ns.score)
best = ns;
}
}
if (!w.singleWord)
throw new IllegalArgumentException();
seqs.add(w);
if (best == null || best.score < w.score)
best = w;
}
return best;
}
示例14: shouldMemoizeIntToDoubleFunctionWithKeyFunction
import java.util.function.IntToDoubleFunction; //导入依赖的package包/类
/**
*
*/
@Test
public void shouldMemoizeIntToDoubleFunctionWithKeyFunction() {
// given
final IntToDoubleFunction function = a -> 123D;
final IntFunction<String> keyFunction = a -> "key";
// when
final IntToDoubleFunction memoize = CaffeineMemoize.intToDoubleFunction(function, keyFunction);
// then
Assert.assertNotNull("Memoized IntToDoubleFunction is NULL", memoize);
}
示例15: shouldMemoizeIntToDoubleFunction
import java.util.function.IntToDoubleFunction; //导入依赖的package包/类
/**
*
*/
@Test
public void shouldMemoizeIntToDoubleFunction() {
// given
final IntToDoubleFunction function = a -> 123D;
// when
final IntToDoubleFunction memoize = CaffeineMemoize.intToDoubleFunction(function);
// then
Assert.assertNotNull("Memoized IntToDoubleFunction is NULL", memoize);
}