當前位置: 首頁>>代碼示例>>Java>>正文


Java BiConsumer類代碼示例

本文整理匯總了Java中java.util.function.BiConsumer的典型用法代碼示例。如果您正苦於以下問題:Java BiConsumer類的具體用法?Java BiConsumer怎麽用?Java BiConsumer使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


BiConsumer類屬於java.util.function包,在下文中一共展示了BiConsumer類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: testTickAlignment1

import java.util.function.BiConsumer; //導入依賴的package包/類
/**
 * Test the alignment of the ticks
 * @throws InterruptedException
 * @throws IOException
 * @throws ParseException
 */
@Test(timeout=10000)
public void testTickAlignment1() throws InterruptedException, IOException, ParseException {
	
       final SimpleDateFormat parser = new SimpleDateFormat("HH:mm:ss");
       
	final CountDownLatch latch = new CountDownLatch(3);
	
	final BiConsumer<BitfinexCurrencyPair, Tick> tickConsumer = (s, t) -> {
		Assert.assertTrue(t.getEndTime().getSecond() == 59);
		latch.countDown();
	};
	
	final TickMerger tickMerger = new TickMerger(BitfinexCurrencyPair.BTC_USD, Timeframe.MINUTES_1, tickConsumer);
	tickMerger.addNewPrice(parser.parse("01:01:23").getTime(), 1.0, 5.0);
	tickMerger.addNewPrice(parser.parse("01:02:33").getTime(), 2.0, 5.0);
	tickMerger.addNewPrice(parser.parse("02:03:53").getTime(), 2.0, 5.0);
	tickMerger.addNewPrice(parser.parse("22:22:53").getTime(), 2.0, 5.0);

	tickMerger.close();
	
	latch.await();
}
 
開發者ID:jnidzwetzki,項目名稱:crypto-bot,代碼行數:29,代碼來源:TickMegerTest.java

示例2: writeRelatedCollection

import java.util.function.BiConsumer; //導入依賴的package包/類
/**
 * Writes the related collection's URL, using a {@code BiConsumer}.
 *
 * @param relatedCollection the related collection
 * @param parentEmbeddedPathElements the list of embedded path elements
 * @param biConsumer the {@code BiConsumer} that writes the related
 *        collection URL
 */
public <U> void writeRelatedCollection(
	RelatedCollection<T, U> relatedCollection, String resourceName,
	FunctionalList<String> parentEmbeddedPathElements,
	BiConsumer<String, FunctionalList<String>> biConsumer) {

	Predicate<String> fieldsPredicate = getFieldsPredicate();

	String key = relatedCollection.getKey();

	if (!fieldsPredicate.test(key)) {
		return;
	}

	String url = createNestedCollectionURL(
		_requestInfo.getServerURL(), _path, resourceName);

	FunctionalList<String> embeddedPathElements = new FunctionalList<>(
		parentEmbeddedPathElements, key);

	biConsumer.accept(url, embeddedPathElements);
}
 
開發者ID:liferay,項目名稱:com-liferay-apio-architect,代碼行數:30,代碼來源:FieldsWriter.java

示例3: testDoubleBadOriginBound

import java.util.function.BiConsumer; //導入依賴的package包/類
void testDoubleBadOriginBound(BiConsumer<Double, Double> bi) {
        executeAndCatchIAE(() -> bi.accept(17.0, 2.0));
        executeAndCatchIAE(() -> bi.accept(0.0, 0.0));
        executeAndCatchIAE(() -> bi.accept(Double.NaN, FINITE));
        executeAndCatchIAE(() -> bi.accept(FINITE, Double.NaN));
        executeAndCatchIAE(() -> bi.accept(Double.NEGATIVE_INFINITY, Double.NEGATIVE_INFINITY));

        // Returns NaN
//        executeAndCatchIAE(() -> bi.accept(Double.NEGATIVE_INFINITY, FINITE));
//        executeAndCatchIAE(() -> bi.accept(Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY));

        executeAndCatchIAE(() -> bi.accept(FINITE, Double.NEGATIVE_INFINITY));

        // Returns Double.MAX_VALUE
//        executeAndCatchIAE(() -> bi.accept(FINITE, Double.POSITIVE_INFINITY));

        executeAndCatchIAE(() -> bi.accept(Double.POSITIVE_INFINITY, Double.NEGATIVE_INFINITY));
        executeAndCatchIAE(() -> bi.accept(Double.POSITIVE_INFINITY, FINITE));
        executeAndCatchIAE(() -> bi.accept(Double.POSITIVE_INFINITY, Double.POSITIVE_INFINITY));
    }
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:21,代碼來源:RandomTest.java

示例4: invokeEntity

import java.util.function.BiConsumer; //導入依賴的package包/類
@Override
protected <RS, R1 extends Request<RS>> void invokeEntity(E entity, R1 request, BiConsumer<RS, Throwable> callback) throws Exception {
    if (!(request instanceof InvocationRequest)) {
        callback.accept(null, new IllegalArgumentException("Someone managed to call internal dispatcher of "+ProxiedSyncEventSourcingRuntime.this.getClass().getSimpleName()+" directly."));        
    }
    InvocationRequest r = (InvocationRequest)request;
    R handler = entity.requestHandler();
    if (handler == null) {
        callback.accept(null, new NullPointerException("Entity "+entity.getIdentity()+" returned null command handler"));
    } else {
        try {
            callback.accept((RS) r.m.invoke(handler, r.arguments),null);
        } catch (InvocationTargetException ite) {
            logger.info("Caught", ite);
            callback.accept(null, ite.getTargetException());
        } catch (Throwable t) {
             logger.info("Caught", t);
            callback.accept(null, t);
        }
    }
}
 
開發者ID:goodees,項目名稱:goodees,代碼行數:22,代碼來源:ProxiedSyncEventSourcingRuntime.java

示例5: runAlert

import java.util.function.BiConsumer; //導入依賴的package包/類
public static void runAlert(BiConsumer<Stage, AlertWindowController> setup) {
    try {
        // JavaFX2 doesn't actually have a standard alert template. Instead the Scene Builder app will create FXML
        // files for an alert window for you, and then you customise it as you see fit. I guess it makes sense in
        // an odd sort of way.
        Stage dialogStage = new Stage();
        dialogStage.initModality(Modality.APPLICATION_MODAL);
        FXMLLoader loader = new FXMLLoader(GuiUtils.class.getResource("alert.fxml"));
        Pane pane = loader.load();
        AlertWindowController controller = loader.getController();
        setup.accept(dialogStage, controller);
        dialogStage.setScene(new Scene(pane));
        dialogStage.showAndWait();
    } catch (IOException e) {
        // We crashed whilst trying to show the alert dialog (this should never happen). Give up!
        throw new RuntimeException(e);
    }
}
 
開發者ID:creativechain,項目名稱:creacoinj,代碼行數:19,代碼來源:GuiUtils.java

示例6: forEachNamedParamInfoParam

import java.util.function.BiConsumer; //導入依賴的package包/類
private <T> void forEachNamedParamInfoParam(Map<T, List<NamedParamInfo>> paramInfo, int level, int subLevel, BiConsumer<T, StatsSet> consumer)
{
	paramInfo.forEach((scope, namedParamInfos) ->
	{
		namedParamInfos.forEach(namedParamInfo ->
		{
			if (((namedParamInfo.getFromLevel() == null) && (namedParamInfo.getToLevel() == null)) || ((namedParamInfo.getFromLevel() <= level) && (namedParamInfo.getToLevel() >= level)))
			{
				if (((namedParamInfo.getFromSubLevel() == null) && (namedParamInfo.getToSubLevel() == null)) || ((namedParamInfo.getFromSubLevel() <= subLevel) && (namedParamInfo.getToSubLevel() >= subLevel)))
				{
					final StatsSet params = Optional.ofNullable(namedParamInfo.getInfo().getOrDefault(level, Collections.emptyMap()).get(subLevel)).orElseGet(() -> new StatsSet());
					namedParamInfo.getGeneralInfo().getSet().forEach((k, v) -> params.getSet().putIfAbsent(k, v));
					params.set(".name", namedParamInfo.getName());
					consumer.accept(scope, params);
				}
			}
		});
	});
}
 
開發者ID:rubenswagner,項目名稱:L2J-Global,代碼行數:20,代碼來源:SkillData.java

示例7: operate

import java.util.function.BiConsumer; //導入依賴的package包/類
@Override
public void operate(MergeEngine set) {

    for (MethodMatchEntry match : set.getAllMethodMatches()) {
        if (match.getNewMethod() == null || match.isMerged()) {
            continue;
        }
        MethodEntry old = match.getOldMethod();
        MappingsSet old_set = set.getOldMappings();
        String key = "L" + old_set.mapTypeSafe(old.getOwnerName()) + ";"
                + old_set.mapMethodSafe(old.getOwnerName(), old.getName(), old.getDescription())
                + MappingsSet.MethodMapping.mapSig(old.getDescription(), old_set);
        BiConsumer<MethodMatchEntry, MergeEngine> merger = custom_mergers.get(key);
        if (merger != null) {
            merger.accept(match, set);
            match.setMerged();
        }
    }

}
 
開發者ID:Despector,項目名稱:ObfuscationMapper,代碼行數:21,代碼來源:CustomMethodMergers.java

示例8: initializeBackground

import java.util.function.BiConsumer; //導入依賴的package包/類
private void initializeBackground() {
    final Component component = controller.getComponent();

    // Bind the background width and height to the values in the model
    controller.background.widthProperty().bindBidirectional(component.widthProperty());
    controller.background.heightProperty().bindBidirectional(component.heightProperty());

    final BiConsumer<Color, Color.Intensity> updateColor = (newColor, newIntensity) -> {
        // Set the background color to the lightest possible version of the color
        controller.background.setFill(newColor.getColor(newIntensity.next(-10).next(2)));
    };

    updateColorDelegates.add(updateColor);

    component.colorProperty().addListener(observable -> {
        updateColor.accept(component.getColor(), component.getColorIntensity());
    });

    updateColor.accept(component.getColor(), component.getColorIntensity());
}
 
開發者ID:ulriknyman,項目名稱:H-Uppaal,代碼行數:21,代碼來源:ComponentPresentation.java

示例9: forEach

import java.util.function.BiConsumer; //導入依賴的package包/類
@SuppressWarnings("unchecked")
@Override
public synchronized void forEach(BiConsumer<? super K, ? super V> action) {
    Objects.requireNonNull(action);     // explicit check required in case
                                        // table is empty.
    final int expectedModCount = modCount;

    Entry<?, ?>[] tab = table;
    for (Entry<?, ?> entry : tab) {
        while (entry != null) {
            action.accept((K)entry.key, (V)entry.value);
            entry = entry.next;

            if (expectedModCount != modCount) {
                throw new ConcurrentModificationException();
            }
        }
    }
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:20,代碼來源:Hashtable.java

示例10: setUp

import java.util.function.BiConsumer; //導入依賴的package包/類
public void setUp(final BiConsumer<Integer, Builder> consumer) throws Exception {
    clusterName = "es-idxproxy-" + System.currentTimeMillis();
    // create runner instance
    runner = new ElasticsearchClusterRunner();
    // create ES nodes
    runner.onBuild((number, settingsBuilder) -> {
        settingsBuilder.put("http.cors.enabled", true);
        settingsBuilder.put("http.cors.allow-origin", "*");
        settingsBuilder.putArray("discovery.zen.ping.unicast.hosts", "127.0.0.1:9301-9310");
        consumer.accept(number, settingsBuilder);
    }).build(newConfigs().clusterName(clusterName).numOfNode(numOfNode)
            .pluginTypes("org.codelibs.elasticsearch.idxproxy.IndexingProxyPlugin"));

    // wait for yellow status
    runner.ensureYellow();
}
 
開發者ID:codelibs,項目名稱:elasticsearch-indexing-proxy,代碼行數:17,代碼來源:IndexingProxyPluginTest.java

示例11: applyToNodes

import java.util.function.BiConsumer; //導入依賴的package包/類
/**
 * Applies action to all disrupted links between two sets of nodes.
 */
private void applyToNodes(String[] nodes1, String[] nodes2, BiConsumer<MockTransportService, MockTransportService> consumer) {
    for (String node1 : nodes1) {
        if (disruptedLinks.nodes().contains(node1)) {
            for (String node2 : nodes2) {
                if (disruptedLinks.nodes().contains(node2)) {
                    if (node1.equals(node2) == false) {
                        if (disruptedLinks.disrupt(node1, node2)) {
                            consumer.accept(transport(node1), transport(node2));
                        }
                    }
                }
            }
        }
    }
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:19,代碼來源:NetworkDisruption.java

示例12: analyzeRootGroupPorts

import java.util.function.BiConsumer; //導入依賴的package包/類
private void analyzeRootGroupPorts(NiFiFlow nifiFlow, ProcessGroupStatus rootProcessGroup) {
        BiConsumer<PortStatus, Boolean> portEntityCreator = (port, isInput) -> {
            final String typeName = isInput ? TYPE_NIFI_INPUT_PORT : TYPE_NIFI_OUTPUT_PORT;

            final AtlasEntity entity = new AtlasEntity(typeName);
            final String portName = port.getName();

            entity.setAttribute(ATTR_NIFI_FLOW, nifiFlow.getId());
            entity.setAttribute(ATTR_NAME, portName);
            entity.setAttribute(ATTR_QUALIFIED_NAME, port.getId());
            // TODO: do we have anything to set?
//            entity.setAttribute(ATTR_DESCRIPTION, port.getComponent().getComments());

            final AtlasObjectId portId = new AtlasObjectId(typeName, ATTR_QUALIFIED_NAME, port.getId());
            final Map<AtlasObjectId, AtlasEntity> ports = isInput ? nifiFlow.getRootInputPortEntities() : nifiFlow.getRootOutputPortEntities();
            ports.put(portId, entity);

            if (isInput) {
                nifiFlow.addRootInputPort(port);
            } else {
                nifiFlow.addRootOutputPort(port);
            }
        };

        rootProcessGroup.getInputPortStatus().forEach(port -> portEntityCreator.accept(port, true));
        rootProcessGroup.getOutputPortStatus().forEach(port -> portEntityCreator.accept(port, false));
    }
 
開發者ID:bcgov,項目名稱:nifi-atlas,代碼行數:28,代碼來源:NiFiFlowAnalyzer.java

示例13: fillOptionParams

import java.util.function.BiConsumer; //導入依賴的package包/類
public static void fillOptionParams(String value, String option, boolean isToast,
        BiConsumer<String, String> c) {
    String quotedOption = PgDiffUtils.getQuotedName(option);
    if (isToast) {
        quotedOption = "toast."+ option;
    }
    c.accept(quotedOption, value);
}
 
開發者ID:pgcodekeeper,項目名稱:pgcodekeeper,代碼行數:9,代碼來源:ParserAbstract.java

示例14: calculatePrice

import java.util.function.BiConsumer; //導入依賴的package包/類
/**
 * The callback is invoked when it finishes calculating the price.
 */
private static void calculatePrice(String product, BiConsumer<RuntimeException, Double> callback) {
    // !!!!! CUIDADO não fazer isto
    Thread th = new Thread(() -> {
        delay(3000);
        if(product.length() > 4 ) callback.accept(new RuntimeException("Illegal Product " + product), null);
        double res = random.nextDouble() * product.charAt(0) + product.charAt(1);
        double price = ((int) (res * 100)) / 100.0;
        callback.accept(null, price);
    });
    th.start();
}
 
開發者ID:isel-leic-mpd,項目名稱:mpd-2017-i41d,代碼行數:15,代碼來源:App.java

示例15: forEach

import java.util.function.BiConsumer; //導入依賴的package包/類
public void forEach(BiConsumer<String, String> consumer) {
    Map<String, Integer> currentIndex = new HashMap<>(valuesByCapitalizedName.size());
    for (String name : headerNames) {
        String key = name.toUpperCase();
        currentIndex.merge(key, 0, (a, b) -> a + 1);
        String value = valuesByCapitalizedName.get(key).get(currentIndex.get(key));
        consumer.accept(name, value);
    }
}
 
開發者ID:renatoathaydes,項目名稱:rawhttp,代碼行數:10,代碼來源:RawHttpHeaders.java


注:本文中的java.util.function.BiConsumer類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。