• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java Either类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中io.vavr.control.Either的典型用法代码示例。如果您正苦于以下问题:Java Either类的具体用法?Java Either怎么用?Java Either使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



Either类属于io.vavr.control包,在下文中一共展示了Either类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: addCase

import io.vavr.control.Either; //导入依赖的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);
}
 
开发者ID:vavr-io,项目名称:vavr-jackson,代码行数:17,代码来源:ParameterizedPojo.java


示例2: test7

import io.vavr.control.Either; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Test
public void test7() throws IOException {
    Either<List<Integer>, Set<Double>> either = Either.left(List.of(42));
    String json = mapper().writer().writeValueAsString(either);
    Either<List<Integer>, Set<Double>> restored = mapper().readValue(json, new TypeReference<Either<List<Integer>, Set<Double>>>() {});
    Assert.assertEquals(either, restored);
}
 
开发者ID:vavr-io,项目名称:vavr-jackson,代码行数:9,代码来源:EitherTest.java


示例3: testDeserializingScalaEither

import io.vavr.control.Either; //导入依赖的package包/类
@Test
public void testDeserializingScalaEither() throws IOException {
    final scala.util.Either<String, BigInteger> left = scala.util.Left.apply("test");
    final scala.util.Either<String, BigInteger> right = scala.util.Right.apply(BigInteger.ONE);
    final ObjectMapper mapper = mapper().registerModule(new DefaultScalaModule());

    final String serializedLeft = mapper.writeValueAsString(left);
    final Either<String, BigInteger> deserializedLeft =
            mapper.readValue(serializedLeft, new TypeReference<Either<String, BigInteger>>() { });
    Assert.assertEquals("test", deserializedLeft.left().get());

    final String serializedRight = mapper.writeValueAsString(right);
    final Either<String, BigInteger> deserializedRight =
            mapper.readValue(serializedRight, new TypeReference<Either<String, BigInteger>>() { });
    Assert.assertEquals(BigInteger.ONE, deserializedRight.right().get());
}
 
开发者ID:vavr-io,项目名称:vavr-jackson,代码行数:17,代码来源:EitherTest.java


示例4: BeanObjectOptional

import io.vavr.control.Either; //导入依赖的package包/类
public BeanObjectOptional(boolean empty) {
    if (empty) {
        charSeq = CharSeq.empty();
        either = Either.left(EITHER_VALUE);
        option = Option.none();
        map = HashMap.empty();
        multimap = HashMultimap.withSeq().empty();
        seq = List.empty();
        set = HashSet.empty();
    } else {
        charSeq = CharSeq.of(CHARSEQ_VALUE);
        either = Either.right(EITHER_VALUE);
        option = Option.of(OPTION_VALUE);
        map = HashMap.of("key", MAP_VALUE);
        multimap = HashMultimap.withSeq().of("key", MULTIMAP_VALUE);
        seq = List.of(SEQ_VALUE);
        set = HashSet.of(SET_VALUE);
    }
}
 
开发者ID:vavr-io,项目名称:vavr-jackson,代码行数:20,代码来源:BeanAnnotationTest.java


示例5: create

import io.vavr.control.Either; //导入依赖的package包/类
public Either<String, Slide> create(final Slide slide) {
    String sql = "INSERT INTO slides(title, body, visible, type, index, name, color) VALUES(?, ?, ?, ?, ?, ?, ?)";
    return updateQuery(dataSource, c -> {
        PreparedStatement p = c.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS);
        p.setString(1, slide.title);
        p.setString(2, slide.body);
        p.setBoolean(3, slide.visible);
        p.setString(4, slide.type);
        p.setInt(5, slide.index);
        p.setString(6, slide.name);
        p.setString(7, slide.color);
        return p;
    }, (st, i) -> {
        ResultSet keySet = st.getGeneratedKeys();
        if (keySet.next()) {
            return slide.withId(keySet.getLong(1));
        } else {
            return null;
        }
    }, "Could not create slide");
}
 
开发者ID:javaBin,项目名称:Switcharoo,代码行数:22,代码来源:SlidesDao.java


示例6: update

import io.vavr.control.Either; //导入依赖的package包/类
public Either<String, Slide> update(final Slide slide) {
    String sql = "UPDATE slides SET title = ?, body = ?, visible = ?, type = ?, index = ?, name = ?, color = ?, updated_at = ? WHERE id = ?";
    return get(slide.id).flatMap(dbSlide -> updateQuery(dataSource, c -> {
        PreparedStatement p = c.prepareStatement(sql);
        p.setString(1, slide.title);
        p.setString(2, slide.body);
        p.setBoolean(3, slide.visible);
        p.setString(4, slide.type);
        p.setInt(5, slide.index);
        p.setString(6, slide.name);
        p.setString(7, slide.color);
        p.setTimestamp(8, Timestamp.from(Instant.now()));
        p.setLong(9, slide.id);
        return p;
    }, (st, i) -> i > 0 ? slide : null,
        "Could not update slide"));
}
 
开发者ID:javaBin,项目名称:Switcharoo,代码行数:18,代码来源:SlidesDao.java


示例7: create

import io.vavr.control.Either; //导入依赖的package包/类
public Either<String, Setting> create(final Setting setting) {
    String sql = "INSERT INTO settings(key, hint, value) VALUES(?, ?, ?)";
    return updateQuery(dataSource, c -> {
        PreparedStatement s = c.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS);
        s.setString(1, setting.key);
        s.setString(2, setting.hint);
        s.setObject(3, toJson(setting.value));
        return s;
    }, (st, i) -> {
        ResultSet keySet = st.getGeneratedKeys();
        if (keySet.next()) {
            return setting.withId(keySet.getLong(1));
        } else {
            return null;
        }
    }, "Could not create setting");
}
 
开发者ID:javaBin,项目名称:Switcharoo,代码行数:18,代码来源:SettingsDao.java


示例8: create

import io.vavr.control.Either; //导入依赖的package包/类
public Either<String, Css> create(final Css css) {
    String sql = "INSERT INTO csses(selector, property, value, type, title) VALUES(?, ?, ?, ?, ?)";
    return updateQuery(dataSource, c -> {
        PreparedStatement p = c.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS);
        p.setString(1, css.selector);
        p.setString(2, css.property);
        p.setString(3, css.value);
        p.setString(4, css.type);
        p.setString(5, css.title);
        return p;
    }, (st, i) -> {
        ResultSet rs = st.getGeneratedKeys();
        if (rs.next()) {
            return css.withId(rs.getLong("id"));
        } else {
            return null;
        }
    }, "Could not create css");
}
 
开发者ID:javaBin,项目名称:Switcharoo,代码行数:20,代码来源:CssDao.java


示例9: create

import io.vavr.control.Either; //导入依赖的package包/类
public Either<String, Service> create(final Service service) {
    String sql = "INSERT INTO services(key, value) VALUES(?, ?)";
    return updateQuery(dataSource, c -> {
        PreparedStatement p = c.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS);
        p.setString(1, service.key);
        p.setBoolean(2, service.value);
        return p;
    }, (st, i) -> {
        ResultSet keySet = st.getGeneratedKeys();
        if (keySet.next()) {
            return service.withId(keySet.getLong(1));
        } else {
            return null;
        }
    }, "Could not create service");
}
 
开发者ID:javaBin,项目名称:Switcharoo,代码行数:17,代码来源:ServiceDao.java


示例10: writeTo

import io.vavr.control.Either; //导入依赖的package包/类
/**
 * {@inheritDoc}
 */
@SuppressWarnings("unchecked")
@Override
public void writeTo(Either<?, ?> entity,
                    Class<?> type,
                    Type genericType,
                    Annotation[] annotations,
                    MediaType mediaType,
                    MultivaluedMap<String, Object> httpHeaders,
                    OutputStream entityStream)
        throws IOException {
    final Object entityValue;
    final int typeArgumentIndex;
    if (entity.isLeft()) {
        entityValue = entity.getLeft();
        typeArgumentIndex = 0;
    } else {
        entityValue = entity.get();
        typeArgumentIndex = 1;
    }
    final Class<?> entityClass = entityValue.getClass();

    final Type actualGenericTypeArgument;
    if (genericType instanceof ParameterizedType) {
        actualGenericTypeArgument = ((ParameterizedType) genericType).getActualTypeArguments()[typeArgumentIndex];
    } else {
        actualGenericTypeArgument = entityClass;
    }

    final MessageBodyWriter writer = mbw.get().getMessageBodyWriter(entityClass,
            actualGenericTypeArgument, annotations, mediaType);
    writer.writeTo(entityValue, entityClass,
            actualGenericTypeArgument,
            annotations, mediaType, httpHeaders, entityStream);
}
 
开发者ID:dropwizard,项目名称:dropwizard-vavr,代码行数:38,代码来源:EitherMessageBodyWriter.java


示例11: eitherTest

import io.vavr.control.Either; //导入依赖的package包/类
@Test
public void eitherTest() {
    assertThat(Vavr.either(Either.right("hello world"))
                        .map(String::toUpperCase)
                        .to(ANY_M_LIST_FUNCTION),
               equalTo(Arrays.asList("HELLO WORLD")));
}
 
开发者ID:aol,项目名称:cyclops,代码行数:8,代码来源:AnyJavaslangMTest.java


示例12: eitherLeftTest

import io.vavr.control.Either; //导入依赖的package包/类
@Test
public void eitherLeftTest() {
    assertThat(Vavr.either(Either.<String, String> left("hello world"))
                        .map(String::toUpperCase)
                        .to(ANY_M_LIST_FUNCTION),
               equalTo(Arrays.asList()));
}
 
开发者ID:aol,项目名称:cyclops,代码行数:8,代码来源:AnyJavaslangMTest.java


示例13: eitherFlatMapTest

import io.vavr.control.Either; //导入依赖的package包/类
@Test
public void eitherFlatMapTest() {
    assertThat(Vavr.either(Either.<Object, String> right("hello world"))
                        .map(String::toUpperCase)

                        .to(ANY_M_LIST_FUNCTION),
               equalTo(Arrays.asList("HELLO WORLD")));
}
 
开发者ID:aol,项目名称:cyclops,代码行数:9,代码来源:AnyJavaslangMTest.java


示例14: streamEither

import io.vavr.control.Either; //导入依赖的package包/类
@Test
public void streamEither(){
    Higher<stream, Integer> res = StreamNested.either(Stream.of(Either.right(1)))
                                              .map(i -> i * 20)
                                              .foldLeft(Monoids.intMax);
    Stream<Integer> fi = StreamKind.narrow(res);
    assertThat(fi.get(0),equalTo(20));
}
 
开发者ID:aol,项目名称:cyclops,代码行数:9,代码来源:NestedTest.java


示例15: serialize

import io.vavr.control.Either; //导入依赖的package包/类
@Override
public void serialize(Either<?, ?> value, JsonGenerator gen, SerializerProvider provider) throws IOException {
    gen.writeStartArray();
    if (value.isLeft()) {
        gen.writeString("left");
        write(value.left().get(), 0, gen, provider);
    } else {
        gen.writeString("right");
        write(value.right().get(), 1, gen, provider);
    }
    gen.writeEndArray();
}
 
开发者ID:vavr-io,项目名称:vavr-jackson,代码行数:13,代码来源:EitherSerializer.java


示例16: publicVavrClass

import io.vavr.control.Either; //导入依赖的package包/类
public static Class<?> publicVavrClass(Class<?> clz) {
    if (Either.class.isAssignableFrom(clz)) {
        return Either.class;
    }
    if (Option.class.isAssignableFrom(clz)) {
        return Option.class;
    }
    if (List.class.isAssignableFrom(clz)) {
        return List.class;
    }
    if (Stream.class.isAssignableFrom(clz)) {
        return Stream.class;
    }
    return clz;
}
 
开发者ID:vavr-io,项目名称:vavr-jackson,代码行数:16,代码来源:Initializer.java


示例17: expectedJson

import io.vavr.control.Either; //导入依赖的package包/类
public static String expectedJson(Object o, int opts) {
    if (o instanceof Either) {
        return expectedEitherJson((Either<?, ?>) o, opts);
    }
    if (o instanceof Lazy) {
        return expectedLazyJson((Lazy<?>) o, opts);
    }
    if (o instanceof Option) {
        return expectedOptionJson((Option<?>) o, opts);
    }
    if (o instanceof PriorityQueue) {
        return expectedPriorityQueueJson((PriorityQueue<?>) o, opts);
    }
    if (o instanceof Seq) {
        return expectedSeqJson((Seq<?>) o, opts);
    }
    if (o instanceof Set) {
        return expectedSetJson((Set<?>) o, opts);
    }
    if (o instanceof Map) {
        return expectedMapJson((Map<?, ?>) o, opts);
    }
    if (o instanceof Multimap) {
        return expectedMultimapJson((Multimap<?, ?>) o, opts);
    }
    if (o instanceof Tuple) {
        return expectedTupleJson((Tuple) o, opts);
    }
    if (o instanceof String) {
        return "\"" + o.toString().replace("\"", "\\\"") + "\"";
    }
    return o.toString();
}
 
开发者ID:vavr-io,项目名称:vavr-jackson,代码行数:34,代码来源:Serializer.java


示例18: expectedEitherJson

import io.vavr.control.Either; //导入依赖的package包/类
private static String expectedEitherJson(Either<?, ?> either, int opts) {
    if (either.isLeft()) {
        return "[\"left\"," + expectedJson(either.left().get(), opts) + "]";
    } else {
        return "[\"right\"," + expectedJson(either.right().get(), opts) + "]";
    }
}
 
开发者ID:vavr-io,项目名称:vavr-jackson,代码行数:8,代码来源:Serializer.java


示例19: testWrapperObject

import io.vavr.control.Either; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Test
public void testWrapperObject() throws IOException {
    ObjectMapper mapper = mapper().addMixIn(Either.class, WrapperObject.class);
    Either<Integer, Integer> src = Either.right(1);
    String plainJson = mapper().writeValueAsString(src);
    String wrappedJson = mapper.writeValueAsString(src);
    Assert.assertEquals(wrappedJson, wrapToObject(Either.Right.class.getName(), plainJson));
    Either<Integer, Integer> restored = (Either<Integer, Integer>) mapper.readValue(wrappedJson, Either.class);
    Assert.assertEquals(src, restored);
}
 
开发者ID:vavr-io,项目名称:vavr-jackson,代码行数:12,代码来源:EitherTest.java


示例20: test1

import io.vavr.control.Either; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Test
public void test1() throws IOException {
    Either<String, Integer> left = Either.left("left");
    String json = mapper().writer().writeValueAsString(left);
    Either<String, Integer> restored = mapper().readValue(json, Either.class);
    Assert.assertEquals(left, restored);
}
 
开发者ID:vavr-io,项目名称:vavr-jackson,代码行数:9,代码来源:EitherTest.java



注:本文中的io.vavr.control.Either类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java Element类代码示例发布时间:2022-05-22
下一篇:
Java MIMEEntity类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap