Java 类java.util.function.ToLongBiFunction 实例源码

项目:memoization.java    文件:JCacheBasedToLongBiFunctionMemoizerTest.java   
/**
*
*/
@Test
public void shouldMemoizeBiFunction() {
    // given
    final ToLongBiFunction<String, String> function = (first, second) -> 123;
    final BiFunction<String, String, String> keyfunction = hashCodeKeyFunction();
    try (final Cache<String, Long> cache = JCacheMemoize.createCache(ToLongBiFunction.class)) {
        // when
        final JCacheBasedToLongBiFunctionMemoizer<String, String, String> loader = new JCacheBasedToLongBiFunctionMemoizer<>(
                cache, keyfunction, function);

        // then
        Assert.assertEquals("Memoized value does not match expectation", 123,
                loader.applyAsLong("first", "second"));
    }
}
项目:memoization.java    文件:ConcurrentMapBasedToLongBiFunctionMemoizerTest.java   
/**
 *
 */
@Test
@SuppressWarnings(CompilerWarnings.UNUSED)
public void shouldRequireNonNullCache() {
    // given
    final ConcurrentMap<String, Long> cache = null;
    final BiFunction<String, String, String> keyFunction = (a, b) -> "key";
    final ToLongBiFunction<String, String> biFunction = (a, b) -> 123L;

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

    // then
    new ConcurrentMapBasedToLongBiFunctionMemoizer<>(cache, keyFunction, biFunction);
}
项目:memoization.java    文件:ConcurrentMapBasedToLongBiFunctionMemoizerTest.java   
/**
 *
 */
@Test
@SuppressWarnings(CompilerWarnings.UNUSED)
public void shouldRequireNonNullKeyBiFunction() {
    // given
    final ConcurrentMap<String, Long> cache = new ConcurrentHashMap<>();
    final BiFunction<String, String, String> keyFunction = null;
    final ToLongBiFunction<String, String> biFunction = (a, b) -> 123L;

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

    // then
    new ConcurrentMapBasedToLongBiFunctionMemoizer<>(cache, keyFunction, biFunction);
}
项目:memoization.java    文件:ConcurrentMapBasedToLongBiFunctionMemoizerTest.java   
/**
 *
 */
@Test
@SuppressWarnings(CompilerWarnings.UNUSED)
public void shouldRequireNonNullBiFunction() {
    // given
    final ConcurrentMap<String, Long> cache = new ConcurrentHashMap<>();
    final BiFunction<String, String, String> keyFunction = (a, b) -> "key";
    final ToLongBiFunction<String, String> biFunction = null;

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

    // then
    new ConcurrentMapBasedToLongBiFunctionMemoizer<>(cache, keyFunction, biFunction);
}
项目:memoization.java    文件:ConcurrentMapBasedToLongBiFunctionMemoizerTest.java   
/**
*
*/
@Test
public void shouldUseSetCacheKeyAndValue() {
    // given
    final ConcurrentMap<String, Long> cache = new ConcurrentHashMap<>();
    final BiFunction<String, String, String> keyFunction = (a, b) -> "key";
    final ToLongBiFunction<String, String> biFunction = (a, b) -> 123L;

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

    // then
    memoizer.applyAsLong("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", 123L,
            memoizer.viewCacheForTest().values().iterator().next().longValue());
}
项目:memoization.java    文件:ConcurrentMapBasedToLongBiFunctionMemoizerTest.java   
/**
*
*/
@Test
@SuppressWarnings(CompilerWarnings.UNCHECKED)
public void shouldUseCallWrappedBiFunction() {
    // given
    final ConcurrentMap<String, Long> cache = new ConcurrentHashMap<>();
    final BiFunction<String, String, String> keyFunction = (a, b) -> "key";
    final ToLongBiFunction<String, String> biFunction = Mockito.mock(ToLongBiFunction.class);

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

    // then
    memoizer.applyAsLong("123.456", "789.123");
    Mockito.verify(biFunction).applyAsLong("123.456", "789.123");
}
项目:speedment    文件:SqlStreamOptimizerInfo.java   
static <ENTITY> SqlStreamOptimizerInfo<ENTITY> of(
    final DbmsType dbmsType,
    final String sqlSelect,
    final String sqlSelectCount,
    final ToLongBiFunction<String, List<Object>> counter,
    final Function<Field<ENTITY>, String> sqlColumnNamer,
    final Function<Field<ENTITY>, Class<?>> sqlDatabaseTypeFunction
) {
    return new SqlStreamOptimizerInfoImpl<>(
        dbmsType,
        sqlSelect,
        sqlSelectCount,
        counter,
        sqlColumnNamer,
        sqlDatabaseTypeFunction
    );
}
项目:jOOL    文件:CheckedBiFunctionTest.java   
@Test
public void testCheckedToLongBiFunction() {
    final CheckedToLongBiFunction<Object, Object> toLongBiFunction = (t, u) -> {
        throw new Exception(t + ":" + u);
    };

    ToLongBiFunction<Object, Object> f1 = Unchecked.toLongBiFunction(toLongBiFunction);
    ToLongBiFunction<Object, Object> f2 = CheckedToLongBiFunction.unchecked(toLongBiFunction);
    ToLongBiFunction<Object, Object> f3 = Sneaky.toLongBiFunction(toLongBiFunction);
    ToLongBiFunction<Object, Object> f4 = CheckedToLongBiFunction.sneaky(toLongBiFunction);

    assertToLongBiFunction(f1, UncheckedException.class);
    assertToLongBiFunction(f2, UncheckedException.class);
    assertToLongBiFunction(f3, Exception.class);
    assertToLongBiFunction(f4, Exception.class);
}
项目:OpenJSharp    文件:ConcurrentHashMap.java   
MapReduceMappingsToLongTask
    (BulkTask<K,V,?> p, int b, int i, int f, Node<K,V>[] t,
     MapReduceMappingsToLongTask<K,V> nextRight,
     ToLongBiFunction<? super K, ? super V> transformer,
     long basis,
     LongBinaryOperator reducer) {
    super(p, b, i, f, t); this.nextRight = nextRight;
    this.transformer = transformer;
    this.basis = basis; this.reducer = reducer;
}
项目:OpenJSharp    文件:ConcurrentHashMap.java   
public final void compute() {
    final ToLongBiFunction<? super K, ? super V> transformer;
    final LongBinaryOperator reducer;
    if ((transformer = this.transformer) != null &&
        (reducer = this.reducer) != null) {
        long r = this.basis;
        for (int i = baseIndex, f, h; batch > 0 &&
                 (h = ((f = baseLimit) + i) >>> 1) > i;) {
            addToPendingCount(1);
            (rights = new MapReduceMappingsToLongTask<K,V>
             (this, batch >>>= 1, baseLimit = h, f, tab,
              rights, transformer, r, reducer)).fork();
        }
        for (Node<K,V> p; (p = advance()) != null; )
            r = reducer.applyAsLong(r, transformer.applyAsLong(p.key, p.val));
        result = r;
        CountedCompleter<?> c;
        for (c = firstComplete(); c != null; c = c.nextComplete()) {
            @SuppressWarnings("unchecked")
            MapReduceMappingsToLongTask<K,V>
                t = (MapReduceMappingsToLongTask<K,V>)c,
                s = t.rights;
            while (s != null) {
                t.result = reducer.applyAsLong(t.result, s.result);
                s = t.rights = s.nextRight;
            }
        }
    }
}
项目:jdk8u-jdk    文件:ConcurrentHashMap.java   
MapReduceMappingsToLongTask
    (BulkTask<K,V,?> p, int b, int i, int f, Node<K,V>[] t,
     MapReduceMappingsToLongTask<K,V> nextRight,
     ToLongBiFunction<? super K, ? super V> transformer,
     long basis,
     LongBinaryOperator reducer) {
    super(p, b, i, f, t); this.nextRight = nextRight;
    this.transformer = transformer;
    this.basis = basis; this.reducer = reducer;
}
项目:jdk8u-jdk    文件:ConcurrentHashMap.java   
public final void compute() {
    final ToLongBiFunction<? super K, ? super V> transformer;
    final LongBinaryOperator reducer;
    if ((transformer = this.transformer) != null &&
        (reducer = this.reducer) != null) {
        long r = this.basis;
        for (int i = baseIndex, f, h; batch > 0 &&
                 (h = ((f = baseLimit) + i) >>> 1) > i;) {
            addToPendingCount(1);
            (rights = new MapReduceMappingsToLongTask<K,V>
             (this, batch >>>= 1, baseLimit = h, f, tab,
              rights, transformer, r, reducer)).fork();
        }
        for (Node<K,V> p; (p = advance()) != null; )
            r = reducer.applyAsLong(r, transformer.applyAsLong(p.key, p.val));
        result = r;
        CountedCompleter<?> c;
        for (c = firstComplete(); c != null; c = c.nextComplete()) {
            @SuppressWarnings("unchecked")
            MapReduceMappingsToLongTask<K,V>
                t = (MapReduceMappingsToLongTask<K,V>)c,
                s = t.rights;
            while (s != null) {
                t.result = reducer.applyAsLong(t.result, s.result);
                s = t.rights = s.nextRight;
            }
        }
    }
}
项目:openjdk-jdk10    文件:ConcurrentHashMap.java   
MapReduceMappingsToLongTask
    (BulkTask<K,V,?> p, int b, int i, int f, Node<K,V>[] t,
     MapReduceMappingsToLongTask<K,V> nextRight,
     ToLongBiFunction<? super K, ? super V> transformer,
     long basis,
     LongBinaryOperator reducer) {
    super(p, b, i, f, t); this.nextRight = nextRight;
    this.transformer = transformer;
    this.basis = basis; this.reducer = reducer;
}
项目:openjdk-jdk10    文件:ConcurrentHashMap.java   
public final void compute() {
    final ToLongBiFunction<? super K, ? super V> transformer;
    final LongBinaryOperator reducer;
    if ((transformer = this.transformer) != null &&
        (reducer = this.reducer) != null) {
        long r = this.basis;
        for (int i = baseIndex, f, h; batch > 0 &&
                 (h = ((f = baseLimit) + i) >>> 1) > i;) {
            addToPendingCount(1);
            (rights = new MapReduceMappingsToLongTask<K,V>
             (this, batch >>>= 1, baseLimit = h, f, tab,
              rights, transformer, r, reducer)).fork();
        }
        for (Node<K,V> p; (p = advance()) != null; )
            r = reducer.applyAsLong(r, transformer.applyAsLong(p.key, p.val));
        result = r;
        CountedCompleter<?> c;
        for (c = firstComplete(); c != null; c = c.nextComplete()) {
            @SuppressWarnings("unchecked")
            MapReduceMappingsToLongTask<K,V>
                t = (MapReduceMappingsToLongTask<K,V>)c,
                s = t.rights;
            while (s != null) {
                t.result = reducer.applyAsLong(t.result, s.result);
                s = t.rights = s.nextRight;
            }
        }
    }
}
项目:openjdk9    文件:ConcurrentHashMap.java   
MapReduceMappingsToLongTask
    (BulkTask<K,V,?> p, int b, int i, int f, Node<K,V>[] t,
     MapReduceMappingsToLongTask<K,V> nextRight,
     ToLongBiFunction<? super K, ? super V> transformer,
     long basis,
     LongBinaryOperator reducer) {
    super(p, b, i, f, t); this.nextRight = nextRight;
    this.transformer = transformer;
    this.basis = basis; this.reducer = reducer;
}
项目:openjdk9    文件:ConcurrentHashMap.java   
public final void compute() {
    final ToLongBiFunction<? super K, ? super V> transformer;
    final LongBinaryOperator reducer;
    if ((transformer = this.transformer) != null &&
        (reducer = this.reducer) != null) {
        long r = this.basis;
        for (int i = baseIndex, f, h; batch > 0 &&
                 (h = ((f = baseLimit) + i) >>> 1) > i;) {
            addToPendingCount(1);
            (rights = new MapReduceMappingsToLongTask<K,V>
             (this, batch >>>= 1, baseLimit = h, f, tab,
              rights, transformer, r, reducer)).fork();
        }
        for (Node<K,V> p; (p = advance()) != null; )
            r = reducer.applyAsLong(r, transformer.applyAsLong(p.key, p.val));
        result = r;
        CountedCompleter<?> c;
        for (c = firstComplete(); c != null; c = c.nextComplete()) {
            @SuppressWarnings("unchecked")
            MapReduceMappingsToLongTask<K,V>
                t = (MapReduceMappingsToLongTask<K,V>)c,
                s = t.rights;
            while (s != null) {
                t.result = reducer.applyAsLong(t.result, s.result);
                s = t.rights = s.nextRight;
            }
        }
    }
}
项目:Java8CN    文件:ConcurrentHashMap.java   
MapReduceMappingsToLongTask
    (BulkTask<K,V,?> p, int b, int i, int f, Node<K,V>[] t,
     MapReduceMappingsToLongTask<K,V> nextRight,
     ToLongBiFunction<? super K, ? super V> transformer,
     long basis,
     LongBinaryOperator reducer) {
    super(p, b, i, f, t); this.nextRight = nextRight;
    this.transformer = transformer;
    this.basis = basis; this.reducer = reducer;
}
项目:Java8CN    文件:ConcurrentHashMap.java   
public final void compute() {
    final ToLongBiFunction<? super K, ? super V> transformer;
    final LongBinaryOperator reducer;
    if ((transformer = this.transformer) != null &&
        (reducer = this.reducer) != null) {
        long r = this.basis;
        for (int i = baseIndex, f, h; batch > 0 &&
                 (h = ((f = baseLimit) + i) >>> 1) > i;) {
            addToPendingCount(1);
            (rights = new MapReduceMappingsToLongTask<K,V>
             (this, batch >>>= 1, baseLimit = h, f, tab,
              rights, transformer, r, reducer)).fork();
        }
        for (Node<K,V> p; (p = advance()) != null; )
            r = reducer.applyAsLong(r, transformer.applyAsLong(p.key, p.val));
        result = r;
        CountedCompleter<?> c;
        for (c = firstComplete(); c != null; c = c.nextComplete()) {
            @SuppressWarnings("unchecked")
            MapReduceMappingsToLongTask<K,V>
                t = (MapReduceMappingsToLongTask<K,V>)c,
                s = t.rights;
            while (s != null) {
                t.result = reducer.applyAsLong(t.result, s.result);
                s = t.rights = s.nextRight;
            }
        }
    }
}
项目:NonDex    文件:ConcurrentHashMap.java   
MapReduceMappingsToLongTask
    (BulkTask<K,V,?> p, int b, int i, int f, Node<K,V>[] t,
     MapReduceMappingsToLongTask<K,V> nextRight,
     ToLongBiFunction<? super K, ? super V> transformer,
     long basis,
     LongBinaryOperator reducer) {
    super(p, b, i, f, t); this.nextRight = nextRight;
    this.transformer = transformer;
    this.basis = basis; this.reducer = reducer;
}
项目:NonDex    文件:ConcurrentHashMap.java   
@Override
public final void compute() {
    final ToLongBiFunction<? super K, ? super V> transformer;
    final LongBinaryOperator reducer;
    if ((transformer = this.transformer) != null &&
        (reducer = this.reducer) != null) {
        long 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 MapReduceMappingsToLongTask<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.applyAsLong(r, transformer.applyAsLong(p.key, p.val));
        }
        this.result = r;
        CountedCompleter<?> c;
        for (c = this.firstComplete(); c != null; c = c.nextComplete()) {
            @SuppressWarnings("unchecked")
            MapReduceMappingsToLongTask<K,V>
                t = (MapReduceMappingsToLongTask<K,V>)c,
                s = t.rights;
            while (s != null) {
                t.result = reducer.applyAsLong(t.result, s.result);
                s = t.rights = s.nextRight;
            }
        }
    }
}
项目:Diorite-old    文件:ConcurrentIdentityHashMap.java   
MapReduceMappingsToLongTask(final BulkTask<K, V, ?> p, final int b, final int i, final int f, final Node<K, V>[] t, final MapReduceMappingsToLongTask<K, V> nextRight, final ToLongBiFunction<? super K, ? super V> transformer, final long basis, final LongBinaryOperator reducer)
{
    super(p, b, i, f, t);
    this.nextRight = nextRight;
    this.transformer = transformer;
    this.basis = basis;
    this.reducer = reducer;
}
项目:Diorite-old    文件:ConcurrentIdentityHashMap.java   
@Override
public final void compute()
{
    final ToLongBiFunction<? super K, ? super V> transformer;
    final LongBinaryOperator reducer;
    if ((((transformer = this.transformer)) != null) && (((reducer = this.reducer)) != null))
    {
        long 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 MapReduceMappingsToLongTask<>(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.applyAsLong(r, transformer.applyAsLong(p.key, p.val));
        }
        this.result = r;
        CountedCompleter<?> c;
        for (c = this.firstComplete(); c != null; c = c.nextComplete())
        {
            @SuppressWarnings("unchecked")
            final MapReduceMappingsToLongTask<K, V> t = (MapReduceMappingsToLongTask<K, V>) c;
            @SuppressWarnings("unchecked")
            MapReduceMappingsToLongTask<K, V> s = t.rights;
            while (s != null)
            {
                t.result = reducer.applyAsLong(t.result, s.result);
                s = t.rights = s.nextRight;
            }
        }
    }
}
项目:rheem    文件:DefaultCardinalityEstimator.java   
public DefaultCardinalityEstimator(double certaintyProb,
                                   int numInputs,
                                   boolean isAllowMoreInputs,
                                   ToLongBiFunction<long[], Configuration> singlePointEstimator) {
    this.certaintyProb = certaintyProb;
    this.numInputs = numInputs;
    this.singlePointEstimator = singlePointEstimator;
    this.isAllowMoreInputs = isAllowMoreInputs;
}
项目:rheem    文件:DefaultLoadEstimator.java   
public DefaultLoadEstimator(int numInputs,
                            int numOutputs,
                            double correctnessProbability,
                            CardinalityEstimate nullCardinalityReplacement,
                            ToLongBiFunction<long[], long[]> singlePointFunction) {
    this(
            numInputs, numOutputs, correctnessProbability, nullCardinalityReplacement,
            (context, inputEstimates, outputEstimates) -> singlePointFunction.applyAsLong(inputEstimates, outputEstimates)
    );
}
项目:rheem    文件:IntervalLoadEstimator.java   
public IntervalLoadEstimator(int numInputs,
                             int numOutputs,
                             double correctnessProbability,
                             ToLongBiFunction<long[], long[]> lowerBoundEstimator,
                             ToLongBiFunction<long[], long[]> upperBoundEstimator) {
    this(numInputs, numOutputs, correctnessProbability, null, lowerBoundEstimator, upperBoundEstimator);
}
项目:rheem    文件:IntervalLoadEstimator.java   
public IntervalLoadEstimator(int numInputs,
                             int numOutputs,
                             double correctnessProbablity,
                             CardinalityEstimate nullCardinalityReplacement,
                             ToLongBiFunction<long[], long[]> lowerBoundEstimator,
                             ToLongBiFunction<long[], long[]> upperBoundEstimator) {

    super(nullCardinalityReplacement);
    this.numInputs = numInputs;
    this.numOutputs = numOutputs;
    this.correctnessProbablity = correctnessProbablity;
    this.lowerBoundEstimator = lowerBoundEstimator;
    this.upperBoundEstimator = upperBoundEstimator;
}
项目:jdk8u_jdk    文件:ConcurrentHashMap.java   
MapReduceMappingsToLongTask
    (BulkTask<K,V,?> p, int b, int i, int f, Node<K,V>[] t,
     MapReduceMappingsToLongTask<K,V> nextRight,
     ToLongBiFunction<? super K, ? super V> transformer,
     long basis,
     LongBinaryOperator reducer) {
    super(p, b, i, f, t); this.nextRight = nextRight;
    this.transformer = transformer;
    this.basis = basis; this.reducer = reducer;
}
项目:jdk8u_jdk    文件:ConcurrentHashMap.java   
public final void compute() {
    final ToLongBiFunction<? super K, ? super V> transformer;
    final LongBinaryOperator reducer;
    if ((transformer = this.transformer) != null &&
        (reducer = this.reducer) != null) {
        long r = this.basis;
        for (int i = baseIndex, f, h; batch > 0 &&
                 (h = ((f = baseLimit) + i) >>> 1) > i;) {
            addToPendingCount(1);
            (rights = new MapReduceMappingsToLongTask<K,V>
             (this, batch >>>= 1, baseLimit = h, f, tab,
              rights, transformer, r, reducer)).fork();
        }
        for (Node<K,V> p; (p = advance()) != null; )
            r = reducer.applyAsLong(r, transformer.applyAsLong(p.key, p.val));
        result = r;
        CountedCompleter<?> c;
        for (c = firstComplete(); c != null; c = c.nextComplete()) {
            @SuppressWarnings("unchecked")
            MapReduceMappingsToLongTask<K,V>
                t = (MapReduceMappingsToLongTask<K,V>)c,
                s = t.rights;
            while (s != null) {
                t.result = reducer.applyAsLong(t.result, s.result);
                s = t.rights = s.nextRight;
            }
        }
    }
}
项目:lookaside_java-1.8.0-openjdk    文件:ConcurrentHashMap.java   
MapReduceMappingsToLongTask
    (BulkTask<K,V,?> p, int b, int i, int f, Node<K,V>[] t,
     MapReduceMappingsToLongTask<K,V> nextRight,
     ToLongBiFunction<? super K, ? super V> transformer,
     long basis,
     LongBinaryOperator reducer) {
    super(p, b, i, f, t); this.nextRight = nextRight;
    this.transformer = transformer;
    this.basis = basis; this.reducer = reducer;
}
项目:lookaside_java-1.8.0-openjdk    文件:ConcurrentHashMap.java   
public final void compute() {
    final ToLongBiFunction<? super K, ? super V> transformer;
    final LongBinaryOperator reducer;
    if ((transformer = this.transformer) != null &&
        (reducer = this.reducer) != null) {
        long r = this.basis;
        for (int i = baseIndex, f, h; batch > 0 &&
                 (h = ((f = baseLimit) + i) >>> 1) > i;) {
            addToPendingCount(1);
            (rights = new MapReduceMappingsToLongTask<K,V>
             (this, batch >>>= 1, baseLimit = h, f, tab,
              rights, transformer, r, reducer)).fork();
        }
        for (Node<K,V> p; (p = advance()) != null; )
            r = reducer.applyAsLong(r, transformer.applyAsLong(p.key, p.val));
        result = r;
        CountedCompleter<?> c;
        for (c = firstComplete(); c != null; c = c.nextComplete()) {
            @SuppressWarnings("unchecked")
            MapReduceMappingsToLongTask<K,V>
                t = (MapReduceMappingsToLongTask<K,V>)c,
                s = t.rights;
            while (s != null) {
                t.result = reducer.applyAsLong(t.result, s.result);
                s = t.rights = s.nextRight;
            }
        }
    }
}
项目:memoization.java    文件:CaffeineMemoizeCustomKeyTest.java   
/**
*
*/
@Test
public void shouldMemoizeToLongBiFunctionWithKeyFunction() {
    // given
    final ToLongBiFunction<Long, Long> function = (first, second) -> first.longValue()
            + second.longValue();
    final BiFunction<Long, Long, String> keyFunction = hashCodeKeyFunction();

    // when
    final ToLongBiFunction<Long, Long> memoize = CaffeineMemoize.toLongBiFunction(function, keyFunction);

    // then
    Assert.assertNotNull("Memoized ToLongBiFunction is NULL", memoize);
}
项目:memoization.java    文件:CaffeineMemoizeDefaultsTest.java   
/**
*
*/
@Test
public void shouldMemoizeToLongBiFunction() {
    // given
    final ToLongBiFunction<Long, Long> function = (first, second) -> first.longValue()
            + second.longValue();

    // when
    final ToLongBiFunction<Long, Long> memoize = CaffeineMemoize.toLongBiFunction(function);

    // then
    Assert.assertNotNull("Memoized ToLongBiFunction is NULL", memoize);
}
项目:memoization.java    文件:CaffeineMemoizeLambdaTest.java   
/**
*
*/
@Test
public void shouldMemoizeToLongBiFunctionWithLambda() {
    // given

    // when
    final ToLongBiFunction<Long, Long> memoize = CaffeineMemoize
            .toLongBiFunction((first, second) -> first.longValue() + second.longValue());

    // then
    Assert.assertNotNull("Memoized ToLongBiFunction is NULL", memoize);
}
项目:memoization.java    文件:GuavaCacheBasedToLongBiFunctionMemoizer.java   
GuavaCacheBasedToLongBiFunctionMemoizer(
        final Cache<KEY, Long> cache,
        final BiFunction<FIRST, SECOND, KEY> keyFunction,
        final ToLongBiFunction<FIRST, SECOND> biFunction) {
    super(cache);
    this.keyFunction = keyFunction;
    this.biFunction = biFunction;
}
项目:memoization.java    文件:GuavaMemoizeCustomKeyTest.java   
/**
*
*/
@Test
public void shouldMemoizeToLongBiFunctionWithKeyFunction() {
    // given
    final ToLongBiFunction<String, String> function = (a, b) -> 123;
    final BiFunction<String, String, String> keyFunction = (a, b) -> "key";

    // when
    final ToLongBiFunction<String, String> memoize = GuavaMemoize.toLongBiFunction(function, keyFunction);

    // then
    Assert.assertNotNull("Memoized ToLongBiFunction is NULL", memoize);
}
项目:memoization.java    文件:GuavaCacheBasedToLongBiFunctionMemoizerTest.java   
/**
*
*/
@Test
public void shouldAcceptCacheAndKeyFunctionAndBiFunction() {
    // given
    final ToLongBiFunction<String, String> biFunction = (first, second) -> 123;
    final BiFunction<String, String, String> keyFunction = (first, second) -> second + first;
    final Cache<String, Long> cache = CacheBuilder.newBuilder().build();

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

    // then
    Assert.assertNotNull(memoizer);
}
项目:memoization.java    文件:GuavaCacheBasedToLongBiFunctionMemoizerTest.java   
/**
*
*/
@Test
public void shouldTransformInput() {
    // given
    final ToLongBiFunction<String, String> biFunction = (first, second) -> 123;
    final BiFunction<String, String, String> keyFunction = (first, second) -> second + first;
    final Cache<String, Long> cache = CacheBuilder.newBuilder().build();

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

    // then
    Assert.assertEquals("firstsecond", 123, memoizer.applyAsLong("first", "second"));
}
项目:memoization.java    文件:GuavaMemoizeLambdaTest.java   
/**
*
*/
@Test
public void shouldMemoizeToLongBiFunctionWithLambda() {
    // given

    // when
    final ToLongBiFunction<String, String> memoize = GuavaMemoize.toLongBiFunction((a, b) -> 123);

    // then
    Assert.assertNotNull("Memoized ToLongBiFunction is NULL", memoize);
}
项目:memoization.java    文件:GuavaMemoizeDefaultsTest.java   
/**
*
*/
@Test
public void shouldMemoizeToLongBiFunction() {
    // given
    final ToLongBiFunction<String, String> function = (a, b) -> 123;

    // when
    final ToLongBiFunction<String, String> memoize = GuavaMemoize.toLongBiFunction(function);

    // then
    Assert.assertNotNull("Memoized ToLongBiFunction is NULL", memoize);
}
项目:memoization.java    文件:JCacheBasedToLongBiFunctionMemoizer.java   
JCacheBasedToLongBiFunctionMemoizer(
        final Cache<KEY, Long> cache,
        final BiFunction<FIRST, SECOND, KEY> keyFunction,
        final ToLongBiFunction<FIRST, SECOND> biFunction) {
    super(cache);
    this.keyFunction = keyFunction;
    this.biFunction = biFunction;
}