Java Code Examples for io.vavr.collection.Stream#of()
The following examples show how to use
io.vavr.collection.Stream#of() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ExtFieldsPojoTest.java From vavr-jackson with Apache License 2.0 | 5 votes |
@Test void testStream() throws Exception { Stream<A> src = Stream.of(new B("a", "b")); String json = MAPPER.writeValueAsString(new StreamPojo().setValue(src)); Assertions.assertEquals(json, "{\"value\":[{\"ExtFieldsPojoTest$B\":{\"a\":\"a\",\"b\":\"b\"}}]}"); StreamPojo pojo = MAPPER.readValue(json, StreamPojo.class); Stream<A> restored = pojo.getValue(); Assertions.assertTrue(restored.get(0) instanceof B); Assertions.assertEquals(restored.get(0).a, "a"); Assertions.assertEquals(((B) restored.get(0)).b, "b"); }
Example 2
Source File: ParameterizedPojoTest.java From vavr-jackson with Apache License 2.0 | 5 votes |
@Test void testStreamOfString() throws Exception { String src0 = "A"; String src1 = "B"; String src2 = "C"; Stream<String> src = Stream.of(src0, src1, src2); String json = MAPPER.writeValueAsString(new ParameterizedStreamPojo<>(src)); Assertions.assertEquals(json, "{\"value\":[\"A\",\"B\",\"C\"]}"); ParameterizedStreamPojo<java.lang.String> restored = MAPPER.readValue(json, new TypeReference<ParameterizedStreamPojo<java.lang.String>>(){}); Assertions.assertEquals(src, restored.getValue()); }
Example 3
Source File: ParameterizedPojoTest.java From vavr-jackson with Apache License 2.0 | 5 votes |
@Test void testStreamOfTuple() throws Exception { String src00 = "A"; String src01 = "B"; Tuple2<String, String> src0 = Tuple.of(src00, src01); Stream<Tuple2<String, String>> src = Stream.of(src0); String json = MAPPER.writeValueAsString(new ParameterizedStreamPojo<>(src)); Assertions.assertEquals(json, "{\"value\":[[\"A\",\"B\"]]}"); ParameterizedStreamPojo<io.vavr.Tuple2<java.lang.String, java.lang.String>> restored = MAPPER.readValue(json, new TypeReference<ParameterizedStreamPojo<io.vavr.Tuple2<java.lang.String, java.lang.String>>>(){}); Assertions.assertEquals(src, restored.getValue()); }
Example 4
Source File: SimplePojoTest.java From vavr-jackson with Apache License 2.0 | 5 votes |
@Test void testStreamOfString() throws Exception { String src0 = "A"; String src1 = "B"; String src2 = "C"; Stream<String> src = Stream.of(src0, src1, src2); String json = MAPPER.writeValueAsString(new StreamOfString().setValue(src)); Assertions.assertEquals(json, "{\"value\":[\"A\",\"B\",\"C\"]}"); StreamOfString restored = MAPPER.readValue(json, StreamOfString.class); Assertions.assertEquals(src, restored.getValue()); }
Example 5
Source File: SimplePojoTest.java From vavr-jackson with Apache License 2.0 | 5 votes |
@Test void testStreamOfTuple() throws Exception { String src00 = "A"; String src01 = "B"; Tuple2<String, String> src0 = Tuple.of(src00, src01); Stream<Tuple2<String, String>> src = Stream.of(src0); String json = MAPPER.writeValueAsString(new StreamOfTuple().setValue(src)); Assertions.assertEquals(json, "{\"value\":[[\"A\",\"B\"]]}"); StreamOfTuple restored = MAPPER.readValue(json, StreamOfTuple.class); Assertions.assertEquals(src, restored.getValue()); }
Example 6
Source File: PolymorphicPojoTest.java From vavr-jackson with Apache License 2.0 | 5 votes |
@Test void testStream() throws Exception { Stream<I> src = Stream.of(new A(), new B()); String json = MAPPER.writeValueAsString(new StreamPojo().setValue(src)); Assertions.assertEquals(json, "{\"value\":[{\"type\":\"a\"},{\"type\":\"b\"}]}"); StreamPojo pojo = MAPPER.readValue(json, StreamPojo.class); Stream<I> restored = pojo.getValue(); Assertions.assertTrue(restored.get(0) instanceof A); Assertions.assertTrue(restored.get(1) instanceof B); }
Example 7
Source File: VavrSampler.java From tutorials with MIT License | 5 votes |
public static void vavrStreamElementAccess() { System.out.println("Vavr Element Access"); System.out.println("===================================="); Stream<Integer> vavredStream = Stream.ofAll(intArray); System.out.println("Vavr index access: " + vavredStream.get(2)); System.out.println("Vavr head element access: " + vavredStream.get()); Stream<String> vavredStringStream = Stream.of("foo", "bar", "baz"); System.out.println("Find foo " + vavredStringStream.indexOf("foo")); }
Example 8
Source File: VavrSampler.java From tutorials with MIT License | 5 votes |
public static void vavrStreamDistinct() { Stream<String> vavredStream = Stream.of("foo", "bar", "baz", "buxx", "bar", "bar", "foo"); Stream<String> distinctVavrStream = vavredStream.distinctBy((y, z) -> { return y.compareTo(z); }); distinctVavrStream.forEach(item -> System.out.println("Vavr Stream item after distinct query " + item)); }
Example 9
Source File: VavrSampler.java From tutorials with MIT License | 5 votes |
public static void vavrStreamElementAccess() { System.out.println("Vavr Element Access"); System.out.println("===================================="); Stream<Integer> vavredStream = Stream.ofAll(intArray); System.out.println("Vavr index access: " + vavredStream.get(2)); System.out.println("Vavr head element access: " + vavredStream.get()); Stream<String> vavredStringStream = Stream.of("foo", "bar", "baz"); System.out.println("Find foo " + vavredStringStream.indexOf("foo")); }
Example 10
Source File: VavrSampler.java From tutorials with MIT License | 5 votes |
public static void vavrStreamDistinct() { Stream<String> vavredStream = Stream.of("foo", "bar", "baz", "buxx", "bar", "bar", "foo"); Stream<String> distinctVavrStream = vavredStream.distinctBy((y, z) -> { return y.compareTo(z); }); distinctVavrStream.forEach(item -> System.out.println("Vavr Stream item after distinct query " + item)); }
Example 11
Source File: CollectionsInteroperabilityUnitTest.java From tutorials with MIT License | 5 votes |
@Test public void givenParams_whenVavrStream_thenReturnJavaStream() { Stream<String> vavrStream = Stream.of("JAVA", "Javascript", "Scala"); java.util.stream.Stream<String> javaParallelStream = vavrStream.toJavaParallelStream(); assertTrue(javaParallelStream instanceof java.util.stream.Stream); java.util.List<String> javaStringList = vavrStream.toJavaList(); assertTrue(javaStringList instanceof java.util.List); }