本文整理汇总了Java中java.util.function.BiFunction.apply方法的典型用法代码示例。如果您正苦于以下问题:Java BiFunction.apply方法的具体用法?Java BiFunction.apply怎么用?Java BiFunction.apply使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.function.BiFunction
的用法示例。
在下文中一共展示了BiFunction.apply方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: computeIfPresent
import java.util.function.BiFunction; //导入方法依赖的package包/类
/**
* {@inheritDoc}
*
* <p>This method will, on a best-effort basis, throw a
* {@link ConcurrentModificationException} if it is detected that the
* remapping function modifies this map during computation.
*
* @throws ConcurrentModificationException if it is detected that the
* remapping function modified this map
*/
@Override
public V computeIfPresent(K key,
BiFunction<? super K, ? super V, ? extends V> remappingFunction) {
if (remappingFunction == null)
throw new NullPointerException();
Node<K,V> e; V oldValue;
int hash = hash(key);
if ((e = getNode(hash, key)) != null &&
(oldValue = e.value) != null) {
int mc = modCount;
V v = remappingFunction.apply(key, oldValue);
if (mc != modCount) { throw new ConcurrentModificationException(); }
if (v != null) {
e.value = v;
afterNodeAccess(e);
return v;
}
else
removeNode(hash, key, null, false, true);
}
return null;
}
示例2: replaceAll
import java.util.function.BiFunction; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public void replaceAll(BiFunction<? super K, ? super V, ? extends V> function) {
Objects.requireNonNull(function);
int expectedModCount = modCount;
Object[] t = table;
for (int index = 0; index < t.length; index += 2) {
Object k = t[index];
if (k != null) {
t[index + 1] = function.apply((K) unmaskNull(k), (V) t[index + 1]);
}
if (modCount != expectedModCount) {
throw new ConcurrentModificationException();
}
}
}
示例3: testExecutorServiceRunnables
import java.util.function.BiFunction; //导入方法依赖的package包/类
private void testExecutorServiceRunnables(
BiFunction<ExecutorService, Runnable, Future<Object>> testMethod) throws Exception {
// Setup
ExecutorService e = Executors.newCachedThreadPool();
ExecutorService f = StateCapture.capturingDecorator(e);
CapturedState mockCapturedState = mock(CapturedState.class);
Runnable mockRunnable = mock(Runnable.class);
ThreadLocalStateCaptor.THREAD_LOCAL.set(mockCapturedState);
// Execution
testMethod.apply(f, mockRunnable);
f.shutdown();
f.awaitTermination(10, TimeUnit.HOURS);
verifyStandardCaptures(mockCapturedState, mockRunnable);
}
示例4: compute
import java.util.function.BiFunction; //导入方法依赖的package包/类
public final void compute() {
final BiFunction<? super K, ? super V, ? extends U> transformer;
final Consumer<? super U> action;
if ((transformer = this.transformer) != null &&
(action = this.action) != null) {
for (int i = baseIndex, f, h; batch > 0 &&
(h = ((f = baseLimit) + i) >>> 1) > i;) {
addToPendingCount(1);
new ForEachTransformedMappingTask<K,V,U>
(this, batch >>>= 1, baseLimit = h, f, tab,
transformer, action).fork();
}
for (Node<K,V> p; (p = advance()) != null; ) {
U u;
if ((u = transformer.apply(p.key, p.val)) != null)
action.accept(u);
}
propagateCompletion();
}
}
示例5: isValid
import java.util.function.BiFunction; //导入方法依赖的package包/类
@Override
public boolean isValid(String value, ConstraintValidatorContext context) {
String[] prefixes = annotation.value();
BiFunction<String, String, Boolean> fct =
!annotation.ignoreCase() ?
StringUtils::endsWith :
StringUtils::endsWithIgnoreCase;
for(String p : prefixes) {
if (fct.apply(value, p)) {
return true;
}
}
return false;
}
示例6: testArray
import java.util.function.BiFunction; //导入方法依赖的package包/类
@Test(dataProvider = "arrayTypesProvider")
public void testArray(ArrayType<?> arrayType) {
BiFunction<ArrayType<?>, Integer, Object> constructor = (at, s) -> {
Object a = at.construct(s);
for (int x = 0; x < s; x++) {
at.set(a, x, x % 8);
}
return a;
};
BiFunction<ArrayType<?>, Object, Object> cloner = (at, a) ->
constructor.apply(at, Array.getLength(a));
testArrayType(arrayType, constructor, cloner);
}
示例7: compute
import java.util.function.BiFunction; //导入方法依赖的package包/类
public final void compute() {
final Function<? super V, ? extends U> transformer;
final BiFunction<? super U, ? super U, ? extends U> reducer;
if ((transformer = this.transformer) != null &&
(reducer = this.reducer) != null) {
for (int i = baseIndex, f, h; batch > 0 &&
(h = ((f = baseLimit) + i) >>> 1) > i;) {
addToPendingCount(1);
(rights = new MapReduceValuesTask<K,V,U>
(this, batch >>>= 1, baseLimit = h, f, tab,
rights, transformer, reducer)).fork();
}
U r = null;
for (Node<K,V> p; (p = advance()) != null; ) {
U u;
if ((u = transformer.apply(p.val)) != null)
r = (r == null) ? u : reducer.apply(r, u);
}
result = r;
CountedCompleter<?> c;
for (c = firstComplete(); c != null; c = c.nextComplete()) {
@SuppressWarnings("unchecked")
MapReduceValuesTask<K,V,U>
t = (MapReduceValuesTask<K,V,U>)c,
s = t.rights;
while (s != null) {
U tr, sr;
if ((sr = s.result) != null)
t.result = (((tr = t.result) == null) ? sr :
reducer.apply(tr, sr));
s = t.rights = s.nextRight;
}
}
}
}
示例8: replaceAll
import java.util.function.BiFunction; //导入方法依赖的package包/类
public void replaceAll(BiFunction<? super K, ? super V, ? extends V> function) {
if (function == null) throw new NullPointerException();
V v;
for (Node<K,V> n = findFirst(); n != null; n = n.next) {
while ((v = n.getValidValue()) != null) {
V r = function.apply(n.key, v);
if (r == null) throw new NullPointerException();
if (n.casValue(v, r))
break;
}
}
}
示例9: replaceAll
import java.util.function.BiFunction; //导入方法依赖的package包/类
public void replaceAll(BiFunction<? super K, ? super V, ? extends V> function) {
if (function == null)
throw new NullPointerException();
int mc = modCount;
for (LinkedHashMap.Entry<K,V> e = head; e != null; e = e.after)
e.value = function.apply(e.key, e.value);
if (modCount != mc)
throw new ConcurrentModificationException();
}
示例10: compute
import java.util.function.BiFunction; //导入方法依赖的package包/类
public final void compute() {
final BiFunction<Map.Entry<K,V>, Map.Entry<K,V>, ? extends Map.Entry<K,V>> reducer;
if ((reducer = this.reducer) != null) {
for (int i = baseIndex, f, h; batch > 0 &&
(h = ((f = baseLimit) + i) >>> 1) > i;) {
addToPendingCount(1);
(rights = new ReduceEntriesTask<K,V>
(this, batch >>>= 1, baseLimit = h, f, tab,
rights, reducer)).fork();
}
Map.Entry<K,V> r = null;
for (Node<K,V> p; (p = advance()) != null; )
r = (r == null) ? p : reducer.apply(r, p);
result = r;
CountedCompleter<?> c;
for (c = firstComplete(); c != null; c = c.nextComplete()) {
@SuppressWarnings("unchecked")
ReduceEntriesTask<K,V>
t = (ReduceEntriesTask<K,V>)c,
s = t.rights;
while (s != null) {
Map.Entry<K,V> tr, sr;
if ((sr = s.result) != null)
t.result = (((tr = t.result) == null) ? sr :
reducer.apply(tr, sr));
s = t.rights = s.nextRight;
}
}
}
}
示例11: replaceAll
import java.util.function.BiFunction; //导入方法依赖的package包/类
@Override
public void replaceAll(BiFunction<? super K, ? super V, ? extends V> function) {
Objects.requireNonNull(function);
int expectedModCount = modCount;
for (Entry<K, V> e = getFirstEntry(); e != null; e = successor(e)) {
e.value = function.apply(e.key, e.value);
if (expectedModCount != modCount) {
throw new ConcurrentModificationException();
}
}
}
示例12: damagePacketReceived
import java.util.function.BiFunction; //导入方法依赖的package包/类
private void damagePacketReceived(long targetId, int damage,
BiFunction<Integer, GameObject, GraphicGameObject> damageLabelCreator)
{
Monster attackTarget = (Monster) gameObjects.get(targetId);
attackTarget.gotHitBy(damage);
GraphicGameObject damageNumber = damageLabelCreator.apply(damage, attackTarget);
GraphicGameObject bloodAnimation = new BloodAnimation(attackTarget);
clientGraphics.add(damageNumber);
clientGraphics.add(bloodAnimation);
if (attackTarget == player)
userInterface.updateHitPointManaPointDialog();
}
示例13: makeRef
import java.util.function.BiFunction; //导入方法依赖的package包/类
/**
* Constructs a {@code TerminalOp} that implements a functional reduce on
* reference values.
*
* @param <T> the type of the input elements
* @param <U> the type of the result
* @param seed the identity element for the reduction
* @param reducer the accumulating function that incorporates an additional
* input element into the result
* @param combiner the combining function that combines two intermediate
* results
* @return a {@code TerminalOp} implementing the reduction
*/
public static <T, U> TerminalOp<T, U>
makeRef(U seed, BiFunction<U, ? super T, U> reducer, BinaryOperator<U> combiner) {
Objects.requireNonNull(reducer);
Objects.requireNonNull(combiner);
class ReducingSink extends Box<U> implements AccumulatingSink<T, U, ReducingSink> {
@Override
public void begin(long size) {
state = seed;
}
@Override
public void accept(T t) {
state = reducer.apply(state, t);
}
@Override
public void combine(ReducingSink other) {
state = combiner.apply(state, other.state);
}
}
return new ReduceOp<T, U, ReducingSink>(StreamShape.REFERENCE) {
@Override
public ReducingSink makeSink() {
return new ReducingSink();
}
};
}
示例14: copyRecursively
import java.util.function.BiFunction; //导入方法依赖的package包/类
public static boolean copyRecursively( @This File thiz, File target, boolean overwrite,
BiFunction<File, IOException, OnErrorAction> onError,
Predicate<File> filter)
{
if( !thiz.exists() )
{
return OnErrorAction.TERMINATE != onError.apply( thiz, new NoSuchFileException( thiz.toString(), null, "The source file doesn't exist." ) );
}
// We cannot break for loop from inside a lambda, so we have to use an exception here
for( File src : walkTopDown( thiz ).onFail( ( f, e ) ->
{
if( onError.apply( f, e ) == OnErrorAction.TERMINATE )
{
throw new RuntimeException( new TerminateException( f.toString() ) );
}
} ) )
{
if (!filter.test(src)) {
continue;
}
if( !src.exists() )
{
if( OnErrorAction.TERMINATE == onError.apply( src, new NoSuchFileException( src.toString(), null, "The source file doesn't exist." ) ) )
{
return false;
}
}
else
{
String relPath = src.toRelativeString( thiz );
File dstFile = new File( target, relPath );
if( dstFile.exists() && !(src.isDirectory() && dstFile.isDirectory()) )
{
boolean stillExists;
if( !overwrite )
{
stillExists = true;
}
else
{
if( dstFile.isDirectory() )
{
stillExists = !dstFile.deleteRecursively();
}
else
{
stillExists = !dstFile.delete();
}
}
if( stillExists )
{
if( OnErrorAction.TERMINATE == onError.apply( dstFile, new FileAlreadyExistsException( src.toString(), dstFile.toString(), "The destination file already exists." ) ) )
{
return false;
}
continue;
}
}
if( src.isDirectory() )
{
//noinspection ResultOfMethodCallIgnored
dstFile.mkdirs();
}
else
{
if( src.copyTo( dstFile, overwrite, DEFAULT_BUFFER_SIZE ).length() != src.length() )
{
if( OnErrorAction.TERMINATE == onError.apply( src, new IOException( "Source file wasn't copied completely, length of destination file differs." ) ) )
{
return false;
}
}
}
}
}
return true;
}
示例15: pairBinarizeFirst
import java.util.function.BiFunction; //导入方法依赖的package包/类
public static <T, W> Function<Pair<T, W>, Pair<T, W>> pairBinarizeFirst(BiFunction<T, W, W> func) {
return (Pair<T, W> p) -> {
W w = func.apply(p.getFirst(), p.getSecond());
return pair(p.getFirst(), w);
};
}