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


Java BiFunction类代码示例

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


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

示例1: testRandomized

import java.util.function.BiFunction; //导入依赖的package包/类
static void testRandomized(BiFunction<int[], Integer, List<Integer>> solution) {
	Random rnd = new Random(0);

	for (int test = 0; test < 20; test++) {
		int[] arr = new int[rnd.nextInt(MAX_ITEMS) + 1];
		for (int i = 0; i < arr.length; i++) {
			arr[i] = rnd.nextInt(MAX_VALUE);
		}

		for (int j = 0; j < 5; j++) {
			int target = randomDifference(arr, 0, arr.length - 1, rnd);

			System.out.println("Array length: " + arr.length);
			System.out.println("Target: " + target);
			System.out.println("Array:");
			System.out.println(Arrays.toString(arr).replaceAll("[\\[\\],]", " ").trim());

			List<Integer> subtractcionOrder = solution.apply(arr, target);
			verifySolution(arr, target, subtractcionOrder);

			System.out.println("Result: " + subtractcionOrder.toString().replaceAll("[\\[\\],]", " ").trim());
			System.out.println();
		}
	}
}
 
开发者ID:lagodiuk,项目名称:spoj,代码行数:26,代码来源:MINUS_Testing.java

示例2: test2

import java.util.function.BiFunction; //导入依赖的package包/类
public static <R,P1, P2> R test2(String name, R receiver, BiFunction<P1, P2, R> m,
                           P1 arg1, P2 arg2,
                           Class<? extends Exception> ...ex) {
    try {
        R result =  m.apply(arg1, arg2);
        if (!shouldFail(ex)) {
            System.out.println("success: " + name + "(" + arg1 + ", "
                               + arg2 + ")");
            return result;
        } else {
            throw new AssertionError("Expected " + expectedNames(ex)
                + " not raised for "
                + name + "(" + arg1 +", " + arg2 + ")");
        }
    } catch (Exception x) {
        if (!isExpected(x, ex)) {
            throw x;
        } else {
            System.out.println("success: " + name + "(" + arg1 + ", "
                    + arg2 + ") - Got expected exception: " + x);
            return receiver;
        }
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:25,代码来源:HttpRequestBuilderTest.java

示例3: replaceAll

import java.util.function.BiFunction; //导入依赖的package包/类
@Override
public void replaceAll(BiFunction<? super K, ? super V, ? extends V> function) {
    Node<K,V>[] tab;
    if (function == null)
        throw new NullPointerException();
    if (size > 0 && (tab = table) != null) {
        int mc = modCount;
        for (int i = 0; i < tab.length; ++i) {
            for (Node<K,V> e = tab[i]; e != null; e = e.next) {
                e.value = function.apply(e.key, e.value);
            }
        }
        if (modCount != mc)
            throw new ConcurrentModificationException();
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:17,代码来源:HashMap.java

示例4: map

import java.util.function.BiFunction; //导入依赖的package包/类
/**
 * Applies the function {@code f} to each element of the stream.
 * The function {@code f} is called with the index (in {@code ys}) of the
 * element to map (first argument) and with the element itself (second
 * argument). That is: {@code map(f,[v,w,...]) = [f(0,v),f(1,w),...]}.
 * For example (pseudo code) if {@code f(i,x) = i+x} then 
 * {@code map(f,[1,2,3]) = [1,3,5]}.
 * @param <Y> any type.
 * @param <Z> any type.
 * @param f turns an index and a {@code Y} into a {@code Z}.
 * @param ys the list to map.
 * @return a new list with the mapped elements.
 * @throws NullPointerException if any argument is {@code null}.
 */
public static <Y, Z>
Stream<Z> map(BiFunction<Integer, Y, Z> f, Stream<Y> ys) {
    requireNonNull(f, "f");
    requireNonNull(ys, "ys");
    
    Iterator<Y> iy = ys.iterator();
    List<Z> zs = new ArrayList<>();
    
    int index = 0;
    while (iy.hasNext()) {
        zs.add(f.apply(index++, iy.next()));
    }
    
    return zs.stream();
}
 
开发者ID:openmicroscopy,项目名称:omero-ms-queue,代码行数:30,代码来源:Streams.java

示例5: executePreparedStatement

import java.util.function.BiFunction; //导入依赖的package包/类
@Test
public void executePreparedStatement() throws CheckedFutureException {
  final Long result = 413L;
  final String command = "command";
  final Integer set = 223;
  final PreparedStatement ps = PreparedStatement.apply(command).setInteger(set);
  final Supplier<Connection> sup = new ConnectionSupplier() {
    @Override
    BiFunction<String, List<Value<?>>, Exchange<Long>> extendedExecuteExchange() {
      return (c, b) -> {
        assertEquals(command, c);
        assertEquals(Arrays.asList(new IntegerValue(set)), b);
        return Exchange.value(result);
      };
    }
  };
  assertEquals(result, sup.get().execute(ps).get(timeout));
}
 
开发者ID:traneio,项目名称:ndbc,代码行数:19,代码来源:ConnectionTest.java

示例6: zipper

import java.util.function.BiFunction; //导入依赖的package包/类
/**
 * @param first
 * @param second
 * @param function
 * @param <F>
 * @param <S>
 * @param <T>
 * @return
 */
public static <F, S, T> List<T> zipper(
        final List<F> first,
        final List<S> second,
        final BiFunction<F, S, T> function
) {
    final List<T> result = new ArrayList<>();
    Fn.itList(first, (key, index) -> {
        final S value = getEnsure(second, index);
        final T merged = function.apply(key, value);
        if (null != merged) {
            result.add(merged);
        }
    });
    return result;
}
 
开发者ID:silentbalanceyh,项目名称:vertx-zero,代码行数:25,代码来源:Statute.java

示例7: JsonArrayMatcher

import java.util.function.BiFunction; //导入依赖的package包/类
public JsonArrayMatcher(T vnetEntityValue, Function<T, String> getKey1,
                        BiPredicate<T, JsonObject> checkKey1,
                        List<String> jsonFieldNames1,
                        BiFunction<T, String, String> getValue1) {
    vnetEntity = vnetEntityValue;
    getKey = getKey1;
    checkKey = checkKey1;
    jsonFieldNames = jsonFieldNames1;
    getValue = getValue1;
}
 
开发者ID:shlee89,项目名称:athena,代码行数:11,代码来源:VirtualNetworkWebResourceTest.java

示例8: 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();
        }
    };
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:41,代码来源:ReduceOps.java

示例9: accumulatingFunction

import java.util.function.BiFunction; //导入依赖的package包/类
private BiFunction<List<RangeStatistics>, RangeStatistics, List<RangeStatistics>> accumulatingFunction() {
    return (rangeStatistics, rangeStatistic) -> {
        List<RangeStatistics> result = new ArrayList<>(rangeStatistics);
        addOrReplace(rangeStatistics, result, rangeStatistic);
        return result;
    };
}
 
开发者ID:cynicLT,项目名称:counter-cloud,代码行数:8,代码来源:CountService.java

示例10: 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);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:16,代码来源:ArraysEqCmpTest.java

示例11: setUp

import java.util.function.BiFunction; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
    clusterCommunicator = createNiceMock(ClusterCommunicationService.class);
    clusterCommunicator.addSubscriber(anyObject(MessageSubject.class),
                                      anyObject(ClusterMessageHandler.class), anyObject(ExecutorService.class));
    expectLastCall().anyTimes();
    replay(clusterCommunicator);
    ClusterService clusterService = new TestClusterService();

    testGossipDeviceStore = new TestGossipDeviceStore(deviceClockService, clusterService, clusterCommunicator);
    testGossipDeviceStore.mastershipService = new TestMastershipService();

    ecMapBuilder = createNiceMock(EventuallyConsistentMapBuilder.class);
    expect(ecMapBuilder.withName(anyObject(String.class))).andReturn(ecMapBuilder).anyTimes();
    expect(ecMapBuilder.withSerializer(anyObject(KryoNamespace.Builder.class))).andReturn(ecMapBuilder).anyTimes();
    expect(ecMapBuilder.withAntiEntropyPeriod(5, TimeUnit.SECONDS)).andReturn(ecMapBuilder).anyTimes();
    expect(ecMapBuilder.withTimestampProvider(anyObject(BiFunction.class))).andReturn(ecMapBuilder).anyTimes();
    expect(ecMapBuilder.withTombstonesDisabled()).andReturn(ecMapBuilder).anyTimes();

    ecMap = createNiceMock(EventuallyConsistentMap.class);
    expect(ecMapBuilder.build()).andReturn(ecMap).anyTimes();
    testStorageService = createNiceMock(StorageService.class);
    expect(testStorageService.eventuallyConsistentMapBuilder()).andReturn(ecMapBuilder).anyTimes();

    replay(testStorageService, ecMapBuilder, ecMap);

    testGossipDeviceStore.storageService = testStorageService;
    testGossipDeviceStore.deviceClockService = deviceClockService;

    gossipDeviceStore = testGossipDeviceStore;
    gossipDeviceStore.activate();
    deviceStore = gossipDeviceStore;
    verify(clusterCommunicator);
    reset(clusterCommunicator);
}
 
开发者ID:shlee89,项目名称:athena,代码行数:36,代码来源:GossipDeviceStoreTest.java

示例12: throwingRuntime

import java.util.function.BiFunction; //导入依赖的package包/类
/**
 * Converts the provided bifunction into a regular BiFunction, where any thrown exceptions
 * are wrapped in a RuntimeException
 */
static <A, B, R, X extends Exception> BiFunction<A, B, R> throwingRuntime(ThrowingBiFunction<A, B, R, X> f) {
    return (a, b) -> {
        try {
            return f.apply(a, b);
        } catch (Exception ex) {
            throw new RuntimeException(ex);
        }
    };
}
 
开发者ID:unruly,项目名称:control,代码行数:14,代码来源:ThrowingLambdas.java

示例13: asyncRecoverReplica

import java.util.function.BiFunction; //导入依赖的package包/类
public Future<Void> asyncRecoverReplica(IndexShard replica, BiFunction<IndexShard, DiscoveryNode, RecoveryTarget> targetSupplier)
    throws IOException {
    FutureTask<Void> task = new FutureTask<>(() -> {
        recoverReplica(replica, targetSupplier);
        return null;
    });
    threadPool.generic().execute(task);
    return task;
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:10,代码来源:ESIndexLevelReplicationTestCase.java

示例14: UninstallNpmDependencyButtonListener

import java.util.function.BiFunction; //导入依赖的package包/类
UninstallNpmDependencyButtonListener(BiFunction<Collection<String>, IProgressMonitor, IStatus> uninstallAction,
		Supplier<IInputValidator> validator, StatusHelper statusHelper, Supplier<String> initalValue) {
	this.statusHelper = statusHelper;
	this.validator = validator;
	this.uninstallAction = uninstallAction;
	this.initalValue = initalValue;
}
 
开发者ID:eclipse,项目名称:n4js,代码行数:8,代码来源:UninstallNpmDependencyButtonListener.java

示例15: pairOp

import java.util.function.BiFunction; //导入依赖的package包/类
public Vector3d pairOp(Vector3d other, BiFunction<Double, Double, Double> function)
{
	setX(function.apply(x(), other.x()));
	setY(function.apply(y(), other.y()));
	setZ(function.apply(z(), other.z()));
	return this;
}
 
开发者ID:timtomtim7,项目名称:SparseBukkitAPI,代码行数:8,代码来源:Vector3d.java


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