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:software.uncharted.service.ClusterService.java

public ClusterResponse getTopClusters(Integer from_) {
    final Integer from = from_ != null ? from_ : 0;

    final String AGGREGATION_NAME = "clusters";
    TermsBuilder termsBuilder = AggregationBuilders.terms(AGGREGATION_NAME).field("lsh")
            .size(from + CLUSTERS_PER_PAGE);

    SearchRequestBuilder searchRequestBuilder = client.prepareSearch().setQuery(QueryBuilders.matchAllQuery())
            .setSize(0).setPreference(preference).addAggregation(termsBuilder);

    SearchResponse searchResponse = client.executeSearch(searchRequestBuilder);

    List<String> topBuckets = ((Terms) searchResponse.getAggregations().get(AGGREGATION_NAME)).getBuckets()
            .stream().map(MultiBucketsAggregation.Bucket::getKeyAsString) // pull out the term as a string
            .collect(Collectors.toList());

    topBuckets = topBuckets.subList(from, Math.min(topBuckets.size(), from + CLUSTERS_PER_PAGE));

    Set<Cluster> clusters = topBuckets.stream().map(lsh -> getCluster(lsh)).collect(Collectors.toSet());

    final boolean hasMore = ((Terms) searchResponse.getAggregations().get(AGGREGATION_NAME))
            .getSumOfOtherDocCounts() > 0L;

    return new ClusterResponse().setClusters(clusters).setHasMore(hasMore);

}

From source file:se.uu.it.cs.recsys.service.preference.SameCourseFinder.java

/**
 * Gets the info about course id collection representing the same course.
 * E.g a course with code "1DL301" can be planned in year 2015 and 2016 and
 * it will have different ids in DB in this case.
 *
 * @param scheduleInfo the info regarding which years are planned, e.g 2015;
 * non-empty input.//from  w  w w. ja  va2  s. com
 * @return non-null collection regarding id set for same course.
 * @throws IllegalArgumentException if input is null or empty
 */
public Set<Set<Integer>> getIdCollectionForSameCourse(Set<CourseSchedule> scheduleInfo) {

    if (scheduleInfo == null || scheduleInfo.isEmpty()) {
        throw new IllegalArgumentException("Schedule input must be non-empty");
    }

    List<Course> allCourses = this.courseRepository.findAll();

    // find the first plan year, e.g 2015
    int firstPlanYear = scheduleInfo.stream().sorted(
            (schedule1, schedule2) -> Short.compare(schedule1.getTaughtYear(), schedule2.getTaughtYear()))
            .findFirst().get().getTaughtYear();

    // only get the course ids for plan year, e.g 2015, 2016
    Set<Course> planYearCourseSet = allCourses.stream()
            .filter(course -> course.getTaughtYear() >= firstPlanYear).collect(Collectors.toSet());

    Map<String, Set<Integer>> codeToIdSet = CourseFlattener.flattenToCodeAndIdSet(planYearCourseSet);

    Set<Set<Integer>> idCollectionForSameCourse = new HashSet<>();

    codeToIdSet.entrySet().stream().filter(entry -> entry.getValue().size() > 1).forEach(entry -> {
        idCollectionForSameCourse.add(entry.getValue());
    });

    return idCollectionForSameCourse;
}

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

public Set<String> getMemberOf() {
    return memberships.stream().map(g -> g.getIdentifier()).collect(Collectors.toSet());
}

From source file:org.arrow.runtime.execution.MultipleEventExecution.java

/**
 * Returns a set of all expected event definition IDs.
 * //from  w  w  w . ja v  a2 s .c  o m
 * @return Set
 */
private Set<String> getExpectedEvendIds() {
    MultipleEventAware mea = (MultipleEventAware) getEntity();
    Set<EventDefinition> definitions = mea.getEventDefinitions();

    if (definitions == null) {
        return Collections.emptySet();
    }
    return definitions.stream().map(EventDefinition::getId).collect(Collectors.toSet());
}

From source file:se.uu.it.cs.recsys.service.resource.CourseResource.java

@Path("/credits")
@GET// ww  w.j a va  2  s.co m
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Get supported course credits.", response = CourseCredit.class, responseContainer = "Set")
public Set<Double> getSupportedCredits() {

    return this.supportedCourseCreditRepository.findAll().stream().map(entity -> entity.getCredit())
            .collect(Collectors.toSet());
}

From source file:org.ow2.proactive.connector.iaas.cloud.provider.azure.AzureProviderUtils.java

public Set<VirtualMachine> getAllVirtualMachines(Azure azureService) {

    return azureService.virtualMachines().list().stream().collect(Collectors.toSet());
}

From source file:com.netflix.genie.common.internal.dto.v4.ExecutionEnvironment.java

/**
 * Constructor./*from w  w  w  .  ja v  a 2s  . c  o m*/
 *
 * @param configs      Any configuration files needed for a resource at execution time. 1024 characters max for
 *                     each. Optional. Any blanks will be removed
 * @param dependencies Any dependency files needed for a resource at execution time. 1024 characters max for each.
 *                     Optional. Any blanks will be removed
 * @param setupFile    Any file that should be run to setup a resource at execution time. 1024 characters max.
 *                     Optional
 */
@JsonCreator
public ExecutionEnvironment(@JsonProperty("configs") @Nullable final Set<String> configs,
        @JsonProperty("dependencies") @Nullable final Set<String> dependencies,
        @JsonProperty("setupFile") @Nullable final String setupFile) {
    this.configs = configs == null ? ImmutableSet.of()
            : ImmutableSet.copyOf(configs.stream().filter(StringUtils::isNotBlank).collect(Collectors.toSet()));
    this.dependencies = dependencies == null ? ImmutableSet.of()
            : ImmutableSet
                    .copyOf(dependencies.stream().filter(StringUtils::isNotBlank).collect(Collectors.toSet()));
    this.setupFile = StringUtils.isBlank(setupFile) ? null : setupFile;
}

From source file:io.microprofile.showcase.web.EndpointService.java

private Endpoints getCachedEndpoints(final String application) throws WebApplicationException {

    Endpoints eps = this.map.get(application);

    if (null == eps) {

        final Properties p = new Properties();

        try (final InputStream is = this.context
                .getResourceAsStream("/WEB-INF/" + application + ".properties")) {
            p.load(is);//from w  w w .j  a  v a 2  s .c  om
        } catch (final Exception e) {
            throw new WebApplicationException("Unexpected error", e);
        }

        final Set<Endpoint> endpointSet = p.entrySet().stream().map(entry -> this
                .getEndpoint(String.class.cast(entry.getKey()), String.class.cast(entry.getValue())))
                .collect(Collectors.toSet());

        eps = new Endpoints();
        eps.setApplication(application);
        eps.setEndpoints(endpointSet);

        eps = this.addHyperMedia(eps);
        this.map.put(application, eps);
    }

    return eps;
}

From source file:org.lizardirc.beancounter.security.FingerprintingSslSocketFactory.java

public FingerprintingSslSocketFactory(Collection<String> c, SSLSocketFactory underlyingFactory) {
    fingerprints = new HashSet<>(c).stream().map(String::toLowerCase).map(s -> s.replaceAll("[^0-9a-f]+", ""))
            .collect(Collectors.toSet());
    this.underlyingFactory = underlyingFactory;
}

From source file:de.ks.flatadocdb.defaults.ReflectionLuceneDocumentExtractor.java

protected Set<DocField> getFields(Class<?> clazz) {

    if (!cache.containsKey(clazz)) {
        @SuppressWarnings("unchecked")
        Set<Field> allFields = ReflectionUtils.getAllFields(clazz, this::filterField);
        Set<DocField> docFields = allFields.stream().map(this::createDocField).filter(Objects::nonNull)
                .collect(Collectors.toSet());
        docFields.forEach(/*from  w  w  w . ja v a 2s . c om*/
                f -> log.debug("Found indexable lucene field {} for {}", f.getField(), clazz.getSimpleName()));
        cache.putIfAbsent(clazz, docFields);
    }
    return cache.get(clazz);
}