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:co.com.carpco.altablero.hibernate.bll.GradeBll.java

private void initializeCache() {
    CachingProvider cachingProvider = Caching.getCachingProvider();
    CacheManager cacheManager = cachingProvider.getCacheManager();

    MutableConfiguration<Integer, Set> config = new MutableConfiguration<Integer, Set>()
            .setTypes(Integer.class, Set.class).setExpiryPolicyFactory(AccessedExpiryPolicy.factoryOf(ONE_DAY))
            .setWriteThrough(true).setReadThrough(true)
            .setCacheLoaderFactory(new Factory<CacheLoader<Integer, Set>>() {

                @Override//from  w  ww  . j  a v  a2 s  .c  om
                public CacheLoader<Integer, Set> create() {
                    return new CacheLoader<Integer, Set>() {

                        @Override
                        public Set load(Integer key) throws CacheLoaderException {
                            final Set<GradeBO> gradeBOSet = new HashSet<>();
                            Set<BzGrade> bzGradeSet = gradeDao.getGradeSet();
                            if (bzGradeSet != null && bzGradeSet.size() > 0) {
                                bzGradeSet.forEach((BzGrade bzGrade) -> gradeBOSet.add(new GradeBO(bzGrade)));
                            }
                            return gradeBOSet;
                        }

                        @Override
                        public Map<Integer, Set> loadAll(Iterable<? extends Integer> itrbl)
                                throws CacheLoaderException {
                            Map<Integer, Set> answer = new HashMap<>();
                            itrbl.forEach((Integer k) -> answer.put(k, load(k)));

                            return answer;
                        }
                    };
                }
            }).setCacheWriterFactory(new Factory<CacheWriter<Integer, Set>>() {
                @Override
                public CacheWriter<Integer, Set> create() {
                    CacheWriter<Integer, Set> writer = new CacheWriter<Integer, Set>() {

                        @Override
                        public void write(Cache.Entry<? extends Integer, ? extends Set> entry)
                                throws CacheWriterException {

                        }

                        @Override
                        public void writeAll(Collection<Cache.Entry<? extends Integer, ? extends Set>> clctn)
                                throws CacheWriterException {

                        }

                        @Override
                        public void delete(Object o) throws CacheWriterException {

                        }

                        @Override
                        public void deleteAll(Collection<?> clctn) throws CacheWriterException {

                        }

                    };
                    return writer;
                }
            }).setStatisticsEnabled(true);

    cache = cacheManager.createCache("gradeCache", config);
    config.isReadThrough();
}

From source file:de.tudarmstadt.ukp.dkpro.core.io.lif.internal.Lif2DKPro.java

private String findRoot(View aView, Annotation aPS) {
    // Get all the constituents int he phrase structure
    Set<String> constituents = new HashSet<>(getSetFeature(aPS, Features.PhraseStructure.CONSTITUENTS));

    List<Annotation> psConstituents = aView.getAnnotations().stream()
            .filter(a -> Discriminators.Uri.CONSTITUENT.equals(a.getAtType()))
            .filter(con -> constituents.contains(con.getId())).collect(Collectors.toList());

    // Remove all constituents that are children of other constituents within the PS
    psConstituents.forEach(con -> {// ww  w .j  a v  a  2  s.  com
        Set<String> children = getSetFeature(con, Features.Constituent.CHILDREN);
        children.forEach(child -> constituents.remove(child));
    });

    // If all went well, only one constituent should be left and that is the root constituent
    assert 1 == constituents.size();

    // Return the ID of the root constituent
    return constituents.iterator().next();
}

From source file:org.usrz.libs.webtools.validation.ValidationInterceptor.java

@Override
public Object aroundReadFrom(ReaderInterceptorContext context) throws IOException, WebApplicationException {
    final Object object = context.proceed();
    if (object == null)
        return null;

    log.debug("Validating class %s", object.getClass().getName());
    final Set<ConstraintViolation<Object>> violations = validator.validate(object);
    if ((violations == null) || (violations.isEmpty()))
        return object;

    final List<Error> errors = new ArrayList<>();
    violations.forEach((violation) -> errors.add(new Error(violation)));

    throw new WebApplicationExceptionBuilder(BAD_REQUEST).message("Violation constraint in API")
            .with(withName, errors).build();
}

From source file:io.seventyone.mongoutils.MongoServiceImplementation.java

@Override
public void autoSetup(String packageName) {

    List<ClassLoader> classLoadersList = Lists.newArrayList();
    ClassLoader contextClassLoader = ClasspathHelper.contextClassLoader();
    classLoadersList.add(contextClassLoader);

    ClassLoader staticClassLoader = ClasspathHelper.staticClassLoader();
    if (staticClassLoader != contextClassLoader) {
        classLoadersList.add(staticClassLoader);
    }//  www  .  jav  a  2 s. co  m

    // formatter: off
    ConfigurationBuilder configuration = new ConfigurationBuilder()
            .setScanners(new SubTypesScanner(false), new TypeAnnotationsScanner())
            .addClassLoaders(classLoadersList).setUrls(ClasspathHelper.forPackage(packageName));
    // formatter: on
    Reflections reflections = new Reflections(configuration);

    Set<Class<?>> collections = reflections
            .getTypesAnnotatedWith(io.seventyone.mongoutils.annotations.MongoCollection.class);
    collections.forEach(c -> {
        io.seventyone.mongoutils.annotations.MongoCollection annotation;
        annotation = c.getAnnotation(io.seventyone.mongoutils.annotations.MongoCollection.class);
        if (annotation.noAutoSetup() == false) {
            this.setupCollection(c, annotation.value());
        }
    });
}

From source file:ai.grakn.test.engine.tasks.storage.TaskStateGraphStoreTest.java

@Test
public void testTaskStatePagination() {
    for (int i = 0; i < 10; i++) {
        stateStorage.newState(task());/*  w  ww .j ava2s . c o  m*/
    }

    Set<TaskState> setA = stateStorage.getTasks(null, null, null, null, 5, 0);
    Set<TaskState> setB = stateStorage.getTasks(null, null, null, null, 5, 5);

    setA.forEach(x -> assertFalse(setB.contains(x)));
}

From source file:org.onosproject.icona.domainmgr.impl.DomainManager.java

@Override
public Set<Link> getIntraLinks(DomainId domainId) {
    Set<Device> domDevices = getDevices(domainId);
    Set<Link> intralinks = new HashSet<>();
    domDevices.forEach(device -> {
        Set<Link> devLinks = linkService.getDeviceLinks(device.id());
        devLinks.forEach(link -> {// w  w  w .  j a va2 s .  c  om
            if (!link.annotations().keys().contains(SRC_DOMAIN_ID)) {
                intralinks.add(link);
            }
        });
    });
    return ImmutableSet.copyOf(intralinks);
}

From source file:org.wso2.extension.siddhi.execution.var.models.parametric.ParametricVaRCalculator.java

/**
 * @param portfolio//from w ww. ja  v a  2 s  .  c  o  m
 * @return Get mean matrix for a given portfolio
 */
private double[][] getMeanMatrix(Portfolio portfolio) {
    Set<String> keys = portfolio.getAssetListKeySet();
    double[][] meanMatrix = new double[1][keys.size()];

    final int[] i = { 0 };
    keys.forEach((symbol) -> {
        meanMatrix[0][i[0]] = getAssetPool().get(symbol).getMean();
        i[0]++;
    });

    return meanMatrix;
}

From source file:org.silverpeas.core.calendar.CalendarComponentDiffDescriptor.java

/**
 * Merges the detected differences into the given component.
 * @param component the component to merge.
 * @return true if something has been merged, false otherwise.
 *///  w w w.ja va2 s.  c o  m
@SuppressWarnings("unchecked")
boolean mergeInto(CalendarComponent component) {
    Mutable<Boolean> dataMerged = Mutable.of(false);
    if (diff.containsKey(TITLE_ATTR)) {
        component.setTitle((String) diff.get(TITLE_ATTR));
        dataMerged.set(true);
    }
    if (diff.containsKey(DESCRIPTION_ATTR)) {
        component.setDescription((String) diff.get(DESCRIPTION_ATTR));
        dataMerged.set(true);
    }
    if (diff.containsKey(LOCATION_ATTR)) {
        component.setLocation((String) diff.get(LOCATION_ATTR));
        dataMerged.set(true);
    }
    if (diff.containsKey(PRIORITY_ATTR)) {
        component.setPriority((Priority) diff.get(PRIORITY_ATTR));
        dataMerged.set(true);
    }
    if (diff.containsKey(SAVE_ATTRIBUTE_ATTR)) {
        Map<String, String> attributesToSave = (Map) diff.get(SAVE_ATTRIBUTE_ATTR);
        attributesToSave.forEach((key, value) -> component.getAttributes().set(key, value));
        dataMerged.set(true);
    }
    if (diff.containsKey(REMOVE_ATTRIBUTE_ATTR)) {
        Set<String> attributesToRemove = (Set) diff.get(REMOVE_ATTRIBUTE_ATTR);
        attributesToRemove.forEach(a -> component.getAttributes().remove(a));
        dataMerged.set(true);
    }
    if (diff.containsKey(SAVE_ATTENDEE_ATTR)) {
        Set<Attendee> attendeesToSave = (Set) diff.get(SAVE_ATTENDEE_ATTR);
        attendeesToSave.forEach(a -> {
            Optional<Attendee> attendee = component.getAttendees().get(a.getId());
            if (attendee.isPresent()) {
                attendee.get().setPresenceStatus(a.getPresenceStatus());
            } else {
                component.getAttendees().add(a.cloneFor(component));
            }
        });
        dataMerged.set(true);
    }
    if (diff.containsKey(REMOVE_ATTENDEE_ATTR)) {
        Set<Attendee> attendeesToRemove = (Set) diff.get(REMOVE_ATTENDEE_ATTR);
        attendeesToRemove.forEach(atr -> component.getAttendees().removeIf(a -> a.getId().equals(atr.getId())));
        dataMerged.set(true);
    }
    if (diff.containsKey(UPDATE_ATTENDEE_STATUS_ATTR)) {
        Set<Attendee> attendeeStatusesToUpdate = (Set) diff.get(UPDATE_ATTENDEE_STATUS_ATTR);
        attendeeStatusesToUpdate.forEach(aS -> {
            Optional<Attendee> attendee = component.getAttendees().get(aS.getId());
            attendee.ifPresent(a -> a.setParticipationStatus(aS.getParticipationStatus()));
            dataMerged.set(attendee.isPresent());
        });
    }
    return dataMerged.is(true);
}

From source file:co.com.carpco.altablero.hibernate.bll.UserBll.java

private void initializeTeacherCache() {
    CachingProvider cachingProvider = Caching.getCachingProvider();
    CacheManager cacheManager = cachingProvider.getCacheManager();

    MutableConfiguration<Integer, Set> config = new MutableConfiguration<Integer, Set>()
            .setTypes(Integer.class, Set.class).setExpiryPolicyFactory(AccessedExpiryPolicy.factoryOf(ONE_DAY))
            .setWriteThrough(true).setReadThrough(true)
            .setCacheLoaderFactory(new Factory<CacheLoader<Integer, Set>>() {

                @Override/*from  w w  w.j a  v a 2  s  . c  om*/
                public CacheLoader<Integer, Set> create() {
                    return new CacheLoader<Integer, Set>() {

                        @Override
                        public Set load(Integer k) throws CacheLoaderException {
                            final Set<UserBO> userBOSet = new HashSet<>();
                            Set<BzUser> bzUserSet = userDao.getTeacherSet(k);
                            if (bzUserSet != null && bzUserSet.size() > 0) {
                                bzUserSet.forEach((BzUser bzUser) -> userBOSet.add(new UserBO(bzUser)));
                            }
                            return userBOSet;
                        }

                        @Override
                        public Map<Integer, Set> loadAll(Iterable<? extends Integer> itrbl)
                                throws CacheLoaderException {
                            Map<Integer, Set> answer = new HashMap<>();
                            itrbl.forEach((Integer k) -> answer.put(k, load(k)));

                            return answer;
                        }
                    };
                }
            }).setStatisticsEnabled(true);

    teacherCache = cacheManager.createCache("teacherCache", config);
    config.isReadThrough();
}

From source file:org.jmingo.query.QueryManager.java

/**
 * Initializes query manager./*from w  w w.  java2 s .  co m*/
 *
 * @param querySetPath the set of querySet paths
 */
private void initialize(Set<String> querySetPath) {
    //register in event bus
    eventBus.register(this);

    querySetPath.forEach(path -> {
        QuerySet qs = loadQuerySet(path);
        querySetRegistry.add(new AtomicReference<>(qs));
    });

    querySetRegistry.forEach(qsRef -> {
        QuerySet querySet = qsRef.get();
        registerInWatchService(querySet.getPath());
        putQueries(querySet);
    });
}