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.infinitechaos.vpcviewer.web.rest.dto.SubnetDTO.java

public SubnetDTO(final Subnet subnet) {
    this.subnetId = subnet.getSubnetId();
    this.vpcId = subnet.getVpcId();
    this.state = subnet.getState();
    this.availabilityZone = subnet.getAvailabilityZone();
    this.cidrBlock = subnet.getCidrBlock();

    this.tags.addAll(subnet.getTags().stream().map(TagDTO::new).collect(Collectors.toList()));

    this.name = subnet.getTags().stream().filter(t -> t.getKey().equals("Name")).findFirst().map(Tag::getValue)
            .orElse("n/a");
}

From source file:enmasse.broker.prestop.QueueDrainerTest.java

private static void sendMessages(TestBroker broker, String prefix, int numMessages)
        throws IOException, InterruptedException {
    List<String> messages = IntStream.range(0, numMessages).mapToObj(i -> prefix + i)
            .collect(Collectors.toList());
    broker.sendMessages(messages);//from  w ww .  j a va  2s  .com
}

From source file:org.obiba.mica.file.search.rest.DraftFilesSearchResource.java

@Override
protected List<Mica.FileDto> searchFiles(int from, int limit, String sort, String order, String queryString) {
    PublishedDocumentService.Documents<AttachmentState> states = esAttachmentService.find(from, limit, sort,
            order, getBasePath(), queryString);

    return states.getList().stream().filter(this::isPermitted).map(state -> dtos.asFileDto(state, false, false))
            .collect(Collectors.toList());
}

From source file:edu.vassar.cs.cmpu331.tvi.Main.java

private static void renumber(String filename) throws IOException {
    Path file = Paths.get(filename);
    if (Files.notExists(file)) {
        System.out.println("File not found: " + filename);
        return;//  w  ww .j  ava  2 s.c o m
    }
    System.out.println("Renumbering " + filename);
    Function<String, String> trim = s -> {
        int i = s.indexOf(':');
        if (i > 0) {
            return s.substring(i + 1).trim();
        }
        return s.trim();
    };
    List<String> list = Files.lines(file).filter(line -> !line.startsWith("CODE")).map(line -> trim.apply(line))
            .collect(Collectors.toList());
    int size = list.size();
    PrintWriter writer = new PrintWriter(Files.newBufferedWriter(file));
    //      PrintStream writer = System.out;
    writer.println("CODE");
    IntStream.range(0, size).forEach(index -> {
        String line = list.get(index);

        writer.println(index + ": " + line);
    });
    writer.close();
    System.out.println("Done.");
}

From source file:io.stallion.utils.TestLiterals.java

@Test
public void testFilterApply() {
    List<Book> books = list(new Book().setTitle("alpha"), new Book().setTitle("beta"));

    books.stream().filter(b -> {/*w  ww  . j a v a  2  s.c o m*/
        return !empty(b.getTitle()) && !empty(b.getAuthor());
    }).collect(Collectors.toList());
    books.stream().filter(b -> !empty(b.getTitle())).map(b -> b.getTitle()).collect(Collectors.toList());
    apply(filter(books, b -> !empty(b.getTitle())), b -> b.getTitle());
    List<String> titles = apply(filter(books, b -> !empty(b.getTitle())), b -> b.getTitle());

}

From source file:com.thoughtworks.go.server.cache.CacheKeyGenerator.java

public String generate(String identifier, Object... args) {
    final List<Object> allArgs = Arrays.stream(args).map(arg -> {
        if (isAllowed(arg)) {
            return arg;
        }//from w  w w.jav  a 2  s.  c  o  m
        throw new IllegalArgumentException("Type " + arg.getClass() + " is not allowed here!");
    }).map(arg -> {
        if (arg instanceof CaseInsensitiveString) {
            return ((CaseInsensitiveString) arg).toLower();
        } else {
            return arg;
        }
    }).collect(Collectors.toList());

    allArgs.add(0, clazz.getName());
    allArgs.add(1, identifier);

    return StringUtils.join(allArgs, DELIMITER).intern();
}

From source file:com.davidmogar.alsa.services.bus.internal.BusManagerServiceImpl.java

@Override
public Page<BusDto> findAll(int pageIndex) {
    Pageable pageable = createPageable(pageIndex);
    Page<Bus> page = busDataService.findAll(pageable);

    List<BusDto> users = page.getContent().stream().map(BusDto::new).collect(Collectors.toList());

    return new PageImpl<>(users, pageable, page.getTotalElements());
}

From source file:com.hp.autonomy.hod.client.api.authentication.SignedRequest.java

static SignedRequest sign(final Hmac hmac, final String endpoint,
        final AuthenticationToken<?, TokenType.HmacSha1> token, final Request<String, String> request) {
    final URIBuilder uriBuilder;

    try {//w  ww . j  a va  2 s.c om
        uriBuilder = new URIBuilder(endpoint + request.getPath());
    } catch (final URISyntaxException e) {
        throw new IllegalArgumentException("Invalid endpoint or request path");
    }

    if (request.getQueryParameters() != null) {
        for (final Map.Entry<String, List<String>> entry : request.getQueryParameters().entrySet()) {
            for (final String value : entry.getValue()) {
                uriBuilder.addParameter(entry.getKey(), value);
            }
        }
    }

    final String bodyString;

    if (request.getBody() == null) {
        bodyString = null;
    } else {
        final List<NameValuePair> pairs = new LinkedList<>();

        for (final Map.Entry<String, List<String>> entry : request.getBody().entrySet()) {
            pairs.addAll(entry.getValue().stream().map(value -> new BasicNameValuePair(entry.getKey(), value))
                    .collect(Collectors.toList()));
        }

        bodyString = URLEncodedUtils.format(pairs, UTF8);
    }

    final String tokenString = hmac.generateToken(request, token);
    return new SignedRequest(uriBuilder.toString(), request.getVerb(), bodyString, tokenString);
}

From source file:pl.java.scalatech.generator.UserGeneratorTest.java

@Test
public void test() {
    RandomPersonService rps = new RandomPersonService();
    List<User> users = rps.generate(20).collect(Collectors.toList());
    log.info(".... {}", users);
}

From source file:com.wrmsr.wava.yen.translation.UnitTranslation.java

public static Function translateFunction(YFunction function, Map<Name, Signature> functionSignatures) {
    requireNonNull(function);/* w w w  .  j a v  a 2 s  .c o  m*/
    checkArgument(function.getName().isPresent());
    checkArgument(function.getResult() != Type.UNREACHABLE);
    checkArgument(function.getBody().isPresent());
    checkArgument(function.getLocalNames().size() == function.getNumLocals());
    checkArgument(function.getLocalIndices().size() == function.getNumLocals());
    List<Pair<Name, Index>> localList = function.getLocalIndices().entrySet().stream()
            .map(e -> ImmutablePair.of(e.getKey(), e.getValue())).collect(Collectors.toList());
    localList.sort((l, r) -> l.getValue().compareTo(r.getValue()));
    checkArgument(
            enumerate(localList.stream().map(Pair::getRight)).allMatch(e -> e.getItem().get() == e.getIndex()));
    Locals locals = Locals
            .of(localList.stream().map(l -> ImmutablePair.of(l.getLeft(), function.getLocalType(l.getRight())))
                    .collect(toImmutableList()));
    Node body = NodeTranslation.translateNode(function.getBody().get(), functionSignatures);
    return new Function(function.getName().get(), function.getResult(), function.getNumParams(), locals, body);
}