Example usage for java.util Set forEach

List of usage examples for java.util Set forEach

Introduction

In this page you can find the example usage for java.util Set forEach.

Prototype

default void forEach(Consumer<? super T> action) 

Source Link

Document

Performs the given action for each element of the Iterable until all elements have been processed or the action throws an exception.

Usage

From source file:com.khartec.waltz.jobs.sample.BusinessRegionProductHierarchyGenerator.java

private static void generateHierarchy(DSLContext dsl) throws IOException {
    System.out.println("Deleting existing  hierarchy ...");
    int deletedCount = dsl.deleteFrom(MEASURABLE)
            .where(MEASURABLE.MEASURABLE_CATEGORY_ID.in(DSL.select(MEASURABLE_CATEGORY.ID)
                    .from(MEASURABLE_CATEGORY).where(MEASURABLE_CATEGORY.EXTERNAL_ID.eq(CATEGORY_EXTERNAL_ID))))
            .and(MEASURABLE.PROVENANCE.eq("demo")).execute();
    System.out.println("Deleted: " + deletedCount + " existing hierarchy");

    Set<String> topLevelRegions = readRegions();
    Set<String> products = readProducts();

    insertCategoryIfNotExists(dsl);//from  www.j  a v a  2s .  c o  m

    final long measurableCategoryId = dsl.select(MEASURABLE_CATEGORY.ID).from(MEASURABLE_CATEGORY)
            .where(MEASURABLE_CATEGORY.EXTERNAL_ID.eq(CATEGORY_EXTERNAL_ID)).fetchAny().value1();

    AtomicInteger insertCount = new AtomicInteger(0);

    Stream.of(businesses).forEach(business -> {
        final long businessId = dsl.insertInto(MEASURABLE)
                .set(createMeasurable(null, business, measurableCategoryId, true)).returning(MEASURABLE.ID)
                .fetchOne().getId();

        insertCount.incrementAndGet();

        topLevelRegions.forEach((region) -> {
            final long regionId = dsl.insertInto(MEASURABLE)
                    .set(createMeasurable(businessId, region, measurableCategoryId, true))
                    .returning(MEASURABLE.ID).fetchOne().getId();
            insertCount.incrementAndGet();

            products.forEach(product -> {
                dsl.insertInto(MEASURABLE).set(createMeasurable(regionId, product, measurableCategoryId, true))
                        .execute();

                insertCount.incrementAndGet();
            });
        });
    });

    System.out.println("Inserted: " + insertCount + " new nodes for hierarchy");
}

From source file:org.apache.pulsar.broker.loadbalance.impl.LoadManagerShared.java

/**
 * It computes least number of namespace owned by any of the domain and then it filters out all the domains that own
 * namespaces more than this count./*from w  ww  .j a v  a 2s.co m*/
 *
 * @param brokerToAntiAffinityNamespaceCount
 * @param candidates
 * @param brokerToDomainMap
 */
private static void filterDomainsNotHavingLeastNumberAntiAffinityNamespaces(
        Map<String, Integer> brokerToAntiAffinityNamespaceCount, Set<String> candidates,
        Map<String, String> brokerToDomainMap) {

    if (brokerToDomainMap == null || brokerToDomainMap.isEmpty()) {
        return;
    }

    final Map<String, Integer> domainNamespaceCount = Maps.newHashMap();
    int leastNamespaceCount = Integer.MAX_VALUE;
    candidates.forEach(broker -> {
        final String domain = brokerToDomainMap.getOrDefault(broker, DEFAULT_DOMAIN);
        final int count = brokerToAntiAffinityNamespaceCount.getOrDefault(broker, 0);
        domainNamespaceCount.compute(domain,
                (domainName, nsCount) -> nsCount == null ? count : nsCount + count);
    });
    // find leastNameSpaceCount
    for (Entry<String, Integer> domainNsCountEntry : domainNamespaceCount.entrySet()) {
        if (domainNsCountEntry.getValue() < leastNamespaceCount) {
            leastNamespaceCount = domainNsCountEntry.getValue();
        }
    }
    final int finalLeastNamespaceCount = leastNamespaceCount;
    // only keep domain brokers which has leastNamespaceCount
    candidates.removeIf(broker -> {
        Integer nsCount = domainNamespaceCount.get(brokerToDomainMap.getOrDefault(broker, DEFAULT_DOMAIN));
        return nsCount != null && nsCount != finalLeastNamespaceCount;
    });
}

From source file:org.apache.jena.fuseki.build.FusekiConfig.java

/** Build a DatasetRef starting at Resource svc, having the services as described by the descriptions. */
private static DataService buildDataService(Resource svc, DatasetDescriptionMap dsDescMap) {
    Resource datasetDesc = ((Resource) BuildLib.getOne(svc, "fu:dataset"));

    Dataset ds = getDataset(datasetDesc, dsDescMap);
    DataService dataService = new DataService(ds.asDatasetGraph());
    Set<Endpoint> endpoints = new HashSet<>();

    accEndpoint(endpoints, Operation.Query, svc, pServiceQueryEP);
    accEndpoint(endpoints, Operation.Update, svc, pServiceUpdateEP);
    accEndpoint(endpoints, Operation.Upload, svc, pServiceUploadEP);
    accEndpoint(endpoints, Operation.GSP_R, svc, pServiceReadGraphStoreEP);
    accEndpoint(endpoints, Operation.GSP_RW, svc, pServiceReadWriteGraphStoreEP);

    endpoints.forEach(dataService::addEndpoint);

    // TODO/* w  w  w  .j  av  a2s .  c  o  m*/
    // Setting timeout. This needs sorting out -- here, it is only on the whole server, not per dataset or even per service.
    //        // Extract timeout overriding configuration if present.
    //        if ( svc.hasProperty(FusekiVocab.pAllowTimeoutOverride) ) {
    //            sDesc.allowTimeoutOverride = svc.getProperty(FusekiVocab.pAllowTimeoutOverride).getObject().asLiteral().getBoolean();
    //            if ( svc.hasProperty(FusekiVocab.pMaximumTimeoutOverride) ) {
    //                sDesc.maximumTimeoutOverride = (int)(svc.getProperty(FusekiVocab.pMaximumTimeoutOverride).getObject().asLiteral().getFloat() * 1000);
    //            }
    //        }
    return dataService;
}

From source file:org.dllearner.utilities.QueryUtils.java

public static DirectedGraph<Node, LabeledEdge> asJGraphT(Query query) {
    QueryUtils utils = new QueryUtils();

    Set<Triple> tps = utils.extractTriplePattern(query);

    DirectedGraph<Node, LabeledEdge> g = new DefaultDirectedGraph<Node, LabeledEdge>(LabeledEdge.class);

    tps.forEach(tp -> {
        g.addVertex(tp.getSubject());/*from w w  w.j av  a 2  s  .  c om*/
        g.addVertex(tp.getObject());
        g.addEdge(tp.getSubject(), tp.getObject(),
                new LabeledEdge(tp.getSubject(), tp.getObject(), tp.getPredicate()));
    });

    return g;
}

From source file:org.onosproject.faultmanagement.alarms.cli.GetAllActiveAlarms.java

void printAlarms(Set<Alarm> alarms) {
    alarms.forEach((alarm) -> {
        print(ToStringBuilder.reflectionToString(alarm, ToStringStyle.SHORT_PREFIX_STYLE));
    });
}

From source file:org.commonjava.propulsor.deploy.resteasy.helper.CdiInjectorFactoryImpl.java

@Override
protected BeanManager lookupBeanManager() {
    final BeanManager bmgr = CDI.current().getBeanManager();

    Logger logger = LoggerFactory.getLogger(getClass());

    Set<Bean<?>> mappers = bmgr.getBeans(ObjectMapper.class);
    mappers.forEach(bean -> {
        CreationalContext ctx = bmgr.createCreationalContext(null);
        logger.debug("Found ObjectMapper: {}", bean.create(ctx));
        ctx.release();/*  w w w.j av  a  2s .  co m*/
    });

    logger.debug("\n\n\n\nRESTEasy CDI Injector Factory Using BeanManager: {} (@{})\n\n\n\n", bmgr,
            bmgr.hashCode());

    return bmgr;
}

From source file:org.apache.geode.geospatial.grid.IndexHAMaintenance.java

@Override
public void afterPrimary(int bucketId) {
    if (region != null) {
        Bucket b = region.getRegionAdvisor().getBucket(bucketId);
        BucketRegion bucketRegion = b.getBucketAdvisor().getProxyBucketRegion().getHostedBucketRegion();
        Set<Map.Entry> entries = bucketRegion.entrySet();
        entries.forEach(curr -> geospatialIndex.upsert(curr.getKey(), curr.getValue()));
    }/*from   www  .j  a  v  a 2 s.co m*/
}

From source file:org.apache.geode.geospatial.grid.IndexHAMaintenance.java

@Override
public void afterRegionCreate(Region<?, ?> reg) {
    region = (PartitionedRegion) reg;//from w  w w.  ja  va 2s  .  c  o m

    // We are going to re-index all of the primary data so clear out anything we might have and re-index.
    geospatialIndex.clear();
    Region localPrimaryData = PartitionRegionHelper.getLocalPrimaryData(region);
    Set<Map.Entry> entries = localPrimaryData.entrySet();
    entries.forEach(curr -> geospatialIndex.upsert(curr.getKey(), curr.getValue()));
}

From source file:com.ibasco.agql.core.AbstractWebApiRequest.java

@SuppressWarnings("unchecked")
protected void urlParam(AbstractCriteriaBuilder criteria) {
    Set<Map.Entry<String, Object>> criteraSet = criteria.getCriteriaSet();
    criteraSet.forEach(c -> urlParam(c.getKey(), c.getValue()));
}

From source file:com.sandornemeth.metrics.spring.autoconfigure.ReporterTestCaseBase.java

protected void verifyRegisteredJvmMetrics(String output) {
    Set<String> registeredMemoryUsageGaugeKeys = new MemoryUsageGaugeSet().getMetrics().keySet();
    registeredMemoryUsageGaugeKeys.forEach(k -> assertThat(output, containsString(k)));
}