Java Code Examples for java.util.OptionalInt#orElse()

The following examples show how to use java.util.OptionalInt#orElse() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: OmUtils.java    From hadoop-ozone with Apache License 2.0 6 votes vote down vote up
/**
 * Returns the http address of peer OM node.
 * @param conf Configuration
 * @param omNodeId peer OM node ID
 * @param omNodeHostAddr peer OM node host address
 * @return http address of peer OM node in the format <hostName>:<port>
 */
public static String getHttpAddressForOMPeerNode(ConfigurationSource conf,
    String omServiceId, String omNodeId, String omNodeHostAddr) {
  final Optional<String> bindHost = getHostNameFromConfigKeys(conf,
      addKeySuffixes(OZONE_OM_HTTP_BIND_HOST_KEY, omServiceId, omNodeId));

  final OptionalInt addressPort = getPortNumberFromConfigKeys(conf,
      addKeySuffixes(OZONE_OM_HTTP_ADDRESS_KEY, omServiceId, omNodeId));

  final Optional<String> addressHost = getHostNameFromConfigKeys(conf,
      addKeySuffixes(OZONE_OM_HTTP_ADDRESS_KEY, omServiceId, omNodeId));

  String hostName = bindHost.orElse(addressHost.orElse(omNodeHostAddr));

  return hostName + ":" + addressPort.orElse(OZONE_OM_HTTP_BIND_PORT_DEFAULT);
}
 
Example 2
Source File: OmUtils.java    From hadoop-ozone with Apache License 2.0 6 votes vote down vote up
/**
 * Returns the https address of peer OM node.
 * @param conf Configuration
 * @param omNodeId peer OM node ID
 * @param omNodeHostAddr peer OM node host address
 * @return https address of peer OM node in the format <hostName>:<port>
 */
public static String getHttpsAddressForOMPeerNode(ConfigurationSource conf,
    String omServiceId, String omNodeId, String omNodeHostAddr) {
  final Optional<String> bindHost = getHostNameFromConfigKeys(conf,
      addKeySuffixes(OZONE_OM_HTTPS_BIND_HOST_KEY, omServiceId, omNodeId));

  final OptionalInt addressPort = getPortNumberFromConfigKeys(conf,
      addKeySuffixes(OZONE_OM_HTTPS_ADDRESS_KEY, omServiceId, omNodeId));

  final Optional<String> addressHost = getHostNameFromConfigKeys(conf,
      addKeySuffixes(OZONE_OM_HTTPS_ADDRESS_KEY, omServiceId, omNodeId));

  String hostName = bindHost.orElse(addressHost.orElse(omNodeHostAddr));

  return hostName + ":" +
      addressPort.orElse(OZONE_OM_HTTPS_BIND_PORT_DEFAULT);
}
 
Example 3
Source File: MainnetProtocolSpecs.java    From besu with Apache License 2.0 6 votes vote down vote up
public static ProtocolSpecBuilder homesteadDefinition(
    final OptionalInt configContractSizeLimit, final OptionalInt configStackSizeLimit) {
  final int contractSizeLimit = configContractSizeLimit.orElse(FRONTIER_CONTRACT_SIZE_LIMIT);
  return frontierDefinition(configContractSizeLimit, configStackSizeLimit)
      .gasCalculator(HomesteadGasCalculator::new)
      .evmBuilder(MainnetEvmRegistries::homestead)
      .contractCreationProcessorBuilder(
          (gasCalculator, evm) ->
              new MainnetContractCreationProcessor(
                  gasCalculator,
                  evm,
                  true,
                  Collections.singletonList(MaxCodeSizeRule.of(contractSizeLimit)),
                  0))
      .transactionValidatorBuilder(
          gasCalculator -> new MainnetTransactionValidator(gasCalculator, true, Optional.empty()))
      .difficultyCalculator(MainnetDifficultyCalculators.HOMESTEAD)
      .name("Homestead");
}
 
Example 4
Source File: MainnetProtocolSpecs.java    From besu with Apache License 2.0 6 votes vote down vote up
public static ProtocolSpecBuilder istanbulDefinition(
    final Optional<BigInteger> chainId,
    final OptionalInt configContractSizeLimit,
    final OptionalInt configStackSizeLimit,
    final boolean enableRevertReason) {
  final int contractSizeLimit =
      configContractSizeLimit.orElse(SPURIOUS_DRAGON_CONTRACT_SIZE_LIMIT);
  return constantinopleFixDefinition(
          chainId, configContractSizeLimit, configStackSizeLimit, enableRevertReason)
      .gasCalculator(IstanbulGasCalculator::new)
      .evmBuilder(
          gasCalculator ->
              MainnetEvmRegistries.istanbul(gasCalculator, chainId.orElse(BigInteger.ZERO)))
      .precompileContractRegistryBuilder(MainnetPrecompiledContractRegistries::istanbul)
      .contractCreationProcessorBuilder(
          (gasCalculator, evm) ->
              new MainnetContractCreationProcessor(
                  gasCalculator,
                  evm,
                  true,
                  Collections.singletonList(MaxCodeSizeRule.of(contractSizeLimit)),
                  1,
                  SPURIOUS_DRAGON_FORCE_DELETE_WHEN_EMPTY_ADDRESSES))
      .name("Istanbul");
}
 
Example 5
Source File: PageProcessor.java    From presto with Apache License 2.0 6 votes vote down vote up
@VisibleForTesting
public PageProcessor(Optional<PageFilter> filter, List<? extends PageProjection> projections, OptionalInt initialBatchSize, ExpressionProfiler expressionProfiler)
{
    this.filter = requireNonNull(filter, "filter is null")
            .map(pageFilter -> {
                if (pageFilter.getInputChannels().size() == 1 && pageFilter.isDeterministic()) {
                    return new DictionaryAwarePageFilter(pageFilter);
                }
                return pageFilter;
            });
    this.projections = requireNonNull(projections, "projections is null").stream()
            .map(projection -> {
                if (projection.getInputChannels().size() == 1 && projection.isDeterministic()) {
                    return new DictionaryAwarePageProjection(projection, dictionarySourceIdFunction, projection instanceof InputPageProjection);
                }
                return projection;
            })
            .collect(toImmutableList());
    this.projectBatchSize = initialBatchSize.orElse(1);
    this.expressionProfiler = requireNonNull(expressionProfiler, "expressionProfiler is null");
}
 
Example 6
Source File: VirtualChestActionIntervalManager.java    From VirtualChest with GNU Lesser General Public License v3.0 6 votes vote down vote up
public boolean allowAction(Player player, OptionalInt acceptableActionIntervalTickForInventory)
{
    boolean denyAction = false;
    long now = player.getWorld().getProperties().getTotalTime();
    if (!player.hasPermission("virtualchest.bypass") && this.tickFromLastAction.containsKey(player))
    {
        int coolDown = acceptableActionIntervalTickForInventory.orElse(this.acceptableActionIntervalTick);
        long boundary = this.tickFromLastAction.get(player) + coolDown;
        denyAction = now < boundary;
    }
    if (denyAction)
    {
        return false;
    }
    this.tickFromLastAction.put(player, now);
    return true;
}
 
Example 7
Source File: AbstractLoader.java    From bonita-ui-designer with GNU General Public License v2.0 6 votes vote down vote up
@Override
public String getNextAvailableObjectId(Path directory, String objectName) throws IOException {
    if (!Files.exists(directory.resolve(objectName))) {
        return objectName;
    }
    Pattern pattern = Pattern.compile(objectName + "(\\d+)$");
    String nextAvailableObjectId;
    try (final Stream<Path> directoryStream = Files.list(directory)) {
        OptionalInt maxInt = directoryStream.map(directoryPath -> pattern.matcher(directoryPath.getFileName().toString()))
                .filter(Matcher::find)
                .mapToInt(m -> Integer.valueOf(m.group(1)))
                .max();
        nextAvailableObjectId = objectName + (maxInt.orElse(0) + 1);
    }
    return nextAvailableObjectId;
}
 
Example 8
Source File: MainnetProtocolSpecs.java    From besu with Apache License 2.0 5 votes vote down vote up
public static ProtocolSpecBuilder byzantiumDefinition(
    final Optional<BigInteger> chainId,
    final OptionalInt contractSizeLimit,
    final OptionalInt configStackSizeLimit,
    final boolean enableRevertReason) {
  final int stackSizeLimit = configStackSizeLimit.orElse(MessageFrame.DEFAULT_MAX_STACK_SIZE);
  return spuriousDragonDefinition(chainId, contractSizeLimit, configStackSizeLimit)
      .evmBuilder(MainnetEvmRegistries::byzantium)
      .precompileContractRegistryBuilder(MainnetPrecompiledContractRegistries::byzantium)
      .difficultyCalculator(MainnetDifficultyCalculators.BYZANTIUM)
      .transactionReceiptFactory(
          enableRevertReason
              ? MainnetProtocolSpecs::byzantiumTransactionReceiptFactoryWithReasonEnabled
              : MainnetProtocolSpecs::byzantiumTransactionReceiptFactory)
      .blockReward(BYZANTIUM_BLOCK_REWARD)
      .privateTransactionValidatorBuilder(() -> new PrivateTransactionValidator(chainId))
      .privateTransactionProcessorBuilder(
          (gasCalculator,
              transactionValidator,
              contractCreationProcessor,
              messageCallProcessor,
              privateTransactionValidator) ->
              new PrivateTransactionProcessor(
                  gasCalculator,
                  transactionValidator,
                  contractCreationProcessor,
                  messageCallProcessor,
                  false,
                  stackSizeLimit,
                  Account.DEFAULT_VERSION,
                  privateTransactionValidator))
      .name("Byzantium");
}
 
Example 9
Source File: AbstractCredentialsServiceTest.java    From hono with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Create a new password secret.
 *
 * @param password The password to use.
 * @param maxBcryptIterations max bcrypt iterations to use.
 * @return The password secret instance.
 */
public static PasswordSecret createPasswordSecret(final String password, final OptionalInt maxBcryptIterations) {
    final SpringBasedHonoPasswordEncoder encoder = new SpringBasedHonoPasswordEncoder(
            maxBcryptIterations.orElse(SpringBasedHonoPasswordEncoder.DEFAULT_BCRYPT_STRENGTH));
    final EncodedPassword encodedPwd = EncodedPassword.fromHonoSecret(encoder.encode(password));

    final PasswordSecret s = new PasswordSecret();
    s.setHashFunction(encodedPwd.hashFunction);
    if (encodedPwd.salt != null) {
        s.setSalt(Base64.getEncoder().encodeToString(encodedPwd.salt));
    }
    s.setPasswordHash(encodedPwd.password);
    return s;
}
 
Example 10
Source File: ReadSessionCreator.java    From spark-bigquery-connector with Apache License 2.0 4 votes vote down vote up
static int getMaxNumPartitionsRequested(OptionalInt maxParallelism, StandardTableDefinition tableDefinition) {
    return maxParallelism.orElse(Math.max(
            (int) (tableDefinition.getNumBytes() / DEFAULT_BYTES_PER_PARTITION), 1));
}
 
Example 11
Source File: MainnetProtocolSpecs.java    From besu with Apache License 2.0 4 votes vote down vote up
public static ProtocolSpecBuilder frontierDefinition(
    final OptionalInt configContractSizeLimit, final OptionalInt configStackSizeLimit) {
  final int contractSizeLimit = configContractSizeLimit.orElse(FRONTIER_CONTRACT_SIZE_LIMIT);
  final int stackSizeLimit = configStackSizeLimit.orElse(MessageFrame.DEFAULT_MAX_STACK_SIZE);
  return new ProtocolSpecBuilder()
      .gasCalculator(FrontierGasCalculator::new)
      .evmBuilder(MainnetEvmRegistries::frontier)
      .precompileContractRegistryBuilder(MainnetPrecompiledContractRegistries::frontier)
      .messageCallProcessorBuilder(MainnetMessageCallProcessor::new)
      .contractCreationProcessorBuilder(
          (gasCalculator, evm) ->
              new MainnetContractCreationProcessor(
                  gasCalculator,
                  evm,
                  false,
                  Collections.singletonList(MaxCodeSizeRule.of(contractSizeLimit)),
                  0))
      .transactionValidatorBuilder(
          gasCalculator ->
              new MainnetTransactionValidator(gasCalculator, false, Optional.empty()))
      .transactionProcessorBuilder(
          (gasCalculator,
              transactionValidator,
              contractCreationProcessor,
              messageCallProcessor) ->
              new MainnetTransactionProcessor(
                  gasCalculator,
                  transactionValidator,
                  contractCreationProcessor,
                  messageCallProcessor,
                  false,
                  stackSizeLimit,
                  Account.DEFAULT_VERSION,
                  TransactionPriceCalculator.frontier(),
                  CoinbaseFeePriceCalculator.frontier()))
      .privateTransactionProcessorBuilder(
          (gasCalculator,
              transactionValidator,
              contractCreationProcessor,
              messageCallProcessor,
              privateTransactionValidator) ->
              new PrivateTransactionProcessor(
                  gasCalculator,
                  transactionValidator,
                  contractCreationProcessor,
                  messageCallProcessor,
                  false,
                  stackSizeLimit,
                  Account.DEFAULT_VERSION,
                  new PrivateTransactionValidator(Optional.empty())))
      .difficultyCalculator(MainnetDifficultyCalculators.FRONTIER)
      .blockHeaderValidatorBuilder(MainnetBlockHeaderValidator.create())
      .ommerHeaderValidatorBuilder(MainnetBlockHeaderValidator.createOmmerValidator())
      .blockBodyValidatorBuilder(MainnetBlockBodyValidator::new)
      .transactionReceiptFactory(MainnetProtocolSpecs::frontierTransactionReceiptFactory)
      .blockReward(FRONTIER_BLOCK_REWARD)
      .skipZeroBlockRewards(false)
      .blockProcessorBuilder(MainnetBlockProcessor::new)
      .blockValidatorBuilder(MainnetBlockValidator::new)
      .blockImporterBuilder(MainnetBlockImporter::new)
      .blockHeaderFunctions(new MainnetBlockHeaderFunctions())
      .miningBeneficiaryCalculator(BlockHeader::getCoinbase)
      .name("Frontier");
}
 
Example 12
Source File: MainnetProtocolSpecs.java    From besu with Apache License 2.0 4 votes vote down vote up
public static ProtocolSpecBuilder spuriousDragonDefinition(
    final Optional<BigInteger> chainId,
    final OptionalInt configContractSizeLimit,
    final OptionalInt configStackSizeLimit) {
  final int contractSizeLimit =
      configContractSizeLimit.orElse(SPURIOUS_DRAGON_CONTRACT_SIZE_LIMIT);
  final int stackSizeLimit = configStackSizeLimit.orElse(MessageFrame.DEFAULT_MAX_STACK_SIZE);

  return tangerineWhistleDefinition(OptionalInt.empty(), configStackSizeLimit)
      .gasCalculator(SpuriousDragonGasCalculator::new)
      .skipZeroBlockRewards(true)
      .messageCallProcessorBuilder(
          (evm, precompileContractRegistry) ->
              new MainnetMessageCallProcessor(
                  evm,
                  precompileContractRegistry,
                  SPURIOUS_DRAGON_FORCE_DELETE_WHEN_EMPTY_ADDRESSES))
      .contractCreationProcessorBuilder(
          (gasCalculator, evm) ->
              new MainnetContractCreationProcessor(
                  gasCalculator,
                  evm,
                  true,
                  Collections.singletonList(MaxCodeSizeRule.of(contractSizeLimit)),
                  1,
                  SPURIOUS_DRAGON_FORCE_DELETE_WHEN_EMPTY_ADDRESSES))
      .transactionValidatorBuilder(
          gasCalculator -> new MainnetTransactionValidator(gasCalculator, true, chainId))
      .transactionProcessorBuilder(
          (gasCalculator,
              transactionValidator,
              contractCreationProcessor,
              messageCallProcessor) ->
              new MainnetTransactionProcessor(
                  gasCalculator,
                  transactionValidator,
                  contractCreationProcessor,
                  messageCallProcessor,
                  true,
                  stackSizeLimit,
                  Account.DEFAULT_VERSION,
                  TransactionPriceCalculator.frontier(),
                  CoinbaseFeePriceCalculator.frontier()))
      .name("SpuriousDragon");
}
 
Example 13
Source File: ClassicProtocolSpecs.java    From besu with Apache License 2.0 4 votes vote down vote up
public static ProtocolSpecBuilder atlantisDefinition(
    final Optional<BigInteger> chainId,
    final OptionalInt configContractSizeLimit,
    final OptionalInt configStackSizeLimit,
    final boolean enableRevertReason) {
  final int contractSizeLimit =
      configContractSizeLimit.orElse(MainnetProtocolSpecs.SPURIOUS_DRAGON_CONTRACT_SIZE_LIMIT);
  final int stackSizeLimit = configStackSizeLimit.orElse(MessageFrame.DEFAULT_MAX_STACK_SIZE);
  return gothamDefinition(chainId, configContractSizeLimit, configStackSizeLimit)
      .evmBuilder(MainnetEvmRegistries::byzantium)
      .gasCalculator(SpuriousDragonGasCalculator::new)
      .skipZeroBlockRewards(true)
      .messageCallProcessorBuilder(
          (evm, precompileContractRegistry) ->
              new MainnetMessageCallProcessor(evm, precompileContractRegistry))
      .precompileContractRegistryBuilder(MainnetPrecompiledContractRegistries::byzantium)
      .difficultyCalculator(ClassicDifficultyCalculators.EIP100)
      .transactionReceiptFactory(
          enableRevertReason
              ? ClassicProtocolSpecs::byzantiumTransactionReceiptFactoryWithReasonEnabled
              : ClassicProtocolSpecs::byzantiumTransactionReceiptFactory)
      .contractCreationProcessorBuilder(
          (gasCalculator, evm) ->
              new MainnetContractCreationProcessor(
                  gasCalculator,
                  evm,
                  true,
                  Collections.singletonList(MaxCodeSizeRule.of(contractSizeLimit)),
                  1))
      .transactionProcessorBuilder(
          (gasCalculator,
              transactionValidator,
              contractCreationProcessor,
              messageCallProcessor) ->
              new MainnetTransactionProcessor(
                  gasCalculator,
                  transactionValidator,
                  contractCreationProcessor,
                  messageCallProcessor,
                  true,
                  stackSizeLimit,
                  Account.DEFAULT_VERSION,
                  TransactionPriceCalculator.frontier(),
                  CoinbaseFeePriceCalculator.frontier()))
      .name("Atlantis");
}
 
Example 14
Source File: TimeWheelTest.java    From JavaBase with MIT License 4 votes vote down vote up
private long calculate() {
  runRecord.add(System.currentTimeMillis());

  OptionalInt reduce = IntStream.rangeClosed(0, 200).reduce(Integer::sum);
  return reduce.orElse(0);
}
 
Example 15
Source File: JsonbParserTest.java    From typescript-generator with MIT License 4 votes vote down vote up
@JsonbCreator
public RequiredOptional(final OptionalInt foo) {
    this.foo = foo.orElse(1);
}
 
Example 16
Source File: LoopExtractionPass.java    From incubator-nemo with Apache License 2.0 3 votes vote down vote up
/**
 * This method finds the maximum loop vertex stack depth of a specific DAG. This is to handle nested loops.
 *
 * @param dag DAG to observe.
 * @return The maximum stack depth of the DAG.
 * @throws Exception exceptions through the way.
 */
private Integer findMaxLoopVertexStackDepth(final DAG<IRVertex, IREdge> dag) {
  final OptionalInt maxDepth = dag.getVertices().stream().filter(dag::isCompositeVertex)
    .mapToInt(dag::getLoopStackDepthOf)
    .max();
  return maxDepth.orElse(0);
}