|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectuk.org.blankaspect.nlf.Id
public class Id
This class implements an identifier that is used to identify the chunks in a Nested List File. An identifier is a string that is encoded as a size byte followed by a UTF-8 sequence. The size of the UTF-8 sequence must be between 1 and 255 bytes.
Identifiers that start with the '$' character (U+0024) are reserved.
To allow the conversion of a Nested List File to XML, a non-reserved identifer must be a valid unprefixed name (ie, a name that doesn't contain a ':') under XML 1.1. Note that XML 1.1 names are less restrictive than those of XML 1.0, so that a name that is valid under XML 1.1 might not be valid under XML 1.0.
Field Summary | |
---|---|
static int |
MAX_SIZE
|
static int |
MIN_SIZE
|
static java.lang.String |
RESERVED_PREFIX
|
static char |
RESERVED_PREFIX_CHAR
|
protected static int |
SIZE_MASK
|
static int |
SIZE_SIZE
|
Constructor Summary | |
---|---|
Id(byte[] bytes)
Constructs an identifier from an array of bytes. |
|
Id(byte[] bytes,
int offset)
Constructs an identifier from an array of bytes, starting at the specified offset. |
|
Id(java.lang.String str)
Constructs an identifier from a string. |
Method Summary | |
---|---|
int |
compareTo(Id id)
Compares this identifier with the specified Id object. |
boolean |
equals(java.lang.Object obj)
Compares this identifier with the specified object. |
byte[] |
getBytes()
Returns the encoded form of the identifier (a size byte followed by a UTF-8 sequence) as an array of bytes. |
int |
getFieldSize()
Returns the size of the field that the identifier would occupy in a Nested List File. |
int |
getSize()
Returns the size of the identifier when it is encoded as a UTF-8 sequence. |
static int |
getSize(byte[] bytes,
int offset)
Returns the size of an identifier that is encoded in an array of bytes at a specified offset. |
java.lang.String |
getValue()
Returns the value of the identifier. |
int |
hashCode()
Returns the hash code for this object. |
boolean |
isReserved()
Tests whether an identifier is reserved (ie, whether it starts with the reserved prefix). |
static boolean |
isValidId(java.lang.String str)
Tests whether the specified string is a valid identifier. |
java.lang.String |
toName(java.lang.String prefix)
Converts this identifier to a name, using the specified prefix. |
java.lang.String |
toString()
Returns the identifier as a string. |
void |
write(java.io.DataOutput dataOutput)
Writes the encoded form of the identifier (a size byte followed by a UTF-8 sequence) to the specified data output (an instance of java.io.DataOuput ). |
Methods inherited from class java.lang.Object |
---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public static final int SIZE_SIZE
public static final int MIN_SIZE
public static final int MAX_SIZE
protected static final int SIZE_MASK
public static final char RESERVED_PREFIX_CHAR
public static final java.lang.String RESERVED_PREFIX
Constructor Detail |
---|
public Id(byte[] bytes) throws java.lang.IllegalArgumentException
bytes
- the array of bytes from which the identifier is constructed. The first byte of the
array is the size of the UTF-8 sequence that follows.
java.lang.IllegalArgumentException
- if
bytes
is zero, orbytes[1]
are not a valid UTF-8 sequence, orpublic Id(byte[] bytes, int offset) throws java.lang.IllegalArgumentException
offset
is the length of the UTF-8 sequence that follows. The UTF-8 sequence is an encoding of the
value of the identifier.
bytes
- the array of bytes from which the identifier is constructed. The byte of the array
at offset
is the size of the UTF-8 sequence that follows.offset
- the offset to bytes
at which the identifier begins.
java.lang.IllegalArgumentException
- if
bytes
at offset
is zero, orbytes[offset+1]
are not a valid UTF-8 sequence, orpublic Id(java.lang.String str) throws java.lang.IllegalArgumentException
str
- the string from which the identifier is constructed.
java.lang.IllegalArgumentException
- if
Method Detail |
---|
public static int getSize(byte[] bytes, int offset)
bytes
- the array of bytes that contains the encoded identifier.offset
- the offset to bytes
at which the identifier begins.
bytes
at offset
).public static boolean isValidId(java.lang.String str)
str
- the string that is to be tested.
true
the specified string is a valid identifier; false
otherwise.public int compareTo(Id id)
Id
object. The comparison is performed by
comparing the values of the two objects using java.lang.String.compareTo(java.lang.String)
,
which compares strings lexicographically by the Unicode value of each character in the strings.
The result is
A result of zero implies that the equals(Object)
method would return true
.
Because of the restrictions on the characters in an identifier, reserved identifiers will always precede non-reserved identifiers.
compareTo
in interface java.lang.Comparable<Id>
id
- the Id
object with which the comparison is to be made.
0
(zero) if the value of this identifier is equal to the value of id
;0
if the value of this identifier is lexicographically less
than the value of id
;0
if the value of this identifier is lexicographically
greater than the value of id
.public boolean equals(java.lang.Object obj)
true
if and only if obj
is an Id
object that has the same value as this identifier.
equals
in class java.lang.Object
obj
- the object with which the comparison is to be made.
true
if the objects have the same value; false
otherwise.public int hashCode()
hashCode
in class java.lang.Object
equals(Object)
public java.lang.String toString()
getValue()
).
toString
in class java.lang.Object
getValue()
public java.lang.String getValue()
public int getSize()
getFieldSize()
public int getFieldSize()
getSize()
public boolean isReserved()
true
if the identifier is reserved; false
otherwise.public java.lang.String toName(java.lang.String prefix)
null
, this method returns the string that
is returned by getValue()
; otherwise, it returns the concatenation of the prefix,
a vertical line character (U+007C) and the string that is returned by getValue()
.
prefix
- the prefix that is to be used to form the name.
public byte[] getBytes()
public void write(java.io.DataOutput dataOutput) throws java.io.IOException
java.io.DataOuput
).
dataOutput
- the data output to which the encoded form of the identifier (a size byte followed
by a UTF-8 sequence) is to be written.
java.io.IOException
- if an I/O error occurs.getBytes()
|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |