本文整理匯總了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();
}
示例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);
}
示例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));
}
示例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);
}
}
}
示例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);
}
}
示例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);
}
}
});
});
}
示例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();
}
}
}
示例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());
}
示例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();
}
}
}
}
示例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();
}
示例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));
}
}
}
}
}
}
}
示例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));
}
示例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);
}
示例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();
}
示例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);
}
}