当前位置: 首页>>代码示例>>Java>>正文


Java ObjIntConsumer类代码示例

本文整理汇总了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);
}
 
开发者ID:sebhoss,项目名称:memoization.java,代码行数:20,代码来源:GuavaCacheBasedObjIntConsumerMemoizerTest.java

示例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);
    }
}
 
开发者ID:sebhoss,项目名称:memoization.java,代码行数:20,代码来源:JCacheBasedObjIntConsumerMemoizerTest.java

示例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);
}
 
开发者ID:sebhoss,项目名称:memoization.java,代码行数:19,代码来源:ConcurrentMapBasedObjIntConsumerMemoizerTest.java

示例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);
}
 
开发者ID:sebhoss,项目名称:memoization.java,代码行数:20,代码来源:ConcurrentMapBasedObjIntConsumerMemoizerTest.java

示例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);
}
 
开发者ID:sebhoss,项目名称:memoization.java,代码行数:19,代码来源:ConcurrentMapBasedObjIntConsumerMemoizerTest.java

示例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());
}
 
开发者ID:sebhoss,项目名称:memoization.java,代码行数:23,代码来源:ConcurrentMapBasedObjIntConsumerMemoizerTest.java

示例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);
}
 
开发者ID:sebhoss,项目名称:memoization.java,代码行数:20,代码来源:ConcurrentMapBasedObjIntConsumerMemoizerTest.java

示例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;
}
 
开发者ID:phax,项目名称:peppol-directory,代码行数:20,代码来源:PDStorageManager.java

示例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);
  }
}
 
开发者ID:phax,项目名称:ph-commons,代码行数:18,代码来源:StreamHelper.java

示例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);
}
 
开发者ID:jOOQ,项目名称:jOOL,代码行数:17,代码来源:CheckedBiConsumerTest.java

示例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;
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:12,代码来源:Augmentation.java

示例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));
  }
}
 
开发者ID:zugzug90,项目名称:guava-mock,代码行数:8,代码来源:RegularImmutableSortedMultiset.java

示例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();
        }
    };
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:43,代码来源:ReduceOps.java

示例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));
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:11,代码来源:IntPipeline.java

示例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));
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:12,代码来源:IntPipeline.java


注:本文中的java.util.function.ObjIntConsumer类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。