本文整理汇总了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);
}
示例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);
}
示例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);
}
示例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());
}
示例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");
}
示例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;
}
示例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);
}
示例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 );
}
示例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);
}
示例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;
}
示例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;
}
}
}
}
示例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;
}
示例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;
}
}
}
}
示例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;
}
示例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;
}
}
}
}