jET
1.0beta1


prv.doman.util
Class HexadecimalFormat

java.lang.Object
  |
  +--java.text.Format
        |
        +--prv.doman.util.HexadecimalFormat
All Implemented Interfaces:
java.lang.Cloneable, java.io.Serializable

public class HexadecimalFormat
extends java.text.Format

This class enables format and parse hexadecimal numbers. It works with Java standard types of numbers: byte, short, int, and long. Floating point types are discarded.

Hexadacimal format is not locale dependent.

See Also:
Serialized Form

Field Summary
static int DECORATION_NONE
          Decoration means additional format of hexadacimal format.
static int DECORATION_PREFIX
          Sets at the begining of output symbols: 0x.
static int DECORATION_SUFFIX
          Sets at the end of output symbol: h.
 
Constructor Summary
HexadecimalFormat()
          Creates default hexadecimal formatter.
 
Method Summary
 java.lang.String format(byte b)
          Format single byte.
 java.lang.StringBuffer format(byte b, java.lang.StringBuffer toAppendTo, java.text.FieldPosition pos)
          Formats single byte to the hexadecimal textual representation.
 java.lang.String format(int i)
          Formats integer value to the hexadecimal representation.
 java.lang.StringBuffer format(int i, java.lang.StringBuffer toAppendTo, java.text.FieldPosition pos)
          Formats integer value to the hexidecimal textual representation.
 java.lang.String format(long l)
          Formats long value to the hexadecimal representation.
 java.lang.StringBuffer format(long l, java.lang.StringBuffer toAppendTo, java.text.FieldPosition pos)
          Formats long value to the hexidecimal textual representation.
 java.lang.StringBuffer format(java.lang.Object obj, java.lang.StringBuffer toAppendTo, java.text.FieldPosition pos)
          See note on superclass.
 java.lang.String format(short s)
          Formats short value to the hexadecimal textual representation.
 java.lang.StringBuffer format(short s, java.lang.StringBuffer toAppendTo, java.text.FieldPosition pos)
          Formats short value to the hexidecimal textual representation.
 int getDecoration()
          Gets decoration style of this format.
 boolean isLowerCase()
          Checks if hexadecimal digits from a to f are lower or upper cased in this format.
 java.lang.Number parse(java.lang.String source)
          Parses text containing hexadecimal number.
 java.lang.Number parse(java.lang.String source, java.text.ParsePosition pos)
          Parses text at specified position.
 java.lang.Object parseObject(java.lang.String source, java.text.ParsePosition pos)
          Parses text to find hexadecimal numbers.
 void setDecoration(int d)
          Sets decoration for this format.
 void toLowerCase()
          Sets hexadecimal digits from a to f to be lower cased.
 void toUpperCase()
          Sets hexadecimal digits from a to f to be upper cased.
 
Methods inherited from class java.text.Format
clone, format, formatToCharacterIterator, parseObject
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DECORATION_NONE

public static final int DECORATION_NONE
Decoration means additional format of hexadacimal format. This constant means no decoration.

See Also:
Constant Field Values

DECORATION_PREFIX

public static final int DECORATION_PREFIX
Sets at the begining of output symbols: 0x.

See Also:
Constant Field Values

DECORATION_SUFFIX

public static final int DECORATION_SUFFIX
Sets at the end of output symbol: h.

See Also:
Constant Field Values
Constructor Detail

HexadecimalFormat

public HexadecimalFormat()
Creates default hexadecimal formatter. It uses symbols: 0 - 9 and a - f. It defines no decoration and lower case.

Method Detail

format

public java.lang.StringBuffer format(java.lang.Object obj,
                                     java.lang.StringBuffer toAppendTo,
                                     java.text.FieldPosition pos)
See note on superclass.

Specified by:
format in class java.text.Format

format

public final java.lang.String format(byte b)
Format single byte. Result will be two hexadecimal digits.

Parameters:
b - Byte value.
Returns:
Hexadecimal textual representation of this byte.

format

public java.lang.StringBuffer format(byte b,
                                     java.lang.StringBuffer toAppendTo,
                                     java.text.FieldPosition pos)
Formats single byte to the hexadecimal textual representation. The result appends to string buffer.

Parameters:
b - Byte value.
toAppendTo - String buffer where append to.
pos - Unused.

format

public final java.lang.String format(short s)
Formats short value to the hexadecimal textual representation.

Parameters:
s - Short value.
Returns:
Four hexadecimal digits.

format

public java.lang.StringBuffer format(short s,
                                     java.lang.StringBuffer toAppendTo,
                                     java.text.FieldPosition pos)
Formats short value to the hexidecimal textual representation.

Parameters:
s - Short value.
toAppendTo - Where text should be appended.
pos - Unused.
Returns:
String buffer with appended hexadecimal number.

format

public final java.lang.String format(int i)
Formats integer value to the hexadecimal representation.

Parameters:
i - Integer value.
Returns:
Eight hexadecimal digits.

format

public java.lang.StringBuffer format(int i,
                                     java.lang.StringBuffer toAppendTo,
                                     java.text.FieldPosition pos)
Formats integer value to the hexidecimal textual representation.

Parameters:
i - Integer value.
toAppendTo - Where text should be appended.
pos - Unused.
Returns:
String buffer with appended hexadecimal number.

format

public final java.lang.String format(long l)
Formats long value to the hexadecimal representation.

Parameters:
l - Long value.
Returns:
Sixteen hexadecimal digits.

format

public java.lang.StringBuffer format(long l,
                                     java.lang.StringBuffer toAppendTo,
                                     java.text.FieldPosition pos)
Formats long value to the hexidecimal textual representation.

Parameters:
l - Long value.
toAppendTo - Where text should be appended.
pos - Unused.
Returns:
String buffer with appended hexadecimal number.

parseObject

public final java.lang.Object parseObject(java.lang.String source,
                                          java.text.ParsePosition pos)
Parses text to find hexadecimal numbers. Returned object are instances of java.lang.Number class.

Specified by:
parseObject in class java.text.Format
Parameters:
source - Text to search.
pos - Starting position of searching.
Returns:
Returned number.

parse

public java.lang.Number parse(java.lang.String source,
                              java.text.ParsePosition pos)
Parses text at specified position.

Parameters:
source - Source of text.
pos - Position to start searching from.
Returns:
Byte, short, integer or long wrapper of hexadecimal number in source.

parse

public java.lang.Number parse(java.lang.String source)
                       throws java.text.ParseException
Parses text containing hexadecimal number. A number must have at most 16 digits. Otherwise parse exception is thrown. Hexadecimal representation may contains prefix 0x or suffix h.

Exception is thrown when number hasn't got proper digit count or has bad format, or text isn't a hexadecimal number.

Parameters:
source - Text containing hexadecimal number.
Returns:
Byte, short, integer or long wrapper if text contains number, or null when excpetion is thrown.
Throws:
java.text.ParseException - Exception.

setDecoration

public void setDecoration(int d)
Sets decoration for this format. Decaration styles are constants. Note that decoration with suffix and decoration with prefix exclude each other.

Parameters:
d - Decoration styles as integer.

getDecoration

public int getDecoration()
Gets decoration style of this format.

Returns:
Decoration style represented by integer constant.

toUpperCase

public void toUpperCase()
Sets hexadecimal digits from a to f to be upper cased.


toLowerCase

public void toLowerCase()
Sets hexadecimal digits from a to f to be lower cased.


isLowerCase

public boolean isLowerCase()
Checks if hexadecimal digits from a to f are lower or upper cased in this format.

Returns:
True if digits are lower cased.

jET
1.0beta1