当前位置: 首页>>代码示例>>Java>>正文


Java Option类代码示例

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


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

示例1: assertControllerBoundToTestPane

import io.vavr.control.Option; //导入依赖的package包/类
/**
 * We have to sleep here because the event firing in JavaFX can't be waited on all the way.
 * So if we don't wait, as soon as the click is actually sent, but not yet registered,
 * we are already asserting.
 * The wait is a horrific thing that the whole async life promised to save us from. But it did
 * not deliver (yet).
 *
 * @param testPane         The pane to test bounding on
 * @param controllerLookup The controller as an {@link Option} so we can know if the test
 *                         actually failed because of some outside reason.
 */
private void assertControllerBoundToTestPane(final Pane testPane, final Option<FxmlController> controllerLookup) {
    assertThat(controllerLookup.isDefined()).isTrue();
    assertThat(controllerLookup.get().getClass()).isEqualTo(SAMPLE_CONTROL_CLASS.class);

    Stages.stageOf("TEST_PANE", testPane)
        .whenCompleteAsync((stage, err) -> Stages.scheduleDisplaying(stage))
        .whenCompleteAsync((stage, err) -> {
            final Button btn = (Button) stage.getScene().getRoot().getChildrenUnmodifiable().get(0);
            btn.fire();
            Stages.asyncStageOperation(stage, Stage::hide);
        })
        .whenCompleteAsync((stage, err) -> {
            final SAMPLE_CONTROL_CLASS testController = (SAMPLE_CONTROL_CLASS) controllerLookup.get();
            assertThat(testController.locatedInstance).isTrue();
        })
        .toCompletableFuture()
        .join();
}
 
开发者ID:Tristan971,项目名称:EasyFXML,代码行数:30,代码来源:BaseEasyFxmlTest.java

示例2: setupTests

import io.vavr.control.Option; //导入依赖的package包/类
@Before
public void setupTests() throws IOException {
    final DataSourceFactory dataSourceFactory = new DataSourceFactory();
    dataSourceFactory.setDriverClass("org.h2.Driver");
    dataSourceFactory.setUrl("jdbc:h2:mem:test-" + System.currentTimeMillis() + "?user=sa");
    dataSourceFactory.setInitialSize(1);
    final DBI dbi = new VavrDBIFactory().build(env, dataSourceFactory, "test");
    try (Handle h = dbi.open()) {
        h.execute("CREATE TABLE tasks (" +
                "id INT PRIMARY KEY, " +
                "assignee VARCHAR(255) NOT NULL, " +
                "start_date TIMESTAMP, " +
                "end_date TIMESTAMP, " +
                "comments VARCHAR(1024) " +
                ")");
    }
    dao = dbi.onDemand(TaskDao.class);

    dao.insert(100, Option.some("Name 1"), LocalDate.parse("2017-08-24"), Option.none(), Option.none());
    dao.insert(200, Option.some("Name 2"), LocalDate.parse("2017-08-25"), Option.none(), Option.some("To be done"));
}
 
开发者ID:dropwizard,项目名称:dropwizard-vavr,代码行数:22,代码来源:VavrDBIFactoryTest.java

示例3: testHead

import io.vavr.control.Option; //导入依赖的package包/类
@Test
public void testHead() {
    assertThat(
            head(List.of("Hey", "ho")),
            is(Option.of("Hey"))
    );

    assertThat(
            head(List.of()),
            is(Option.none())
    );

    /*
    assertThat(
            head("Hey"),
            is(Option.some('H'))
    );

    assertThat(
            head(""),
            is(Option.none())
    );
    */
}
 
开发者ID:RedNifre,项目名称:ravr,代码行数:25,代码来源:RavrTest.java

示例4: testConcatOptions

import io.vavr.control.Option; //导入依赖的package包/类
@Test
public void testConcatOptions() {

    assertThat(
            concatOptions(List.of(Option.some("he"), Option.none(), Option.some("hm"))),
            is(List.of("he", "hm"))
    );

    Function1<String, Option<String>> removeFoo = s ->
            s.equals("foo") ? Option.none() : Option.some(s);

    assertThat(
            pipe(
                    (List<String> x) -> map(removeFoo, x),
                    concatOptions()
            ).apply(List.of("Hey", "foo", "keep")),
            is(List.of("Hey", "keep"))
    );

}
 
开发者ID:RedNifre,项目名称:ravr,代码行数:21,代码来源:RavrTest.java

示例5: assertPaneFailedLoadingAndDidNotRegister

import io.vavr.control.Option; //导入依赖的package包/类
private void assertPaneFailedLoadingAndDidNotRegister(
    final Try<? extends Node> failingLoadResult,
    final Option<FxmlController> controllerLookup,
    final Class<? extends Throwable> expectedExceptionClass
) {
    assertThat(failingLoadResult.isFailure()).isTrue();
    assertThat(failingLoadResult.getCause()).isInstanceOf(expectedExceptionClass);
    assertThat(controllerLookup.isEmpty()).isTrue();
}
 
开发者ID:Tristan971,项目名称:EasyFXML,代码行数:10,代码来源:BaseEasyFxmlTest.java

示例6: matches

import io.vavr.control.Option; //导入依赖的package包/类
@Override
public final boolean matches(TypeDescription target) {
    Option<TypeDescription> optSuperClass = Option
            .of(target.getSuperClass())
            .map(TypeDescription.Generic::asErasure);
    return optSuperClass
            .map(sc -> superClassMatcher.matches(sc))
            .getOrElse(Boolean.FALSE);
}
 
开发者ID:project-avral,项目名称:oo-atom,代码行数:10,代码来源:Extending.java

示例7: succeedsWhenConstraintsMet

import io.vavr.control.Option; //导入依赖的package包/类
@Test
public void succeedsWhenConstraintsMet() {
    Example example = new Example();
    example.three = Option.of(10);
    Set<ConstraintViolation<Example>> violations = validator.validate(example);
    assertThat(violations).isEmpty();
}
 
开发者ID:dropwizard,项目名称:dropwizard-vavr,代码行数:8,代码来源:ValueValidatedValueUnwrapperTest.java

示例8: should_fail_if_option_is_empty

import io.vavr.control.Option; //导入依赖的package包/类
@Test
public void should_fail_if_option_is_empty() {
  Option<Object> actual = Option.none();

  Throwable thrown = catchThrowable(() -> assertThat(actual).containsInstanceOf(Object.class));

  assertThat(thrown).isInstanceOf(AssertionError.class)
                    .hasMessage(OptionShouldBePresent.shouldBePresent().create());
}
 
开发者ID:assertj,项目名称:assertj-vavr,代码行数:10,代码来源:OptionAssert_containsInstanceOf_Test.java

示例9: failsWhenFailingConstraint

import io.vavr.control.Option; //导入依赖的package包/类
@Test
public void failsWhenFailingConstraint() {
    Example example = new Example();
    example.three = Option.of(2);
    Set<ConstraintViolation<Example>> violations = validator.validate(example);
    assertThat(violations).hasSize(1);
}
 
开发者ID:dropwizard,项目名称:dropwizard-vavr,代码行数:8,代码来源:ValueValidatedValueUnwrapperTest.java

示例10: updateNote

import io.vavr.control.Option; //导入依赖的package包/类
@Nullable
@Override
public Note updateNote(String id, String content) {
    Option<Note> noteById = getNoteById(id);
    Note toAdd = noteById.map(n -> n.withContent(content)).getOrNull();
    if (toAdd == null) {
        return null;
    }
    notes = noteById.map(notes::remove).getOrElse(notes).add(toAdd);
    return toAdd;
}
 
开发者ID:anton-tregubov,项目名称:javaee-design-patterns,代码行数:12,代码来源:NoteFacadeImpl.java

示例11: pipeK_Option

import io.vavr.control.Option; //导入依赖的package包/类
public static <A, B, C, D>
Function<A, Option<D>> pipeK_Option(
        Function<? super A, Option<B>> f_A_B,
        Function<? super B, Option<C>> f_B_C,
        Function<? super C, Option<D>> f_C_D
) {
    return value -> f_A_B.apply(value).flatMap(f_B_C).flatMap(f_C_D);
}
 
开发者ID:RedNifre,项目名称:ravr,代码行数:9,代码来源:Ravr.java

示例12: should_fail_if_option_does_not_contain_expected_value

import io.vavr.control.Option; //导入依赖的package包/类
@Test
public void should_fail_if_option_does_not_contain_expected_value() throws Exception {
  Option<String> actual = Option.of("not-expected");
  String expectedValue = "something";

  thrown.expectAssertionError(shouldContain(actual, expectedValue).create());

  assertThat(actual).contains(expectedValue);
}
 
开发者ID:assertj,项目名称:assertj-vavr,代码行数:10,代码来源:OptionAssert_contains_Test.java

示例13: testPresent

import io.vavr.control.Option; //导入依赖的package包/类
@Test
public void testPresent() {
    final Option<LocalDate> endDate = Option.some(LocalDate.parse("2015-11-03"));
    dao.insert(1, Option.some("John Hughes"), LocalDate.now(), endDate, Option.none());

    assertThat(dao.findEndDateById(1)).isEqualTo(endDate);
}
 
开发者ID:dropwizard,项目名称:dropwizard-vavr,代码行数:8,代码来源:VavrDBIFactoryTest.java

示例14: addNewSession

import io.vavr.control.Option; //导入依赖的package包/类
public void addNewSession(final TwitterHandler twitterHandler) {
    final AccessToken accessToken = twitterHandler.getAccessToken();
    final Session session = new Session(
            accessToken.getScreenName(),
            accessToken,
            twitterHandler
    );

    this.loadSession(session);
    this.setCurrentSession(Option.of(session));
    this.saveAllSessions();
}
 
开发者ID:Tristan971,项目名称:Lyrebird,代码行数:13,代码来源:SessionManager.java

示例15: apOption

import io.vavr.control.Option; //导入依赖的package包/类
@Test
public void apOption() {
    Option<Function<String, Integer>>
            f = Option.some(String::length);
    Option<String>
            s = Option.some("hey");

    assertThat(ap(f, s), is(Option.some(3)));
    assertThat(ap(Option.none(), s), is(Option.none()));
    assertThat(ap(f, Option.none()), is(Option.none()));
    assertThat(ap(Option.none(), Option.none()), is(Option.none()));
}
 
开发者ID:RedNifre,项目名称:ravr,代码行数:13,代码来源:RavrTest.java


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