本文整理汇总了Java中io.vavr.Tuple类的典型用法代码示例。如果您正苦于以下问题:Java Tuple类的具体用法?Java Tuple怎么用?Java Tuple使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Tuple类属于io.vavr包,在下文中一共展示了Tuple类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getFactoryAnnotationMetaData
import io.vavr.Tuple; //导入依赖的package包/类
private Tuple2<Class<?>, String> getFactoryAnnotationMetaData() {
val constructor = testMethod.getConstructorOrMethod().getConstructor();
val method = testMethod.getConstructorOrMethod().getMethod();
val factoryAnnotation = nonNull(method)
? ofNullable(method.getDeclaredAnnotation(Factory.class))
: ofNullable(constructor.getDeclaredAnnotation(Factory.class));
val dataProviderClass = factoryAnnotation
.map(fa -> (Class) fa.dataProviderClass())
.filter(cl -> cl != Object.class)
.orElseGet(() -> testMethod.getConstructorOrMethod().getDeclaringClass());
val dataProviderMethod = factoryAnnotation.map(Factory::dataProvider).orElse("");
return Tuple.of(dataProviderClass, dataProviderMethod);
}
示例2: wrap
import io.vavr.Tuple; //导入依赖的package包/类
private StreamEx<?> wrap(final Object data) {
return Match(data).of(
Case($(isNull()), () -> {
throw new IllegalArgumentException(format(
"Nothing to return from data supplier. The following test will be skipped: %s.%s.",
testMethod.getConstructorOrMethod().getDeclaringClass().getSimpleName(),
testMethod.getConstructorOrMethod().getName()));
}),
Case($(instanceOf(Collection.class)), d -> StreamEx.of((Collection<?>) d)),
Case($(instanceOf(Map.class)), d -> EntryStream.of((Map<?, ?>) d).mapKeyValue(SimpleEntry::new)),
Case($(instanceOf(Map.Entry.class)), d -> StreamEx.of(d.getKey(), d.getValue())),
Case($(instanceOf(Object[].class)), d -> StreamEx.of((Object[]) d)),
Case($(instanceOf(double[].class)), d -> DoubleStreamEx.of((double[]) d).boxed()),
Case($(instanceOf(int[].class)), d -> IntStreamEx.of((int[]) d).boxed()),
Case($(instanceOf(long[].class)), d -> LongStreamEx.of((long[]) d).boxed()),
Case($(instanceOf(Stream.class)), d -> StreamEx.of((Stream<?>) d)),
Case($(instanceOf(Tuple.class)), d -> StreamEx.of(((Tuple) d).toSeq().toJavaArray())),
Case($(), d -> StreamEx.of(d)));
}
示例3: set
import io.vavr.Tuple; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public void set(Consumer<Object> dispatcher, Object parent, String name, Array<VNode> vNodeList) {
final List list;
try {
list = (List) getter.invoke(parent);
} catch (Throwable throwable) {
throw new IllegalStateException("Unable to read property " + name + " from class " + parent.getClass(), throwable);
}
if (vNodeList.isEmpty()) {
list.clear();
} else {
list.clear();
final Array<Tuple2<VNode, Object>> nodeList = vNodeList
.map(vNode -> Tuple.of(vNode, NodeBuilder.create(vNode)))
.filter(tuple -> tuple._2.isDefined())
.map(tuple -> Tuple.of(tuple._1, tuple._2.get()));
list.addAll(nodeList.map(tuple -> tuple._2).toJavaList());
nodeList.forEach(tuple -> NodeBuilder.init(dispatcher, tuple._2, tuple._1));
}
}
示例4: diffAttributes
import io.vavr.Tuple; //导入依赖的package包/类
private static Map<Phase, Vector<Patch>> diffAttributes(Vector<Object> path, VNode a, VNode b) {
final Map<String, VProperty> removedProperties = a.getProperties().removeAll(b.getProperties().keySet()).map((key, value) -> Tuple.of(key, Factory.property(value.getPhase(), key)));
final Map<String, VProperty> updatedProperties = b.getProperties().filter(propertyB -> !Option.of(propertyB._2).equals(a.getProperties().get(propertyB._1)));
final Map<VEventType, Option<VEventHandler>> removedEventHandlers = a.getEventHandlers().removeAll(b.getEventHandlers().keySet()).map((key, value) -> Tuple.of(key, Option.none()));
final Map<VEventType, Option<VEventHandler>> updatedEventHandlers = b.getEventHandlers().filter(handlerB -> !Objects.equals(Option.of(handlerB._2), a.getEventHandlers().get(handlerB._1))).map((key, value) -> Tuple.of(key, Option.of(value)));
final Map<VEventType, Option<VEventHandler>> diffEventHandlers = removedEventHandlers.merge(updatedEventHandlers);
return removedProperties.merge(updatedProperties)
.groupBy(tuple -> tuple._2.getPhase())
.map((phase, properties) ->
Tuple.of(phase, Vector.of(
new AttributesPatch(
path,
properties,
phase == Phase.DEFAULT ? diffEventHandlers : HashMap.empty()
)
))
);
}
示例5: deserialize
import io.vavr.Tuple; //导入依赖的package包/类
@Override
public Map<?, ?> deserialize(JsonParser p, DeserializationContext ctxt) throws IOException {
final java.util.List<Tuple2<Object, Object>> result = new java.util.ArrayList<>();
while (p.nextToken() != JsonToken.END_OBJECT) {
String name = p.getCurrentName();
Object key = keyDeserializer.deserializeKey(name, ctxt);
p.nextToken();
result.add(Tuple.of(key, valueDeserializer.deserialize(p, ctxt)));
}
if (SortedMap.class.isAssignableFrom(handledType())) {
return TreeMap.ofEntries(keyComparator, result);
}
if (LinkedHashMap.class.isAssignableFrom(handledType())) {
return LinkedHashMap.ofEntries(result);
}
// default deserialization [...] -> Map
return HashMap.ofEntries(result);
}
示例6: deserialize
import io.vavr.Tuple; //导入依赖的package包/类
@Override
public Multimap<?, ?> deserialize(JsonParser p, DeserializationContext ctxt) throws IOException {
final java.util.List<Tuple2<Object, Object>> result = new java.util.ArrayList<>();
while (p.nextToken() != JsonToken.END_OBJECT) {
String name = p.getCurrentName();
Object key = keyDeserializer.deserializeKey(name, ctxt);
p.nextToken();
ArrayList<?> list = (ArrayList<?>) containerDeserializer.deserialize(p, ctxt);
for (Object elem : list) {
result.add(Tuple.of(key, elem));
}
}
if (TreeMultimap.class.isAssignableFrom(handledType())) {
return TreeMultimap.withSeq().ofEntries(keyComparator, result);
}
if (LinkedHashMultimap.class.isAssignableFrom(handledType())) {
return LinkedHashMultimap.withSeq().ofEntries(result);
}
// default deserialization [...] -> Map
return HashMultimap.withSeq().ofEntries(result);
}
示例7: addCase
import io.vavr.Tuple; //导入依赖的package包/类
private static void addCase(TypeSpec.Builder builder, String pojoName, Object value) {
Class<?> clz = publicVavrClass(value.getClass());
if (!generated.contains(clz)) {
int arity;
if (Tuple.class.isAssignableFrom(clz)) {
arity = ((Tuple) value).arity();
} else if (Map.class.isAssignableFrom(clz) || Multimap.class.isAssignableFrom(clz) || Either.class.isAssignableFrom(clz)) {
arity = 2;
} else {
arity = 1;
}
addPojo(builder, clz, arity);
generated.add(clz);
}
addCase(builder, pojoName, value, clz.getSimpleName(), 0);
}
示例8: build
import io.vavr.Tuple; //导入依赖的package包/类
@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()
);
}
示例9: testTuple5
import io.vavr.Tuple; //导入依赖的package包/类
@Test
public void testTuple5() throws Exception {
Tuple5<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"));
String json = MAPPER.writeValueAsString(new Tuple5Pojo().setValue(src));
Assert.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\"}}]}");
Tuple5Pojo pojo = MAPPER.readValue(json, Tuple5Pojo.class);
Tuple5<A, A, A, A, A> restored = pojo.getValue();
Assert.assertTrue(restored._1 instanceof B);
Assert.assertEquals(restored._1.a, "a");
Assert.assertEquals(((B) restored._1).b, "b");
Assert.assertTrue(restored._2 instanceof B);
Assert.assertEquals(restored._2.a, "a");
Assert.assertEquals(((B) restored._2).b, "b");
Assert.assertTrue(restored._3 instanceof B);
Assert.assertEquals(restored._3.a, "a");
Assert.assertEquals(((B) restored._3).b, "b");
Assert.assertTrue(restored._4 instanceof B);
Assert.assertEquals(restored._4.a, "a");
Assert.assertEquals(((B) restored._4).b, "b");
Assert.assertTrue(restored._5 instanceof B);
Assert.assertEquals(restored._5.a, "a");
Assert.assertEquals(((B) restored._5).b, "b");
}
示例10: testTuple6
import io.vavr.Tuple; //导入依赖的package包/类
@Test
public 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));
Assert.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();
Assert.assertTrue(restored._1 instanceof B);
Assert.assertEquals(restored._1.a, "a");
Assert.assertEquals(((B) restored._1).b, "b");
Assert.assertTrue(restored._2 instanceof B);
Assert.assertEquals(restored._2.a, "a");
Assert.assertEquals(((B) restored._2).b, "b");
Assert.assertTrue(restored._3 instanceof B);
Assert.assertEquals(restored._3.a, "a");
Assert.assertEquals(((B) restored._3).b, "b");
Assert.assertTrue(restored._4 instanceof B);
Assert.assertEquals(restored._4.a, "a");
Assert.assertEquals(((B) restored._4).b, "b");
Assert.assertTrue(restored._5 instanceof B);
Assert.assertEquals(restored._5.a, "a");
Assert.assertEquals(((B) restored._5).b, "b");
Assert.assertTrue(restored._6 instanceof B);
Assert.assertEquals(restored._6.a, "a");
Assert.assertEquals(((B) restored._6).b, "b");
}
示例11: testTuple3OfTuple
import io.vavr.Tuple; //导入依赖的package包/类
@Test
public 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 ParameterizedTuple3Pojo<>(src));
Assert.assertEquals(json, "{\"value\":[\"A\",[\"B\",\"C\"],[\"D\",\"E\"]]}");
ParameterizedTuple3Pojo<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<ParameterizedTuple3Pojo<java.lang.String, io.vavr.Tuple2<java.lang.String, java.lang.String>, io.vavr.Tuple2<java.lang.String, java.lang.String>>>(){});
Assert.assertEquals(src, restored.getValue());
}
示例12: testTuple5OfTuple
import io.vavr.Tuple; //导入依赖的package包/类
@Test
public void testTuple5OfTuple() 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";
Tuple5<String, Tuple2<String, String>, Tuple2<String, String>, Tuple2<String, String>, String> src = Tuple.of(src0, src1, src2, src3, src4);
String json = MAPPER.writeValueAsString(new ParameterizedTuple5Pojo<>(src));
Assert.assertEquals(json, "{\"value\":[\"A\",[\"B\",\"C\"],[\"D\",\"E\"],[\"F\",\"1\"],\"A\"]}");
ParameterizedTuple5Pojo<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> restored =
MAPPER.readValue(json, new TypeReference<ParameterizedTuple5Pojo<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>>(){});
Assert.assertEquals(src, restored.getValue());
}
示例13: testTuple7OfString
import io.vavr.Tuple; //导入依赖的package包/类
@Test
public void testTuple7OfString() throws Exception {
String src0 = "A";
String src1 = "B";
String src2 = "C";
String src3 = "D";
String src4 = "E";
String src5 = "F";
String src6 = "1";
Tuple7<String, String, String, String, String, String, String> src = Tuple.of(src0, src1, src2, src3, src4, src5, src6);
String json = MAPPER.writeValueAsString(new ParameterizedTuple7Pojo<>(src));
Assert.assertEquals(json, "{\"value\":[\"A\",\"B\",\"C\",\"D\",\"E\",\"F\",\"1\"]}");
ParameterizedTuple7Pojo<java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String> restored =
MAPPER.readValue(json, new TypeReference<ParameterizedTuple7Pojo<java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String>>(){});
Assert.assertEquals(src, restored.getValue());
}
示例14: testTuple7OfTuple
import io.vavr.Tuple; //导入依赖的package包/类
@Test
public 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 ParameterizedTuple7Pojo<>(src));
Assert.assertEquals(json, "{\"value\":[\"A\",[\"B\",\"C\"],[\"D\",\"E\"],[\"F\",\"1\"],\"A\",[\"B\",\"C\"],[\"D\",\"E\"]]}");
ParameterizedTuple7Pojo<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>> restored =
MAPPER.readValue(json, new TypeReference<ParameterizedTuple7Pojo<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>>>(){});
Assert.assertEquals(src, restored.getValue());
}
示例15: testTuple8OfString
import io.vavr.Tuple; //导入依赖的package包/类
@Test
public void testTuple8OfString() throws Exception {
String src0 = "A";
String src1 = "B";
String src2 = "C";
String src3 = "D";
String src4 = "E";
String src5 = "F";
String src6 = "1";
String src7 = "2";
Tuple8<String, String, String, String, String, String, String, String> src = Tuple.of(src0, src1, src2, src3, src4, src5, src6, src7);
String json = MAPPER.writeValueAsString(new ParameterizedTuple8Pojo<>(src));
Assert.assertEquals(json, "{\"value\":[\"A\",\"B\",\"C\",\"D\",\"E\",\"F\",\"1\",\"2\"]}");
ParameterizedTuple8Pojo<java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String> restored =
MAPPER.readValue(json, new TypeReference<ParameterizedTuple8Pojo<java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String>>(){});
Assert.assertEquals(src, restored.getValue());
}