@Test public void shouldMemoizeConsumer() { final ConcurrentMap<String, String> cache = new ConcurrentHashMap<>(); final ObjLongFunction<String, String> keyFunction = (first, second) -> first + second; final ObjLongConsumer<String> consumer = (first, second) -> System.out.println(first + second); final ConcurrentMapBasedObjLongConsumerMemoizer<String, String> memoizer = new ConcurrentMapBasedObjLongConsumerMemoizer<>( cache, keyFunction, consumer); memoizer.accept("test", 123); }
@Override public void accept(final INPUT input, final long value) { final KEY key = keyFunction.apply(input, value); computeIfAbsent(key, givenKey -> { consumer.accept(input, value); return input; }); }
ConcurrentMapBasedObjLongConsumerMemoizer extends ConcurrentMapBasedMemoizer<KEY, INPUT> implements ObjLongConsumer<INPUT> { @Override public void accept(final INPUT input, final long value) { final KEY key = keyFunction.apply(input, value); computeIfAbsent(key, givenKey -> { consumer.accept(input, value); return input; }); } }
ConcurrentMapBasedObjLongConsumerMemoizer extends ConcurrentMapBasedMemoizer<KEY, INPUT> implements ObjLongConsumer<INPUT> { @Override public void accept(final INPUT input, final long value) { final KEY key = keyFunction.apply(input, value); computeIfAbsent(key, givenKey -> { consumer.accept(input, value); return input; }); } @SuppressWarnings(CompilerWarnings.NLS)  ConcurrentMapBasedObjLongConsumerMemoizer(
            final ConcurrentMap<KEY, INPUT> cache,
            final ObjLongFunction<INPUT, KEY> keyFunction,
            final ObjLongConsumer<INPUT> consumer); }
ConcurrentMapBasedObjLongConsumerMemoizer extends ConcurrentMapBasedMemoizer<KEY, INPUT> implements ObjLongConsumer<INPUT> { @Override public void accept(final INPUT input, final long value) { final KEY key = keyFunction.apply(input, value); computeIfAbsent(key, givenKey -> { consumer.accept(input, value); return input; }); } @SuppressWarnings(CompilerWarnings.NLS)  ConcurrentMapBasedObjLongConsumerMemoizer(
            final ConcurrentMap<KEY, INPUT> cache,
            final ObjLongFunction<INPUT, KEY> keyFunction,
            final ObjLongConsumer<INPUT> consumer); @Override void accept(final INPUT input, final long value); }
ConcurrentMapBasedObjLongConsumerMemoizer extends ConcurrentMapBasedMemoizer<KEY, INPUT> implements ObjLongConsumer<INPUT> { @Override public void accept(final INPUT input, final long value) { final KEY key = keyFunction.apply(input, value); computeIfAbsent(key, givenKey -> { consumer.accept(input, value); return input; }); } @SuppressWarnings(CompilerWarnings.NLS)  ConcurrentMapBasedObjLongConsumerMemoizer(
            final ConcurrentMap<KEY, INPUT> cache,
            final ObjLongFunction<INPUT, KEY> keyFunction,
            final ObjLongConsumer<INPUT> consumer); @Override void accept(final INPUT input, final long value);  }