Version 4.10.0

hirondelle.web4j.model
Class Id

Object
  extended by hirondelle.web4j.model.Id
All Implemented Interfaces:
Serializable, Comparable<Id>

public final class Id
extends Object
implements Serializable, Comparable<Id>

Building block class for identifiers.

Identifiers are both common and important. Unfortunately, there is no class in the JDK specifically for identifiers.

An Id class is useful for these reasons :

The underlying database column may be modeled as either text or as a number. If the underlying column is of a numeric type, however, then a Data Access Object will need to pass Id parameters to Db using asInteger() or asLong().

Design Note :
This class is final, immutable, Serializable, and Comparable, in imitation of the other building block classes such as String, Integer, and so on.

See Also:
Serialized Form

Constructor Summary
Id(String aText)
          Construct an identifier using an arbitrary String.
 
Method Summary
 Integer asInteger()
          Return this id as an Integer, if possible.
 Long asLong()
          Return this id as a Long, if possible.
 int compareTo(Id aThat)
           
 boolean equals(Object aThat)
           
static Id from(String aText)
          Factory method.
 String getRawString()
          Return the text passed to the constructor.
 String getXmlSafe()
          Return the text with special XML characters esacped.
 int hashCode()
           
 String toString()
          Return the id, with special characters escaped.
 
Methods inherited from class Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Id

public Id(String aText)
Construct an identifier using an arbitrary String. This class uses a SafeText object internally.

Parameters:
aText - is non-null, and contains characters that are allowed by PermittedCharacters.
Method Detail

from

public static Id from(String aText)
Factory method. Simply a slightly more compact way of building an object, as opposed to 'new'.


asInteger

public Integer asInteger()
Return this id as an Integer, if possible.

See class comment.

If this Id is not convertible to an Integer, then a RuntimeException is thrown.


asLong

public Long asLong()
Return this id as a Long, if possible.

See class comment.

If this Id is not convertible to a Long, then a RuntimeException is thrown.


toString

public String toString()
Return the id, with special characters escaped.

The return value either has content (with no leading or trailing spaces), or is empty. See EscapeChars.forHTML(String) for a list of escaped characters.

Overrides:
toString in class Object

getRawString

public String getRawString()
Return the text passed to the constructor.


getXmlSafe

public String getXmlSafe()
Return the text with special XML characters esacped. See SafeText.getXmlSafe().


equals

public boolean equals(Object aThat)
Overrides:
equals in class Object

hashCode

public int hashCode()
Overrides:
hashCode in class Object

compareTo

public int compareTo(Id aThat)
Specified by:
compareTo in interface Comparable<Id>

Version 4.10.0

Copyright Hirondelle Systems. Published October 19, 2013 - User Guide - All Docs.