當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。