Package com.jcabi.urn
Class URN
java.lang.Object
com.jcabi.urn.URN
- All Implemented Interfaces:
Serializable,Comparable<URN>
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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionintstatic URNCreates an instance of URN and throws a runtime exception if its syntax is not valid.booleaninthashCode()booleanWhether this URN has params?booleanisEmpty()Is it empty?static booleanIs it a valid URN?booleanDoes it match the pattern?nid()Get namespace ID.nss()Get namespace specific string.Get query param by name.Add (overwrite) a query param and return a new URN.params()Get all params.pure()Get just body of URN, without params.toString()toURI()Convert it to URI.
-
Constructor Details
-
URN
public URN()Public ctor (for JAXB mostly) that creates an "empty" URN. -
URN
Public ctor.- Parameters:
text- The text of the URN- Throws:
URISyntaxException- If syntax is not correct- Suppressed Checkstyle violations:
- ConstructorsCodeFreeCheck (10 lines)
-
URN
Public ctor.- Parameters:
nid- The namespace IDnss- The namespace specific string- Suppressed Checkstyle violations:
- ConstructorsCodeFreeCheck (20 lines), ConstructorsOrderCheck (20 lines)
-
-
Method Details
-
create
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
-
equals
-
hashCode
public int hashCode() -
compareTo
- Specified by:
compareToin interfaceComparable<URN>
-
isValid
Is it a valid URN?- Parameters:
text- The text to validate- Returns:
- Yes of no
-
matches
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
Convert it to URI.- Returns:
- The URI
-
nid
Get namespace ID.- Returns:
- Namespace ID
-
nss
Get namespace specific string.- Returns:
- Namespace specific string
-
params
Get all params.- Returns:
- The params
-
param
Get query param by name.- Parameters:
name- Name of parameter- Returns:
- The value of it
-
param
Add (overwrite) a query param and return a new URN.- Parameters:
name- Name of parametervalue- The value of parameter- Returns:
- New 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?
-