Package com.jcabi.urn

Class URN

java.lang.Object
com.jcabi.urn.URN
All Implemented Interfaces:
Serializable, Comparable<URN>

@Immutable public final class URN extends Object implements Comparable<URN>, Serializable
Uniform Resource Name (URN) as in RFC 2141.

Usage is similar to URI or URL:

 URN urn = new URN("urn:foo:A123,456");
 assert urn.nid().equals("foo");
 assert urn.nss().equals("A123,456");

NOTICE: the implementation is not fully compliant with RFC 2141. It will become compliant in one of our future versions. Once it becomes fully compliant this notice will be removed.

Since:
0.6
See Also:
Suppressed Checkstyle violations:
AbbreviationAsWordInNameCheck (500 lines)
  • Constructor Details

    • URN

      public URN()
      Public ctor (for JAXB mostly) that creates an "empty" URN.
    • URN

      public URN(String text) throws URISyntaxException
      Public ctor.
      Parameters:
      text - The text of the URN
      Throws:
      URISyntaxException - If syntax is not correct
      Suppressed Checkstyle violations:
      ConstructorsCodeFreeCheck (10 lines)
    • URN

      public URN(String nid, String nss)
      Public ctor.
      Parameters:
      nid - The namespace ID
      nss - The namespace specific string
      Suppressed Checkstyle violations:
      ConstructorsCodeFreeCheck (20 lines), ConstructorsOrderCheck (20 lines)
  • Method Details

    • create

      public static URN create(String text)
      Creates an instance of URN and throws a runtime exception if its syntax is not valid.
      Parameters:
      text - The text of the URN
      Returns:
      The URN created
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • compareTo

      public int compareTo(URN urn)
      Specified by:
      compareTo in interface Comparable<URN>
    • isValid

      public static boolean isValid(String text)
      Is it a valid URN?
      Parameters:
      text - The text to validate
      Returns:
      Yes of no
    • matches

      public boolean matches(String pattern)
      Does it match the pattern?
      Parameters:
      pattern - The pattern to match
      Returns:
      Yes of no
    • isEmpty

      public boolean isEmpty()
      Is it empty?
      Returns:
      Yes of no
    • toURI

      public URI toURI()
      Convert it to URI.
      Returns:
      The URI
    • nid

      public String nid()
      Get namespace ID.
      Returns:
      Namespace ID
    • nss

      public String nss()
      Get namespace specific string.
      Returns:
      Namespace specific string
    • params

      public Map<String,String> params()
      Get all params.
      Returns:
      The params
    • param

      public String param(String name)
      Get query param by name.
      Parameters:
      name - Name of parameter
      Returns:
      The value of it
    • param

      public URN param(String name, Object value)
      Add (overwrite) a query param and return a new URN.
      Parameters:
      name - Name of parameter
      value - The value of parameter
      Returns:
      New URN
    • pure

      public URN pure()
      Get just body of URN, without params.
      Returns:
      Clean version of it
    • hasParams

      public boolean hasParams()
      Whether this URN has params?
      Returns:
      Has them?