List of usage examples for java.util Collection forEach
default void forEach(Consumer<? super T> action)
From source file:org.artifactory.ui.rest.model.artifacts.browse.treebrowser.nodes.JunctionNode.java
/** * get repository or folder children/* w w w.j ava 2 s . co m*/ * * @param authService - authorization service * @param isCompact - is compacted * @param request * @return */ private Collection<? extends RestModel> getRepoOrFolderChildren(AuthorizationService authService, boolean isCompact, ArtifactoryRestRequest request) { Collection<? extends RestTreeNode> items = getChildren(authService, isCompact, request); List<RestModel> treeModel = new ArrayList<>(); items.forEach(item -> { // update additional data ((INode) item).updateNodeData(); treeModel.add(item); }); return treeModel; }
From source file:at.grahsl.kafka.connect.mongodb.MongoDbSinkTask.java
Map<String, MongoDbSinkRecordBatches> createSinkRecordBatchesPerTopic(Collection<SinkRecord> records) { LOGGER.debug("number of sink records to process: {}", records.size()); Map<String, MongoDbSinkRecordBatches> batchMapping = new HashMap<>(); LOGGER.debug("buffering sink records into grouped topic batches"); records.forEach(r -> { String collection = sinkConfig.getString(MongoDbSinkConnectorConfig.MONGODB_COLLECTION_CONF, r.topic()); if (collection.isEmpty()) { LOGGER.debug("no explicit collection name mapping found for topic {} " + "and default collection name was empty ", r.topic()); LOGGER.debug("using topic name {} as collection name", r.topic()); collection = r.topic();//ww w .ja v a 2s . c o m } String namespace = database.getName() + MongoDbSinkConnectorConfig.MONGODB_NAMESPACE_SEPARATOR + collection; MongoCollection<BsonDocument> mongoCollection = cachedCollections.get(namespace); if (mongoCollection == null) { mongoCollection = database.getCollection(collection, BsonDocument.class); cachedCollections.put(namespace, mongoCollection); } MongoDbSinkRecordBatches batches = batchMapping.get(namespace); if (batches == null) { int maxBatchSize = sinkConfig.getInt(MongoDbSinkConnectorConfig.MONGODB_MAX_BATCH_SIZE, collection); LOGGER.debug("batch size for collection {} is at most {} record(s)", collection, maxBatchSize); batches = new MongoDbSinkRecordBatches(maxBatchSize, records.size()); batchMapping.put(namespace, batches); } batches.buffer(r); }); return batchMapping; }
From source file:com.netflix.spinnaker.fiat.roles.google.GoogleDirectoryUserRolesProvider.java
@Override public Map<String, Collection<Role>> multiLoadRoles(Collection<String> userEmails) { if (userEmails == null || userEmails.isEmpty()) { return new HashMap<>(); }// www. ja v a 2s . c o m HashMap<String, Collection<Role>> emailGroupsMap = new HashMap<>(); Directory service = getDirectoryService(); BatchRequest batch = service.batch(); userEmails.forEach(email -> { try { GroupBatchCallback callback = new GroupBatchCallback().setEmailGroupsMap(emailGroupsMap) .setEmail(email); HttpRequest request = service.groups().list().setDomain(config.getDomain()).setUserKey(email) .buildHttpRequest(); HttpBackOffUnsuccessfulResponseHandler handler = new HttpBackOffUnsuccessfulResponseHandler( new ExponentialBackOff()); handler.setBackOffRequired(response -> { int code = response.getStatusCode(); // 403 is Google's Rate limit exceeded response. return code == 403 || code / 100 == 5; }); request.setUnsuccessfulResponseHandler(handler); batch.queue(request, Groups.class, GoogleJsonErrorContainer.class, callback); } catch (IOException ioe) { throw new RuntimeException(ioe); } }); try { batch.execute(); } catch (IOException ioe) { throw new RuntimeException(ioe); } return emailGroupsMap; }
From source file:net.dv8tion.jda.core.managers.PermOverrideManagerUpdatable.java
/** * Grants the specified {@link net.dv8tion.jda.core.Permission Permissions} * to the target {@link net.dv8tion.jda.core.entities.PermissionOverride} * * @param permissions/* w w w .java 2 s .c o m*/ * Permissions to grant * * @throws net.dv8tion.jda.core.exceptions.PermissionException * If any of the provided permissions are not accessible * @throws IllegalArgumentException * If any of the provided permissions is {@code null} * * @return The current Manager instance for chaining convenience */ @CheckReturnValue public PermOverrideManagerUpdatable grant(Collection<Permission> permissions) { Checks.notNull(permissions, "Permission Collection"); permissions.forEach(perm -> { Checks.notNull(perm, "Permission in Permission Collection"); //checkPermission(perm); }); setupValues(); long allowBits = Permission.getRaw(permissions); allow |= allowBits; deny &= ~allowBits; return this; }
From source file:net.dv8tion.jda.core.managers.PermOverrideManagerUpdatable.java
/** * Denies the specified {@link net.dv8tion.jda.core.Permission Permissions} * from the target {@link net.dv8tion.jda.core.entities.PermissionOverride} * * @param permissions/*from w w w.j a v a 2 s. c o m*/ * Permissions to deny * * @throws net.dv8tion.jda.core.exceptions.PermissionException * If any of the provided permissions are not accessible * @throws IllegalArgumentException * If any of the provided permissions is {@code null} * * @return The current Manager instance for chaining convenience */ @CheckReturnValue public PermOverrideManagerUpdatable deny(Collection<Permission> permissions) { Checks.notNull(permissions, "Permission Collection"); permissions.forEach(perm -> { Checks.notNull(perm, "Permission in Permission Collection"); //checkPermission(perm); }); setupValues(); long denyBits = Permission.getRaw(permissions); allow &= ~denyBits; deny |= denyBits; return this; }
From source file:net.dv8tion.jda.core.managers.PermOverrideManagerUpdatable.java
/** * Clears the specified {@link net.dv8tion.jda.core.Permission Permissions} * from the target {@link net.dv8tion.jda.core.entities.PermissionOverride} * <br>This will make the specified Permissions be inherited * * @param permissions/*from ww w.ja va 2s.c o m*/ * Permissions to clear * * @throws net.dv8tion.jda.core.exceptions.PermissionException * If any of the provided permissions are not accessible * @throws IllegalArgumentException * If any of the provided permissions is {@code null} * * @return The current Manager instance for chaining convenience */ @CheckReturnValue public PermOverrideManagerUpdatable clear(Collection<Permission> permissions) { Checks.notNull(permissions, "Permission Collection"); permissions.forEach(perm -> { Checks.notNull(perm, "Permission in Permission Collection"); //checkPermission(perm); }); setupValues(); long clearBits = Permission.getRaw(permissions); allow &= ~clearBits; deny &= ~clearBits; return this; }
From source file:org.haiku.haikudepotserver.pkg.job.PkgScreenshotImportArchiveJobRunner.java
/** * <p>This method will re-order the inbound screenshots such that they appear in the same order as inbound</p> *//* www . ja va 2 s .co m*/ private void blendInArtificialOrderings(Collection<ScreenshotImportMetadatas> metadatas) { metadatas.forEach(this::blendInArtificialOrderings); }
From source file:org.loklak.susi.SusiMind.java
/** * This is the core principle of creativity: being able to match a given input * with problem-solving knowledge.//from ww w. j ava 2s .co m * This method finds ideas (with a query instantiated rules) for a given query. * The rules are selected using a scoring system and pattern matching with the query. * Not only the most recent user query is considered for rule selection but also * previously requested queries and their answers to be able to set new rule selections * in the context of the previous conversation. * @param query the user input * @param previous_argument the latest conversation with the same user * @param maxcount the maximum number of ideas to return * @return an ordered list of ideas, first idea should be considered first. */ public List<SusiIdea> creativity(String query, SusiThought latest_thought, int maxcount) { // tokenize query to have hint for idea collection final List<SusiIdea> ideas = new ArrayList<>(); this.reader.tokenizeSentence(query).forEach(token -> { Set<SusiRule> rule_for_category = this.ruletrigger.get(token.categorized); Set<SusiRule> rule_for_original = token.original.equals(token.categorized) ? null : this.ruletrigger.get(token.original); Set<SusiRule> r = new HashSet<>(); if (rule_for_category != null) r.addAll(rule_for_category); if (rule_for_original != null) r.addAll(rule_for_original); r.forEach(rule -> ideas.add(new SusiIdea(rule).setIntent(token))); }); //for (SusiIdea idea: ideas) System.out.println("idea.phrase-1:" + idea.getRule().getPhrases().toString()); // add catchall rules always (those are the 'bad ideas') Collection<SusiRule> ca = this.ruletrigger.get(SusiRule.CATCHALL_KEY); if (ca != null) ca.forEach(rule -> ideas.add(new SusiIdea(rule))); // create list of all ideas that might apply TreeMap<Long, List<SusiIdea>> scored = new TreeMap<>(); AtomicLong count = new AtomicLong(0); ideas.forEach(idea -> { int score = idea.getRule().getScore(); long orderkey = Long.MAX_VALUE - ((long) score) * 1000L + count.incrementAndGet(); List<SusiIdea> r = scored.get(orderkey); if (r == null) { r = new ArrayList<>(); scored.put(orderkey, r); } r.add(idea); }); // make a sorted list of all ideas ideas.clear(); scored.values().forEach(r -> ideas.addAll(r)); //for (SusiIdea idea: ideas) System.out.println("idea.phrase-2: score=" + idea.getRule().getScore() + " : " + idea.getRule().getPhrases().toString()); // test ideas and collect those which match up to maxcount List<SusiIdea> plausibleIdeas = new ArrayList<>(Math.min(10, maxcount)); for (SusiIdea idea : ideas) { SusiRule rule = idea.getRule(); Collection<Matcher> m = rule.matcher(query); if (m.isEmpty()) continue; // TODO: evaluate leading SEE flow commands right here as well plausibleIdeas.add(idea); if (plausibleIdeas.size() >= maxcount) break; } for (SusiIdea idea : plausibleIdeas) System.out.println("idea.phrase-3: score=" + idea.getRule().getScore() + " : " + idea.getRule().getPhrases().toString()); return plausibleIdeas; }
From source file:org.ops4j.pax.web.resources.extender.internal.IndexedOsgiResourceLocator.java
@Override public void register(final Bundle bundle) { Collection<URL> urls; try {/*from ww w. j ava2 s . c o m*/ urls = Collections.list(bundle.findEntries(RESOURCE_ROOT, "*.*", true)); } catch (IllegalStateException e) { logger.error("Error retrieving bundle-resources from bundle '{}'", bundle.getSymbolicName(), e); urls = Collections.emptyList(); } urls.forEach( url -> index.addResourceToIndex(url.getPath(), new ResourceInfo(url, LocalDateTime .ofInstant(Instant.ofEpochMilli(bundle.getLastModified()), ZoneId.systemDefault()), bundle.getBundleId()), bundle)); logger.info("Bundle '{}' scanned for resources in '{}': {} entries added to index.", new Object[] { bundle.getSymbolicName(), RESOURCE_ROOT, urls.size() }); }
From source file:com.bgh.myopeninvoice.jsf.jsfbeans.UsersBean.java
private void fillDualList() { final Iterable<RolesEntity> allRolesEntity = invoiceDAO.getRolesRepository().findAll(); final Collection<UserRoleEntity> assignedRolesEntity = selectedUsersEntity.getUserRolesByUserId(); List<RolesEntity> sourceList = new ArrayList<>(); List<RolesEntity> targetList = new ArrayList<>(); rolesDualListModel = new DualListModel<>(); allRolesEntity.forEach(sourceList::add); assignedRolesEntity.forEach(r -> targetList.add(r.getRolesByRoleId())); sourceList.removeAll(targetList);// w w w . j a v a 2s . c om rolesDualListModel.setSource(sourceList); rolesDualListModel.setTarget(targetList); }