本文整理匯總了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;
}
示例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);
}
示例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);
}
}
示例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;
}
示例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);
}
}
示例6: isAnonymousRest
import com.google.common.primitives.Ints; //導入方法依賴的package包/類
private static boolean isAnonymousRest(String lastPart) {
return Ints.tryParse(lastPart) != null;
}