Example usage for java.util.stream Collectors toCollection

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

Introduction

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

Prototype

public static <T, C extends Collection<T>> Collector<T, ?, C> toCollection(Supplier<C> collectionFactory) 

Source Link

Document

Returns a Collector that accumulates the input elements into a new Collection , in encounter order.

Usage

From source file:com.epam.ta.reportportal.info.ExtensionsInfoContributor.java

@Override
public Map<String, ?> contribute() {
    Set<String> collect = discoveryClient.getServices().stream()
            .flatMap(service -> discoveryClient.getInstances(service).stream())
            .filter(instance -> instance.getMetadata().containsKey(EXTENSION_KEY))
            .map(instance -> instance.getMetadata().get(EXTENSION_KEY))
            .collect(Collectors.toCollection(TreeSet::new));
    return ImmutableMap.<String, Object>builder().put(BUGTRACKING_KEY, collect).build();
}

From source file:org.codice.ddf.registry.rest.endpoint.publication.RegistryPublicationHelper.java

public void publish(String registryId, String sourceId) throws FederationAdminException {
    Metacard mcard = getMetacard(registryId);
    String mcardId = mcard.getId();
    List<Serializable> locations = new ArrayList<>();
    Attribute locAttr = mcard.getAttribute(RegistryObjectMetacardType.PUBLISHED_LOCATIONS);
    if (locAttr != null) {
        locations = new HashSet<>(locAttr.getValues()).stream().map(Object::toString)
                .collect(Collectors.toCollection(ArrayList::new));
    }/*from  w w w.j  a  v a 2s  .  c  o  m*/

    if (locations.contains(sourceId)) {
        return;
    }

    federationAdmin.addRegistryEntry(mcard, Collections.singleton(sourceId));

    //need to reset the id since the framework rest it in the groomer plugin
    //and we don't want to update with the wrong id
    mcard.setAttribute(new AttributeImpl(Metacard.ID, mcardId));
    locations.add(sourceId);
    if (locAttr != null) {
        locAttr.getValues().add(sourceId);
    } else {
        locAttr = new AttributeImpl(RegistryObjectMetacardType.PUBLISHED_LOCATIONS, locations);
    }
    mcard.setAttribute(locAttr);

    federationAdmin.updateRegistryEntry(mcard);

}

From source file:ph.com.fsoft.temp.service.blue.service.PersonServiceImpl.java

@Override
public HashSet<PersonDto> findByLastName(String firstName) {
    return personRepository
            .findByLastName(firstName).map(person -> new PersonDto(person.getId(), person.getFirstName(),
                    person.getMiddleName(), person.getLastName()))
            .collect(Collectors.toCollection(HashSet::new));
}

From source file:net.jodah.failsafe.internal.actions.DoThrowAction.java

DoThrowAction(ActionRegistry<R>.Expectation expectation, String name,
        Class<? extends Throwable>... throwables) {
    super(expectation, name);
    Validate.notNull(throwables, "invalid null throwables");
    Validate.noNullElements(throwables, "invalid null throwable");
    this.arguments = Arrays.asList(throwables);
    this.throwables = Stream.of(throwables).map(t -> ThrowableSupport.instantiate(controller, t))
            .collect(Collectors.toCollection(LinkedList::new));
    this.current = Collections.synchronizedList(new LinkedList<>(this.throwables));
}

From source file:org.hsweb.web.controller.login.UserModuleController.java

@RequestMapping
@Authorize//www  .  j a  v a 2s  .c  om
@AccessLogger("??")
public ResponseMessage userModule() throws Exception {
    String[] includes = { "name", "id", "parentId", "icon", "uri", "optional" };
    User user = WebUtil.getLoginUser();
    List<Module> modules;
    if (user == null) {
        QueryParam queryParam = new QueryParam();
        queryParam.includes(includes).orderBy("sortIndex");
        modules = moduleService.select(queryParam);
        modules = modules.stream().filter(module -> {
            Object obj = module.getOptionalMap().get("M");
            if (obj instanceof Map)
                return StringUtils.isTrue(((Map) obj).get("checked"));
            return false;
        }).collect(Collectors.toCollection(() -> new LinkedList<>()));
    } else {
        modules = user.getModules().stream().filter(module -> user.hasAccessModuleAction(module.getId(), "M"))
                .sorted().collect(Collectors.toList());
    }

    return ResponseMessage.ok(modules).include(Module.class, includes).exclude(Module.class, "optional")
            .onlyData();
}

From source file:com.yahoo.bard.webservice.config.ModuleLoader.java

/**
 * Get a stream of configurations in descending order of precedence given a list of dependent modules.
 *
 * @param dependentModules  The list of modules which are depended on
 *
 * @return A stream of module configurations in descending order of precedence
 *//*from   w w  w .ja v  a2 s  . co  m*/
public Stream<Configuration> getConfigurations(List<String> dependentModules) {
    LOG.debug("Resolving dependent modules: {}", dependentModules);
    ConfigurationGraph graph = loadConfigurationGraph();

    Iterable<String> reverseList = () -> dependentModules.stream()
            .collect(Collectors.toCollection(LinkedList::new)).descendingIterator();

    // Because we want the configurations in precedence order, process the dependent modules from right to left,
    // deduping redundant (repeated with lower precedence) dependencies
    return StreamSupport.stream(reverseList.spliterator(), false).flatMap(graph::preOrderRightToLeftTraversal)
            .distinct().map(graph::getConfiguration);
}

From source file:mcnutty.music.get.ProcessQueue.java

QueueItem next_item() {
    //Return an enpty item if there is nothing to play
    if (bucket_queue.isEmpty()) {
        return new QueueItem();
    }//from ww  w. jav a 2  s.c  om

    //Return the next item in the current bucket
    ArrayList<String> played_ips = bucket_played.stream().map(item -> item.ip)
            .collect(Collectors.toCollection(ArrayList::new));
    for (QueueItem item : bucket_queue) {
        if (!played_ips.contains(item.ip)) {
            return item;
        }
    }

    //If the current bucket it empty, start the next one
    System.out.println("REACHED END OF BUCKET");
    bucket_played.clear();
    return next_item();
}

From source file:com.yahoo.bard.webservice.druid.model.aggregation.FilteredAggregation.java

@JsonIgnore
@Override/*w w w .  ja  v a 2s  . c o m*/
public Set<Dimension> getDependentDimensions() {
    return Stream.concat(aggregation.getDependentDimensions().stream(), getFilterDimensions().stream())
            .collect(Collectors.toCollection(LinkedHashSet::new));
}

From source file:com.thoughtworks.go.server.service.WebpackAssetsService.java

public Set<String> getJSAssetPathsFor(String... assetNames) throws IOException {
    return getAssetPathsFor(assetNames).stream().filter(assetName -> assetName.endsWith(".js"))
            .collect(Collectors.toCollection(LinkedHashSet::new));
}

From source file:edu.wpi.checksims.token.TokenList.java

/**
 * Perform a deep copy of a TokenList.//from  ww w. ja  v  a  2 s. c o m
 *
 * TODO add a copy constructor as well
 *
 * @param cloneFrom List to deep copy
 * @return Cloned copy of the tokenization list
 */
public static TokenList cloneTokenList(TokenList cloneFrom) {
    checkNotNull(cloneFrom);

    Supplier<TokenList> tokenListSupplier = () -> new TokenList(cloneFrom.type);

    return cloneFrom.stream().map(Token::cloneToken).collect(Collectors.toCollection(tokenListSupplier));
}