Example usage for org.springframework.data.util Pair of

List of usage examples for org.springframework.data.util Pair of

Introduction

In this page you can find the example usage for org.springframework.data.util Pair of.

Prototype

public static <S, T> Pair<S, T> of(S first, T second) 

Source Link

Document

Creates a new Pair for the given elements.

Usage

From source file:com.ethercamp.harmony.service.BlockchainConsts.java

/**
 * Return pair of name and explorer url.
 *///from   w ww.  java 2 s.  c  o m
public static Pair<String, Optional<String>> getNetworkInfo(Environment env, String genesisHash) {
    final String networkNameKey = String.format("network.%s.networkName", genesisHash);
    final String explorerUrlKey = String.format("network.%s.explorerUrl", genesisHash);

    return Optional.ofNullable(env.getProperty(networkNameKey))
            .map(name -> Pair.of(name, Optional.ofNullable(env.getProperty(explorerUrlKey))))
            .orElse(Pair.of("Unknown network", Optional.empty()));
}

From source file:com.ethercamp.harmony.service.BlockchainInfoService.java

@Override
public void onApplicationEvent(ApplicationEvent event) {
    if (event instanceof EmbeddedServletContainerInitializedEvent) {
        serverPort = ((EmbeddedServletContainerInitializedEvent) event).getEmbeddedServletContainer().getPort();

        final boolean isPrivateNetwork = env.getProperty("networkProfile", "").equalsIgnoreCase("private");
        final boolean isClassicNetwork = env.getProperty("networkProfile", "").equalsIgnoreCase("classic");

        // find out network name
        final Optional<String> blockHash = Optional.ofNullable(blockchain.getBlockByNumber(0l))
                .map(block -> Hex.toHexString(block.getHash()));
        final Pair<String, Optional<String>> networkInfo;
        if (isPrivateNetwork) {
            networkInfo = Pair.of("Private Miner Network", Optional.empty());
        } else if (isClassicNetwork) {
            networkInfo = Pair.of("Classic ETC", Optional.empty());
        } else {/*from w  ww  .j av a 2  s .c o m*/
            networkInfo = blockHash
                    .flatMap(hash -> Optional.ofNullable(BlockchainConsts.getNetworkInfo(env, hash)))
                    .orElse(Pair.of("Unknown network", Optional.empty()));
        }

        final boolean isContractsFeatureEnabled = env.getProperty("feature.contract.enabled", "false")
                .equalsIgnoreCase("true");
        if (!isContractsFeatureEnabled) {
            VM.setVmHook(null);
            log.info("Disabled VM hook due to contracts feature disabled");
        }

        initialInfo.set(new InitialInfoDTO(config.projectVersion() + "-" + config.projectVersionModifier(),
                "Hash: " + BuildInfo.buildHash + ",   Created: " + BuildInfo.buildTime,
                env.getProperty("app.version"), networkInfo.getFirst(), networkInfo.getSecond().orElse(null),
                blockHash.orElse(null), System.currentTimeMillis(), Hex.toHexString(config.nodeId()),
                serverPort, isPrivateNetwork, env.getProperty("portCheckerUrl"), config.bindIp(),
                isContractsFeatureEnabled));

        final String ANSI_RESET = "\u001B[0m";
        final String ANSI_BLUE = "\u001B[34m";
        System.out.println("EthereumJ database dir location: " + systemProperties.databaseDir());
        System.out.println("EthereumJ keystore dir location: " + keystore.getKeyStoreLocation());
        System.out.println(ANSI_BLUE + "Server started at http://localhost:" + serverPort + "" + ANSI_RESET);

        if (!config.getConfig().hasPath("logs.keepStdOut")
                || !config.getConfig().getBoolean("logs.keepStdOut")) {
            createLogAppenderForMessaging();
        }
    }
}