Example usage for java.util Collection stream

List of usage examples for java.util Collection stream

Introduction

In this page you can find the example usage for java.util Collection stream.

Prototype

default Stream<E> stream() 

Source Link

Document

Returns a sequential Stream with this collection as its source.

Usage

From source file:org.trustedanalytics.user.current.AuthDetailsFinder.java

@Override
public UserRole getRole(Authentication authentication) {
    Collection<? extends GrantedAuthority> authorities = authentication.getAuthorities();
    if (authorities == null || authorities.isEmpty())
        return UserRole.USER;

    boolean isAdmin = authorities.stream().map(GrantedAuthority::getAuthority)
            .filter(ADMIN_ROLE::equalsIgnoreCase).count() > 0;

    return isAdmin ? UserRole.ADMIN : UserRole.USER;
}

From source file:delfos.rs.contentbased.vsm.booleanvsm.SparseVector.java

public SparseVector(Collection<Key> domain) {
    map = Collections.synchronizedMap(new HashMap<>());

    this.domain = Collections.synchronizedSet(domain.stream().collect(Collectors.toSet()));
}

From source file:sagan.projects.support.BadgeController.java

private Optional<ProjectRelease> getRelease(Collection<ProjectRelease> projectReleases,
        Predicate<ProjectRelease> predicate) {

    Optional<ProjectRelease> first = projectReleases //
            .stream() //
            .filter(projectRelease -> predicate.test(projectRelease) && projectRelease.isCurrent()) //
            .findFirst();/*from   ww w . j a v  a 2 s  .  com*/

    if (first.isPresent()) {
        return first;
    }

    return projectReleases //
            .stream() //
            .filter(projectRelease -> predicate.test(projectRelease)) //
            .findFirst();
}

From source file:de.science.hack.Main.java

/**
 * This method process the arguments.//w  ww. j  a  va  2s.  c om
 *
 * @param args
 * @throws ParseException
 */
private void process(String[] args) throws ParseException {
    CommandLine commandLine = parser.parse(options, args);
    Collection<File> inputFiles = getInputFiles(commandLine);

    if (!inputFiles.isEmpty()) {
        JetStreamModelWriter modelWriter = createModelWriter(commandLine);

        inputFiles.stream().forEach((f) -> {
            TriangleMesh mesh = windModelBuilder.build(f);
            modelWriter.addWindModel(mesh);
        });

        modelWriter.write(getOutput(commandLine));
    } else {
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp(APP, options);
    }
}

From source file:net.riezebos.thoth.user.BasicUserManager.java

@Override
public List<User> listUsers() throws UserManagerException {
    Collection<Identity> identities = identityDao.getIdentities().values();
    Stream<User> filter = identities.stream()//
            .filter(usr -> usr instanceof User)//
            .map(u -> (User) u);//www  .ja  va 2s  . c o m
    List<User> users = filter.collect(Collectors.toList());
    Collections.sort(users);
    return users;
}

From source file:org.trustedanalytics.servicecatalog.service.rest.ServiceInstancesControllerHelpers.java

public void mergeServiceKeys(Collection<ServiceInstance> instances, Observable<ServiceKey> serviceKeys) {
    Map<UUID, List<ServiceKey>> serviceKeysIndex = createServiceKeysIndex(serviceKeys);

    instances.stream().forEach(i -> i
            .setServiceKeys(Optional.ofNullable(serviceKeysIndex.get(i.getGuid())).orElse(new ArrayList<>())));
}

From source file:net.riezebos.thoth.user.BasicUserManager.java

@Override
public List<Group> listGroups() throws UserManagerException {
    Collection<Identity> identities = identityDao.getIdentities().values();
    Stream<Group> filter = identities.stream()//
            .filter(grp -> grp instanceof Group)//
            .map(g -> (Group) g);
    List<Group> groups = filter.collect(Collectors.toList());
    Collections.sort(groups);//from ww  w . j a v a 2s .  c o  m
    return groups;
}

From source file:bjerne.gallery.service.impl.GalleryAuthorizationServiceSSImpl.java

private Map<String, File> getRootPathsForRoles(Collection<String> roles, Collection<GalleryRootDir> rootDirs) {
    Map<String, File> rootPathsForRoles = rootDirs.stream().filter(r -> roles.contains(r.getRole()))
            .collect(Collectors.toMap(GalleryRootDir::getName, GalleryRootDir::getDir));
    LOG.debug("Root paths for roles {}: {}", roles, rootPathsForRoles);
    return rootPathsForRoles;
}

From source file:com.evolveum.midpoint.wf.impl.processors.primary.policy.PolicyRuleBasedAspect.java

List<EvaluatedPolicyRule> selectTriggeredApprovalActionRules(Collection<EvaluatedPolicyRule> rules) {
    return rules.stream()
            .filter(r -> r.isTriggered() && r.containsEnabledAction(ApprovalPolicyActionType.class))
            .collect(Collectors.toList());
}

From source file:com.ibm.watson.catalyst.jumpqa.template.ATemplate.java

private final List<Answer> trecs2answers(Collection<Trec> trecs) {
    final List<Answer> result = new ArrayList<Answer>();
    trecs.stream().forEachOrdered((t) -> result.addAll(t.splitInto(_answerSize)));
    return result;
}