diff --git a/settings.gradle.kts b/settings.gradle.kts index 172e883..1c4c265 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -15,5 +15,5 @@ include( "xml", "jackson", "jsoup", "markdown", "network", "httpd", "properties", "serial-io", "mustache", "thymeleaf", "locale", "quartz", "sysinfo", - "imaging" + "imaging", "stream" ) diff --git a/stream/build.gradle.kts b/stream/build.gradle.kts new file mode 100644 index 0000000..02030a8 --- /dev/null +++ b/stream/build.gradle.kts @@ -0,0 +1,14 @@ +/* + * Examples for Java + * + * Copyright (c) 2021. Elex. All Rights Reserved. + * https://www.elex-project.com/ + */ + +plugins { + id("elex-java") +} + +dependencies { + runtimeOnly ("org.xerial:sqlite-jdbc:3.36.0.1") +} diff --git a/stream/src/main/java/kr/pe/elex/examples/Sample.java b/stream/src/main/java/kr/pe/elex/examples/Sample.java new file mode 100644 index 0000000..8a60fd7 --- /dev/null +++ b/stream/src/main/java/kr/pe/elex/examples/Sample.java @@ -0,0 +1,27 @@ +/* + * Examples for Java + * + * Copyright (c) 2021. Elex. All Rights Reserved. + * https://www.elex-project.com/ + */ + +package kr.pe.elex.examples; + +import lombok.extern.slf4j.Slf4j; + +import java.util.List; +import java.util.stream.Stream; + +@Slf4j +public class Sample { + public static void main(String... args) { + + } + + + public Stream toStream(List list) { + return null == list ? Stream.empty() : list.stream(); + } + + +} diff --git a/stream/src/test/java/kr/pe/elex/examples/SampleTest.java b/stream/src/test/java/kr/pe/elex/examples/SampleTest.java new file mode 100644 index 0000000..52f52c6 --- /dev/null +++ b/stream/src/test/java/kr/pe/elex/examples/SampleTest.java @@ -0,0 +1,92 @@ +/* + * Examples for Java + * + * Copyright (c) 2021. Elex. All Rights Reserved. + * https://www.elex-project.com/ + */ + +package kr.pe.elex.examples; + +import org.junit.jupiter.api.Test; + +import java.io.IOException; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.sql.ResultSet; +import java.util.*; +import java.util.function.Predicate; +import java.util.function.Supplier; +import java.util.function.UnaryOperator; +import java.util.regex.Pattern; +import java.util.stream.*; + +class SampleTest { + + @Test + void create_stream() { + Stream stream1 = Stream.empty(); + + List list = new ArrayList<>(); + Stream stream2 = list.stream(); + + Set set = new HashSet<>(); + Stream stream3 = set.stream(); + + Collection collection = new HashSet<>(); + Stream stream4 = collection.stream(); + + Stream stream5 = Stream.of("1", "2", "3"); + + String[] strings = new String[]{"1", "2", "3"}; + Stream stream6 = Stream.of(strings); + stream6 = Arrays.stream(strings); + + Stream stream7 = Stream.builder() + .add("1").add("2").add("3") + .build(); + + Stream stream8 = Stream.generate(new Supplier() { + private int idx = 0; + + @Override + public String get() { + return strings[idx++]; + } + }).limit(strings.length); + + Stream stream9 = Stream.iterate(strings[0], new Predicate() { + @Override + public boolean test(String s) { + return false; + } + }, new UnaryOperator() { + @Override + public String apply(String s) { + return null; + } + }); + } + + @Test + void test_2() throws IOException { + IntStream stream1 = IntStream.range(0, 10); + IntStream stream2 = IntStream.rangeClosed(0, 10); + + LongStream stream3 = LongStream.range(0, 10); + DoubleStream stream4 = DoubleStream.empty(); + + IntStream stream5 = new Random().ints().limit(10); + + Stream stream6 = "Hello\nWorld".lines(); + IntStream stream7 = "Hello".chars(); + Stream stream8 = Pattern.compile(", ").splitAsStream("1, 2, 3"); + + Path path = Paths.get(""); + Stream stream9 = Files.lines(path, StandardCharsets.UTF_8); + + } + + +} diff --git a/stream/test.db b/stream/test.db new file mode 100644 index 0000000..0cd6005 Binary files /dev/null and b/stream/test.db differ