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


Java Ints.tryParse方法代码示例

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


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

示例1: findAllShardsForIndex

import com.google.common.primitives.Ints; //导入方法依赖的package包/类
private static Set<ShardId> findAllShardsForIndex(Path indexPath) throws IOException {
    Set<ShardId> shardIds = new HashSet<>();
    if (Files.isDirectory(indexPath)) {
        try (DirectoryStream<Path> stream = Files.newDirectoryStream(indexPath)) {
            String currentIndex = indexPath.getFileName().toString();
            for (Path shardPath : stream) {
                if (Files.isDirectory(shardPath)) {
                    Integer shardId = Ints.tryParse(shardPath.getFileName().toString());
                    if (shardId != null) {
                        ShardId id = new ShardId(currentIndex, shardId);
                        shardIds.add(id);
                    }
                }
            }
        }
    }
    return shardIds;
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:19,代码来源:NodeEnvironment.java

示例2: configureErrorRetryCount

import com.google.common.primitives.Ints; //导入方法依赖的package包/类
private Optional<Integer> configureErrorRetryCount(String property) {
    Integer count = null;
    if (null != property) {
        count = Ints.tryParse(property);
        if (null == count || count < 0) {
            throw new IllegalArgumentException("System property [" + S3_MAX_ERROR_RETRY + "=" + property + "]  must be a valid positive Integer");

        }
    }
    return Optional.fromNullable(count);
}
 
开发者ID:lxxlxx888,项目名称:Reer,代码行数:12,代码来源:S3ConnectionProperties.java

示例3: save

import com.google.common.primitives.Ints; //导入方法依赖的package包/类
@Override
public void save() {
    String text = getTextField().getText();
    Integer value = Ints.tryParse(text);
    if (value == null) {
        getOption().resetToDefault();
        load();
    } else {
        getOption().set(value);
    }
}
 
开发者ID:lttng,项目名称:lttng-scope,代码行数:12,代码来源:DebugOptionsDialog.java

示例4: onCommand

import com.google.common.primitives.Ints; //导入方法依赖的package包/类
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
    if (args.length < 3) {
        sender.sendMessage((Object)ChatColor.RED + "Usage: " + this.getUsage(label));
        return true;
    }
    Integer amount = Ints.tryParse((String)args[2]);
    if (amount == null) {
        sender.sendMessage((Object)ChatColor.RED + "'" + args[2] + "' is not a number.");
        return true;
    }
    if (amount <= 0) {
        sender.sendMessage((Object)ChatColor.RED + "The amount of lives must be positive.");
        return true;
    }
    OfflinePlayer target = Bukkit.getOfflinePlayer((String)args[1]);
    if (!target.hasPlayedBefore() && !target.isOnline()) {
        sender.sendMessage(String.format(BaseConstants.PLAYER_WITH_NAME_OR_UUID_NOT_FOUND, args[1]));
        return true;
    }
    Player onlineTarget = target.getPlayer();
    if (sender instanceof Player && !sender.hasPermission(PERMISSION)) {
        Player player = (Player)sender;
        int ownedLives = this.plugin.getDeathbanManager().getLives(player.getUniqueId());
        if (amount > ownedLives) {
            sender.sendMessage((Object)ChatColor.RED + "You tried to give " + target.getName() + ' ' + amount + " lives, but you only have " + ownedLives + '.');
            return true;
        }
        this.plugin.getDeathbanManager().takeLives(player.getUniqueId(), amount);
    }
    final int targetLives = this.plugin.getDeathbanManager().getLives(target.getUniqueId());
    this.plugin.getDeathbanManager().addLives(target.getUniqueId(), amount);
    sender.sendMessage((Object)ChatColor.YELLOW + "You have sent " + (Object)ChatColor.GOLD + target.getName() + (Object)ChatColor.YELLOW + ' ' + amount + ' ' + (amount > 1 ? "life" : "lives") + '.');
    sender.sendMessage(ChatColor.GREEN + "Remaining Lives: " + ChatColor.RED + targetLives +  ChatColor.RED + ' ' + ((targetLives == 1) ? "life" : "lives") + '.');
    if (onlineTarget != null) {
        onlineTarget.sendMessage((Object)ChatColor.GOLD + sender.getName() + (Object)ChatColor.YELLOW + " has sent you " + (Object)ChatColor.GOLD + amount + ' ' + (amount > 1 ? "life" : "lives") + '.');
    }
    return true;
}
 
开发者ID:funkemunky,项目名称:HCFCore,代码行数:39,代码来源:LivesGiveArgument.java

示例5: resizeImage

import com.google.common.primitives.Ints; //导入方法依赖的package包/类
/**
 * This resizes the picture according to
 * 1. height and width value of the div tag enclosing the img tag
 * 2. scaling mode. 0 - Scale proportionally, 1 - Scale to fit
 *    which correspond to the choices in ScalingChoicePropertyEditor
 *
 * This should be called whenever a property affecting the size is changed
 */
private void resizeImage() {
  if (image.getUrl().equals(getIconImage().getUrl())) {
    unclipImage();
    return;
  }

  String width = getElement().getStyle().getWidth();
  String height = getElement().getStyle().getHeight();

  // the situation right after refreshing the page
  if (width.isEmpty() || height.isEmpty()) {
    return;
  }

  int frameWidth = Ints.tryParse(width.substring(0, width.indexOf("px")));
  int frameHeight = Ints.tryParse(height.substring(0, height.indexOf("px")));

  if (scalingMode.equals("0")) {
    float ratio = Math.min(frameWidth / (float) getPreferredWidth(),
        frameHeight / (float) getPreferredHeight());
    int scaledWidth = Double.valueOf(getPreferredWidth() * ratio).intValue();
    int scaledHeight = Double.valueOf(getPreferredHeight() * ratio).intValue();
    image.setSize(scaledWidth + "px", scaledHeight + "px");

  } else if (scalingMode.equals("1")) {
    image.setSize("100%", "100%");

  } else {
    throw new IllegalStateException("Illegal scaling mode: " + scalingMode);
  }
}
 
开发者ID:mit-cml,项目名称:appinventor-extensions,代码行数:40,代码来源:MockImageBase.java

示例6: isAnonymousRest

import com.google.common.primitives.Ints; //导入方法依赖的package包/类
private static boolean isAnonymousRest(String lastPart) {
    return Ints.tryParse(lastPart) != null;
}
 
开发者ID:TNG,项目名称:ArchUnit,代码行数:4,代码来源:Formatters.java


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