List of usage examples for java.util.stream Collectors toCollection
public static <T, C extends Collection<T>> Collector<T, ?, C> toCollection(Supplier<C> collectionFactory)
From source file:org.kuali.coeus.s2sgen.impl.generate.support.NASASeniorKeyPersonSupplementalDataSheetV1_0Generator.java
private void populateInvestigators(NASASeniorKeyPersonSupplementalDataSheet nasaSeniorKPDataSheet) { List<? extends ProposalPersonContract> proposalPersonns = pdDoc.getDevelopmentProposal() .getProposalPersons();//from w ww . ja va 2s . c om Collections.sort(proposalPersonns, new ProposalPersonComparator()); List<ProposalPersonContract> keyPersons = pdDoc.getDevelopmentProposal().getProposalPersons().stream() .filter(proposalPerson -> proposalPerson.getProposalPersonRoleId() != null && (CO_INVESTIGATOR.equalsIgnoreCase(proposalPerson.getProposalPersonRoleId()) || ROLE_COLLABORATOR.equalsIgnoreCase(proposalPerson.getProjectRole()))) .collect(Collectors.toCollection(LinkedList::new)); if (keyPersons.isEmpty()) { nasaSeniorKPDataSheet.addNewSeniorKeyPerson(); return; } List<ProposalPersonContract> nKeyPersons = s2SProposalPersonService.getNKeyPersons(keyPersons, MAX_KEY_PERSON_COUNT); extraPersons = keyPersons.stream().filter(kp -> !nKeyPersons.contains(kp)).collect(Collectors.toList()); List<gov.grants.apply.forms.nasaSeniorKeyPersonSupplementalDataSheetV10.NASASeniorKeyPersonSupplementalDataSheetDocument.NASASeniorKeyPersonSupplementalDataSheet.SeniorKeyPerson> seniorKeyPersonList = new LinkedList<>(); for (ProposalPersonContract proposalPerson : nKeyPersons) { seniorKeyPersonList.add(getPerson(proposalPerson)); } gov.grants.apply.forms.nasaSeniorKeyPersonSupplementalDataSheetV10.NASASeniorKeyPersonSupplementalDataSheetDocument.NASASeniorKeyPersonSupplementalDataSheet.SeniorKeyPerson[] seniorKeyPersonsArray = new gov.grants.apply.forms.nasaSeniorKeyPersonSupplementalDataSheetV10.NASASeniorKeyPersonSupplementalDataSheetDocument.NASASeniorKeyPersonSupplementalDataSheet.SeniorKeyPerson[0]; nasaSeniorKPDataSheet.setSeniorKeyPersonArray(seniorKeyPersonList.toArray(seniorKeyPersonsArray)); }
From source file:com.mycompany.wolf.Room.java
/** * /*w ww .ja va 2 s . co m*/ */ private void assignRoles() { Multiset<String> roleCounts = HashMultiset.create(roleCounts()); Map<String, String> roleMap = new HashMap(); competeRoles.values().stream().filter(c -> roleCounts.remove(c.role)).forEach(c -> { roleMap.put(c.playerId, c.role); }); List<String> restPlayerId = sessions.stream().map(s -> getPlayerId(s)).filter(s -> !roleMap.containsKey(s)) .collect(Collectors.toList()); Collections.shuffle(restPlayerId); Iterator<String> restRoleIt = roleCounts.iterator(); Iterator<String> restPlayerIdIt = restPlayerId.iterator(); for (; restRoleIt.hasNext();) { String role = restRoleIt.next(); String playerId = restPlayerIdIt.next(); roleMap.put(playerId, role); } sessions.stream().forEach(s -> { s.getUserProperties().put("role", roleMap.get(getPlayerId(s))); }); List<ImmutableMap<String, String>> assignedRoles = roleMap.entrySet().stream() .map(entry -> ImmutableMap.of("playerId", entry.getKey(), "role", entry.getValue())) .collect(Collectors.toCollection(LinkedList::new)); Map<String, Object> assignRoles = ImmutableMap.of("code", "assignRoles", "properties", assignedRoles); String jsonText = JsonUtils.toString(assignRoles); sessions.stream().forEach(s -> { s.getAsyncRemote().sendText(jsonText); }); }
From source file:ch.sdi.core.impl.cfg.ConfigUtils.java
/** * Assembles a set of property names starting with the given prefix. * <p>//ww w. jav a 2 s .c o m * The resulting set is sorted according the natural ordering of the full property name. * <p> * @param aEnv * @param aKeyPrefix * @return */ public static Collection<String> getPropertyNamesStartingWith(ConfigurableEnvironment aEnv, String aKeyPrefix) { return getAllPropertyNames(aEnv).stream().filter(key -> key.startsWith(aKeyPrefix)) .collect(Collectors.toCollection((Supplier<Set<String>>) TreeSet::new)); }
From source file:org.ethereum.net.server.ChannelManagerImpl.java
/** * broadcastTransaction Propagates a transaction message across active peers with exclusion of * the peers with an id belonging to the skip set. * * @param transaction new Transaction to be sent * @param skip the set of peers to avoid sending the message. * @return a set containing the ids of the peers that received the transaction. *//* w w w . ja v a 2s . c o m*/ @Nonnull public Set<NodeID> broadcastTransaction(@Nonnull final Transaction transaction, @Nullable final Set<NodeID> skip) { Metrics.broadcastTransaction(transaction); List<Transaction> transactions = new ArrayList<>(); transactions.add(transaction); final Set<NodeID> res = new HashSet<>(); final EthMessage newTransactions = new RskMessage(new TransactionsMessage(transactions)); synchronized (activePeers) { final Vector<Channel> peers = activePeers.values().stream() .filter(p -> skip == null || !skip.contains(new NodeID(p.getNodeId()))) .collect(Collectors.toCollection(() -> new Vector<>())); for (Channel peer : peers) { res.add(new NodeID(peer.getNodeId())); peer.sendMessage(newTransactions); } } return res; }
From source file:com.github.jackygurui.vertxredissonrepository.repository.Impl.RedisRepositoryImpl.java
private void getByListBlocking(List<String> ids, AsyncResultHandler<List<T>> resultHandler) { if (ids == null) { resultHandler.handle(Future.failedFuture(new IllegalArgumentException("List of ids can't be null."))); return;/*from w w w.j a v a 2s . co m*/ } else if (ids.isEmpty()) { resultHandler.handle(Future.succeededFuture(Collections.emptyList())); return; } AtomicLong c = new AtomicLong(0); ArrayList<T> l = new ArrayList<>(ids.size()); IntStream.range(0, ids.size()).forEach(i -> l.add(null)); ids.stream().forEach(e -> { getBlocking(e, r -> { l.set(ids.indexOf(e), r.result()); if (c.incrementAndGet() == ids.size()) { resultHandler.handle(Future.succeededFuture( l.stream().filter(s -> s != null).collect(Collectors.toCollection(ArrayList::new)))); } }); }); }
From source file:com.thoughtworks.go.config.JobConfig.java
@SuppressWarnings("unused") //used in rails public Tasks getTasksForView() { return tasks.stream().map(task -> { if (task instanceof FetchTask) { return new FetchTaskAdapter((FetchTask) task); }/*from ww w. ja v a 2 s . c om*/ if (task instanceof FetchPluggableArtifactTask) { return new FetchTaskAdapter((FetchPluggableArtifactTask) task); } return task; }).collect(Collectors.toCollection(Tasks::new)); }
From source file:org.apache.nifi.registry.flow.mapping.NiFiRegistryFlowMapper.java
private InstantiatedVersionedProcessGroup mapGroup(final ProcessGroup group, final ControllerServiceProvider serviceLookup, final FlowRegistryClient registryClient, final boolean topLevel, final boolean mapDescendantVersionedFlows) { final InstantiatedVersionedProcessGroup versionedGroup = new InstantiatedVersionedProcessGroup( group.getIdentifier(), group.getProcessGroupIdentifier()); versionedGroup.setIdentifier(getId(group.getVersionedComponentId(), group.getIdentifier())); versionedGroup.setGroupIdentifier(getGroupId(group.getProcessGroupIdentifier())); versionedGroup.setName(group.getName()); versionedGroup.setComments(group.getComments()); versionedGroup.setPosition(mapPosition(group.getPosition())); // If we are at the 'top level', meaning that the given Process Group is the group that we are creating a VersionedProcessGroup for, // then we don't want to include the RemoteFlowCoordinates; we want to include the group contents. The RemoteFlowCoordinates will be used // only for a child group that is itself version controlled. if (!topLevel) { final VersionControlInformation versionControlInfo = group.getVersionControlInformation(); if (versionControlInfo != null) { final VersionedFlowCoordinates coordinates = new VersionedFlowCoordinates(); final String registryId = versionControlInfo.getRegistryIdentifier(); final FlowRegistry registry = registryClient.getFlowRegistry(registryId); if (registry == null) { throw new IllegalStateException("Process Group refers to a Flow Registry with ID " + registryId + " but no Flow Registry exists with that ID. Cannot resolve to a URL."); }//from w w w .jav a 2s . c om coordinates.setRegistryUrl(registry.getURL()); coordinates.setBucketId(versionControlInfo.getBucketIdentifier()); coordinates.setFlowId(versionControlInfo.getFlowIdentifier()); coordinates.setVersion(versionControlInfo.getVersion()); versionedGroup.setVersionedFlowCoordinates(coordinates); // We need to register the Port ID -> Versioned Component ID's in our versionedComponentIds member variable for all input & output ports. // Otherwise, we will not be able to lookup the port when connecting to it. for (final Port port : group.getInputPorts()) { getId(port.getVersionedComponentId(), port.getIdentifier()); } for (final Port port : group.getOutputPorts()) { getId(port.getVersionedComponentId(), port.getIdentifier()); } // If the Process Group itself is remotely versioned, then we don't want to include its contents // because the contents are remotely managed and not part of the versioning of this Process Group if (!mapDescendantVersionedFlows) { return versionedGroup; } } } versionedGroup.setControllerServices(group.getControllerServices(false).stream() .map(service -> mapControllerService(service, serviceLookup)) .collect(Collectors.toCollection(LinkedHashSet::new))); versionedGroup.setFunnels(group.getFunnels().stream().map(this::mapFunnel) .collect(Collectors.toCollection(LinkedHashSet::new))); versionedGroup.setInputPorts(group.getInputPorts().stream().map(this::mapPort) .collect(Collectors.toCollection(LinkedHashSet::new))); versionedGroup.setOutputPorts(group.getOutputPorts().stream().map(this::mapPort) .collect(Collectors.toCollection(LinkedHashSet::new))); versionedGroup.setLabels(group.getLabels().stream().map(this::mapLabel) .collect(Collectors.toCollection(LinkedHashSet::new))); versionedGroup.setProcessors( group.getProcessors().stream().map(processor -> mapProcessor(processor, serviceLookup)) .collect(Collectors.toCollection(LinkedHashSet::new))); versionedGroup.setRemoteProcessGroups(group.getRemoteProcessGroups().stream() .map(this::mapRemoteProcessGroup).collect(Collectors.toCollection(LinkedHashSet::new))); versionedGroup.setProcessGroups(group.getProcessGroups().stream() .map(grp -> mapGroup(grp, serviceLookup, registryClient, false, mapDescendantVersionedFlows)) .collect(Collectors.toCollection(LinkedHashSet::new))); versionedGroup.setConnections(group.getConnections().stream().map(this::mapConnection) .collect(Collectors.toCollection(LinkedHashSet::new))); versionedGroup.setVariables(group.getVariableRegistry().getVariableMap().entrySet().stream() .collect(Collectors.toMap(entry -> entry.getKey().getName(), Map.Entry::getValue))); return versionedGroup; }
From source file:com.hp.autonomy.hod.client.api.userstore.user.UserStoreUsersServiceImpl.java
private Requester.BackendCaller<EntityType, TokenType.Simple> addUserMetadataBackendCaller( final ResourceIdentifier userStore, final UUID userUuid, final Map<String, ?> metadata) { final List<Metadata<?>> metadataList = metadata.entrySet().stream() .map(entry -> new Metadata<>(entry.getKey(), entry.getValue())) .collect(Collectors.toCollection(LinkedList::new)); return authenticationToken -> backend.addUserMetadata(authenticationToken, userStore, userUuid, metadataList);//w w w.j av a 2s . c o m }
From source file:com.steelbridgelabs.oss.neo4j.structure.Neo4JGraph.java
public Iterator<Vertex> vertices(Statement statement) { Objects.requireNonNull(statement, "statement cannot be null"); // get current session Neo4JSession session = currentSession(); // transaction should be ready for io operations transaction.readWrite();// ww w . ja v a 2s.c om // execute statement StatementResult result = session.executeStatement(statement); // find vertices Iterator<Vertex> iterator = session.vertices(result).collect(Collectors.toCollection(LinkedList::new)) .iterator(); // process summary (query has been already consumed by collect) ResultSummaryLogger.log(result.consume()); // return iterator return iterator; }
From source file:com.evolveum.midpoint.common.refinery.RefinedObjectClassDefinitionImpl.java
@Override public Collection<QName> getNamesOfAssociations() { return getAssociationDefinitions().stream().map(a -> a.getName()) .collect(Collectors.toCollection(HashSet::new)); }