List of usage examples for java.util Collection stream
default Stream<E> stream()
From source file:com.github.horrorho.inflatabledonkey.BackupAssistant.java
public Map<Device, List<Snapshot>> deviceSnapshots(HttpClient httpClient, Collection<Device> devices) throws IOException { Map<SnapshotID, Device> snapshotDevice = devices.stream().distinct() .flatMap(d -> d.snapshotIDs().stream().map(s -> new SimpleImmutableEntry<>(s, d))) .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); List<SnapshotID> snapshotIDs = devices.stream().map(Device::snapshotIDs).flatMap(Collection::stream) .collect(Collectors.toList()); return snapshots(httpClient, snapshotIDs).stream() .collect(Collectors.groupingBy(s -> snapshotDevice.get(s.snapshotID()))); }
From source file:io.github.moosbusch.permagon.application.spi.AbstractPermagonApplicationContext.java
protected boolean isValidBeanConfigurationClasses(Collection<Class<?>> beanConfigurationClasses) { return beanConfigurationClasses.stream().anyMatch((beanConfigurationClass) -> (JavaFXBeanConfiguration.class .isAssignableFrom(beanConfigurationClass))); }
From source file:com.ibm.watson.catalyst.jumpqa.template.ATemplate.java
private final <T> List<T> filter(Collection<T> aCollection, Predicate<T> aPredicate) { return aCollection.stream().filter(aPredicate).collect(Collectors.toList()); }
From source file:ua.pp.msk.cliqr.CliQrHostnameVerifier.java
@Override public final void verify(String host, X509Certificate cert) throws SSLException { Principal subjectDN = cert.getSubjectDN(); try {//from www. ja v a 2 s . c o m Collection<List<?>> subjectAlternativeNames = cert.getSubjectAlternativeNames(); if (subjectAlternativeNames != null) { subjectAlternativeNames.stream().map((subList) -> { logger.debug("Processing alternative"); return subList; }).map((subList) -> { StringBuilder sb = new StringBuilder(); subList.stream().forEach((o) -> { sb.append(o.toString()).append(", "); }); return sb; }).forEach((sb) -> { logger.debug(sb.toString()); }); } } catch (CertificateParsingException ex) { logger.info("It is useful to ignore such king of exceptions", ex); } logger.debug("Subject distiguished name: " + subjectDN.getName()); }
From source file:edu.umd.umiacs.clip.tools.lang.TFIDFVector.java
public TFIDFVector(Collection<Triple<String, Integer, Integer>> terms, double logNumDocs) { double one_over_n_j = 1.0d / terms.parallelStream().mapToInt(Triple::getMiddle).sum(); termToTFIDF = terms.stream().collect(toMap(Triple::getLeft, triple -> (triple.getMiddle() * one_over_n_j) * (logNumDocs - log(triple.getRight())))); normalize();// w w w . ja v a2s . c o m }
From source file:ru.anr.base.BaseParent.java
/** * Determines whether the given collection contains specified strings or * not. The parameter conjunction must be 'true' if we expect all strings to * be included in the source collection, otherwise it is 'false' (That means * at least one must be included).// w w w . ja va 2 s .c o m * * @param coll * A source collection * @param conjunction * true, if all inclusion are expected, or false, if at least * one. * @param items * Expected strings * @return true, if the given collection contains the specified items * according to the condition 'conjunction'. */ protected static boolean contains(Collection<String> coll, boolean conjunction, String... items) { Set<String> s = set(items); return conjunction ? // coll.containsAll(list(items)) : // coll.stream().parallel().filter(a -> s.contains(a)).count() > 0; }
From source file:io.gravitee.repository.mongodb.management.MongoApplicationRepository.java
private Set<Application> mapApplications(Collection<ApplicationMongo> applications) { return applications.stream().map(this::mapApplication).collect(Collectors.toSet()); }
From source file:io.gravitee.management.rest.enhancer.ApplicationEnhancer.java
public Function<ApplicationEntity, ApplicationEntity> enhance(String currentUser) { return application -> { // Add primary owner Collection<MemberEntity> members = applicationService.getMembers(application.getId(), null); Collection<MemberEntity> primaryOwnerMembers = members.stream() .filter(m -> MembershipType.PRIMARY_OWNER.equals(m.getType())).collect(Collectors.toSet()); if (!primaryOwnerMembers.isEmpty()) { MemberEntity primaryOwner = primaryOwnerMembers.iterator().next(); UserEntity user = userService.findByName(primaryOwner.getUser()); PrimaryOwnerEntity owner = new PrimaryOwnerEntity(); owner.setUsername(user.getUsername()); owner.setEmail(user.getEmail()); owner.setFirstname(user.getFirstname()); owner.setLastname(user.getLastname()); application.setPrimaryOwner(owner); }/*from ww w .j a va 2 s . c om*/ // Add Members size application.setMembersSize(members.size()); // Add permission for current user (if authenticated) if (currentUser != null) { MemberEntity member = applicationService.getMember(application.getId(), currentUser); if (member != null) { application.setPermission(member.getType()); } } // Add APIs size application.setApisSize(apiService.countByApplication(application.getId())); return application; }; }
From source file:io.pivotal.cla.data.repository.CorporateSignatureRepository.java
default CorporateSignature findSignature(String claName, Collection<String> organizations, Collection<String> emails) { PageRequest pageable = new PageRequest(0, 1); List<String> emailDomains = emails == null || emails.isEmpty() ? EMPTY_LIST_FOR_QUERY : emails.stream().map(e -> e.substring(e.lastIndexOf("@") + 1)).collect(Collectors.toList()); organizations = organizations.isEmpty() ? EMPTY_LIST_FOR_QUERY : organizations; List<CorporateSignature> results = findSignatures(pageable, claName, organizations, emailDomains); return results.isEmpty() ? null : results.get(0); }
From source file:org.trustedanalytics.servicecatalog.service.rest.ServiceInstancesControllerHelpers.java
public void mergeInstances(Collection<Service> services, Collection<ServiceInstance> instances) { Map<UUID, List<ServiceInstance>> instancesIndex = createInstancesIndex(instances); services.stream().forEach(b -> b .setInstances(Optional.ofNullable(instancesIndex.get(b.getGuid())).orElse(new ArrayList<>()))); }