List of usage examples for java.util.function BiConsumer accept
void accept(T t, U u);
From source file:com.devicehive.service.DeviceCommandService.java
public CompletableFuture<Pair<String, DeviceCommand>> sendSubscribeToUpdateRequest(final long commandId, final String guid, BiConsumer<DeviceCommand, String> callback) { CompletableFuture<Pair<String, DeviceCommand>> future = new CompletableFuture<>(); final String subscriptionId = UUID.randomUUID().toString(); Consumer<Response> responseConsumer = response -> { String resAction = response.getBody().getAction(); if (resAction.equals(Action.COMMAND_UPDATE_SUBSCRIBE_RESPONSE.name())) { future.complete(/*from w w w . ja v a 2 s .c o m*/ Pair.of(response.getBody().cast(CommandUpdateSubscribeResponse.class).getSubscriptionId(), response.getBody().cast(CommandUpdateSubscribeResponse.class).getDeviceCommand())); } else if (resAction.equals(Action.COMMAND_UPDATE_EVENT.name())) { callback.accept(response.getBody().cast(CommandUpdateEvent.class).getDeviceCommand(), subscriptionId); } else { logger.warn("Unknown action received from backend {}", resAction); } }; rpcClient.call(Request.newBuilder() .withBody(new CommandUpdateSubscribeRequest(commandId, guid, subscriptionId)).build(), responseConsumer); return future; }
From source file:com.diversityarrays.kdxplore.field.OriginDirectionTraversalChoicePanel.java
public void setOnlyAllow(OrOrTr... oots) { List<OrOrTr> list = Arrays.asList(oots); Set<Orientation> orientationSet = list.stream().map(OrOrTr::getOrientation).collect(Collectors.toSet()); Set<Origin> originSet = list.stream().map(OrOrTr::getOrigin).collect(Collectors.toSet()); Set<Traversal> traversalSet = list.stream().map(OrOrTr::getTraversal).collect(Collectors.toSet()); BiConsumer<RbPair, OT_RadioButton> consumer = new BiConsumer<RbPair, OT_RadioButton>() { @Override/*from ww w . j a v a2s.co m*/ public void accept(RbPair rbPair, OT_RadioButton btn) { boolean enable = orientationSet.contains(btn.orientation) && traversalSet.contains(btn.traversal) && originSet.contains(rbPair.cardName.origin); btn.setEnabled(enable); } }; for (RbPair rbp : rbPairs) { consumer.accept(rbp, rbp.rb1); consumer.accept(rbp, rbp.rb2); } for (CornerLabel label : cornerLabels) { label.setEnabled(originSet.contains(label.origin)); } for (CornerDirectionRadioButton cdrb : cornerDirectionButtons) { cdrb.setEnabled(cdrb.rbPair.isEitherButtonEnabled()); } for (OT_RadioButton rb : orientationTraversalButtons) { rb.setEnabled(orientationSet.contains(rb.orientation) && traversalSet.contains(rb.traversal)); } }
From source file:com.github.jsonj.JsonObject.java
public void forEachString(BiConsumer<String, String> f) { forEach((k, v) -> { f.accept(k, v.asString()); }); }
From source file:com.example.app.profile.model.company.CompanyDAO.java
/** * Save the given Company into the database * * @param company the company to save/*from w ww .ja v a 2s . c o m*/ * @return the saved Company */ public Company saveCompany(Company company) { BiConsumer<Company, Session> presave = (toSave, session) -> { if (toSave.getProfileTerms() == null) toSave.setProfileTerms(new ProfileTerms()); AuthenticationDomain domain = toSave.getHostname().getDomain(); if (domain != null && (domain.getId() == null || domain.getId() == 0L)) { session.save(domain); } }; return doInTransaction(session -> { Company retVal = company; presave.accept(company, session); if (isAttached(company)) session.saveOrUpdate(company); else retVal = (Company) session.merge(company); return retVal; }); }
From source file:nu.yona.server.analysis.service.ActivityService.java
private <T extends IntervalActivityDto> void addMissingInactivity(Goal activeGoal, ZonedDateTime dateAtStartOfInterval, Set<T> activityEntitiesAtDate, BiFunction<Goal, ZonedDateTime, T> inactivityEntitySupplier, BiConsumer<Goal, T> existingEntityInactivityCompletor) { Optional<T> activityForGoal = getActivityForGoal(activityEntitiesAtDate, activeGoal); if (activityForGoal.isPresent()) { // even if activity was already recorded, it might be that this is // not for the complete period // so make the interval activity complete with a consumer existingEntityInactivityCompletor.accept(activeGoal, activityForGoal.get()); } else {/* ww w . j av a 2 s .c om*/ activityEntitiesAtDate.add(inactivityEntitySupplier.apply(activeGoal, dateAtStartOfInterval)); } }
From source file:com.devicehive.service.DeviceCommandService.java
public Pair<String, CompletableFuture<List<DeviceCommand>>> sendSubscribeRequest(final Set<String> devices, final Set<String> names, final Date timestamp, final BiConsumer<DeviceCommand, String> callback) throws InterruptedException { final String subscriptionId = UUID.randomUUID().toString(); Collection<CompletableFuture<Collection<DeviceCommand>>> futures = devices.stream() .map(device -> new CommandSubscribeRequest(subscriptionId, device, names, timestamp)) .map(subscribeRequest -> { CompletableFuture<Collection<DeviceCommand>> future = new CompletableFuture<>(); Consumer<Response> responseConsumer = response -> { String resAction = response.getBody().getAction(); if (resAction.equals(Action.COMMAND_SUBSCRIBE_RESPONSE.name())) { future.complete(response.getBody().cast(CommandSubscribeResponse.class).getCommands()); } else if (resAction.equals(Action.COMMAND_EVENT.name())) { callback.accept(response.getBody().cast(CommandEvent.class).getCommand(), subscriptionId); } else { logger.warn("Unknown action received from backend {}", resAction); }/*from w w w.j a v a 2s . c om*/ }; Request request = Request.newBuilder().withBody(subscribeRequest) .withPartitionKey(subscribeRequest.getDevice()).withSingleReply(false).build(); rpcClient.call(request, responseConsumer); return future; }).collect(Collectors.toList()); CompletableFuture<List<DeviceCommand>> future = CompletableFuture .allOf(futures.toArray(new CompletableFuture[futures.size()])).thenApply(v -> futures.stream() .map(CompletableFuture::join).flatMap(Collection::stream).collect(Collectors.toList())); return Pair.of(subscriptionId, future); }
From source file:de.dentrassi.pm.storage.web.channel.ChannelController.java
protected ModelAndView modifyDeployGroup(final String channelId, final String groupId, final BiConsumer<Channel, String> cons) { final Channel channel = this.service.getChannel(channelId); if (channel == null) { return CommonController.createNotFound("channel", channelId); }// w ww .jav a2 s. c o m cons.accept(channel, groupId); return new ModelAndView("redirect:/channel/" + channelId + "/deployKeys"); }
From source file:com.dgtlrepublic.anitomyj.Tokenizer.java
/** Validates tokens(e.g make sure certain words delimited by certain tokens aren't spit). */ @SuppressWarnings("CodeBlock2Expr") private void validateDelimiterTokens() { Function<Result, Boolean> isDelimiterToken = r -> { return r != null && r.token != null && r.token.getCategory() == TokenCategory.kDelimiter; };/*from w w w . java 2s . c o m*/ Function<Result, Boolean> isUnknownToken = r -> { return r != null && r.token != null && r.token.getCategory() == TokenCategory.kUnknown; }; Function<Result, Boolean> isSingleCharacterToken = r -> { return isUnknownToken.apply(r) && r.token.getContent().length() == 1 && !r.token.getContent().equals("-"); }; BiConsumer<Token, Result> appendTokenTo = (src, dest) -> { dest.token.setContent(dest.token.getContent() + src.getContent()); src.setCategory(TokenCategory.kInvalid); /** make dest as invalid so it's removed later */ }; for (int i = 0; i < tokens.size(); i++) { Token token = tokens.get(i); if (token.getCategory() != TokenCategory.kDelimiter) continue; char delimiter = token.getContent().charAt(0); Result prevToken = Token.findPrevToken(tokens, i, kFlagValid); Result nextToken = Token.findNextToken(tokens, i, kFlagValid); // Check for single-character tokens to prevent splitting group names, // keywords, episode number, etc. if (delimiter != ' ' && delimiter != '_') { /** single character token */ if (isSingleCharacterToken.apply(prevToken)) { appendTokenTo.accept(token, prevToken); while (isUnknownToken.apply(nextToken)) { appendTokenTo.accept(nextToken.token, prevToken); nextToken = Token.findNextToken(tokens, i, kFlagValid); if (isDelimiterToken.apply(nextToken) && nextToken.token.getContent().charAt(0) == delimiter) { appendTokenTo.accept(nextToken.token, prevToken); nextToken = Token.findNextToken(tokens, nextToken, kFlagValid); } } continue; } if (isSingleCharacterToken.apply(nextToken)) { appendTokenTo.accept(token, prevToken); appendTokenTo.accept(nextToken.token, prevToken); continue; } } /** Check for adjacent delimiters */ if (isUnknownToken.apply(prevToken) && isDelimiterToken.apply(nextToken)) { char nextDelimiter = nextToken.token.getContent().charAt(0); if (delimiter != nextDelimiter && delimiter != ',') { if (nextDelimiter == ' ' || nextDelimiter == '_') { appendTokenTo.accept(token, prevToken); } } } } /** remove invalid tokens */ tokens.removeIf(token -> token.getCategory() == TokenCategory.kInvalid); }
From source file:io.atomix.cluster.messaging.impl.NettyMessagingService.java
@Override public void registerHandler(String type, BiConsumer<Address, byte[]> handler, Executor executor) { handlers.put(type, (message, connection) -> executor .execute(() -> handler.accept(message.sender(), message.payload()))); }
From source file:org.eclipse.packagedrone.repo.channel.web.channel.ChannelController.java
protected ModelAndView modifyDeployGroup(final String channelId, final String groupId, final BiConsumer<DeployKeysChannelAdapter, String> cons) { return withChannel(channelId, DeployKeysChannelAdapter.class, channel -> { cons.accept(channel, groupId); return new ModelAndView("redirect:/channel/" + channelId + "/deployKeys"); });//from w ww . j av a 2 s . c om }