Example usage for java.util.stream Collectors toSet

List of usage examples for java.util.stream Collectors toSet

Introduction

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

Prototype

public static <T> Collector<T, ?, Set<T>> toSet() 

Source Link

Document

Returns a Collector that accumulates the input elements into a new Set .

Usage

From source file:nu.yona.server.analysis.service.InactivityManagementService.java

public void createInactivityEntities(UUID userAnonymizedId, Set<IntervalInactivityDto> intervalInactivities) {
    try (LockPool<UUID>.Lock lock = userAnonymizedSynchronizer.lock(userAnonymizedId)) {
        transactionHelper.executeInNewTransaction(() -> {
            UserAnonymizedDto userAnonymized = userAnonymizedService.getUserAnonymized(userAnonymizedId);
            createWeekInactivityEntities(userAnonymizedId, intervalInactivities.stream()
                    .filter(ia -> ia.getTimeUnit() == ChronoUnit.WEEKS).collect(Collectors.toSet()));
            createDayInactivityEntities(userAnonymized, intervalInactivities.stream()
                    .filter(ia -> ia.getTimeUnit() == ChronoUnit.DAYS).collect(Collectors.toSet()));
        });/*from  www.  jav a  2s  .  c om*/
    }
}

From source file:com.netflix.spinnaker.fiat.controllers.AuthorizeController.java

@ApiOperation(value = "Used mostly for testing. Not really any real value to the rest of "
        + "the system. Disabled by default.")
@RequestMapping(method = RequestMethod.GET)
public Set<UserPermission.View> getAll(HttpServletResponse response) throws IOException {
    if (!configProps.isGetAllEnabled()) {
        response.sendError(HttpServletResponse.SC_METHOD_NOT_ALLOWED, "/authorize is disabled");
        return null;
    }// w  w w . j  av a 2 s  .  c  om

    log.debug("UserPermissions requested for all users");
    return permissionsRepository.getAllById().values().stream().map(UserPermission::getView)
            .collect(Collectors.toSet());
}

From source file:edu.pitt.dbmi.ccd.anno.user.UserResource.java

/**
 * Constructor// ww w.  j a v  a 2 s. c o m
 *
 * @param user content
 * @return new UserResource
 */
public UserResource(UserAccount user) {
    this.username = user.getUsername();

    final Person person = user.getPerson();
    this.firstName = person.getFirstName();
    this.middleName = person.getMiddleName();
    this.lastName = person.getLastName();
    this.email = person.getEmail();
    this.roles.addAll(user.getUserRoles().stream().map(r -> r.getName()).collect(Collectors.toSet()));
}

From source file:edu.pitt.dbmi.ccd.anno.vocabulary.attribute.AttributeResourceAssembler.java

/**
 * convert Attribute to AttributeResource
 *
 * @param attribute entity/*  w  w w.  j a  v  a 2  s  .co m*/
 * @return resource
 */
@Override
public AttributeResource toResource(Attribute attribute) {
    Assert.notNull(attribute);

    // create resource
    AttributeResource resource = createResourceWithId(attribute.getId(), attribute);

    // make child attributes resources if there are any
    Set<AttributeResource> subAttributes = attribute.getChildren().stream().map(this::toResource)
            .collect(Collectors.toSet());
    if (subAttributes.size() > 0) {
        resource.addSubAttributes(subAttributes);
    }

    // add link to parent attribute if it has one
    if (attribute.getParent() != null) {
        resource.add(attributeLinks.parent(attribute));
    }

    // add link to vocabulary
    Vocabulary vocabulary = attribute.getVocabulary();
    resource.add(vocabLinks.vocabulary(vocabulary));

    return resource;
}

From source file:edu.pitt.dbmi.ccd.anno.annotation.data.AnnotationDataResourceAssembler.java

/**
 * convert AnnotationData to AnnotationDataResource
 *
 * @param data entity//from  w w w  .j  av a 2  s .  c  o m
 * @return resource
 */
@Override
public AnnotationDataResource toResource(AnnotationData data) {
    AnnotationDataResource resource = createResourceWithId(data.getId(), data);
    Set<AnnotationDataResource> children = data.getSubData().stream().map(this::toResource)
            .collect(Collectors.toSet());
    resource.addSubData(children);
    if (data.getAttribute() != null) {
        resource.add(vocabularyLinks.attribute(data.getAttribute().getVocabulary(), data.getAttribute()));
    }
    resource.setAttributeResource(attributeResourceAssembler.toResource(data.getAttribute()));
    return resource;
}

From source file:com.vsct.dt.hesperides.templating.packages.event.TemplatePackageContainer.java

/**
 * Return list of template./*w ww  .j a  v a2 s. co m*/
 *
 * @return set of template
 */
@Override
public Set<Template> loadAllTemplate() {
    return this.template.entrySet().stream().map(Map.Entry::getValue).collect(Collectors.toSet());
}

From source file:se.uu.it.cs.recsys.persistence.repository.CourseRepositoryIT.java

@Test
public void testFindByAutoGenIds() {
    Set<Integer> ids = Stream.of(1, 2, 3, 4, 5).collect(Collectors.toSet());

    Assert.assertTrue(!this.courseRepository.findByAutoGenIds(ids).isEmpty());
}

From source file:pt.ist.fenixedu.delegates.ui.DelegateCrudController.java

@RequestMapping(value = "/search", method = RequestMethod.POST)
public String search(@ModelAttribute DelegateSearchBean searchBean, Model model) {
    searchBean.setExecutionYear(ExecutionYear.readCurrentExecutionYear());
    searchBean = delegateService.generateNewBean(searchBean);
    model.addAttribute("searchBean", searchBean);
    Set<DelegateBean> delegateBeanSet = delegateService.searchDelegates(searchBean, new DateTime()).stream()
            .collect(Collectors.toSet());
    delegateBeanSet.addAll(delegateService.getDegreePositions(searchBean.getDegree()));
    model.addAttribute("delegates", delegateBeanSet.stream().distinct().collect(Collectors.toList()));
    return search(model);
}

From source file:org.hsweb.web.mybatis.MybatisProperties.java

public Resource[] resolveMapperLocations() {
    Map<String, Resource> resources = new HashMap<>();
    Set<String> locations;

    if (this.getMapperLocations() == null)
        locations = new HashSet<>();
    else/*from  w w w . java  2 s  .  c  om*/
        locations = Arrays.stream(getMapperLocations()).collect(Collectors.toSet());
    locations.add(defaultMapperLocation);
    for (String mapperLocation : locations) {
        Resource[] mappers;
        try {
            mappers = new PathMatchingResourcePatternResolver().getResources(mapperLocation);
            for (Resource mapper : mappers) {
                resources.put(mapper.getURL().toString(), mapper);
            }
        } catch (IOException e) {
        }
    }
    //???
    if (mapperLocationExcludes != null && mapperLocationExcludes.length > 0) {
        for (String mapperLocationExclude : mapperLocationExcludes) {
            try {
                Resource[] excludesMappers = new PathMatchingResourcePatternResolver()
                        .getResources(mapperLocationExclude);
                for (Resource excludesMapper : excludesMappers) {
                    resources.remove(excludesMapper.getURL().toString());
                }
            } catch (IOException e) {
            }
        }
    }
    Resource[] mapperLocations = new Resource[resources.size()];
    mapperLocations = resources.values().toArray(mapperLocations);
    return mapperLocations;
}