Example usage for java.util.stream Collectors toList

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

Introduction

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

Prototype

public static <T> Collector<T, ?, List<T>> toList() 

Source Link

Document

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

Usage

From source file:com.thoughtworks.go.domain.AllConfigErrors.java

public String asString() {
    return StringUtils.join(this.stream().map(new Function<ConfigErrors, String>() {
        @Override// w w  w. j  av  a  2s .  co m
        public String apply(ConfigErrors errors) {
            return errors.asString();
        }
    }).collect(Collectors.toList()), ", ");
}

From source file:com.simiacryptus.mindseye.applications.HadoopUtil.java

/**
 * Gets files./*  www  .  j a  va 2s . c o  m*/
 *
 * @param file the file
 * @return the files
 */
public static List<CharSequence> getFiles(CharSequence file) {
    try {
        FileSystem fileSystem = getFileSystem(file);
        Path path = new Path(file.toString());
        if (!fileSystem.exists(path))
            throw new IllegalStateException(path + " does not exist");
        List<CharSequence> collect = toStream(fileSystem.listFiles(path, false)).map(FileStatus::getPath)
                .map(Path::toString).collect(Collectors.toList());
        collect.stream().forEach(child -> {
            try {
                if (!fileSystem.exists(new Path(child.toString())))
                    throw new IllegalStateException(child + " does not exist");
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        });
        return collect;
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}

From source file:com.miserablemind.api.consumer.tradeking.api.impl.response_entities.TKAllWatchListsResponse.java

@JsonSetter("watchlists")
@SuppressWarnings("unchecked")
public void setWatchLists(LinkedHashMap<String, Object> watchListsResponse) {

    ArrayList<String> resultList = new ArrayList<>();

    Object list = watchListsResponse.get("watchlist");

    ArrayList<LinkedHashMap<String, String>> itemList = new ArrayList<>();

    if (list.getClass() == ArrayList.class) {
        //we know from condition this is right
        itemList = (ArrayList) list;
    } else {/* w ww  .  ja va2 s.  com*/
        itemList.add((LinkedHashMap) watchListsResponse.get("watchlist"));
    }

    resultList.addAll(itemList.stream().map(item -> item.get("id")).collect(Collectors.toList()));

    this.watchLists = new String[resultList.size()];
    this.watchLists = resultList.toArray(this.watchLists);

}

From source file:de.dhbw.vetaraus.SanitizeUtils.java

public static List<Case> sanitizeCases(List<Case> cases) {
    return cases.stream()
            .map(c -> new Case(c.getNumber(), sanitizeRecordValue(c.getAge()),
                    sanitizeRecordValue(c.getGender()), sanitizeRecordValue(c.getMarried()),
                    sanitizeRecordValue(c.getChildCount()), sanitizeRecordValue(c.getDegree()),
                    sanitizeRecordValue(c.getOccupation()), sanitizeRecordValue(c.getIncome()), c.getTariff()))
            .collect(Collectors.toList());
}

From source file:br.com.Summoner.core.base.cartas.monk.MonkCard.java

@Override
public long CalculaBonus(Jogada jogada, List<Card> listaMonstrosAdversarios) {
    List<Card> cartasUtilizadasCombo = jogada.CartasUtilizadas.stream()
            .filter(carta -> carta.TipoCarta == TipoCarta.Item && carta.TipoMonstro == TipoMonstro.Monk)
            .collect(Collectors.toList());
    MonkComboResult comboResult = new MonkComboResult();
    long forcaBonus = 0;

    if (cartasUtilizadasCombo.size() > 0) {
        String[] golpesCombo = cartasUtilizadasCombo
                .stream().map(carta -> ((MonkItemCard) carta).Golpes.stream()
                        .map(golpe -> golpe.tipoGolpe.toString()).collect(Collectors.joining()))
                .collect(Collectors.joining()).split("");
        Arrays.sort(golpesCombo);
        String comboRealizado = StringUtils.join(Arrays.asList(golpesCombo), "");
        comboResult.ComboRealizado = comboRealizado;
        //          comboResult.CombosCarta.addAll(this.Combos);

        for (int i = 0; i < this.Combos.size(); i++) {
            MonkMonsterCombo combo = this.Combos.get(i);

            char[] criaturaCombo = combo.CombinacaoCombo.toCharArray();
            Arrays.sort(criaturaCombo);
            String comboDaCriatura = new String(criaturaCombo);

            boolean encontrou = comboRealizado.contains(comboDaCriatura);

            if (encontrou && forcaBonus < combo.DanoCombo) {

                forcaBonus = combo.DanoCombo;
                comboResult.ValorComboRealizado = forcaBonus;
                comboResult.ComboCriatura = comboDaCriatura;

            }//from   www . j  a v  a2 s .  co m
        }

        CombosRealizados.add(comboResult);
    }

    return forcaBonus;
}

From source file:io.kamax.mxisd.profile.ProfileManager.java

public ProfileManager(List<ProfileProvider> providers) {
    this.providers = providers.stream().filter(ProfileProvider::isEnabled).collect(Collectors.toList());
}

From source file:com.groovycoder.BookService.java

public Collection<Book> listAvailableBooks() {
    Collection<Book> existingBooks = bookRepository.findAll();

    Collection<Book> availableBooks = existingBooks.stream().filter(Book::isAvailable)
            .collect(Collectors.toList());

    return availableBooks;
}

From source file:io.fabric8.che.starter.util.WorkspaceHelper.java

public List<Workspace> filterByRepository(final List<Workspace> workspaces, final String repository) {
    return workspaces.stream().filter(w -> {
        String description = w.getConfig().getDescription();
        return description != null && description.split(REPO_BRANCH_DELIMITER)[0].equals(repository);
    }).collect(Collectors.toList());
}

From source file:com.netflix.spinnaker.echo.pubsub.PubsubSubscriptionController.java

@RequestMapping(value = "/pubsub/subscriptions", method = RequestMethod.GET)
List<String> getSubscriptions() {
    return pubsubSubscribers.getAll().stream().map(s -> s.getName()).collect(Collectors.toList());
}

From source file:com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.distributed.kubernetes.v1.ResourceBuilder.java

static Container buildContainer(String name, ServiceSettings settings, List<ConfigSource> configSources,
        DeploymentEnvironment deploymentEnvironment) {
    int port = settings.getPort();
    List<EnvVar> envVars = settings.getEnv().entrySet().stream().map(e -> {
        EnvVarBuilder envVarBuilder = new EnvVarBuilder();
        return envVarBuilder.withName(e.getKey()).withValue(e.getValue()).build();
    }).collect(Collectors.toList());

    configSources.forEach(c -> {// w  w  w . jav a 2  s .c o m
        c.getEnv().entrySet().forEach(envEntry -> {
            EnvVarBuilder envVarBuilder = new EnvVarBuilder();
            envVars.add(envVarBuilder.withName(envEntry.getKey()).withValue(envEntry.getValue()).build());
        });
    });

    ProbeBuilder probeBuilder = new ProbeBuilder();

    String scheme = settings.getScheme();
    if (StringUtils.isNotEmpty(scheme)) {
        scheme = scheme.toUpperCase();
    } else {
        scheme = null;
    }

    if (settings.getHealthEndpoint() != null) {
        probeBuilder = probeBuilder.withNewHttpGet().withNewPort(port).withPath(settings.getHealthEndpoint())
                .withScheme(scheme).endHttpGet();
    } else {
        probeBuilder = probeBuilder.withNewTcpSocket().withNewPort().withIntVal(port).endPort().endTcpSocket();
    }

    List<VolumeMount> volumeMounts = configSources.stream().map(c -> {
        return new VolumeMountBuilder().withMountPath(c.getMountPath()).withName(c.getId()).build();
    }).collect(Collectors.toList());

    ContainerBuilder containerBuilder = new ContainerBuilder();
    containerBuilder = containerBuilder.withName(name).withImage(settings.getArtifactId())
            .withPorts(new ContainerPortBuilder().withContainerPort(port).build())
            .withVolumeMounts(volumeMounts).withEnv(envVars).withReadinessProbe(probeBuilder.build())
            .withResources(buildResourceRequirements(name, deploymentEnvironment));

    return containerBuilder.build();
}