本文整理汇总了Java中java.util.function.ObjLongConsumer类的典型用法代码示例。如果您正苦于以下问题:Java ObjLongConsumer类的具体用法?Java ObjLongConsumer怎么用?Java ObjLongConsumer使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ObjLongConsumer类属于java.util.function包,在下文中一共展示了ObjLongConsumer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: shouldAcceptInput
import java.util.function.ObjLongConsumer; //导入依赖的package包/类
/**
*
*/
@Test
@SuppressWarnings(CompilerWarnings.UNCHECKED)
public void shouldAcceptInput() {
// given
final ObjLongConsumer<String> biConsumer = Mockito.mock(ObjLongConsumer.class);
final ObjLongFunction<String, String> keyFunction = (first, second) -> second + first;
final Cache<String, String> cache = CacheBuilder.newBuilder().build();
// when
final GuavaCacheBasedObjLongConsumerMemoizer<String, String> memoizer = new GuavaCacheBasedObjLongConsumerMemoizer<>(
cache, keyFunction, biConsumer);
// then
memoizer.accept("first", 123);
Mockito.verify(biConsumer).accept("first", 123);
}
示例2: shouldAcceptInput
import java.util.function.ObjLongConsumer; //导入依赖的package包/类
/**
*
*/
@Test
@SuppressWarnings(CompilerWarnings.UNCHECKED)
public void shouldAcceptInput() {
// given
final ObjLongConsumer<String> biConsumer = Mockito.mock(ObjLongConsumer.class);
final ObjLongFunction<String, String> keyfunction = (a, b) -> "key";
try (final Cache<String, String> cache = JCacheMemoize.createCache(BiConsumer.class)) {
// when
final JCacheBasedObjLongConsumerMemoizer<String, String> memoizer = new JCacheBasedObjLongConsumerMemoizer<>(
cache, keyfunction, biConsumer);
// then
memoizer.accept("first", 123);
Mockito.verify(biConsumer).accept("first", 123);
}
}
示例3: shouldRequireNonNullCache
import java.util.function.ObjLongConsumer; //导入依赖的package包/类
/**
*
*/
@Test
@SuppressWarnings(CompilerWarnings.UNUSED)
public void shouldRequireNonNullCache() {
// given
final ConcurrentMap<String, String> cache = null;
final ObjLongFunction<String, String> keyFunction = (first, second) -> first + second;
final ObjLongConsumer<String> consumer = (first, second) -> System.out.println(first + second);
// when
thrown.expect(NullPointerException.class);
thrown.expectMessage("Provide an empty map instead of NULL.");
// then
new ConcurrentMapBasedObjLongConsumerMemoizer<>(cache, keyFunction, consumer);
}
示例4: shouldRequireNonNullKeyFunction
import java.util.function.ObjLongConsumer; //导入依赖的package包/类
/**
*
*/
@Test
@SuppressWarnings(CompilerWarnings.UNUSED)
public void shouldRequireNonNullKeyFunction() {
// given
final ConcurrentMap<String, String> cache = new ConcurrentHashMap<>();
final ObjLongFunction<String, String> keyFunction = null;
final ObjLongConsumer<String> consumer = (first, second) -> System.out.println(first + second);
// when
thrown.expect(NullPointerException.class);
thrown.expectMessage(
"Provide a key function, might just be 'MemoizationDefaults.objLongConsumerHashCodeKeyFunction()'.");
// then
new ConcurrentMapBasedObjLongConsumerMemoizer<>(cache, keyFunction, consumer);
}
示例5: shouldRequireNonNullConsumer
import java.util.function.ObjLongConsumer; //导入依赖的package包/类
/**
*
*/
@Test
@SuppressWarnings(CompilerWarnings.UNUSED)
public void shouldRequireNonNullConsumer() {
// given
final ConcurrentMap<String, String> cache = new ConcurrentHashMap<>();
final ObjLongFunction<String, String> keyFunction = (first, second) -> first + second;
final ObjLongConsumer<String> consumer = null;
// when
thrown.expect(NullPointerException.class);
thrown.expectMessage("Cannot memoize a NULL Consumer - provide an actual Consumer to fix this.");
// then
new ConcurrentMapBasedObjLongConsumerMemoizer<>(cache, keyFunction, consumer);
}
示例6: shouldUseSetCacheKeyAndValue
import java.util.function.ObjLongConsumer; //导入依赖的package包/类
/**
*
*/
@Test
public void shouldUseSetCacheKeyAndValue() {
// given
final ConcurrentMap<String, String> cache = new ConcurrentHashMap<>();
final ObjLongFunction<String, String> keyFunction = (first, second) -> first + second;
final ObjLongConsumer<String> consumer = (first, second) -> System.out.println(first + second);
// when
final ConcurrentMapBasedObjLongConsumerMemoizer<String, String> memoizer = new ConcurrentMapBasedObjLongConsumerMemoizer<>(
cache, keyFunction, consumer);
// then
memoizer.accept("test", 123L);
Assert.assertFalse("Cache is still empty after memoization", memoizer.viewCacheForTest().isEmpty());
Assert.assertEquals("Memoization key does not match expectations", "test123",
memoizer.viewCacheForTest().keySet().iterator().next());
Assert.assertEquals("Memoization value does not match expectations", "test",
memoizer.viewCacheForTest().values().iterator().next());
}
示例7: shouldUseCallWrappedConsumer
import java.util.function.ObjLongConsumer; //导入依赖的package包/类
/**
*
*/
@Test
@SuppressWarnings(CompilerWarnings.UNCHECKED)
public void shouldUseCallWrappedConsumer() {
// given
final ConcurrentMap<String, String> cache = new ConcurrentHashMap<>();
final ObjLongFunction<String, String> keyFunction = (first, second) -> first + second;
final ObjLongConsumer<String> consumer = Mockito.mock(ObjLongConsumer.class);
// when
final ConcurrentMapBasedObjLongConsumerMemoizer<String, String> memoizer = new ConcurrentMapBasedObjLongConsumerMemoizer<>(
cache, keyFunction, consumer);
// then
memoizer.accept("test", 123L);
Mockito.verify(consumer).accept("test", 123L);
}
示例8: testCheckedObjLongConsumer
import java.util.function.ObjLongConsumer; //导入依赖的package包/类
@Test
public void testCheckedObjLongConsumer() {
final CheckedObjLongConsumer<Object> objLongConsumer = (o1, o2) -> {
throw new Exception(o1 + ":" + o2);
};
ObjLongConsumer<Object> c1 = Unchecked.objLongConsumer(objLongConsumer);
ObjLongConsumer<Object> c2 = CheckedObjLongConsumer.unchecked(objLongConsumer);
ObjLongConsumer<Object> c3 = Sneaky.objLongConsumer(objLongConsumer);
ObjLongConsumer<Object> c4 = CheckedObjLongConsumer.sneaky(objLongConsumer);
assertObjLongConsumer(c1, UncheckedException.class);
assertObjLongConsumer(c2, UncheckedException.class);
assertObjLongConsumer(c3, Exception.class);
assertObjLongConsumer(c4, Exception.class);
}
示例9: makeLong
import java.util.function.ObjLongConsumer; //导入依赖的package包/类
/**
* Constructs a {@code TerminalOp} that implements a mutable reduce on
* {@code long} values.
*
* @param <R> the type of the result
* @param supplier a factory to produce a new accumulator of the result type
* @param accumulator a function to incorporate an int into an
* accumulator
* @param combiner a function to combine an accumulator into another
* @return a {@code TerminalOp} implementing the reduction
*/
public static <R> TerminalOp<Long, R>
makeLong(Supplier<R> supplier,
ObjLongConsumer<R> accumulator,
BinaryOperator<R> combiner) {
Objects.requireNonNull(supplier);
Objects.requireNonNull(accumulator);
Objects.requireNonNull(combiner);
class ReducingSink extends Box<R>
implements AccumulatingSink<Long, R, ReducingSink>, Sink.OfLong {
@Override
public void begin(long size) {
state = supplier.get();
}
@Override
public void accept(long t) {
accumulator.accept(state, t);
}
@Override
public void combine(ReducingSink other) {
state = combiner.apply(state, other.state);
}
}
return new ReduceOp<Long, R, ReducingSink>(StreamShape.LONG_VALUE) {
@Override
public ReducingSink makeSink() {
return new ReducingSink();
}
};
}
示例10: collect
import java.util.function.ObjLongConsumer; //导入依赖的package包/类
@Override
public final <R> R collect(Supplier<R> supplier,
ObjLongConsumer<R> accumulator,
BiConsumer<R, R> combiner) {
BinaryOperator<R> operator = (left, right) -> {
combiner.accept(left, right);
return left;
};
return evaluate(ReduceOps.makeLong(supplier, accumulator, operator));
}
示例11: collect
import java.util.function.ObjLongConsumer; //导入依赖的package包/类
@Override
public final <R> R collect(Supplier<R> supplier,
ObjLongConsumer<R> accumulator,
BiConsumer<R, R> combiner) {
Objects.requireNonNull(combiner);
BinaryOperator<R> operator = (left, right) -> {
combiner.accept(left, right);
return left;
};
return evaluate(ReduceOps.makeLong(supplier, accumulator, operator));
}
示例12: CollectLongTerminatorImpl
import java.util.function.ObjLongConsumer; //导入依赖的package包/类
public CollectLongTerminatorImpl(
HasNext<Long, LongStream> previous,
boolean parallel,
Supplier<R> supplier,
ObjLongConsumer<R> accumulator,
BiConsumer<R, R> combiner) {
super(previous, parallel);
this.supplier = requireNonNull(supplier);
this.accumulator = requireNonNull(accumulator);
this.combiner = requireNonNull(combiner);
}
示例13: create
import java.util.function.ObjLongConsumer; //导入依赖的package包/类
static <R> CollectLongTerminator<R> create(
HasNext<Long, LongStream> previous,
boolean parallel,
Supplier<R> supplier,
ObjLongConsumer<R> accumulator,
BiConsumer<R, R> merger) {
return new CollectLongTerminatorImpl<>(
previous, parallel, supplier, accumulator, merger
);
}
示例14: shouldMemoizeObjLongConsumerWithKeyFunction
import java.util.function.ObjLongConsumer; //导入依赖的package包/类
/**
*
*/
@Test
public void shouldMemoizeObjLongConsumerWithKeyFunction() {
// given
final ObjLongConsumer<Long> function = (first, second) -> System.out.println(first.toString() + second);
final ObjLongFunction<Long, String> keyFunction = MemoizationDefaults.objLongConsumerHashCodeKeyFunction();
// when
final ObjLongConsumer<Long> memoize = CaffeineMemoize.objLongConsumer(function, keyFunction);
// then
Assert.assertNotNull("Memoized ObjLongConsumer is NULL", memoize);
}
示例15: shouldMemoizeObjLongConsumer
import java.util.function.ObjLongConsumer; //导入依赖的package包/类
/**
*
*/
@Test
public void shouldMemoizeObjLongConsumer() {
// given
final ObjLongConsumer<Long> function = (first, second) -> System.out.println(first + " " + second);
// when
final ObjLongConsumer<Long> memoize = CaffeineMemoize.objLongConsumer(function);
// then
Assert.assertNotNull("Memoized ObjLongConsumer is NULL", memoize);
}