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


Java ToIntBiFunction类代码示例

本文整理汇总了Java中java.util.function.ToIntBiFunction的典型用法代码示例。如果您正苦于以下问题:Java ToIntBiFunction类的具体用法?Java ToIntBiFunction怎么用?Java ToIntBiFunction使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


ToIntBiFunction类属于java.util.function包,在下文中一共展示了ToIntBiFunction类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: shouldRequireNonNullCache

import java.util.function.ToIntBiFunction; //导入依赖的package包/类
/**
 *
 */
@Test
@SuppressWarnings(CompilerWarnings.UNUSED)
public void shouldRequireNonNullCache() {
    // given
    final ConcurrentMap<String, Integer> cache = null;
    final BiFunction<String, String, String> keyFunction = (a, b) -> "key";
    final ToIntBiFunction<String, String> biFunction = (a, b) -> 123;

    // when
    thrown.expect(NullPointerException.class);
    thrown.expectMessage("Provide an empty map instead of NULL.");

    // then
    new ConcurrentMapBasedToIntBiFunctionMemoizer<>(cache, keyFunction, biFunction);
}
 
开发者ID:sebhoss,项目名称:memoization.java,代码行数:19,代码来源:ConcurrentMapBasedToIntBiFunctionMemoizerTest.java

示例2: shouldRequireNonNullKeyBiFunction

import java.util.function.ToIntBiFunction; //导入依赖的package包/类
/**
 *
 */
@Test
@SuppressWarnings(CompilerWarnings.UNUSED)
public void shouldRequireNonNullKeyBiFunction() {
    // given
    final ConcurrentMap<String, Integer> cache = new ConcurrentHashMap<>();
    final BiFunction<String, String, String> keyFunction = null;
    final ToIntBiFunction<String, String> biFunction = (a, b) -> 123;

    // when
    thrown.expect(NullPointerException.class);
    thrown.expectMessage("Provide a key function, might just be 'MemoizationDefaults.hashCodeKeyFunction()'.");

    // then
    new ConcurrentMapBasedToIntBiFunctionMemoizer<>(cache, keyFunction, biFunction);
}
 
开发者ID:sebhoss,项目名称:memoization.java,代码行数:19,代码来源:ConcurrentMapBasedToIntBiFunctionMemoizerTest.java

示例3: shouldRequireNonNullBiFunction

import java.util.function.ToIntBiFunction; //导入依赖的package包/类
/**
 *
 */
@Test
@SuppressWarnings(CompilerWarnings.UNUSED)
public void shouldRequireNonNullBiFunction() {
    // given
    final ConcurrentMap<String, Integer> cache = new ConcurrentHashMap<>();
    final BiFunction<String, String, String> keyFunction = (a, b) -> "key";
    final ToIntBiFunction<String, String> biFunction = null;

    // when
    thrown.expect(NullPointerException.class);
    thrown.expectMessage(
            "Cannot memoize a NULL ToIntBiFunction - provide an actual ToIntBiFunction to fix this.");

    // then
    new ConcurrentMapBasedToIntBiFunctionMemoizer<>(cache, keyFunction, biFunction);
}
 
开发者ID:sebhoss,项目名称:memoization.java,代码行数:20,代码来源:ConcurrentMapBasedToIntBiFunctionMemoizerTest.java

示例4: shouldUseSetCacheKeyAndValue

import java.util.function.ToIntBiFunction; //导入依赖的package包/类
/**
*
*/
@Test
public void shouldUseSetCacheKeyAndValue() {
    // given
    final ConcurrentMap<String, Integer> cache = new ConcurrentHashMap<>();
    final BiFunction<String, String, String> keyFunction = (a, b) -> "key";
    final ToIntBiFunction<String, String> biFunction = (a, b) -> 123;

    // when
    final ConcurrentMapBasedToIntBiFunctionMemoizer<String, String, String> memoizer = new ConcurrentMapBasedToIntBiFunctionMemoizer<>(
            cache, keyFunction, biFunction);

    // then
    memoizer.applyAsInt("123.456", "789.123");
    Assert.assertFalse("Cache is still empty after memoization", memoizer.viewCacheForTest().isEmpty());
    Assert.assertEquals("Memoization key does not match expectations", "key",
            memoizer.viewCacheForTest().keySet().iterator().next());
    Assert.assertEquals("Memoization value does not match expectations", 123,
            memoizer.viewCacheForTest().values().iterator().next().intValue());
}
 
开发者ID:sebhoss,项目名称:memoization.java,代码行数:23,代码来源:ConcurrentMapBasedToIntBiFunctionMemoizerTest.java

示例5: shouldUseCallWrappedBiFunction

import java.util.function.ToIntBiFunction; //导入依赖的package包/类
/**
*
*/
@Test
@SuppressWarnings(CompilerWarnings.UNCHECKED)
public void shouldUseCallWrappedBiFunction() {
    // given
    final ConcurrentMap<String, Integer> cache = new ConcurrentHashMap<>();
    final BiFunction<String, String, String> keyFunction = (a, b) -> "key";
    final ToIntBiFunction<String, String> biFunction = Mockito.mock(ToIntBiFunction.class);

    // when
    final ConcurrentMapBasedToIntBiFunctionMemoizer<String, String, String> memoizer = new ConcurrentMapBasedToIntBiFunctionMemoizer<>(
            cache, keyFunction, biFunction);

    // then
    memoizer.applyAsInt("123.456", "789.123");
    Mockito.verify(biFunction).applyAsInt("123.456", "789.123");
}
 
开发者ID:sebhoss,项目名称:memoization.java,代码行数:20,代码来源:ConcurrentMapBasedToIntBiFunctionMemoizerTest.java

示例6: compareTo

import java.util.function.ToIntBiFunction; //导入依赖的package包/类
/**
 * Compares two segments, first by start positions, then end positions, then
 * content, then sources.
 *
 * @param other
 *            Sequence segment which needs to be compared.
 * @return the compare value of the start positions.
 */
@Override
public int compareTo(final SequenceSegment other) {
    for (ToIntBiFunction<SequenceSegment, SequenceSegment> comp : COMPARATORS) {
        int result = comp.applyAsInt(this, other);
        if (result != 0) {
            return result;
        }
    }
    int candidateComp = 0;
    Iterator<Sequence> thisIt = this.getSources().iterator();
    Iterator<Sequence> otherIt = other.getSources().iterator();
    while (thisIt.hasNext()) {
        candidateComp = thisIt.next().getIdentifier()
                .compareTo(otherIt.next().getIdentifier());
        if (candidateComp != 0) {
            return candidateComp;
        }
    }
    if (this.getIdentifier() == other.getIdentifier()) {
        candidateComp = 0;
    }
    return candidateComp;
}
 
开发者ID:ProgrammingLife2015,项目名称:LifeTiles,代码行数:32,代码来源:SequenceSegment.java

示例7: SimpleBufferTrigger

import java.util.function.ToIntBiFunction; //导入依赖的package包/类
SimpleBufferTrigger(Supplier<Object> bufferFactory, ToIntBiFunction<Object, E> queueAdder,
        ScheduledExecutorService scheduledExecutorService,
        ThrowableConsumer<Object, Throwable> consumer,
        TriggerStrategy triggerStrategy, BiConsumer<Throwable, Object> exceptionHandler,
        long maxBufferCount, Consumer<E> rejectHandler) {
    this.queueAdder = queueAdder;
    this.bufferFactory = bufferFactory;
    this.consumer = consumer;
    this.exceptionHandler = exceptionHandler;
    this.maxBufferCount = maxBufferCount;
    this.rejectHandler = rejectHandler;
    this.buffer.set(this.bufferFactory.get());
    ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
    readLock = lock.readLock();
    writeLock = lock.writeLock();
    scheduledExecutorService.schedule(
            new TriggerRunnable(scheduledExecutorService, triggerStrategy),
            DEFAULT_NEXT_TRIGGER_PERIOD, MILLISECONDS);
}
 
开发者ID:PhantomThief,项目名称:buffer-trigger,代码行数:20,代码来源:SimpleBufferTrigger.java

示例8: dateTimeFromTemporal

import java.util.function.ToIntBiFunction; //导入依赖的package包/类
private static Optional<ZonedDateTime> dateTimeFromTemporal( TemporalAccessor ta ) {
    ToIntBiFunction<ChronoField, Integer> getField = ( field, orElse ) ->
            ta.isSupported( field ) ? ta.get( field ) : orElse;

    ZoneId zone = Optional.<ZoneId>ofNullable( ta.query( offset() ) )
            .orElse( Optional.ofNullable( ta.query( zoneId() ) )
                    .orElse( ZoneOffset.UTC ) );

    int year = getField.applyAsInt( ChronoField.YEAR, THIS_YEAR );
    int month = getField.applyAsInt( ChronoField.MONTH_OF_YEAR, 1 );
    int day = getField.applyAsInt( ChronoField.DAY_OF_MONTH, 1 );
    int hour = getField.applyAsInt( ChronoField.HOUR_OF_DAY, 0 );
    int minute = getField.applyAsInt( ChronoField.MINUTE_OF_HOUR, 0 );
    int second = getField.applyAsInt( ChronoField.SECOND_OF_MINUTE, 0 );
    int nanos = getField.applyAsInt( ChronoField.NANO_OF_SECOND, 0 );

    ZonedDateTime dateTime = ZonedDateTime.of( year, month, day, hour, minute, second, nanos, zone );

    return Optional.of( dateTime );
}
 
开发者ID:renatoathaydes,项目名称:LogFX,代码行数:21,代码来源:DateTimeFormatGuesser.java

示例9: testCheckedToIntBiFunction

import java.util.function.ToIntBiFunction; //导入依赖的package包/类
@Test
public void testCheckedToIntBiFunction() {
    final CheckedToIntBiFunction<Object, Object> toIntBiFunction = (t, u) -> {
        throw new Exception(t + ":" + u);
    };

    ToIntBiFunction<Object, Object> f1 = Unchecked.toIntBiFunction(toIntBiFunction);
    ToIntBiFunction<Object, Object> f2 = CheckedToIntBiFunction.unchecked(toIntBiFunction);
    ToIntBiFunction<Object, Object> f3 = Sneaky.toIntBiFunction(toIntBiFunction);
    ToIntBiFunction<Object, Object> f4 = CheckedToIntBiFunction.sneaky(toIntBiFunction);

    assertToIntBiFunction(f1, UncheckedException.class);
    assertToIntBiFunction(f2, UncheckedException.class);
    assertToIntBiFunction(f3, Exception.class);
    assertToIntBiFunction(f4, Exception.class);
}
 
开发者ID:jOOQ,项目名称:jOOL,代码行数:17,代码来源:CheckedBiFunctionTest.java

示例10: super

import java.util.function.ToIntBiFunction; //导入依赖的package包/类
MapReduceMappingsToIntTask
    (BulkTask<K,V,?> p, int b, int i, int f, Node<K,V>[] t,
     MapReduceMappingsToIntTask<K,V> nextRight,
     ToIntBiFunction<? super K, ? super V> transformer,
     int basis,
     IntBinaryOperator reducer) {
    super(p, b, i, f, t); this.nextRight = nextRight;
    this.transformer = transformer;
    this.basis = basis; this.reducer = reducer;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:11,代码来源:ConcurrentHashMap.java

示例11: compute

import java.util.function.ToIntBiFunction; //导入依赖的package包/类
public final void compute() {
    final ToIntBiFunction<? super K, ? super V> transformer;
    final IntBinaryOperator reducer;
    if ((transformer = this.transformer) != null &&
        (reducer = this.reducer) != null) {
        int r = this.basis;
        for (int i = baseIndex, f, h; batch > 0 &&
                 (h = ((f = baseLimit) + i) >>> 1) > i;) {
            addToPendingCount(1);
            (rights = new MapReduceMappingsToIntTask<K,V>
             (this, batch >>>= 1, baseLimit = h, f, tab,
              rights, transformer, r, reducer)).fork();
        }
        for (Node<K,V> p; (p = advance()) != null; )
            r = reducer.applyAsInt(r, transformer.applyAsInt(p.key, p.val));
        result = r;
        CountedCompleter<?> c;
        for (c = firstComplete(); c != null; c = c.nextComplete()) {
            @SuppressWarnings("unchecked")
            MapReduceMappingsToIntTask<K,V>
                t = (MapReduceMappingsToIntTask<K,V>)c,
                s = t.rights;
            while (s != null) {
                t.result = reducer.applyAsInt(t.result, s.result);
                s = t.rights = s.nextRight;
            }
        }
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:30,代码来源:ConcurrentHashMap.java

示例12: PartitionedFeatureVectors

import java.util.function.ToIntBiFunction; //导入依赖的package包/类
public PartitionedFeatureVectors(int numPartitions,
                                 ExecutorService executor,
                                 ToIntBiFunction<String,float[]> partitioner) {
  Preconditions.checkArgument(numPartitions > 0);
  Objects.requireNonNull(executor);
  Objects.requireNonNull(partitioner);
  partitions = new FeatureVectorsPartition[numPartitions];
  for (int i = 0; i < numPartitions; i++) {
    partitions[i] = new FeatureVectorsPartition();
  }
  partitionMap = HashObjIntMaps.newMutableMap();
  partitionMapLock = new AutoReadWriteLock();
  this.partitioner = partitioner;
  this.executor = executor;
}
 
开发者ID:oncewang,项目名称:oryx2,代码行数:16,代码来源:PartitionedFeatureVectors.java

示例13: compute

import java.util.function.ToIntBiFunction; //导入依赖的package包/类
@Override
public final void compute() {
    final ToIntBiFunction<? super K, ? super V> transformer;
    final IntBinaryOperator reducer;
    if ((transformer = this.transformer) != null &&
        (reducer = this.reducer) != null) {
        int r = this.basis;
        for (int i = this.baseIndex, f, h; this.batch > 0 &&
                 (h = ((f = this.baseLimit) + i) >>> 1) > i;) {
            this.addToPendingCount(1);
            (this.rights = new MapReduceMappingsToIntTask<K,V>
             (this, this.batch >>>= 1, this.baseLimit = h, f, this.tab,
              this.rights, transformer, r, reducer)).fork();
        }
        for (Node<K,V> p; (p = this.advance()) != null; ) {
            r = reducer.applyAsInt(r, transformer.applyAsInt(p.key, p.val));
        }
        this.result = r;
        CountedCompleter<?> c;
        for (c = this.firstComplete(); c != null; c = c.nextComplete()) {
            @SuppressWarnings("unchecked")
            MapReduceMappingsToIntTask<K,V>
                t = (MapReduceMappingsToIntTask<K,V>)c,
                s = t.rights;
            while (s != null) {
                t.result = reducer.applyAsInt(t.result, s.result);
                s = t.rights = s.nextRight;
            }
        }
    }
}
 
开发者ID:TestingResearchIllinois,项目名称:NonDex,代码行数:32,代码来源:ConcurrentHashMap.java

示例14: MapReduceMappingsToIntTask

import java.util.function.ToIntBiFunction; //导入依赖的package包/类
MapReduceMappingsToIntTask(final BulkTask<K, V, ?> p, final int b, final int i, final int f, final Node<K, V>[] t, final MapReduceMappingsToIntTask<K, V> nextRight, final ToIntBiFunction<? super K, ? super V> transformer, final int basis, final IntBinaryOperator reducer)
{
    super(p, b, i, f, t);
    this.nextRight = nextRight;
    this.transformer = transformer;
    this.basis = basis;
    this.reducer = reducer;
}
 
开发者ID:Diorite,项目名称:Diorite-old,代码行数:9,代码来源:ConcurrentIdentityHashMap.java

示例15: compute

import java.util.function.ToIntBiFunction; //导入依赖的package包/类
@Override
public final void compute()
{
    final ToIntBiFunction<? super K, ? super V> transformer;
    final IntBinaryOperator reducer;
    if ((((transformer = this.transformer)) != null) && (((reducer = this.reducer)) != null))
    {
        int r = this.basis;
        for (int i = this.baseIndex, f, h; (this.batch > 0) && (((h = (((f = this.baseLimit)) + i) >>> 1)) > i); )
        {
            this.addToPendingCount(1);
            (this.rights = new MapReduceMappingsToIntTask<>(this, this.batch >>>= 1, this.baseLimit = h, f, this.tab, this.rights, transformer, r, reducer)).fork();
        }
        for (Node<K, V> p; (p = this.advance()) != null; )
        {
            r = reducer.applyAsInt(r, transformer.applyAsInt(p.key, p.val));
        }
        this.result = r;
        CountedCompleter<?> c;
        for (c = this.firstComplete(); c != null; c = c.nextComplete())
        {
            @SuppressWarnings("unchecked")
            final MapReduceMappingsToIntTask<K, V> t = (MapReduceMappingsToIntTask<K, V>) c;
            @SuppressWarnings("unchecked")
            MapReduceMappingsToIntTask<K, V> s = t.rights;
            while (s != null)
            {
                t.result = reducer.applyAsInt(t.result, s.result);
                s = t.rights = s.nextRight;
            }
        }
    }
}
 
开发者ID:Diorite,项目名称:Diorite-old,代码行数:34,代码来源:ConcurrentIdentityHashMap.java


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