22 package com.realtime.crossfire.jxclient.util;
24 import java.io.IOException;
25 import org.jetbrains.annotations.NotNull;
45 public static int parseInt(@NotNull
final String
string,
final int defaultValue) {
47 return Integer.parseInt(
string);
48 }
catch (
final NumberFormatException ignored) {
49 System.err.println(
"Warning: invalid value "+
string+
", using "+defaultValue+
" instead.");
63 public static int parseInt(@NotNull
final String
string,
final int defaultValue,
final int minValue,
final int maxValue) {
64 final int value =
parseInt(
string, defaultValue);
65 if (value < minValue || value > maxValue) {
66 System.err.println(
"Warning: invalid value "+
string+
", using "+defaultValue+
" instead.");
79 public static long parseLong(@NotNull
final String
string,
final long defaultValue) {
81 return Long.parseLong(
string);
82 }
catch (
final NumberFormatException ignored) {
83 System.err.println(
"Warning: invalid value "+
string+
", using "+defaultValue+
" instead.");
94 public static float parseFloat(@NotNull
final String str)
throws IOException {
96 return Float.parseFloat(str);
97 }
catch (
final NumberFormatException ex) {
98 throw new IOException(
"invalid number: "+str, ex);
108 public static boolean parseBoolean(@NotNull
final String str)
throws IOException {
110 return Boolean.parseBoolean(str);
111 }
catch (
final NumberFormatException ex) {
112 throw new IOException(
"invalid boolean: "+str, ex);
127 public static <T extends Enum<T>> T
parseEnum(@NotNull
final Class<T> class_, @NotNull
final String name, @NotNull
final String ident)
throws IOException {
129 return Enum.valueOf(class_, name);
130 }
catch (
final IllegalArgumentException ex) {
131 throw new IOException(
"no such "+ident+
" type: "+name, ex);
static< T extends Enum< T > T parseEnum(@NotNull final Class< T > class_, @NotNull final String name, @NotNull final String ident)
Parses an enum constant.
static long parseLong(@NotNull final String string, final long defaultValue)
Converts a string into a long value.
static float parseFloat(@NotNull final String str)
Parses a float constant.
static boolean parseBoolean(@NotNull final String str)
Parses a boolean constant.
static int parseInt(@NotNull final String string, final int defaultValue)
Converts a string into an int value.
Utility class for parsing strings into numbers.
static int parseInt(@NotNull final String string, final int defaultValue, final int minValue, final int maxValue)
Converts a string into an int value in the given bounds.
NumberParser()
Private constructor to prevent instantiation.