uk.org.blankaspect.nlf
Class Attributes.Attr

java.lang.Object
  extended by uk.org.blankaspect.nlf.Attributes.Attr
All Implemented Interfaces:
java.lang.Comparable<Attributes.Attr>
Enclosing class:
Attributes

public static class Attributes.Attr
extends java.lang.Object
implements java.lang.Comparable<Attributes.Attr>

This class implements an attribute name-value pair. An attributes chunk consists of a list of name-value pairs.

Since:
1.0

Constructor Summary
Attributes.Attr(java.lang.String name)
          Constructs an attribute name-value pair with the specified name.
Attributes.Attr(java.lang.String name, java.lang.String value)
          Constructs an attribute name-value pair with the specified name and value.
 
Method Summary
 int compareTo(Attributes.Attr attr)
          Compares this attribute with the specified Attr object.
 boolean equals(java.lang.Object obj)
          Compares this attribute with the specified object.
 byte[] getBytes(boolean littleEndian)
          Returns this Attr object in its encoded form (ie, in the form in which it is encoded in an attributes chunk in a Nested List File).
 java.lang.String getName()
          Returns the name of the attribute.
 int getSize()
          Returns the size of this Attr object in its encoded form (ie, in the form in which it is encoded in an attributes chunk in a Nested List File).
 java.lang.String getValue()
          Returns the value of the attribute.
 int hashCode()
          Returns the hash code for this object.
 java.lang.String toString()
          Returns the attribute as a string.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Attributes.Attr

public Attributes.Attr(java.lang.String name)
                throws java.lang.IllegalArgumentException
Constructs an attribute name-value pair with the specified name. The implicit attribute value is an empty string.

Parameters:
name - the attribute name.
Throws:
java.lang.IllegalArgumentException - if
  • name is null, or
  • the length of the UTF-8 encoding of name is greater than 65535 bytes, or
  • name is not a valid attribute name.
Since:
1.0

Attributes.Attr

public Attributes.Attr(java.lang.String name,
                       java.lang.String value)
                throws java.lang.IllegalArgumentException
Constructs an attribute name-value pair with the specified name and value.

Parameters:
name - the attribute name.
value - the attribute value.
Throws:
java.lang.IllegalArgumentException - if
  • name is null, or
  • the length of the UTF-8 encoding of name is greater than 65535 bytes, or
  • name is not a valid attribute name, or
  • value is null, or
  • the length of the UTF-8 encoding of value is greater than 65535 bytes.
Since:
1.0
Method Detail

compareTo

public int compareTo(Attributes.Attr attr)
Compares this attribute with the specified Attr object. The comparison is performed by comparing the names 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

Note that a result of zero does not imply that the equals(Object) method would return true, although the converse is true.

Specified by:
compareTo in interface java.lang.Comparable<Attributes.Attr>
Parameters:
attr - the Attr object with which the comparison is to be made.
Returns:
  • 0 (zero) if the name of this attribute is equal to the name of attr;
  • a value less than 0 if the name of this attribute is lexicographically less than the name of attr;
  • a value greater than 0 if the name of this attribute is lexicographically greater than the name of attr.
Since:
1.0
See Also:
String.compareTo(java.lang.String)

equals

public boolean equals(java.lang.Object obj)
Compares this attribute with the specified object. The result is true if and only if obj is an Attr object that has the same name and value as this object.

Overrides:
equals in class java.lang.Object
Parameters:
obj - the object with which the comparison is to be made.
Returns:
true if obj is an Attr object with the same name and value as this object; false otherwise.
Since:
1.0

hashCode

public int hashCode()
Returns the hash code for this object.

Overrides:
hashCode in class java.lang.Object
Returns:
the hash code for this object.
Since:
1.1
See Also:
equals(Object)

toString

public java.lang.String toString()
Returns the attribute as a string. The string is in the form name="value".

Overrides:
toString in class java.lang.Object
Returns:
the attribute as a string, in the form name="value".
Since:
1.0

getName

public java.lang.String getName()
Returns the name of the attribute.

Returns:
the name of the attribute.
Since:
1.0

getValue

public java.lang.String getValue()
Returns the value of the attribute.

Returns:
the value of the attribute.
Since:
1.0

getSize

public int getSize()
Returns the size of this Attr object in its encoded form (ie, in the form in which it is encoded in an attributes chunk in a Nested List File). The name and value of the attribute are each encoded as two size bytes followed by a UTF-8 sequence.

Returns:
the size of the Attr object in its encoded form.
Since:
1.0
See Also:
getBytes(boolean)

getBytes

public byte[] getBytes(boolean littleEndian)
Returns this Attr object in its encoded form (ie, in the form in which it is encoded in an attributes chunk in a Nested List File). The name and value of the attribute are each encoded as two size bytes followed by a UTF-8 sequence.

Parameters:
littleEndian - true if the byte order of the size of the name and value is little-endian; false if the byte order of the size of the name and value is big-endian.
Returns:
the Attr object in its encoded form.
Since:
1.0
See Also:
getSize()