List of usage examples for java.util Collection forEach
default void forEach(Consumer<? super T> action)
From source file:org.apache.syncope.core.provisioning.java.data.AbstractAnyDataBinder.java
protected MembershipTO getMembershipTO(final Collection<? extends PlainAttr<?>> plainAttrs, final Map<DerSchema, String> derAttrs, final Map<VirSchema, List<String>> virAttrs, final Membership<? extends Any<?>> membership) { MembershipTO membershipTO = new MembershipTO.Builder() .group(membership.getRightEnd().getKey(), membership.getRightEnd().getName()).build(); plainAttrs.forEach(plainAttr -> { membershipTO.getPlainAttrs()//from w w w.ja v a 2s . c o m .add(new AttrTO.Builder().schema(plainAttr.getSchema().getKey()) .values(plainAttr.getValuesAsStrings()) .schemaInfo(schemaDataBinder.getPlainSchemaTO(plainAttr.getSchema())).build()); }); derAttrs.entrySet().forEach(entry -> { membershipTO.getDerAttrs().add(new AttrTO.Builder().schema(entry.getKey().getKey()) .value(entry.getValue()).schemaInfo(schemaDataBinder.getDerSchemaTO(entry.getKey())).build()); }); virAttrs.entrySet().forEach(entry -> { membershipTO.getVirAttrs().add(new AttrTO.Builder().schema(entry.getKey().getKey()) .values(entry.getValue()).schemaInfo(schemaDataBinder.getVirSchemaTO(entry.getKey())).build()); }); return membershipTO; }
From source file:com.qwazr.search.index.IndexInstance.java
final <T> Collection<Object> postDocuments(final Map<String, Field> fields, final Collection<T> documents) throws IOException, InterruptedException { if (documents == null || documents.isEmpty()) return null; final Semaphore sem = schema.acquireWriteSemaphore(); try {//from ww w .jav a 2s .c o m schema.checkSize(documents.size()); RecordsPoster.UpdateObjectDocument poster = getDocumentPoster(fields); documents.forEach(poster); nrtCommit(); return poster.ids; } finally { if (sem != null) sem.release(); } }
From source file:com.qwazr.search.index.IndexInstance.java
final Collection<Object> postMappedDocuments(final Collection<Map<String, Object>> documents) throws IOException, InterruptedException { if (documents == null || documents.isEmpty()) return null; final Semaphore sem = schema.acquireWriteSemaphore(); try {//from w ww .j av a 2 s . c om schema.checkSize(documents.size()); RecordsPoster.UpdateMapDocument poster = getDocumentPoster(); documents.forEach(poster); nrtCommit(); return poster.ids; } finally { if (sem != null) sem.release(); } }
From source file:org.sleuthkit.autopsy.timeline.ui.listvew.ListTimeline.java
/** * Set the combined events that are selected in this view. * * @param selectedEvents The events that should be selected. *//*from w ww .jav a 2 s .co m*/ void selectEvents(Collection<CombinedEvent> selectedEvents) { CombinedEvent firstSelected = selectedEvents.stream() .min(Comparator.comparing(CombinedEvent::getStartMillis)).orElse(null); table.getSelectionModel().clearSelection(); table.scrollTo(firstSelected); selectedEvents.forEach(table.getSelectionModel()::select); table.requestFocus(); }
From source file:io.pravega.service.server.host.ZKSegmentContainerMonitor.java
/** * The container assignment monitor. This is executed in a single threaded executor and hence there will never be * parallel invocations of this method./*w w w .j ava 2s. com*/ * This method will fetch the current owned containers for this host and ensures that the local containers' state * reflects this. */ private void checkAssignment() { Exceptions.checkNotClosed(closed.get(), this); long traceId = LoggerHelpers.traceEnter(log, "checkAssignment"); // Fetch the list of containers that is supposed to be owned by this host. Set<Integer> desiredList = getDesiredContainerList(); if (desiredList != null) { Collection<Integer> runningContainers = new HashSet<>(this.handles.keySet()); Collection<Integer> containersPendingTasks = new HashSet<>(this.pendingTasks); // Filter out containers which have pending tasks so we don't initiate conflicting events on the same // containers. Events for these containers will be tried on subsequent runs of this executor. Collection<Integer> containersToBeStarted = CollectionHelpers.filterOut(desiredList, runningContainers); containersToBeStarted = CollectionHelpers.filterOut(containersToBeStarted, containersPendingTasks); Collection<Integer> containersToBeStopped = CollectionHelpers.filterOut(runningContainers, desiredList); containersToBeStopped = CollectionHelpers.filterOut(containersToBeStopped, containersPendingTasks); log.info("Container Changes: Desired = {}, Current = {}, PendingTasks = {}, ToStart = {}, ToStop = {}.", desiredList, runningContainers, containersPendingTasks, containersToBeStarted, containersToBeStopped); // Initiate the start and stop tasks asynchronously. containersToBeStarted.forEach(this::startContainer); containersToBeStopped.forEach(this::stopContainer); } else { log.warn("No segment container assignments found"); } LoggerHelpers.traceLeave(log, "checkAssignment", traceId); }
From source file:com.okta.swagger.codegen.AbstractOktaJavaClientCodegen.java
@Override public CodegenModel fromModel(String name, Model model, Map<String, Model> allDefinitions) { CodegenModel codegenModel = super.fromModel(name, model, allDefinitions); // super add these imports, and we don't want that dependency codegenModel.imports.remove("ApiModel"); if (model.getVendorExtensions().containsKey("x-baseType")) { String baseType = (String) model.getVendorExtensions().get("x-baseType"); codegenModel.vendorExtensions.put("baseType", toModelName(baseType)); codegenModel.imports.add(toModelName(baseType)); }//from ww w .ja v a 2 s. c o m Collection<CodegenOperation> operations = (Collection<CodegenOperation>) codegenModel.vendorExtensions .get("operations"); if (operations != null) { operations.forEach(op -> { if (op.returnType != null) { codegenModel.imports.add(op.returnType); } if (op.allParams != null) { op.allParams.stream().filter(param -> needToImport(param.dataType)) .forEach(param -> codegenModel.imports.add(param.dataType)); } }); } // force alias == false (likely only relevant for Lists, but something changed in swagger 2.2.3 to require this) codegenModel.isAlias = false; String parent = (String) model.getVendorExtensions().get("x-okta-parent"); if (StringUtils.isNotEmpty(parent)) { codegenModel.parent = toApiName(parent.substring(parent.lastIndexOf("/"))); // figure out the resourceClass if this model has a parent String discriminatorRoot = getRootDiscriminator(name); if (discriminatorRoot != null) { model.getVendorExtensions().put("discriminatorRoot", discriminatorRoot); } } // We use '$ref' attributes with siblings, which isn't valid JSON schema (or swagger), so we need process // additional attributes from the raw schema Map<String, Object> modelDef = getRawSwaggerDefinition(name); codegenModel.vars.forEach(codegenProperty -> { Map<String, Object> rawPropertyMap = getRawSwaggerProperty(modelDef, codegenProperty.baseName); codegenProperty.isReadOnly = Boolean.TRUE.equals(rawPropertyMap.get("readOnly")); }); return codegenModel; }
From source file:org.obiba.mica.file.service.FileSystemService.java
private void batchPublish(Collection<AttachmentState> states, String publisher, boolean publish) { states.forEach(state -> { if (publish) { state.publish(publisher);//from w w w . j av a 2s . co m state.setRevisionStatus(RevisionStatus.DRAFT); } else { state.unPublish(); } state.setLastModifiedDate(DateTime.now()); state.setLastModifiedBy(publisher); attachmentStateRepository.save(state); eventBus.post(publish ? new FilePublishedEvent(state) : new FileUnPublishedEvent(state)); }); }
From source file:org.trustedanalytics.cloud.cc.FeignClient.java
@Override public Collection<CcOrgPermission> getUserPermissions(UUID user, Collection<UUID> orgsFilter) { Collection<CcOrg> orgs = userResource.getUserOrganizations(user).getOrgs(); if (!orgsFilter.isEmpty()) { orgs.removeIf(ccOrg -> !orgsFilter.contains(ccOrg.getGuid())); }//from ww w .j a va 2 s .c om Collection<CcOrg> managedOrganizations = getManagedOrganizations(user); Collection<CcOrg> auditedOrganizations = getAuditedOrganizations(user); Collection<CcOrg> billingManagedOrganizations = getBillingManagedOrganizations(user); Collection<CcOrgPermission> permissions = new ArrayList<>(); orgs.forEach(org -> { boolean isManager = managedOrganizations.contains(org); boolean isAuditor = auditedOrganizations.contains(org); boolean isBillingManager = billingManagedOrganizations.contains(org); permissions.add(new CcOrgPermission(org, isManager, isAuditor, isBillingManager)); }); return permissions; }
From source file:org.opensingular.form.SType.java
private void debugAttributes(Appendable appendable) { try {// w ww. j a va 2 s. c o m Collection<SInstance> attrs = getAttributes(); if (!attrs.isEmpty()) { appendable.append(" {"); attrs.forEach(attr -> debugAttribute(appendable, attr)); appendable.append("}"); } } catch (IOException ex) { LOGGER.log(Level.SEVERE, ex.getMessage(), ex); } }
From source file:io.mindmaps.graql.internal.analytics.AnalyticsTest.java
@Ignore @Test//from ww w . j a v a 2s . c o m public void testDegreeIsPersisted() throws Exception { // create a simple graph RoleType pet = graph.putRoleType("pet"); RoleType owner = graph.putRoleType("owner"); RoleType breeder = graph.putRoleType("breeder"); RelationType mansBestFriend = graph.putRelationType("mans-best-friend").hasRole(pet).hasRole(owner) .hasRole(breeder); EntityType person = graph.putEntityType("person").playsRole(owner).playsRole(breeder); EntityType animal = graph.putEntityType("animal").playsRole(pet); // make one person breeder and owner Entity coco = graph.putEntity("coco", animal); Entity dave = graph.putEntity("dave", person); Relation daveBreedsAndOwnsCoco = graph.addRelation(mansBestFriend).putRolePlayer(pet, coco) .putRolePlayer(owner, dave); // manual degrees Map<String, Long> referenceDegrees = new HashMap<>(); referenceDegrees.put(coco.getId(), 1L); referenceDegrees.put(dave.getId(), 1L); referenceDegrees.put(daveBreedsAndOwnsCoco.getId(), 2L); // validate graph.commit(); // compute and persist degrees Analytics analytics = new Analytics(keyspace); analytics.degreesAndPersist(); // check degrees are correct graph = MindmapsClient.getGraph(keyspace); referenceDegrees.entrySet().forEach(entry -> { Instance instance = graph.getInstance(entry.getKey()); if (instance.isEntity()) { assertTrue(instance.asEntity().resources().iterator().next().getValue().equals(entry.getValue())); } else if (instance.isRelation()) { assertTrue(instance.asRelation().resources().iterator().next().getValue().equals(entry.getValue())); } }); // check only expected resources exist Collection<String> allConcepts = new ArrayList<>(); ResourceType<Long> rt = graph.getResourceType(Analytics.degree); Collection<Resource<Long>> degrees = rt.instances(); Map<Instance, Long> currentDegrees = new HashMap<>(); degrees.forEach(degree -> { Long degreeValue = degree.getValue(); degree.ownerInstances().forEach(instance -> { currentDegrees.put(instance, degreeValue); }); }); // check all resources exist and no more assertTrue(CollectionUtils.isEqualCollection(currentDegrees.values(), referenceDegrees.values())); // persist again and check again analytics.degreesAndPersist(); // check only expected resources exist graph = MindmapsClient.getGraph(keyspace); rt = graph.getResourceType(Analytics.degree); degrees = rt.instances(); degrees.forEach(i -> i.ownerInstances().iterator().forEachRemaining(r -> allConcepts.add(r.getId()))); // check degrees are correct referenceDegrees.entrySet().forEach(entry -> { Instance instance = graph.getInstance(entry.getKey()); if (instance.isEntity()) { assertTrue(instance.asEntity().resources().iterator().next().getValue().equals(entry.getValue())); } else if (instance.isRelation()) { assertTrue(instance.asRelation().resources().iterator().next().getValue().equals(entry.getValue())); } }); degrees = rt.instances(); currentDegrees.clear(); degrees.forEach(degree -> { Long degreeValue = degree.getValue(); degree.ownerInstances().forEach(instance -> { currentDegrees.put(instance, degreeValue); }); }); // check all resources exist and no more assertTrue(CollectionUtils.isEqualCollection(currentDegrees.values(), referenceDegrees.values())); }