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


Java Try.of方法代码示例

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


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

示例1: 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

示例2: getPublicFacingIP

import io.vavr.control.Try; //导入方法依赖的package包/类
public static Try<String> getPublicFacingIP() {
    return Try.of(() -> {
        final Enumeration<NetworkInterface> interfaces = NetworkInterface.getNetworkInterfaces();
        while (interfaces.hasMoreElements()) {
            final NetworkInterface iface = interfaces.nextElement();
            if (iface.isLoopback() || !iface.isUp() || iface.isVirtual() || iface.isPointToPoint()) {
                continue;
            }

            final Enumeration<InetAddress> addresses = iface.getInetAddresses();
            while (addresses.hasMoreElements()) {
                final InetAddress addr = addresses.nextElement();

                final String ip = addr.getHostAddress();
                if (Inet4Address.class == addr.getClass()) {
                    return ip;
                }
            }
        }

        throw new Exception("Could not find public facing IP");
    });
}
 
开发者ID:fabzo,项目名称:kraken,代码行数:24,代码来源:Utils.java

示例3: registerAccessToken

import io.vavr.control.Try; //导入方法依赖的package包/类
public Optional<AccessToken> registerAccessToken(final RequestToken requestToken, final String pinCode) {
    log.info("Registering token {} with pincode {}", requestToken.toString(), pinCode);

    final Try<AccessToken> tryAccessToken = Try.of(() -> {
        // Don't refactor expression lambda into statement lambda. It's too
        // long to be treated that way.
        //noinspection CodeBlock2Expr
        return this.twitter.getOAuthAccessToken(requestToken, pinCode);
    });

    if (tryAccessToken.isFailure()) {
        log.info("Could not get access token! An error was thrown!");
        return Optional.empty();
    }


    final AccessToken successAccessToken = tryAccessToken.get();
    this.twitter.setOAuthAccessToken(successAccessToken);
    log.info(
            "Successfully got access token for user @{}! {}",
            successAccessToken.getScreenName(),
            successAccessToken.toString()
    );
    this.accessToken = successAccessToken;

    this.sessionManager.addNewSession(this);
    return Optional.of(successAccessToken);
}
 
开发者ID:Tristan971,项目名称:Lyrebird,代码行数:29,代码来源:TwitterHandler.java

示例4: remove

import io.vavr.control.Try; //导入方法依赖的package包/类
/**
 * Attempts to remove an existing item at the specified index.
 *
 * @param index The index to remove the item at.
 * @return Returns a Success with the new modified DataColumn, or a Failure.
 */
@Override
public Try<IDataColumn> remove(Integer index) {
    return Try.of(() -> createColumn(this.data.removeAt(index)));
}
 
开发者ID:martincooper,项目名称:java-datatable,代码行数:11,代码来源:DataColumn.java

示例5: insertItem

import io.vavr.control.Try; //导入方法依赖的package包/类
/**
 * Inserts the item at the specified index.
 *
 * @param index The index to insert the item at.
 * @param value The item to insert.
 * @return Returns a new DataColumn with the new item inserted.
 */
public Try<DataColumn<T>> insertItem(Integer index, T value) {
    return Try.of(() -> createColumn(this.data.insert(index, value)));
}
 
开发者ID:martincooper,项目名称:java-datatable,代码行数:11,代码来源:DataColumn.java

示例6: replaceItem

import io.vavr.control.Try; //导入方法依赖的package包/类
/**
 * Replaces the existing item at the specified index with the new item.
 *
 * @param index The index to replace the existing item.
 * @param value The new item to replace the existing one.
 * @return Returns a new DataColumn with the specified item replaced.
 */
public Try<DataColumn<T>> replaceItem(Integer index, T value) {
    return Try.of(() -> createColumn(this.data.update(index, value)));
}
 
开发者ID:martincooper,项目名称:java-datatable,代码行数:11,代码来源:DataColumn.java

示例7: removeItem

import io.vavr.control.Try; //导入方法依赖的package包/类
/**
 * Removes the item at the specified index.
 *
 * @param index The index to remove the item at.
 * @return Returns a new DataColumn with the specified item removed.
 */
public Try<DataColumn<T>> removeItem(Integer index) {
    return Try.of(() -> createColumn(this.data.removeAt(index)));
}
 
开发者ID:martincooper,项目名称:java-datatable,代码行数:10,代码来源:DataColumn.java


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