Example usage for java.util List forEach

List of usage examples for java.util List forEach

Introduction

In this page you can find the example usage for java.util List forEach.

Prototype

default void forEach(Consumer<? super T> action) 

Source Link

Document

Performs the given action for each element of the Iterable until all elements have been processed or the action throws an exception.

Usage

From source file:Main.java

public static void main(String[] args) throws Exception {
    List<Dish> menu = Arrays.asList(new Dish("pork", false, 800, Dish.Type.MEAT),
            new Dish("beef", false, 700, Dish.Type.MEAT), new Dish("chicken", false, 400, Dish.Type.MEAT),
            new Dish("rice", true, 350, Dish.Type.OTHER), new Dish("pizza", true, 550, Dish.Type.OTHER),
            new Dish("prawns", false, 400, Dish.Type.FISH), new Dish("salmon", false, 450, Dish.Type.FISH));
    // Filtering with predicate
    List<Dish> vegetarianMenu = menu.stream().filter(Dish::isVegetarian).collect(Collectors.toList());

    vegetarianMenu.forEach(System.out::println);

}

From source file:Main.java

public static void main(String[] argv) {
    List<Person> persons = new ArrayList<>();
    persons.add(new Person("Joe", 12));
    persons.add(new Person("Jim", 34));
    persons.add(new Person("John", 23));

    List<Person> list = persons.stream().filter(p -> p.getAge() > 18).collect(Collectors.toList());
    list.forEach(p -> System.out.println(p.getFirstName()));

}

From source file:Main.java

public static void main(String[] args) throws Exception {
    List<Dish> menu = Arrays.asList(new Dish("pork", false, 800, Dish.Type.MEAT),
            new Dish("beef", false, 700, Dish.Type.MEAT), new Dish("chicken", false, 400, Dish.Type.MEAT),
            new Dish("rice", true, 350, Dish.Type.OTHER), new Dish("pizza", true, 550, Dish.Type.OTHER),
            new Dish("prawns", false, 400, Dish.Type.FISH), new Dish("salmon", false, 450, Dish.Type.FISH));
    // Skipping elements
    List<Dish> dishesSkip2 = menu.stream().filter(d -> d.getCalories() > 300).skip(2)
            .collect(Collectors.toList());

    dishesSkip2.forEach(System.out::println);

}

From source file:Main.java

public static void main(String[] args) throws Exception {
    List<Dish> menu = Arrays.asList(new Dish("pork", false, 800, Dish.Type.MEAT),
            new Dish("beef", false, 700, Dish.Type.MEAT), new Dish("chicken", false, 400, Dish.Type.MEAT),
            new Dish("rice", true, 350, Dish.Type.OTHER), new Dish("pizza", true, 550, Dish.Type.OTHER),
            new Dish("prawns", false, 400, Dish.Type.FISH), new Dish("salmon", false, 450, Dish.Type.FISH));
    // Truncating a stream
    List<Dish> dishesLimit3 = menu.stream().filter(d -> d.getCalories() > 300).limit(3)
            .collect(Collectors.toList());

    dishesLimit3.forEach(System.out::println);

}

From source file:com.khartec.waltz.jobs.JooqHarness.java

public static void main(String[] args) {

    AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(DIConfiguration.class);

    ApplicationDao appDao = ctx.getBean(ApplicationDao.class);
    ApplicationService appSvc = ctx.getBean(ApplicationService.class);
    DataFlowDao dfDao = ctx.getBean(DataFlowDao.class);
    CapabilityRatingDao capRatDao = ctx.getBean(CapabilityRatingDao.class);
    OrganisationalUnitDao orgDao = ctx.getBean(OrganisationalUnitDao.class);
    AppCapabilityDao appCapDao = ctx.getBean(AppCapabilityDao.class);
    CapabilityDao capDao = ctx.getBean(CapabilityDao.class);
    BookmarkDao bookmarkDao = ctx.getBean(BookmarkDao.class);
    PersonService personDao = ctx.getBean(PersonService.class);

    DSLContext dsl = ctx.getBean(DSLContext.class);

    int FRONT_OFFICE = 260; // app 552
    int EQUITIES = 270; // app 669

    //        appCapDao.findApplicationCapabilitiesForOrgUnit(400).forEach(System.out::println);
    //        System.out.println();
    //        System.out.println();
    //        appCapDao.findCapabilitiesForApp(594).forEach(System.out::println);
    //        System.out.println();
    //        System.out.println();
    ///* www  .  j a  v a2s  .  c om*/
    //        ImmutableGroupedApplications grouped = appCapDao.findGroupedApplicationsByCapability(1200L);
    //
    //        grouped.primaryApps().forEach(System.out::println);
    //        System.out.println("2222222222222");
    //        grouped.secondaryApps().forEach(System.out::println);
    ////
    //
    //        appCapDao.tallyByCapabilityId().forEach(System.out::println);
    //
    //        appCapDao.addCapabilitiesToApp(2010L, ListUtilities.newArrayList(999L));
    //
    //
    //        List<Capability> descendants = capDao.findDescendants(3000);
    //        List<Long> ids = toIds(descendants);
    //        System.out.println(ids);

    //        Bookmark r = bookmarkDao.create(ImmutableBookmark.builder()
    //                .title("test")
    //                .parent(ImmutableEntityReference.builder()
    //                        .id(1)
    //                        .kind(EntityKind.APPLICATION)
    //                        .build())
    //                .kind(BookmarkKind.APPLICATION_INSTANCE)
    //                .description("test desc")
    //                .build());
    //
    //        System.out.println(r);

    List<Person> ellasMgrs = personDao.findAllManagersByEmployeeId("dvkDz0djp");
    ellasMgrs.forEach(m -> System.out.println(m.displayName()));
}

From source file:Main.java

public static void main(String[] argv) {
    List<Person> persons = Arrays.asList(new Person("Joe", 12), new Person("Jim", 34), new Person("John", 23));
    persons.sort((p1, p2) -> p1.getFirstName().compareTo(p2.getFirstName()));
    persons.forEach(p -> System.out.println(p.getFirstName()));
}

From source file:com.github.fhuss.kafka.streams.cep.demo.CEPStockKStreamsDemo.java

public static void main(String[] args) {

    Properties props = new Properties();
    props.put(StreamsConfig.APPLICATION_ID_CONFIG, "streams-cep");
    props.put(StreamsConfig.BOOTSTRAP_SERVERS_CONFIG, "localhost:9092");
    props.put(StreamsConfig.ZOOKEEPER_CONNECT_CONFIG, "localhost:2181");
    props.put(StreamsConfig.KEY_SERDE_CLASS_CONFIG, StockEventSerDe.class);
    props.put(StreamsConfig.VALUE_SERDE_CLASS_CONFIG, StockEventSerDe.class);

    // setting offset reset to earliest so that we can re-run the demo code with the same pre-loaded data
    props.put(ConsumerConfig.AUTO_OFFSET_RESET_CONFIG, "earliest");

    // build query
    final Pattern<Object, StockEvent> pattern = new QueryBuilder<Object, StockEvent>().select()
            .where((k, v, ts, store) -> v.volume > 1000).<Long>fold("avg", (k, v, curr) -> v.price).then()
            .select().zeroOrMore().skipTillNextMatch()
            .where((k, v, ts, state) -> v.price > (long) state.get("avg"))
            .<Long>fold("avg", (k, v, curr) -> (curr + v.price) / 2)
            .<Long>fold("volume", (k, v, curr) -> v.volume).then().select().skipTillNextMatch()
            .where((k, v, ts, state) -> v.volume < 0.8 * state.getOrElse("volume", 0L))
            .within(1, TimeUnit.HOURS).build();

    KStreamBuilder builder = new KStreamBuilder();

    CEPStream<Object, StockEvent> stream = new CEPStream<>(builder.stream("StockEvents"));

    KStream<Object, Sequence<Object, StockEvent>> stocks = stream.query("Stocks", pattern);

    stocks.mapValues(seq -> {//  w  ww  .  j  a  v a2 s .com
        JSONObject json = new JSONObject();
        seq.asMap().forEach((k, v) -> {
            JSONArray events = new JSONArray();
            json.put(k, events);
            List<String> collect = v.stream().map(e -> e.value.name).collect(Collectors.toList());
            Collections.reverse(collect);
            collect.forEach(e -> events.add(e));
        });
        return json.toJSONString();
    }).through(null, Serdes.String(), "Matches").print();

    //Use the topologyBuilder and streamingConfig to start the kafka streams process
    KafkaStreams streaming = new KafkaStreams(builder, props);
    //streaming.cleanUp();
    streaming.start();
}

From source file:com.teslagov.joan.example.Main.java

public static void main(String[] args) throws Exception {
    Properties properties = ArcPropertiesFactory.createArcProperties();

    ArcConfiguration arcConfiguration = arcConfig().arcPortalConfiguration(portalConfig()
            .portalAdminUsername(properties.getString(ArcProperties.PORTAL_ADMIN_USERNAME))
            .portalAdminPassword(properties.getString(ArcProperties.PORTAL_ADMIN_PASSWORD))
            .portalUrl(properties.getString(ArcProperties.PORTAL_URL))
            .portalPort(properties.getInteger(ArcProperties.PORTAL_PORT))
            .portalContextPath(properties.getString(ArcProperties.PORTAL_CONTEXT_PATH))
            .portalIsUsingWebAdaptor(properties.getBoolean(ArcProperties.PORTAL_IS_USING_WEB_ADAPTOR)).build())
            .build();/*from   ww w  .j av  a  2 s .c  o  m*/

    HttpClient httpClient = TrustingHttpClientFactory.createVeryUnsafePortalHttpClient(arcConfiguration, null);

    ArcPortalConfiguration arcPortalConfiguration = arcConfiguration.getArcPortalConfiguration();

    ArcPortalApi arcPortalApi = new ArcPortalApi(httpClient, arcPortalConfiguration, ZoneOffset.UTC,
            new TokenManager(new TokenRefresher(new PortalTokenFetcher(httpClient, arcPortalConfiguration),
                    ZoneOffset.UTC)));

    UserListResponse userListResponse = arcPortalApi.userApi.fetchUsers();
    if (userListResponse.isSuccess()) {
        List<UserResponseModel> users = userListResponse.users;
        users.forEach(u -> logger.debug("User {}", u));
    }

    String username = UUID.randomUUID().toString();
    String id = null;
    String publishedId = null;
    String groupId = null;

    try {
        groupId = createGroupExample(arcPortalApi);

        createNewUserExample(arcPortalApi, username);

        id = uploadItemExample(arcPortalApi, username);

        String analyzeResponse = arcPortalApi.itemApi.analyzeItem(id);

        publishedId = publishItemExample(arcPortalApi, id, username, analyzeResponse);

        shareItemExample(arcPortalApi, publishedId, username, groupId);

        deleteItemExample(arcPortalApi, id, username);

        deleteItemExample(arcPortalApi, publishedId, username);

        removeUserExample(arcPortalApi, username);

        deleteGroupExample(arcPortalApi, groupId);
    } catch (Exception e) {
        if (id != null) {
            arcPortalApi.itemApi.deleteItem(id, username);
        }

        if (publishedId != null) {
            arcPortalApi.itemApi.deleteItem(publishedId, username);
        }

        if (groupId != null) {
            arcPortalApi.groupApi.deleteGroup(groupId);
        }

        arcPortalApi.userApi.deleteUser(username);

        logger.debug("Exception occured {}", e.getMessage());
    }
}

From source file:blog.attributes.DetectGenderAgeFromFileExample.java

public static void main(String[] args) throws IOException {
    FaceScenarios faceScenarios = new FaceScenarios(System.getProperty("azure.cognitive.subscriptionKey"),
            System.getProperty("azure.cognitive.emotion.subscriptionKey"));
    File imageFile = File.createTempFile("DetectSingleFaceFromFileExample", "pic");
    //create a new java.io.File from a remote file
    FileUtils.copyURLToFile(new URL(IMAGE_LOCATION), imageFile);
    FileUtils.forceDeleteOnExit(imageFile);
    ImageOverlayBuilder imageOverlayBuilder = ImageOverlayBuilder.builder(imageFile);
    CognitiveJColourPalette colourPalette = CognitiveJColourPalette.STRAWBERRY;
    List<Face> faces = faceScenarios.findFaces(imageFile);
    faces.forEach(face -> imageOverlayBuilder.outlineFaceOnImage(face, RectangleType.FULL,
            ImageOverlayBuilder.DEFAULT_BORDER_WEIGHT, colourPalette)
            .writeAge(face, colourPalette, RectangleTextPosition.TOP_OF));
    imageOverlayBuilder.launchViewer();/* w w  w. j a  v  a2s. c o  m*/

}

From source file:Main.java

public static void main(String[] args) {
    List<Person> people = new ArrayList<Person>();
    people.add(new Person("C", 21));
    people.add(new Person("T", 20));
    people.add(new Person("B", 35));
    people.add(new Person("A", 22));
    people.sort(Comparator.comparing(Person::getName));
    people.forEach(System.out::println);
}