List of usage examples for java.util Set forEach
default void forEach(Consumer<? super T> action)
From source file:org.onosproject.segmentrouting.config.SegmentRoutingAppConfig.java
/** * Sets vRouters to the config./* ww w .jav a 2 s .co m*/ * * @param vRouterMacs a set of vRouter MAC addresses * @return this {@link SegmentRoutingAppConfig} */ public SegmentRoutingAppConfig setVRouterMacs(Set<MacAddress> vRouterMacs) { if (vRouterMacs == null) { object.remove(VROUTER_MACS); } else { ArrayNode arrayNode = mapper.createArrayNode(); vRouterMacs.forEach(mac -> { arrayNode.add(mac.toString()); }); object.set(VROUTER_MACS, arrayNode); } return this; }
From source file:org.onosproject.segmentrouting.config.SegmentRoutingAppConfig.java
/** * Sets names of ports to which SegmentRouting does not push host rules. * * @param suppressHost names of ports to which SegmentRouting does not push * host rules//from w w w . jav a 2 s . c om * @return this {@link SegmentRoutingAppConfig} */ public SegmentRoutingAppConfig setSuppressHost(Set<ConnectPoint> suppressHost) { if (suppressHost == null) { object.remove(SUPPRESS_HOST); } else { ArrayNode arrayNode = mapper.createArrayNode(); suppressHost.forEach(connectPoint -> { arrayNode.add(connectPoint.deviceId() + "/" + connectPoint.port()); }); object.set(SUPPRESS_HOST, arrayNode); } return this; }
From source file:io.apicurio.hub.core.storage.jdbc.JdbcStorage.java
/** * Converts from a Set of tags to a CSV of those tags. * @param tags/*from w w w. j ava 2 s. c o m*/ */ private static String asCsv(Set<String> tags) { StringBuilder builder = new StringBuilder(); tags.forEach(tag -> { builder.append(tag); builder.append(','); }); if (builder.length() > 0) { return builder.substring(0, builder.length() - 1); } else { return null; } }
From source file:org.kie.workbench.common.forms.migration.tool.pipelines.basic.impl.AbstractFormAdapter.java
protected void migrateFields(final Set<Field> fields, final FormDefinition newForm, final FormMigrationSummary formSummary) { LayoutHelper helper = new LayoutHelper(); fields.forEach(originalField -> { if (!StringUtils.isEmpty(originalField.getMovedToForm())) { return; }/*from ww w . j a v a 2 s. co m*/ if (!Boolean.TRUE.equals(originalField.getGroupWithPrevious())) { helper.newRow(); } String originalTypeCode = originalField.getFieldType().getCode(); FieldAdapter adapter = adaptersRegistry.get(originalTypeCode); if (adapter == null) { // trying a backup adapter UnSupportedFieldAdapter unSupportedFieldAdapter = unSupportedAdapters.get(originalTypeCode); if (unSupportedFieldAdapter != null) { warn("Problems migrating field '" + originalField.getFieldName() + "': the original field has an unsupported field type '" + originalTypeCode + "'. It will be added on the new Form as a '" + unSupportedFieldAdapter.getNewFieldType() + "'"); unSupportedFieldAdapter.parseField(originalField, formSummary, newForm, helper::add); } else { warn("Cannot migrate field '" + originalField.getFieldName() + "': Unsupported field type '" + originalTypeCode + "'"); Formatter formatter = new Formatter(); formatter.format(FormsMigrationConstants.UNSUPORTED_FIELD_HTML_TEMPLATE, originalField.getFieldName(), originalTypeCode); LayoutComponent component = new LayoutComponent(FormsMigrationConstants.HTML_COMPONENT); component.addProperty(FormsMigrationConstants.HTML_CODE_PARAMETER, formatter.toString()); formatter.close(); helper.add(component); } } else { try { adapter.parseField(originalField, formSummary, newForm, helper::add); } catch (Exception ex) { warn("Cannot migrate field '" + originalField.getFieldName() + "': Unexpected error, see message for details"); ex.printStackTrace(migrationContext.getSystem().err()); } } }); newForm.setLayoutTemplate(helper.build()); }
From source file:io.gravitee.management.service.impl.ApiKeyServiceImpl.java
@Override public Map<String, List<ApiKeyEntity>> findByApi(String apiId) { try {//from w w w. ja v a 2s . c o m LOGGER.debug("Find all API keys for API {}", apiId); Set<ApiKey> keys = apiKeyRepository.findByApi(apiId); Map<String, Set<ApiKey>> keysByApplication = new HashMap<>(); keys.forEach(apiKey -> { Set<ApiKey> values = keysByApplication.getOrDefault(apiKey.getApplication(), new HashSet<>()); values.add(apiKey); keysByApplication.put(apiKey.getApplication(), values); }); Map<String, List<ApiKeyEntity>> keysByApplicationResult = new HashMap<>(keysByApplication.size()); keysByApplication.forEach((api, apiKeys) -> keysByApplicationResult.put(api, apiKeys.stream().sorted((key1, key2) -> key2.getCreatedAt().compareTo(key1.getCreatedAt())) .map(ApiKeyServiceImpl::convert).collect(Collectors.toList()))); return keysByApplicationResult; } catch (TechnicalException ex) { LOGGER.error("An error occurs while getting all API keys for API {}", apiId, ex); throw new TechnicalManagementException("An error occurs while getting all API keys for API " + apiId, ex); } }
From source file:org.onosproject.segmentrouting.config.SegmentRoutingAppConfig.java
/** * Sets names of ports to which SegmentRouting does not push subnet rules. * * @param suppressSubnet names of ports to which SegmentRouting does not push * subnet rules//from w w w. ja v a2s. c om * @return this {@link SegmentRoutingAppConfig} */ public SegmentRoutingAppConfig setSuppressSubnet(Set<ConnectPoint> suppressSubnet) { if (suppressSubnet == null) { object.remove(SUPPRESS_SUBNET); } else { ArrayNode arrayNode = mapper.createArrayNode(); suppressSubnet.forEach(connectPoint -> { arrayNode.add(connectPoint.deviceId() + "/" + connectPoint.port()); }); object.set(SUPPRESS_SUBNET, arrayNode); } return this; }
From source file:org.graylog2.search.SearchQueryParserTest.java
private Collection<String> extractFieldNames(Set<Map.Entry<String, QueryCondition>> conditions) { final ImmutableSet.Builder<String> names = ImmutableSet.builder(); // recurse into the tree, conveniently there's no visitor we can use, so it's manual conditions.forEach(entry -> { final String op = entry.getKey(); if (!op.startsWith("$")) { names.add(op);/*www .j a v a 2 s . c o m*/ } final QueryCondition queryCondition = entry.getValue(); if (queryCondition instanceof CollectionQueryCondition) { names.addAll(extractFieldNames(((CollectionQueryCondition) queryCondition).getValues().stream() .map(qc -> Maps.immutableEntry("$dummy", qc)).collect(Collectors.toSet()))); } else if (queryCondition instanceof CompoundQueryCondition) { names.addAll(extractFieldNames(((CompoundQueryCondition) queryCondition).getQuery().conditions())); } }); return names.build(); }
From source file:com.netflix.genie.core.services.impl.FileSystemAttachmentServiceUnitTests.java
/** * Test whether we can successfully delete an attachment from the filesystem. * * @throws GenieException on error/*www . j a va2s. c om*/ * @throws IOException if the attachment file can't be located */ @Test public void canDeleteAttachments() throws GenieException, IOException { final String jobId = UUID.randomUUID().toString(); final Set<File> attachments = this.saveAttachments(jobId); final File jobDir = new File(this.folder.getRoot().getAbsoluteFile(), jobId); Assert.assertTrue(jobDir.exists()); this.service.delete(jobId); Assert.assertFalse(jobDir.exists()); attachments.forEach(file -> Assert.assertFalse(file.exists())); }
From source file:com.devicehive.handler.command.CommandUnsubscribeRequestHandler.java
@Override public Response handle(Request request) { CommandUnsubscribeRequest body = (CommandUnsubscribeRequest) request.getBody(); validate(body);/*from w ww .j av a 2s. c o m*/ if (body.getSubscriptionId() != null) { Subscriber subscriber = new Subscriber(body.getSubscriptionId(), request.getReplyTo(), request.getCorrelationId()); eventBus.unsubscribe(subscriber); CommandUnsubscribeResponse unsubscribeResponse = new CommandUnsubscribeResponse( body.getSubscriptionId(), null); return Response.newBuilder().withBody(unsubscribeResponse).withLast(false) .withCorrelationId(request.getCorrelationId()).buildSuccess(); } else if (body.getDeviceGuids() != null) { Set<Subscription> subscriptions = new HashSet<>(); Set<Subscriber> subscribers = new HashSet<>(); for (String name : body.getDeviceGuids()) { Subscription subscription = new Subscription(Action.COMMAND_EVENT.name(), name); subscriptions.add(subscription); } subscriptions.forEach(subscription -> subscribers.addAll(eventBus.getSubscribers(subscription))); subscribers.forEach(subscriber -> eventBus.unsubscribe(subscriber)); CommandUnsubscribeResponse unsubscribeResponse = new CommandUnsubscribeResponse(null, body.getDeviceGuids()); return Response.newBuilder().withBody(unsubscribeResponse).withLast(false) .withCorrelationId(request.getCorrelationId()).buildSuccess(); } else { throw new IllegalArgumentException("Both subscription id and device guids are null"); } }
From source file:io.gravitee.management.service.impl.ApiKeyServiceImpl.java
@Override public Map<String, List<ApiKeyEntity>> findByApplication(String applicationId) { try {//from ww w. ja va 2s . c om LOGGER.debug("Find all API keys for application {}", applicationId); Set<ApiKey> keys = apiKeyRepository.findByApplication(applicationId); Map<String, Set<ApiKey>> keysByApi = new HashMap<>(); keys.forEach(apiKey -> { Set<ApiKey> values = keysByApi.getOrDefault(apiKey.getApi(), new HashSet<>()); values.add(apiKey); keysByApi.put(apiKey.getApi(), values); }); Map<String, List<ApiKeyEntity>> keysByApiResult = new HashMap<>(keysByApi.size()); keysByApi.forEach((api, apiKeys) -> keysByApiResult.put(api, apiKeys.stream().sorted((key1, key2) -> key2.getCreatedAt().compareTo(key1.getCreatedAt())) .map(ApiKeyServiceImpl::convert).collect(Collectors.toList()))); return keysByApiResult; } catch (TechnicalException ex) { LOGGER.error("An error occurs while getting all API keys for application {}", applicationId, ex); throw new TechnicalManagementException( "An error occurs while getting all API keys for application " + applicationId, ex); } }