本文整理汇总了Java中java.util.function.ObjIntConsumer类的典型用法代码示例。如果您正苦于以下问题:Java ObjIntConsumer类的具体用法?Java ObjIntConsumer怎么用?Java ObjIntConsumer使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ObjIntConsumer类属于java.util.function包,在下文中一共展示了ObjIntConsumer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: shouldAcceptInput
import java.util.function.ObjIntConsumer; //导入依赖的package包/类
/**
*
*/
@Test
@SuppressWarnings(CompilerWarnings.UNCHECKED)
public void shouldAcceptInput() {
// given
final ObjIntConsumer<String> biConsumer = Mockito.mock(ObjIntConsumer.class);
final ObjIntFunction<String, String> keyFunction = (first, second) -> second + first;
final Cache<String, String> cache = CacheBuilder.newBuilder().build();
// when
final GuavaCacheBasedObjIntConsumerMemoizer<String, String> memoizer = new GuavaCacheBasedObjIntConsumerMemoizer<>(
cache, keyFunction, biConsumer);
// then
memoizer.accept("first", 123);
Mockito.verify(biConsumer).accept("first", 123);
}
示例2: shouldAcceptInput
import java.util.function.ObjIntConsumer; //导入依赖的package包/类
/**
*
*/
@Test
@SuppressWarnings(CompilerWarnings.UNCHECKED)
public void shouldAcceptInput() {
// given
final ObjIntConsumer<String> biConsumer = Mockito.mock(ObjIntConsumer.class);
final ObjIntFunction<String, String> keyfunction = (a, b) -> "key";
try (final Cache<String, String> cache = JCacheMemoize.createCache(BiConsumer.class)) {
// when
final JCacheBasedObjIntConsumerMemoizer<String, String> memoizer = new JCacheBasedObjIntConsumerMemoizer<>(
cache, keyfunction, biConsumer);
// then
memoizer.accept("first", 123);
Mockito.verify(biConsumer).accept("first", 123);
}
}
示例3: shouldRequireNonNullCache
import java.util.function.ObjIntConsumer; //导入依赖的package包/类
/**
*
*/
@Test
@SuppressWarnings(CompilerWarnings.UNUSED)
public void shouldRequireNonNullCache() {
// given
final ConcurrentMap<String, String> cache = null;
final ObjIntFunction<String, String> keyFunction = (first, second) -> first + second;
final ObjIntConsumer<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 ConcurrentMapBasedObjIntConsumerMemoizer<>(cache, keyFunction, consumer);
}
示例4: shouldRequireNonNullKeyFunction
import java.util.function.ObjIntConsumer; //导入依赖的package包/类
/**
*
*/
@Test
@SuppressWarnings(CompilerWarnings.UNUSED)
public void shouldRequireNonNullKeyFunction() {
// given
final ConcurrentMap<String, String> cache = new ConcurrentHashMap<>();
final ObjIntFunction<String, String> keyFunction = null;
final ObjIntConsumer<String> consumer = (first, second) -> System.out.println(first + second);
// when
thrown.expect(NullPointerException.class);
thrown.expectMessage(
"Provide a key function, might just be 'MemoizationDefaults.objIntConsumerHashCodeKeyFunction()'.");
// then
new ConcurrentMapBasedObjIntConsumerMemoizer<>(cache, keyFunction, consumer);
}
示例5: shouldRequireNonNullConsumer
import java.util.function.ObjIntConsumer; //导入依赖的package包/类
/**
*
*/
@Test
@SuppressWarnings(CompilerWarnings.UNUSED)
public void shouldRequireNonNullConsumer() {
// given
final ConcurrentMap<String, String> cache = new ConcurrentHashMap<>();
final ObjIntFunction<String, String> keyFunction = (first, second) -> first + second;
final ObjIntConsumer<String> consumer = null;
// when
thrown.expect(NullPointerException.class);
thrown.expectMessage("Cannot memoize a NULL Consumer - provide an actual Consumer to fix this.");
// then
new ConcurrentMapBasedObjIntConsumerMemoizer<>(cache, keyFunction, consumer);
}
示例6: shouldUseSetCacheKeyAndValue
import java.util.function.ObjIntConsumer; //导入依赖的package包/类
/**
*
*/
@Test
public void shouldUseSetCacheKeyAndValue() {
// given
final ConcurrentMap<String, String> cache = new ConcurrentHashMap<>();
final ObjIntFunction<String, String> keyFunction = (first, second) -> first + second;
final ObjIntConsumer<String> consumer = (first, second) -> System.out.println(first + second);
// when
final ConcurrentMapBasedObjIntConsumerMemoizer<String, String> memoizer = new ConcurrentMapBasedObjIntConsumerMemoizer<>(
cache, keyFunction, consumer);
// then
memoizer.accept("test", 123);
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.ObjIntConsumer; //导入依赖的package包/类
/**
*
*/
@Test
@SuppressWarnings(CompilerWarnings.UNCHECKED)
public void shouldUseCallWrappedConsumer() {
// given
final ConcurrentMap<String, String> cache = new ConcurrentHashMap<>();
final ObjIntFunction<String, String> keyFunction = (first, second) -> first + second;
final ObjIntConsumer<String> consumer = Mockito.mock(ObjIntConsumer.class);
// when
final ConcurrentMapBasedObjIntConsumerMemoizer<String, String> memoizer = new ConcurrentMapBasedObjIntConsumerMemoizer<>(
cache, keyFunction, consumer);
// then
memoizer.accept("test", 123);
Mockito.verify(consumer).accept("test", 123);
}
示例8: getAllContainedParticipantIDs
import java.util.function.ObjIntConsumer; //导入依赖的package包/类
@Nonnull
@ReturnsMutableCopy
public ICommonsSortedSet <IParticipantIdentifier> getAllContainedParticipantIDs ()
{
final ICommonsSortedSet <IParticipantIdentifier> aTargetSet = new CommonsTreeSet <> ();
final Query aQuery = PDQueryManager.andNotDeleted (new MatchAllDocsQuery ());
try
{
final ObjIntConsumer <Document> aConsumer = (aDoc,
nDocID) -> aTargetSet.add (PDField.PARTICIPANT_ID.getDocValue (aDoc));
final Collector aCollector = new AllDocumentsCollector (m_aLucene, aConsumer);
searchAtomic (aQuery, aCollector);
}
catch (final IOException ex)
{
s_aLogger.error ("Error searching for documents with query " + aQuery, ex);
}
return aTargetSet;
}
示例9: readUntilEOF
import java.util.function.ObjIntConsumer; //导入依赖的package包/类
public static void readUntilEOF (@Nonnull @WillClose final InputStream aIS,
@Nonnull final byte [] aBuffer,
@Nonnull final ObjIntConsumer <? super byte []> aConsumer) throws IOException
{
try
{
ValueEnforcer.notNull (aIS, "InputStream");
ValueEnforcer.notNull (aBuffer, "Buffer");
ValueEnforcer.notNull (aConsumer, "Consumer");
_readUntilEOF (aIS, aBuffer, aConsumer);
}
finally
{
close (aIS);
}
}
示例10: testCheckedObjIntConsumer
import java.util.function.ObjIntConsumer; //导入依赖的package包/类
@Test
public void testCheckedObjIntConsumer() {
final CheckedObjIntConsumer<Object> objIntConsumer = (o1, o2) -> {
throw new Exception(o1 + ":" + o2);
};
ObjIntConsumer<Object> c1 = Unchecked.objIntConsumer(objIntConsumer);
ObjIntConsumer<Object> c2 = CheckedObjIntConsumer.unchecked(objIntConsumer);
ObjIntConsumer<Object> c3 = Sneaky.objIntConsumer(objIntConsumer);
ObjIntConsumer<Object> c4 = CheckedObjIntConsumer.sneaky(objIntConsumer);
assertObjIntConsumer(c1, UncheckedException.class);
assertObjIntConsumer(c2, UncheckedException.class);
assertObjIntConsumer(c3, Exception.class);
assertObjIntConsumer(c4, Exception.class);
}
示例11: eachWithIndex
import java.util.function.ObjIntConsumer; //导入依赖的package包/类
/**
* Iterates through an iterable type, passing each item and the item's index
* (a counter starting at zero) to the given consumer.
*/
public static <T> Object eachWithIndex(Iterable<T> receiver, ObjIntConsumer<T> consumer) {
int count = 0;
for (T t : receiver) {
consumer.accept(t, count++);
}
return receiver;
}
示例12: forEachEntry
import java.util.function.ObjIntConsumer; //导入依赖的package包/类
@Override
public void forEachEntry(ObjIntConsumer<? super E> action) {
checkNotNull(action);
for (int i = 0; i < length; i++) {
action.accept(elementSet.asList().get(i), getCount(i));
}
}
示例13: makeInt
import java.util.function.ObjIntConsumer; //导入依赖的package包/类
/**
* Constructs a {@code TerminalOp} that implements a mutable reduce on
* {@code int} 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 ReduceOp} implementing the reduction
*/
public static <R> TerminalOp<Integer, R>
makeInt(Supplier<R> supplier,
ObjIntConsumer<R> accumulator,
BinaryOperator<R> combiner) {
Objects.requireNonNull(supplier);
Objects.requireNonNull(accumulator);
Objects.requireNonNull(combiner);
class ReducingSink extends Box<R>
implements AccumulatingSink<Integer, R, ReducingSink>, Sink.OfInt {
@Override
public void begin(long size) {
state = supplier.get();
}
@Override
public void accept(int t) {
accumulator.accept(state, t);
}
@Override
public void combine(ReducingSink other) {
state = combiner.apply(state, other.state);
}
}
return new ReduceOp<Integer, R, ReducingSink>(StreamShape.INT_VALUE) {
@Override
public ReducingSink makeSink() {
return new ReducingSink();
}
};
}
示例14: collect
import java.util.function.ObjIntConsumer; //导入依赖的package包/类
@Override
public final <R> R collect(Supplier<R> supplier,
ObjIntConsumer<R> accumulator,
BiConsumer<R, R> combiner) {
BinaryOperator<R> operator = (left, right) -> {
combiner.accept(left, right);
return left;
};
return evaluate(ReduceOps.makeInt(supplier, accumulator, operator));
}
示例15: collect
import java.util.function.ObjIntConsumer; //导入依赖的package包/类
@Override
public final <R> R collect(Supplier<R> supplier,
ObjIntConsumer<R> accumulator,
BiConsumer<R, R> combiner) {
Objects.requireNonNull(combiner);
BinaryOperator<R> operator = (left, right) -> {
combiner.accept(left, right);
return left;
};
return evaluate(ReduceOps.makeInt(supplier, accumulator, operator));
}