ariba.util.formatter
Class IntegerFormatter

java.lang.Object
  extended by ariba.util.formatter.Formatter
      extended by ariba.util.formatter.IntegerFormatter
All Implemented Interfaces:
Compare, StringParser

public class IntegerFormatter
extends Formatter

IntegerFormatter is a subclass of Formatter which is responsible for formatting, parsing, and comparing int values and/or Integer objects.


Field Summary
static java.lang.String ClassName
          Our Java class name.
 
Fields inherited from interface ariba.util.core.Compare
EqualTo, GreaterThan, LessThan
 
Constructor Summary
IntegerFormatter()
          Creates a new IntegerFormatter.
 
Method Summary
static int compareIntegers(java.lang.Integer i1, java.lang.Integer i2)
          Compares two Integer objects for sorting purposes.
static int compareInts(int i1, int i2)
          Compares two int values for sorting purposes.
 int compareObjects(java.lang.Object o1, java.lang.Object o2, java.util.Locale locale)
          Compares two objects for sorting purposes in the given locale.
static int getIntValue(java.lang.Object object)
          Returns an int value derived from the given object in the default locale.
static java.lang.String getStringValue(int integer)
          Returns a formatted string for the given int value in the default locale.
static java.lang.String getStringValue(java.lang.Integer object)
          Returns a formatted string for the given Integer in the default locale.
static java.lang.String getStringValue(java.lang.Integer object, java.util.Locale locale)
          Returns a formatted string for the given Integer in the given locale.
static java.lang.String getStringValue(java.lang.Integer object, java.util.Locale locale, boolean useGrouping)
          Returns a formatted string for the given Integer in the given locale.
static java.lang.String getStringValue(java.lang.Integer object, java.util.Locale locale, java.lang.String pattern)
          Returns a formatted string for the given Integer in the given locale.
static java.lang.String getStringValue(java.lang.Integer object, java.util.Locale locale, java.lang.String pattern, boolean useGrouping)
          Returns a formatted string for the given Integer in the given locale.
static java.lang.String getStringValue(int integer, java.util.Locale locale)
          Returns a formatted string for the given int value in the given locale.
static java.lang.String getStringValue(int integer, java.util.Locale locale, boolean useGrouping)
          Returns a formatted string for the given int value in the given locale.
static java.lang.String getStringValue(int integer, java.util.Locale locale, java.lang.String pattern)
          Returns a formatted string for the given int value in the given locale.
static java.lang.String getStringValue(int integer, java.util.Locale locale, java.lang.String pattern, boolean useGrouping)
          Returns a formatted string for the given int value in the given locale.
 java.lang.Object getValue(java.lang.Object object, java.util.Locale locale)
          Returns a new Integer derived from the given object in the given locale.
static int parseInt(char[] chars, int offset, int scan)
          Tries to parse the given character array as an int in the default locale.
static int parseInt(char[] chars, int offset, int scan, int base)
          Tries to parse the given character array as an int in the given base.
static int parseInt(java.lang.String string)
          Tries to parse the given string as an integer in the default locale.
static int parseInt(java.lang.String string, int base)
          Tries to parse the given string as an int in the specified base.
static int parseInt(java.lang.String string, java.util.Locale locale)
          Tries to parse the given string as an integer in the given locale.
static int parseInt(java.lang.String string, java.util.Locale locale, java.lang.String pattern, boolean useGrouping)
          Tries to parse the given string as an integer in the given locale.
static int parseInt(java.lang.String string, java.util.Locale locale, java.lang.String pattern, boolean useGrouping, boolean allowOverflow)
          Tries to parse the given string as an integer in the given locale.
static int parseInt(java.lang.String string, java.util.Locale locale, java.lang.String pattern, boolean useGrouping, boolean allowOverflow, boolean strictParsing, int minValue, int maxValue)
          Tries to parse the given string as an integer in the given locale.
static int parseIntNoOverflow(java.lang.String string)
          Tries to parse the given string as an integer in the default locale.
static int parseIntNoOverflow(java.lang.String string, java.util.Locale locale)
          Tries to parse the given string as an integer in the specified locale.
static int parseIntWithDefault(java.lang.String string, int defaultValue)
          Convenience method for parsing a string into an integer in the given base.
 
Methods inherited from class ariba.util.formatter.Formatter
canFormatNulls, compare, compare, equal, equal, getFormat, getFormat, getFormatterClassForType, getFormatterForObject, getFormatterForType, getLocale, getStringValue, getStringValue, getValue, handlesNulls, isBidirectional, makeParseException, makeParseException, makeParseException, makeParseExceptionMessage, makeParseExceptionMessage, objectsAreEqual, objectsAreEqual, parse, parse, parseString, parseString, quickCompare, quickCompare, quickCompareValue, registerFormatter
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ClassName

public static final java.lang.String ClassName
Our Java class name.

See Also:
Constant Field Values
Constructor Detail

IntegerFormatter

public IntegerFormatter()
Creates a new IntegerFormatter.

Method Detail

getStringValue

public static java.lang.String getStringValue(java.lang.Integer object)
Returns a formatted string for the given Integer in the default locale.

Parameters:
object - the Integer to format into a string
Returns:
a string representation of the Integer

getStringValue

public static java.lang.String getStringValue(java.lang.Integer object,
                                              java.util.Locale locale)
Returns a formatted string for the given Integer in the given locale. The locale parameter must be non-null.

Parameters:
object - the Integer to format into a string
locale - the Locale to use for formatting
Returns:
a string representation of the Integer, or empty string if the Integer is null

getStringValue

public static java.lang.String getStringValue(java.lang.Integer object,
                                              java.util.Locale locale,
                                              java.lang.String pattern)
Returns a formatted string for the given Integer in the given locale. The locale parameter must be non-null.

Parameters:
object - the Integer to format into a string
locale - the Locale to use for formatting
pattern - the DecimalFormat pattern to use for formatting
Returns:
a string representation of the Integer, or empty string if the Integer is null
See Also:
DecimalFormat

getStringValue

public static java.lang.String getStringValue(java.lang.Integer object,
                                              java.util.Locale locale,
                                              boolean useGrouping)
Returns a formatted string for the given Integer in the given locale. The locale parameter must be non-null.

Parameters:
object - the Integer to format into a string
locale - the Locale to use for formatting
useGrouping - whether grouping characters should be used
Returns:
a string representation of the Integer, or empty string if the Integer is null

getStringValue

public static java.lang.String getStringValue(java.lang.Integer object,
                                              java.util.Locale locale,
                                              java.lang.String pattern,
                                              boolean useGrouping)
Returns a formatted string for the given Integer in the given locale. The locale parameter must be non-null.

Parameters:
object - the Integer to format into a string
locale - the Locale to use for formatting
pattern - the DecimalFormat pattern to use for formatting
useGrouping - whether grouping characters should be used
Returns:
a string representation of the Integer, or empty string if the Integer is null
See Also:
DecimalFormat

getStringValue

public static java.lang.String getStringValue(int integer)
Returns a formatted string for the given int value in the default locale.

Parameters:
integer - the int value to format into a string
Returns:
a string representation of the int

getStringValue

public static java.lang.String getStringValue(int integer,
                                              java.util.Locale locale)
Returns a formatted string for the given int value in the given locale. The locale parameter must be non-null.

Parameters:
integer - the int value to format into a string
locale - the Locale to use for formatting
Returns:
a string representation of the int

getStringValue

public static java.lang.String getStringValue(int integer,
                                              java.util.Locale locale,
                                              java.lang.String pattern)
Returns a formatted string for the given int value in the given locale. The locale parameter must be non-null.

Parameters:
integer - the int value to format into a string
locale - the Locale to use for formatting
pattern - the DecimalFormat pattern to use for formatting
Returns:
a string representation of the int
See Also:
DecimalFormat

getStringValue

public static java.lang.String getStringValue(int integer,
                                              java.util.Locale locale,
                                              boolean useGrouping)
Returns a formatted string for the given int value in the given locale. The locale parameter must be non-null.

Parameters:
integer - the int value to format into a string
locale - the Locale to use for formatting
useGrouping - whether grouping characters should be used
Returns:
a string representation of the int

getStringValue

public static java.lang.String getStringValue(int integer,
                                              java.util.Locale locale,
                                              java.lang.String pattern,
                                              boolean useGrouping)
Returns a formatted string for the given int value in the given locale. The locale parameter must be non-null.

Parameters:
integer - the int value to format into a string
locale - the Locale to use for formatting
pattern - the DecimalFormat pattern to use for formatting
useGrouping - whether grouping characters should be used
Returns:
a string representation of the int
See Also:
DecimalFormat

parseInt

public static int parseInt(java.lang.String string)
                    throws java.text.ParseException
Tries to parse the given string as an integer in the default locale.

Parameters:
string - the string to parse as an int
Returns:
an int value derived from the string
Throws:
java.text.ParseException - if the string cannot be parsed as an int

parseIntNoOverflow

public static int parseIntNoOverflow(java.lang.String string)
                              throws java.text.ParseException
Tries to parse the given string as an integer in the default locale. If the parsed value is less than Integer.MIN_VALUE or greater than Integer.MAX_VALUE, throws ParseException.

Parameters:
string - the string to parse as an int
Returns:
an int value derived from the string
Throws:
java.text.ParseException - if the string cannot be parsed as an int or if the string causes an overflow / underflow when parsed.

parseIntNoOverflow

public static int parseIntNoOverflow(java.lang.String string,
                                     java.util.Locale locale)
                              throws java.text.ParseException
Tries to parse the given string as an integer in the specified locale. If the parsed value is less than Integer.MIN_VALUE or greater than Integer.MAX_VALUE, throws ParseException.

Parameters:
string - the string to parse as an int
locale - the locale to use for parsing.
Returns:
an int value derived from the string
Throws:
java.text.ParseException - if the string cannot be parsed as an int or if the string causes an overflow / underflow when parsed.

parseInt

public static int parseInt(java.lang.String string,
                           java.util.Locale locale)
                    throws java.text.ParseException
Tries to parse the given string as an integer in the given locale.

Parameters:
string - the string to parse as an int
locale - the Locale to use for parsing
Returns:
an int value derived from the string
Throws:
java.text.ParseException - if the string cannot be parsed as an int

parseInt

public static int parseInt(java.lang.String string,
                           java.util.Locale locale,
                           java.lang.String pattern,
                           boolean useGrouping)
                    throws java.text.ParseException
Tries to parse the given string as an integer in the given locale.

Parameters:
string - the string to parse as an int
locale - the Locale to use for parsing
pattern - the DecimalFormat pattern to use for parsing
useGrouping - whether grouping characters should be used
Returns:
an int value derived from the string
Throws:
java.text.ParseException - if the string cannot be parsed as an int
See Also:
DecimalFormat

parseInt

public static int parseInt(java.lang.String string,
                           java.util.Locale locale,
                           java.lang.String pattern,
                           boolean useGrouping,
                           boolean allowOverflow)
                    throws java.text.ParseException
Tries to parse the given string as an integer in the given locale.

Parameters:
string - the string to parse as an int
locale - the Locale to use for parsing
pattern - the DecimalFormat pattern to use for parsing
useGrouping - whether grouping characters should be used
allowOverflow - if false, then thows ParseException if value is < Integer.MIN_VALUE or Integer.MAX_VALUE > val
Returns:
an int value derived from the string
Throws:
java.text.ParseException - if the string cannot be parsed as an int
See Also:
DecimalFormat

parseInt

public static int parseInt(java.lang.String string,
                           java.util.Locale locale,
                           java.lang.String pattern,
                           boolean useGrouping,
                           boolean allowOverflow,
                           boolean strictParsing,
                           int minValue,
                           int maxValue)
                    throws java.text.ParseException
Tries to parse the given string as an integer in the given locale.

Parameters:
string - the string to parse as an int
locale - the Locale to use for parsing
pattern - the DecimalFormat pattern to use for parsing
useGrouping - whether grouping characters should be used
allowOverflow - if false, then thows ParseException if value is < Integer.MIN_VALUE or Integer.MAX_VALUE > val
strictParsing - if true, then throws ParseException if only a portion of the string was evaluated to an integer. Example: "12 T" would evaluate to 12 if strictParsing is false, but with the flag on, an exception would be thrown
minValue - the minimum valid integer value allowed
maxValue - the maximum valid integer value allowed
Returns:
an int value derived from the string
Throws:
java.text.ParseException - if the string cannot be parsed as an int
See Also:
DecimalFormat

parseInt

public static int parseInt(char[] chars,
                           int offset,
                           int scan)
                    throws java.text.ParseException
Tries to parse the given character array as an int in the default locale. The offset and scan parameters determine where in the character array to begin parsing, and how many characters to use.

Parameters:
chars - the character array to parse as an int
offset - the index of the first character in the array to use
scan - the number of characters from the array to use
Returns:
an int value derived from the array
Throws:
java.text.ParseException - if the character array cannot be parsed as an int

parseInt

public static int parseInt(java.lang.String string,
                           int base)
                    throws java.text.ParseException
Tries to parse the given string as an int in the specified base.

Parameters:
string - the string to parse as an int
base - the numeric base to use for parsing
Returns:
an int value derived from the string
Throws:
java.text.ParseException - if the string cannot be parsed as an int in the specified base

parseInt

public static int parseInt(char[] chars,
                           int offset,
                           int scan,
                           int base)
                    throws java.text.ParseException
Tries to parse the given character array as an int in the given base. The offset and scan parameters determine where in the character array to begin parsing, and how many characters to use.

Parameters:
chars - the character array to parse as an int
offset - the index of the first character in the array to use
scan - the number of characters from the array to use
base - the numeric base to use for parsing
Returns:
an int value derived from the array
Throws:
java.text.ParseException - if the character array cannot be parsed as an int in the specified base

parseIntWithDefault

public static final int parseIntWithDefault(java.lang.String string,
                                            int defaultValue)
Convenience method for parsing a string into an integer in the given base. Uses the IntegerFormatter class to parse the string. If there is an exception while parsing the string, the specified default value is returned.

Parameters:
string - a string representation of an Integer
defaultValue - the value to return if the string can not be parsed
Returns:
an int represented by the specified string if the string could be parsed, defaultValue otherwise
See Also:
parseInt(String)

getIntValue

public static int getIntValue(java.lang.Object object)
Returns an int value derived from the given object in the default locale. If the object is not an Integer, it is converted to a string and parsed. Returns zero if the object can't be converted to an int.

Parameters:
object - the object to convert to an int value
Returns:
an int derived from the given object

compareIntegers

public static int compareIntegers(java.lang.Integer i1,
                                  java.lang.Integer i2)
Compares two Integer objects for sorting purposes. Returns an int value which is less than, equal to, or greater than zero depending on whether the first object sorts before, the same, or after the second object.

Parameters:
i1 - the first Integer to compare
i2 - the second Integer to compare
Returns:
int value which determines how the two objects should be ordered

compareInts

public static int compareInts(int i1,
                              int i2)
Compares two int values for sorting purposes. Returns an int value which is less than, equal to, or greater than zero depending on whether the first value sorts before, the same, or after the second value.

Parameters:
i1 - the first int value to compare
i2 - the second int value to compare
Returns:
int value which determines how the two values should be ordered

getValue

public java.lang.Object getValue(java.lang.Object object,
                                 java.util.Locale locale)
Returns a new Integer derived from the given object in the given locale. If the object is not an Integer, it is converted to a string and parsed. Returns null if the object can't be parsed as a Integer. The locale parameter is currently unused.

Specified by:
getValue in class Formatter
Parameters:
object - the object to convert to an Integer
locale - the Locale to use for conversion (unused)
Returns:
an Integer derived from the given object

compareObjects

public int compareObjects(java.lang.Object o1,
                          java.lang.Object o2,
                          java.util.Locale locale)
Compares two objects for sorting purposes in the given locale. The two objects must be non-null Integer objects. Returns a value which is less than, equal to, or greater than zero depending on whether the first object sorts before, the same, or after the second object. The locale parameter is currently unused.

Parameters:
o1 - the first Integer to compare
o2 - the second Integer to compare
locale - the Locale to use for comparison (unused)
Returns:
int value which determines how the two objects should be ordered


AribaWeb User Interface Development Framework
Copyright © 2000-2014 Ariba, Inc. All Rights Reserved.