Java Code Examples for io.vavr.Tuple#of()

The following examples show how to use io.vavr.Tuple#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 6 votes vote down vote up
@Test
void testTuple6() throws Exception {
    Tuple6<A, A, A, A, A, A> src = Tuple.of(new B("a", "b"), new B("a", "b"), new B("a", "b"), new B("a", "b"), new B("a", "b"), new B("a", "b"));
    String json = MAPPER.writeValueAsString(new Tuple6Pojo().setValue(src));
    Assertions.assertEquals(json, "{\"value\":[{\"ExtFieldsPojoTest$B\":{\"a\":\"a\",\"b\":\"b\"}},{\"ExtFieldsPojoTest$B\":{\"a\":\"a\",\"b\":\"b\"}},{\"ExtFieldsPojoTest$B\":{\"a\":\"a\",\"b\":\"b\"}},{\"ExtFieldsPojoTest$B\":{\"a\":\"a\",\"b\":\"b\"}},{\"ExtFieldsPojoTest$B\":{\"a\":\"a\",\"b\":\"b\"}},{\"ExtFieldsPojoTest$B\":{\"a\":\"a\",\"b\":\"b\"}}]}");
    Tuple6Pojo pojo = MAPPER.readValue(json, Tuple6Pojo.class);
    Tuple6<A, A, A, A, A, A> restored = pojo.getValue();
    Assertions.assertTrue(restored._1 instanceof B);
    Assertions.assertEquals(restored._1.a, "a");
    Assertions.assertEquals(((B) restored._1).b, "b");
    Assertions.assertTrue(restored._2 instanceof B);
    Assertions.assertEquals(restored._2.a, "a");
    Assertions.assertEquals(((B) restored._2).b, "b");
    Assertions.assertTrue(restored._3 instanceof B);
    Assertions.assertEquals(restored._3.a, "a");
    Assertions.assertEquals(((B) restored._3).b, "b");
    Assertions.assertTrue(restored._4 instanceof B);
    Assertions.assertEquals(restored._4.a, "a");
    Assertions.assertEquals(((B) restored._4).b, "b");
    Assertions.assertTrue(restored._5 instanceof B);
    Assertions.assertEquals(restored._5.a, "a");
    Assertions.assertEquals(((B) restored._5).b, "b");
    Assertions.assertTrue(restored._6 instanceof B);
    Assertions.assertEquals(restored._6.a, "a");
    Assertions.assertEquals(((B) restored._6).b, "b");
}
 
Example 2
Source File: ParameterizedPojoTest.java    From vavr-jackson with Apache License 2.0 6 votes vote down vote up
@Test
void testTuple4OfTuple() throws Exception {
    String src0 = "A";
    String src10 = "B";
    String src11 = "C";
    Tuple2<String, String> src1 = Tuple.of(src10, src11);
    String src20 = "D";
    String src21 = "E";
    Tuple2<String, String> src2 = Tuple.of(src20, src21);
    String src30 = "F";
    String src31 = "1";
    Tuple2<String, String> src3 = Tuple.of(src30, src31);
    Tuple4<String, Tuple2<String, String>, Tuple2<String, String>, Tuple2<String, String>> src = Tuple.of(src0, src1, src2, src3);
    String json = MAPPER.writeValueAsString(new ParameterizedTuple4Pojo<>(src));
    Assertions.assertEquals(json, "{\"value\":[\"A\",[\"B\",\"C\"],[\"D\",\"E\"],[\"F\",\"1\"]]}");
    ParameterizedTuple4Pojo<java.lang.String, io.vavr.Tuple2<java.lang.String, java.lang.String>, io.vavr.Tuple2<java.lang.String, java.lang.String>, io.vavr.Tuple2<java.lang.String, java.lang.String>> restored =
            MAPPER.readValue(json, new TypeReference<ParameterizedTuple4Pojo<java.lang.String, io.vavr.Tuple2<java.lang.String, java.lang.String>, io.vavr.Tuple2<java.lang.String, java.lang.String>, io.vavr.Tuple2<java.lang.String, java.lang.String>>>(){});
    Assertions.assertEquals(src, restored.getValue());
}
 
Example 3
Source File: ParameterizedPojoTest.java    From vavr-jackson with Apache License 2.0 6 votes vote down vote up
@Test
void testLinkedHashMultimapOfSeqTuple() throws Exception {
    String src00 = "A";
    String src010 = "A";
    String src011 = "B";
    Tuple2<String, String> src01 = Tuple.of(src010, src011);
    Tuple2<String, Tuple2<String, String>> src0 = Tuple.of(src00, src01);
    String src10 = "A";
    String src110 = "C";
    String src111 = "D";
    Tuple2<String, String> src11 = Tuple.of(src110, src111);
    Tuple2<String, Tuple2<String, String>> src1 = Tuple.of(src10, src11);
    LinkedHashMultimap<String, Tuple2<String, String>> src = LinkedHashMultimap.withSeq().ofEntries(src0, src1);
    String json = MAPPER.writeValueAsString(new ParameterizedLinkedHashMultimapPojo<>(src));
    Assertions.assertEquals(json, "{\"value\":{\"A\":[[\"A\",\"B\"],[\"C\",\"D\"]]}}");
    ParameterizedLinkedHashMultimapPojo<java.lang.String, io.vavr.Tuple2<java.lang.String, java.lang.String>> restored =
            MAPPER.readValue(json, new TypeReference<ParameterizedLinkedHashMultimapPojo<java.lang.String, 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 6 votes vote down vote up
@Test
void testTuple7OfTuple() throws Exception {
    String src0 = "A";
    String src10 = "B";
    String src11 = "C";
    Tuple2<String, String> src1 = Tuple.of(src10, src11);
    String src20 = "D";
    String src21 = "E";
    Tuple2<String, String> src2 = Tuple.of(src20, src21);
    String src30 = "F";
    String src31 = "1";
    Tuple2<String, String> src3 = Tuple.of(src30, src31);
    String src4 = "A";
    String src50 = "B";
    String src51 = "C";
    Tuple2<String, String> src5 = Tuple.of(src50, src51);
    String src60 = "D";
    String src61 = "E";
    Tuple2<String, String> src6 = Tuple.of(src60, src61);
    Tuple7<String, Tuple2<String, String>, Tuple2<String, String>, Tuple2<String, String>, String, Tuple2<String, String>, Tuple2<String, String>> src = Tuple.of(src0, src1, src2, src3, src4, src5, src6);
    String json = MAPPER.writeValueAsString(new Tuple7OfTuple().setValue(src));
    Assertions.assertEquals(json, "{\"value\":[\"A\",[\"B\",\"C\"],[\"D\",\"E\"],[\"F\",\"1\"],\"A\",[\"B\",\"C\"],[\"D\",\"E\"]]}");
    Tuple7OfTuple restored = MAPPER.readValue(json, Tuple7OfTuple.class);
    Assertions.assertEquals(src, restored.getValue());
}
 
Example 5
Source File: ComplexClass.java    From vavr-jackson with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
public static ComplexClass build() {
    return new ComplexClass(
            HashMap.of(Tuple.of("42", ComplexInnerClass.build())),
            TreeMap.of(Tuple.of(42, ComplexInnerClass.buildAnother())),
            HashMultimap.withSeq().of(Tuple.of("42", ComplexInnerClass.build())),
            TreeMultimap.withSeq().of(Tuple.of(42, ComplexInnerClass.buildAnother())),
            Array.of(ComplexInnerClass.build(), ComplexInnerClass.buildAnother()),
            List.of(ComplexInnerClass.build(), ComplexInnerClass.buildAnother()),
            Queue.of(ComplexInnerClass.build(), ComplexInnerClass.buildAnother()),
            Stream.of(ComplexInnerClass.build(), ComplexInnerClass.buildAnother()),
            Vector.of(ComplexInnerClass.build(), ComplexInnerClass.buildAnother()),
            HashSet.of(ComplexInnerClass.build(), ComplexInnerClass.buildAnother()),
            TreeSet.of(ComplexInnerClass.build(), ComplexInnerClass.buildAnother()),
            Tuple.of("42", ComplexInnerClass.build()),
            Option.of(42), Option.none()
    );
}
 
Example 6
Source File: VavrUnitTest.java    From tutorials with MIT License 5 votes vote down vote up
@Test
public void givenTuple_whenMapsComponentWise_thenCorrect() {
    Tuple2<String, Integer> java8 = Tuple.of("Java", 8);
    Tuple2<String, Integer> mapOfJava8 = java8.map(s -> s + "Vavr", i -> i / 2);
    int num = mapOfJava8._2();
    assertEquals("JavaVavr", mapOfJava8._1);

    assertEquals(4, num);

}
 
Example 7
Source File: ParameterizedPojoTest.java    From vavr-jackson with Apache License 2.0 5 votes vote down vote up
@Test
void testTuple2OfTuple() throws Exception {
    String src0 = "A";
    String src10 = "B";
    String src11 = "C";
    Tuple2<String, String> src1 = Tuple.of(src10, src11);
    Tuple2<String, Tuple2<String, String>> src = Tuple.of(src0, src1);
    String json = MAPPER.writeValueAsString(new ParameterizedTuple2Pojo<>(src));
    Assertions.assertEquals(json, "{\"value\":[\"A\",[\"B\",\"C\"]]}");
    ParameterizedTuple2Pojo<java.lang.String, io.vavr.Tuple2<java.lang.String, java.lang.String>> restored =
            MAPPER.readValue(json, new TypeReference<ParameterizedTuple2Pojo<java.lang.String, io.vavr.Tuple2<java.lang.String, java.lang.String>>>(){});
    Assertions.assertEquals(src, restored.getValue());
}
 
Example 8
Source File: ParameterizedPojoTest.java    From vavr-jackson with Apache License 2.0 5 votes vote down vote up
@Test
void testTuple6OfString() throws Exception {
    String src0 = "A";
    String src1 = "B";
    String src2 = "C";
    String src3 = "D";
    String src4 = "E";
    String src5 = "F";
    Tuple6<String, String, String, String, String, String> src = Tuple.of(src0, src1, src2, src3, src4, src5);
    String json = MAPPER.writeValueAsString(new ParameterizedTuple6Pojo<>(src));
    Assertions.assertEquals(json, "{\"value\":[\"A\",\"B\",\"C\",\"D\",\"E\",\"F\"]}");
    ParameterizedTuple6Pojo<java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String> restored =
            MAPPER.readValue(json, new TypeReference<ParameterizedTuple6Pojo<java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String>>(){});
    Assertions.assertEquals(src, restored.getValue());
}
 
Example 9
Source File: ParameterizedPojoTest.java    From vavr-jackson with Apache License 2.0 5 votes vote down vote up
@Test
void testTreeMapOfTuple() throws Exception {
    Integer src00 = 1;
    String src010 = "A";
    String src011 = "B";
    Tuple2<String, String> src01 = Tuple.of(src010, src011);
    Tuple2<Integer, Tuple2<String, String>> src0 = Tuple.of(src00, src01);
    TreeMap<Integer, Tuple2<String, String>> src = TreeMap.ofEntries(src0);
    String json = MAPPER.writeValueAsString(new ParameterizedTreeMapPojo<>(src));
    Assertions.assertEquals(json, "{\"value\":{\"1\":[\"A\",\"B\"]}}");
    ParameterizedTreeMapPojo<java.lang.Integer, io.vavr.Tuple2<java.lang.String, java.lang.String>> restored =
            MAPPER.readValue(json, new TypeReference<ParameterizedTreeMapPojo<java.lang.Integer, io.vavr.Tuple2<java.lang.String, java.lang.String>>>(){});
    Assertions.assertEquals(src, restored.getValue());
}
 
Example 10
Source File: SimplePojoTest.java    From vavr-jackson with Apache License 2.0 5 votes vote down vote up
@Test
void testTuple3OfTuple() throws Exception {
    String src0 = "A";
    String src10 = "B";
    String src11 = "C";
    Tuple2<String, String> src1 = Tuple.of(src10, src11);
    String src20 = "D";
    String src21 = "E";
    Tuple2<String, String> src2 = Tuple.of(src20, src21);
    Tuple3<String, Tuple2<String, String>, Tuple2<String, String>> src = Tuple.of(src0, src1, src2);
    String json = MAPPER.writeValueAsString(new Tuple3OfTuple().setValue(src));
    Assertions.assertEquals(json, "{\"value\":[\"A\",[\"B\",\"C\"],[\"D\",\"E\"]]}");
    Tuple3OfTuple restored = MAPPER.readValue(json, Tuple3OfTuple.class);
    Assertions.assertEquals(src, restored.getValue());
}
 
Example 11
Source File: ParameterizedPojoTest.java    From vavr-jackson with Apache License 2.0 5 votes vote down vote up
@Test
void testRightEitherOfTuple() throws Exception {
    String srcr0 = "A";
    String srcr1 = "B";
    Tuple2<String, String> srcr = Tuple.of(srcr0, srcr1);
    Either<Object, Tuple2<String, String>> src = Either.right(srcr);
    String json = MAPPER.writeValueAsString(new ParameterizedEitherPojo<>(src));
    Assertions.assertEquals(json, "{\"value\":[\"right\",[\"A\",\"B\"]]}");
    ParameterizedEitherPojo<java.lang.Object, io.vavr.Tuple2<java.lang.String, java.lang.String>> restored =
            MAPPER.readValue(json, new TypeReference<ParameterizedEitherPojo<java.lang.Object, io.vavr.Tuple2<java.lang.String, java.lang.String>>>(){});
    Assertions.assertEquals(src, restored.getValue());
}
 
Example 12
Source File: ParameterizedPojoTest.java    From vavr-jackson with Apache License 2.0 5 votes vote down vote up
@Test
void testTuple8OfTuple() throws Exception {
    String src0 = "A";
    String src10 = "B";
    String src11 = "C";
    Tuple2<String, String> src1 = Tuple.of(src10, src11);
    String src20 = "D";
    String src21 = "E";
    Tuple2<String, String> src2 = Tuple.of(src20, src21);
    String src30 = "F";
    String src31 = "1";
    Tuple2<String, String> src3 = Tuple.of(src30, src31);
    String src4 = "A";
    String src50 = "B";
    String src51 = "C";
    Tuple2<String, String> src5 = Tuple.of(src50, src51);
    String src60 = "D";
    String src61 = "E";
    Tuple2<String, String> src6 = Tuple.of(src60, src61);
    String src70 = "F";
    String src71 = "1";
    Tuple2<String, String> src7 = Tuple.of(src70, src71);
    Tuple8<String, Tuple2<String, String>, Tuple2<String, String>, Tuple2<String, String>, String, Tuple2<String, String>, Tuple2<String, String>, Tuple2<String, String>> src = Tuple.of(src0, src1, src2, src3, src4, src5, src6, src7);
    String json = MAPPER.writeValueAsString(new ParameterizedTuple8Pojo<>(src));
    Assertions.assertEquals(json, "{\"value\":[\"A\",[\"B\",\"C\"],[\"D\",\"E\"],[\"F\",\"1\"],\"A\",[\"B\",\"C\"],[\"D\",\"E\"],[\"F\",\"1\"]]}");
    ParameterizedTuple8Pojo<java.lang.String, io.vavr.Tuple2<java.lang.String, java.lang.String>, io.vavr.Tuple2<java.lang.String, java.lang.String>, io.vavr.Tuple2<java.lang.String, java.lang.String>, java.lang.String, io.vavr.Tuple2<java.lang.String, java.lang.String>, io.vavr.Tuple2<java.lang.String, java.lang.String>, io.vavr.Tuple2<java.lang.String, java.lang.String>> restored =
            MAPPER.readValue(json, new TypeReference<ParameterizedTuple8Pojo<java.lang.String, io.vavr.Tuple2<java.lang.String, java.lang.String>, io.vavr.Tuple2<java.lang.String, java.lang.String>, io.vavr.Tuple2<java.lang.String, java.lang.String>, java.lang.String, io.vavr.Tuple2<java.lang.String, java.lang.String>, io.vavr.Tuple2<java.lang.String, java.lang.String>, io.vavr.Tuple2<java.lang.String, java.lang.String>>>(){});
    Assertions.assertEquals(src, restored.getValue());
}
 
Example 13
Source File: SimplePojoTest.java    From vavr-jackson with Apache License 2.0 5 votes vote down vote up
@Test
void testLinkedHashSetOfTuple() throws Exception {
    String src00 = "A";
    String src01 = "B";
    Tuple2<String, String> src0 = Tuple.of(src00, src01);
    LinkedHashSet<Tuple2<String, String>> src = LinkedHashSet.of(src0);
    String json = MAPPER.writeValueAsString(new LinkedHashSetOfTuple().setValue(src));
    Assertions.assertEquals(json, "{\"value\":[[\"A\",\"B\"]]}");
    LinkedHashSetOfTuple restored = MAPPER.readValue(json, LinkedHashSetOfTuple.class);
    Assertions.assertEquals(src, restored.getValue());
}
 
Example 14
Source File: SimplePojoTest.java    From vavr-jackson with Apache License 2.0 5 votes vote down vote up
@Test
void testTreeMapOfTuple() throws Exception {
    Integer src00 = 1;
    String src010 = "A";
    String src011 = "B";
    Tuple2<String, String> src01 = Tuple.of(src010, src011);
    Tuple2<Integer, Tuple2<String, String>> src0 = Tuple.of(src00, src01);
    TreeMap<Integer, Tuple2<String, String>> src = TreeMap.ofEntries(src0);
    String json = MAPPER.writeValueAsString(new TreeMapOfTuple().setValue(src));
    Assertions.assertEquals(json, "{\"value\":{\"1\":[\"A\",\"B\"]}}");
    TreeMapOfTuple restored = MAPPER.readValue(json, TreeMapOfTuple.class);
    Assertions.assertEquals(src, restored.getValue());
}
 
Example 15
Source File: SimplePojoTest.java    From vavr-jackson with Apache License 2.0 5 votes vote down vote up
@Test
void testTuple2OfTuple() throws Exception {
    String src0 = "A";
    String src10 = "B";
    String src11 = "C";
    Tuple2<String, String> src1 = Tuple.of(src10, src11);
    Tuple2<String, Tuple2<String, String>> src = Tuple.of(src0, src1);
    String json = MAPPER.writeValueAsString(new Tuple2OfTuple().setValue(src));
    Assertions.assertEquals(json, "{\"value\":[\"A\",[\"B\",\"C\"]]}");
    Tuple2OfTuple restored = MAPPER.readValue(json, Tuple2OfTuple.class);
    Assertions.assertEquals(src, restored.getValue());
}
 
Example 16
Source File: ParameterizedPojoTest.java    From vavr-jackson with Apache License 2.0 5 votes vote down vote up
@Test
void testLinkedHashMapOfTuple() throws Exception {
    Integer src00 = 1;
    String src010 = "A";
    String src011 = "B";
    Tuple2<String, String> src01 = Tuple.of(src010, src011);
    Tuple2<Integer, Tuple2<String, String>> src0 = Tuple.of(src00, src01);
    LinkedHashMap<Integer, Tuple2<String, String>> src = LinkedHashMap.ofEntries(src0);
    String json = MAPPER.writeValueAsString(new ParameterizedLinkedHashMapPojo<>(src));
    Assertions.assertEquals(json, "{\"value\":{\"1\":[\"A\",\"B\"]}}");
    ParameterizedLinkedHashMapPojo<java.lang.Integer, io.vavr.Tuple2<java.lang.String, java.lang.String>> restored =
            MAPPER.readValue(json, new TypeReference<ParameterizedLinkedHashMapPojo<java.lang.Integer, io.vavr.Tuple2<java.lang.String, java.lang.String>>>(){});
    Assertions.assertEquals(src, restored.getValue());
}
 
Example 17
Source File: SimplePojoTest.java    From vavr-jackson with Apache License 2.0 5 votes vote down vote up
@Test
void testLeftEitherOfTuple() throws Exception {
    String srcl0 = "A";
    String srcl1 = "B";
    Tuple2<String, String> srcl = Tuple.of(srcl0, srcl1);
    Either<Tuple2<String, String>, Object> src = Either.left(srcl);
    String json = MAPPER.writeValueAsString(new LeftEitherOfTuple().setValue(src));
    Assertions.assertEquals(json, "{\"value\":[\"left\",[\"A\",\"B\"]]}");
    LeftEitherOfTuple restored = MAPPER.readValue(json, LeftEitherOfTuple.class);
    Assertions.assertEquals(src, restored.getValue());
}
 
Example 18
Source File: JavaBeanUtil.java    From javabeanutil-benchmark with MIT License 5 votes vote down vote up
private static Tuple2<? extends Class, Function> createTupleWithReturnTypeAndGetter(Method getterMethod) {
    try {
        return Tuple.of(
                getterMethod.getReturnType(),
                (Function) createCallSite(LOOKUP.unreflect(getterMethod)).getTarget().invokeExact()
        );
    } catch (Throwable e) {
        throw new IllegalArgumentException("Lambda creation failed for getterMethod (" + getterMethod.getName() + ").", e);
    }
}
 
Example 19
Source File: ExternalDataSuppliers.java    From test-data-supplier with Apache License 2.0 4 votes vote down vote up
@DataSupplier(transpose = true)
public Tuple getExternalTupleData() {
    return Tuple.of("1", 2, 3.0);
}
 
Example 20
Source File: Tuple1Test.java    From vavr-jackson with Apache License 2.0 4 votes vote down vote up
@Override
protected Tuple1<?> ofObjects(Object head, Object tail) {
    return Tuple.of(head);
}