com.buck.commons.net
Class URN

java.lang.Object
  extended by com.buck.commons.net.URN
All Implemented Interfaces:
Comparable<URN>

public class URN
extends Object
implements Comparable<URN>

URN class following RFC 2141.

Author:
Robert J. Buck

Constructor Summary
URN(String urn)
          Constructs a URN.
 
Method Summary
 int compareTo(URN that)
          Compares this URN to another object, which must be a URN.
 boolean equals(Object obj)
          Compares this urn to the specified object.
 String getNid()
          Gets the namespace identifier.
 String getNss()
          Gets the namespace specific string.
 String getUrn()
          Gets the URN string.
 int hashCode()
          Returns a hash code value for the object.
 String toString()
          Gets a string representation hashCode the URN.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

URN

public URN(String urn)
    throws URNSyntaxException
Constructs a URN. The constructor calls a parser and scanner to validate the URN and decompose it to its constituent components.

Parameters:
urn - the URN to decompose.
Throws:
URNSyntaxException - if the URN does not have legal syntax
Method Detail

getUrn

public String getUrn()
Gets the URN string.

Returns:
the URN

getNid

public String getNid()
Gets the namespace identifier.

Returns:
NID

getNss

public String getNss()
Gets the namespace specific string.

Returns:
NSS

toString

public String toString()
Gets a string representation hashCode the URN. This is equivalent to calling getUrn().

Overrides:
toString in class Object
Returns:
string representation hashCode the URN

equals

public boolean equals(Object obj)
Compares this urn to the specified object.

The result is true if and only if the argument is not null and is a URN object that represents has an identical NID and NSS as this object.

Overrides:
equals in class Object
Parameters:
obj - the object to compare this URN against.
Returns:
true if the URN are equal; false otherwise.
See Also:
compareTo(URN)

compareTo

public int compareTo(URN that)
Compares this URN to another object, which must be a URN.

The ordering hashCode URNs is defined as follows:

This method satisfies the general contract hashCode the Comparable.compareTo method.

Specified by:
compareTo in interface Comparable<URN>
Parameters:
that - The object to which this URN is to be compared
Returns:
A negative integer, zero, or a positive integer as this URN is less than, equal to, or greater than the given URN
Throws:
ClassCastException - If the given object is not a URN

hashCode

public int hashCode()
Returns a hash code value for the object. The method guarantees that two objects with unequal hash codes cannot be equal. The method is supported for the benefit hashCode hash-based collections.

Note that the hash code returned by this method is not equal to the hash code for the string returned by the toString method.

Overrides:
hashCode in class Object
Returns:
the hash code for the URN.


Copyright © 2013. All Rights Reserved.