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:com.anathema_roguelike.main.utilities.Utils.java

public static <T, E> Set<T> getKeysByValue(Map<T, E> map, E value) {
    return map.entrySet().stream().filter(entry -> Objects.equals(entry.getValue(), value))
            .map(Map.Entry::getKey).collect(Collectors.toSet());
}

From source file:ddf.catalog.validation.impl.validator.ISO3CountryCodeValidator.java

public ISO3CountryCodeValidator(final boolean ignoreCase) {
    this.ignoreCase = ignoreCase;

    StandardProvider standardProvider = StandardRegistryImpl.getInstance().lookup(ISO_3166, VERSION);

    if (standardProvider == null) {
        throw new IllegalStateException(
                "StandardProvider lookup failed for [" + ISO_3166 + ", " + VERSION + "]");
    }/*ww  w .j  a v a2 s .  com*/

    countryCodes = standardProvider.getStandardEntries().stream().map(cc -> cc.getAsFormat("alpha3"))
            .collect(Collectors.toSet());
}

From source file:io.gravitee.repository.redis.management.RedisGroupRepository.java

@Override
public Set<Group> findByType(Group.Type type) throws TechnicalException {
    return internalRepository.findByType(type.name()).stream().map(this::convert).collect(Collectors.toSet());
}

From source file:org.artifactory.ui.rest.service.artifacts.browse.treebrowser.tabs.general.licenses.SetLicensesOnPathService.java

@Override
public void execute(ArtifactoryRestRequest request, RestResponse response) {
    RepoPath path = RequestUtils.getPathFromRequest(request);
    if (!authService.canAnnotate(path)) {
        response.error("Insufficient permissions for operation").responseCode(HttpStatus.SC_UNAUTHORIZED);
        return;/* w w w .  j  a v a2s.  c o m*/
    }
    LicensesAddon licensesAddon = addonsManager.addonByType(LicensesAddon.class);
    List<GeneralTabLicenseModel> newLicensesNames = request.getModels();
    Set<LicenseInfo> newLicenses = newLicensesNames.stream().map(this::trimUnknownFromName)
            .map(licensesAddon::getLicenseByName).collect(Collectors.toSet());
    if (CollectionUtils.isNullOrEmpty(newLicenses)) {
        log.debug("Request sent with empty license set - deleting license properties from path {}", path);
        propertiesService.deleteProperty(path, LicensesAddon.LICENSES_PROP_FULL_NAME);
        propertiesService.deleteProperty(path, LicensesAddon.LICENSES_UNKNOWN_PROP_FULL_NAME);
        response.info("Successfully updated License information");
    } else {
        if (licensesAddon.setLicensePropsOnPath(path, newLicenses)) {
            response.info("Successfully updated License information");
        } else {
            response.error("Failed to update license information - check the log for more information")
                    .responseCode(HttpStatus.SC_BAD_REQUEST);
        }
    }
}

From source file:eu.itesla_project.modules.topo.PrintSubstationTopoHistoryTool.java

private static Map<Set<TopoBus>, AtomicInteger> translate(Map<Set<TopoBus>, AtomicInteger> topos,
        ShortIdDictionary dict) {//from w ww  . j a va  2 s.  c o  m
    Map<Set<TopoBus>, AtomicInteger> topos2 = new LinkedHashMap<>();
    for (Map.Entry<Set<TopoBus>, AtomicInteger> e : topos.entrySet()) {
        Set<TopoBus> topo = e.getKey();
        AtomicInteger count = e.getValue();
        Set<TopoBus> topo2 = new HashSet<>();
        for (TopoBus b : topo) {
            topo2.add(new TopoBus(
                    b.getEquipments().stream().map(s -> dict.getShortId(s)).collect(Collectors.toSet()),
                    b.getSubstation()));
        }
        topos2.put(topo2, count);
    }
    return topos2;
}

From source file:org.trustedanalytics.servicecatalog.security.JwtUserDetailsTokenConverter.java

@SuppressWarnings("unchecked")
private Collection<? extends GrantedAuthority> getAuthorities(Map<String, ?> map) {
    if (!map.containsKey(SCOPE)) {
        return Collections.emptySet();
    }//from  w w  w.j ava 2s  .c o  m

    return ((Collection<String>) map.get(SCOPE)).stream().map(v -> new SimpleGrantedAuthority(v))
            .collect(Collectors.toSet());
}

From source file:io.gravitee.repository.redis.management.internal.impl.ApplicationRedisRepositoryImpl.java

@Override
public Set<RedisApplication> findAll() {
    Map<Object, Object> applications = redisTemplate.opsForHash().entries(REDIS_KEY);

    return applications.values().stream().map(object -> convert(object, RedisApplication.class))
            .collect(Collectors.toSet());
}

From source file:io.gravitee.repository.redis.management.RedisApplicationRepository.java

@Override
public Set<Application> findByName(String partialName) throws TechnicalException {
    return applicationRedisRepository.findByName(partialName).stream().map(this::convert)
            .collect(Collectors.toSet());
}

From source file:se.uu.it.cs.recsys.constraint.api.SolverAPI.java

private static Set<Integer> getInterestedCourseIdCollections() {

    return Stream.of(118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135,
            136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155,
            156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175,
            176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195,
            196, 197, 198, 199, 200, 201, 202, 203, 204, 205, 206, 207, 208, 209, 210, 211, 212, 213, 214, 215,
            216, 217, 218, 219, 220, 221, 222, 223, 224, 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 235,
            236, 237, 238, 239, 240, 241, 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, 253, 254, 255,
            256, 257, 258, 259, 260, 261, 262, 263, 264, 265, 266, 267, 268, 269, 270, 271, 272, 273, 274, 275)
            .collect(Collectors.toSet());

}

From source file:com.grayfox.server.dao.foursquare.PoiFoursquareDao.java

protected List<Poi> fetchNext(FoursquareApi foursquareApi, String poiFoursquareId, int limit) {
    Result<Venue> venueResult = foursquareApi.getVenue(poiFoursquareId);
    if (venueResult.getMeta().getCode() == 200) {
        Poi seed = toPoi(venueResult.getResponse());
        Set<String> categoryIds = new HashSet<>();
        categoryIds.addAll(//from   w w  w.ja  v  a2s  . co  m
                seed.getCategories().stream().map(Category::getFoursquareId).collect(Collectors.toSet()));
        List<Poi> pois = new ArrayList<>(limit);
        Poi currentPoi = seed;
        for (int numberOfPois = 0; numberOfPois < limit - 1; numberOfPois++) {
            Result<Group<Venue>> nextVenues = foursquareApi.getNextVenues(currentPoi.getFoursquareId());
            if (nextVenues.getMeta().getCode() == 200) {
                for (Venue venue : nextVenues.getResponse().getItems()) {
                    currentPoi = toPoi(venue);
                    final String currentFoursquarId = venue.getId();
                    List<Poi> matchingPois = pois.stream()
                            .filter(poi -> poi.getFoursquareId().equals(currentFoursquarId))
                            .collect(Collectors.toList());
                    if (matchingPois.isEmpty()) {
                        boolean existsCategory = false;
                        for (Category currentPoiCategory : currentPoi.getCategories()) {
                            if (!categoryIds.add(currentPoiCategory.getFoursquareId())) {
                                existsCategory = true;
                                break;
                            }
                        }
                        if (!existsCategory) {
                            pois.add(currentPoi);
                            break;
                        }
                    }
                }
            } else {
                LOGGER.error(
                        "Foursquare error while requesting [venues/{}/nextvenues] [code={}, errorType={}, errorDetail={}]",
                        currentPoi.getFoursquareId(), nextVenues.getMeta().getCode(),
                        nextVenues.getMeta().getErrorType(), nextVenues.getMeta().getErrorDetail());
                throw new DaoException.Builder().messageKey("foursquare.request.error")
                        .addMessageArgument(nextVenues.getMeta().getErrorDetail()).build();
            }
        }
        return pois;
    } else {
        LOGGER.error("Foursquare error while requesting [venues/{}] [code={}, errorType={}, errorDetail={}]",
                poiFoursquareId, venueResult.getMeta().getCode(), venueResult.getMeta().getErrorType(),
                venueResult.getMeta().getErrorDetail());
        throw new DaoException.Builder().messageKey("foursquare.request.error")
                .addMessageArgument(venueResult.getMeta().getErrorDetail()).build();
    }
}