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

Java Try类代码示例

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

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



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

示例1: testReplaceColumn

import io.vavr.control.Try; //导入依赖的package包/类
@Test
public void testReplaceColumn() {
    DataTable oldTable = createDataTable();

    IDataColumn newCol = createDoubleColumn();
    Try<DataTable> newTable = oldTable.columns().replace("IntegerCol", newCol);

    assertTrue(newTable.isSuccess());
    assertTrue(oldTable.columns().count() == 3);
    assertTrue(newTable.get().columns().count() == 3);

    // Check the correct column was replaced.
    assertTrue(newTable.get().column(0).name().equals("StringCol"));
    assertTrue(newTable.get().column(1).name().equals("DoubleCol"));
    assertTrue(newTable.get().column(2).name().equals("BooleanCol"));
}
 
开发者ID:martincooper,项目名称:java-datatable,代码行数:17,代码来源:DataColumnCollectionTests.java


示例2: listFiles_existing_folder

import io.vavr.control.Try; //导入依赖的package包/类
@Test
public void listFiles_existing_folder() throws IOException {
    final Try<Path> pathUtilsTestFolder = Paths.getPathForResource(PATH_UTIL_TESTS_FOLDER);
    assertThat(pathUtilsTestFolder.isSuccess()).isTrue();

    final List<Path> files = Paths.listFiles(pathUtilsTestFolder.get());
    assertThat(files.size()).isEqualTo(2);

    final List<String> fileNames = files.stream()
        .map(Path::getFileName)
        .map(Path::toString)
        .collect(Collectors.toList());

    assertThat(fileNames).containsExactlyInAnyOrder(
        EXISTING_FILE_NAME,
        EXISTING_ANOTHER_FILE_NAME
    );
}
 
开发者ID:Tristan971,项目名称:EasyFXML,代码行数:19,代码来源:PathsTest.java


示例3: testInsertColumn

import io.vavr.control.Try; //导入依赖的package包/类
@Test
public void testInsertColumn() {
    DataTable oldTable = createDataTable();

    IDataColumn newCol = createDoubleColumn();
    Try<DataTable> newTable = oldTable.columns().insert(0, newCol);

    assertTrue(newTable.isSuccess());
    assertTrue(oldTable.columns().count() == 3);
    assertTrue(newTable.get().columns().count() == 4);

    // Check the column was inserted in the correct place.
    assertTrue(newTable.get().column(0).name().equals("DoubleCol"));
    assertTrue(newTable.get().column(1).name().equals("StringCol"));
    assertTrue(newTable.get().column(2).name().equals("IntegerCol"));
}
 
开发者ID:martincooper,项目名称:java-datatable,代码行数:17,代码来源:DataColumnCollectionTests.java


示例4: value

import io.vavr.control.Try; //导入依赖的package包/类
@Override
public final Try<T> value() {
    if(results.isEmpty()) {
        throw new IllegalStateException("Attempt to combine an empty set");
    }
    return results.map(Result::value)
            .reduce((t1, t2) -> {
                if(t1.isFailure() || t2.isFailure()) {
                    return Try.failure(
                        new RuntimeException(
                            String.join("\r\n", issues())
                        )
                    );
                }
                return Try.success(
                    combineOperator.apply(t1.get(), t2.get())
                );
            });
}
 
开发者ID:project-avral,项目名称:oo-atom,代码行数:20,代码来源:RCombined.java


示例5: getAvailablePort

import io.vavr.control.Try; //导入依赖的package包/类
public static Try<Integer> getAvailablePort() {
    synchronized (ASSIGNED_PORTS_MONITOR) {
        return Try.of(() -> {
            int hostPort;
            do {
                final ServerSocket serverSocket = new ServerSocket(0);
                hostPort = serverSocket.getLocalPort();
                serverSocket.close();
            } while (assignedPorts.contains(hostPort));

            assignedPorts = assignedPorts.add(hostPort);

            return hostPort;
        });
    }
}
 
开发者ID:fabzo,项目名称:kraken,代码行数:17,代码来源:Utils.java


示例6: testSimpleQuickSort

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

    DataTable table = DataTableBuilder
            .create("NewTable")
            .withColumn(Integer.class, "IntCol", List.of(3, 20, 4, 18, 0, -30, 100))
            .build().get();

    Try<DataView> view = table.quickSort("IntCol", SortOrder.Descending);

    assertTrue(view.isSuccess());

    // Check IntCol values are in descending order.
    assertTrue(view.get().row(0).getAs(Integer.class, "IntCol") == 100);
    assertTrue(view.get().row(1).getAs(Integer.class, "IntCol") == 20);
    assertTrue(view.get().row(2).getAs(Integer.class, "IntCol") == 18);
    assertTrue(view.get().row(3).getAs(Integer.class, "IntCol") == 4);
    assertTrue(view.get().row(4).getAs(Integer.class, "IntCol") == 3);
    assertTrue(view.get().row(5).getAs(Integer.class, "IntCol") == 0);
    assertTrue(view.get().row(6).getAs(Integer.class, "IntCol") == -30);
}
 
开发者ID:martincooper,项目名称:java-datatable,代码行数:22,代码来源:QuickSortTests.java


示例7: actionByColumnName

import io.vavr.control.Try; //导入依赖的package包/类
private Try<DataTable> actionByColumnName(String columnName, Function<Integer, Try<DataTable>> action) {
    Integer idx = columnIdxByName(columnName);

    return idx < 0
            ? error("Column not found with name " + columnName)
            : action.apply(idx);
}
 
开发者ID:martincooper,项目名称:java-datatable,代码行数:8,代码来源:DataColumnCollection.java


示例8: loadStylesheet

import io.vavr.control.Try; //导入依赖的package包/类
@Override
protected String loadStylesheet() {
    return Try.of(() -> stylesheetFilePath)
        .mapTry(Files::readAllBytes)
        .map(String::new)
        .getOrElseThrow((Function<? super Throwable, RuntimeException>) RuntimeException::new);
}
 
开发者ID:Tristan971,项目名称:EasyFXML,代码行数:8,代码来源:CachedFileBasedFxmlStylesheet.java


示例9: testDataReplaceRowValues

import io.vavr.control.Try; //导入依赖的package包/类
@Test
public void testDataReplaceRowValues() {
    DataTable table = createDataTable();

    Try<DataTable> result = table.rows().replaceValues(2, "ZZ", 100, true);

    assertTrue(result.isSuccess());
    testDataTableOnReplace(result.get());
}
 
开发者ID:martincooper,项目名称:java-datatable,代码行数:10,代码来源:DataRowModificationTests.java


示例10: testTryNotNullValidArgument

import io.vavr.control.Try; //导入依赖的package包/类
@Test
public void testTryNotNullValidArgument() {
    Try<Integer> result = Guard.tryNotNull(12345, "MyArgName");

    assertTrue(result.isSuccess());
    assertTrue(result.get() == 12345);
}
 
开发者ID:martincooper,项目名称:java-datatable,代码行数:8,代码来源:GuardTests.java


示例11: testDataInsertRowWithInvalidIndex

import io.vavr.control.Try; //导入依赖的package包/类
@Test
public void testDataInsertRowWithInvalidIndex() {
    DataTable table = createDataTable();

    // Insert data at an invalid index.
    Object[] rowValues = { "ZZ", 100, true };
    Try<DataTable> result = table.rows().insert(200, rowValues);

    assertTrue(result.isFailure());
    assertTrue(result.getCause() instanceof IndexOutOfBoundsException);
}
 
开发者ID:martincooper,项目名称:java-datatable,代码行数:12,代码来源:DataRowModificationTests.java


示例12: tryGetAs

import io.vavr.control.Try; //导入依赖的package包/类
/**
 * Returns the value of a particular row column as a specific type.
 * This method performs bounds checks and type checks. Any errors
 * will return a Try.failure.
 *
 * @param type The data type.
 * @param colName The name of the column.
 * @param <T> The value type.
 * @return Returns the value at the specified index.
 */
public <T> Try<T> tryGetAs(Class<T> type, String colName) {

    // Get the column as it's typed version.
    Try<DataColumn<T>> col = this.table.columns()
            .tryGet(colName)
            .flatMap(c -> c.asType(type));

    return col.isFailure()
            ? Try.failure(col.getCause())
            : Try.success(col.get().valueAt(this.rowIdx));
}
 
开发者ID:martincooper,项目名称:java-datatable,代码行数:22,代码来源:DataRow.java


示例13: loadNode

import io.vavr.control.Try; //导入依赖的package包/类
@Override
public <T extends Node> Try<T> loadNode(final FxmlNode nodeInfo, final Class<T> nodeClass) {
    return this.loadNodeImpl(
        this.getSingleStageFxmlLoader(nodeInfo),
        nodeInfo,
        nodeClass
    );
}
 
开发者ID:Tristan971,项目名称:EasyFXML,代码行数:9,代码来源:BaseEasyFxml.java


示例14: loadNodeImpl

import io.vavr.control.Try; //导入依赖的package包/类
/**
 * This method acts just like {@link #loadNode(FxmlNode)} but with no
 * autoconfiguration of controller binding and stylesheet application.
 */
private <T extends Node> Try<T> loadNodeImpl(final FxmlLoader fxmlLoader, final FxmlNode fxmlNode, final Class<T> clazz) {
    final String filePath = this.filePath(fxmlNode);
    fxmlLoader.setLocation(getUrlForResource(filePath));
    final Try<T> loadResult = Try.of(fxmlLoader::load).map(clazz::cast);

    loadResult.onSuccess(fxmlLoader::onSuccess).onFailure(fxmlLoader::onFailure);

    return this.applyStylesheetIfNeeded(
        fxmlNode,
        loadResult
    );
}
 
开发者ID:Tristan971,项目名称:EasyFXML,代码行数:17,代码来源:BaseEasyFxml.java


示例15: testValidToTypedColumn

import io.vavr.control.Try; //导入依赖的package包/类
@Test
public void testValidToTypedColumn() {
    IDataColumn column = createIntegerColumn();
    Try<DataColumn<Integer>> typedCol = column.asType(Integer.class);

    assertTrue(typedCol.isSuccess());
    assertTrue(typedCol.get().valueAt(1) == 7);
}
 
开发者ID:martincooper,项目名称:java-datatable,代码行数:9,代码来源:DataColumnTests.java


示例16: getSingleStageFxmlLoader

import io.vavr.control.Try; //导入依赖的package包/类
private FxmlLoader getSingleStageFxmlLoader(final FxmlNode node) {
    final FxmlLoader loader = this.context.getBean(FxmlLoader.class);
    final Try<FxmlController> instanceLoadingResult = this.makeControllerForNode(node);
    instanceLoadingResult.peek(instance -> {
        loader.setControllerFactory(clazz -> instance);
        loader.setOnSuccess(elem -> this.controllerManager.registerSingle(node, instance));
        loader.setOnFailure(cause -> LOG.error("Could not load node {}", node, cause));
    });
    return loader;
}
 
开发者ID:Tristan971,项目名称:EasyFXML,代码行数:11,代码来源:BaseEasyFxml.java


示例17: getMultiStageFxmlLoader

import io.vavr.control.Try; //导入依赖的package包/类
private FxmlLoader getMultiStageFxmlLoader(final FxmlNode node, final Object selector) {
    final FxmlLoader loader = this.context.getBean(FxmlLoader.class);
    final Try<FxmlController> instanceLoadingResult = this.makeControllerForNode(node);
    instanceLoadingResult.peek(instance -> {
        loader.setControllerFactory(clazz -> instance);
        loader.setOnSuccess(elem -> this.controllerManager.registerMultiple(node, selector, instance));
        loader.setOnFailure(cause -> LOG.error("Could not load node {}", node, cause));
    });
    return loader;
}
 
开发者ID:Tristan971,项目名称:EasyFXML,代码行数:11,代码来源:BaseEasyFxml.java


示例18: testDataRowGetCheckedItemAsTypedByColName

import io.vavr.control.Try; //导入依赖的package包/类
@Test
public void testDataRowGetCheckedItemAsTypedByColName() {
    DataTable table = createDataTable();
    DataRow row = table.row(1);
    Try<Integer> itemData = row.tryGetAs(Integer.class, "IntegerCol");

    assertTrue(itemData.isSuccess());
    assertTrue(itemData.get() == 7);
}
 
开发者ID:martincooper,项目名称:java-datatable,代码行数:10,代码来源:DataRowTests.java


示例19: testDataRowGetItemAsUntypedByInvalidColIndex

import io.vavr.control.Try; //导入依赖的package包/类
@Test
public void testDataRowGetItemAsUntypedByInvalidColIndex() {
    DataTable table = createDataTable();
    DataRow row = table.row(1);
    Try<Object> itemData = row.get(10000);

    assertTrue(itemData.isFailure());
    assertTrue(itemData.getCause().getMessage().equals("Column index out of bounds"));
}
 
开发者ID:martincooper,项目名称:java-datatable,代码行数:10,代码来源:DataRowTests.java


示例20: testDataReplaceRowWithInvalidValueCount

import io.vavr.control.Try; //导入依赖的package包/类
@Test
public void testDataReplaceRowWithInvalidValueCount() {
    DataTable table = createDataTable();

    // Replace data where the number of values doesn't match the number of columns.
    Object[] rowValues = { "ZZ" };
    Try<DataTable> result = table.rows().replace(2, rowValues);

    assertTrue(result.isFailure());
    assertTrue(result.getCause().getMessage().equals("Number of values does not match number of columns."));
}
 
开发者ID:martincooper,项目名称:java-datatable,代码行数:12,代码来源:DataRowModificationTests.java



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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