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
URIorURL: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:
- RFC 2141, Serialized Form
- Suppressed Checkstyle violations:
- AbbreviationAsWordInNameCheck (500 lines)
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description intcompareTo(URN urn)static URNcreate(String text)Creates an instance of URN and throws a runtime exception if its syntax is not valid.booleanhasParams()Whether this URN has params?booleanisEmpty()Is it empty?static booleanisValid(String text)Is it a valid URN?booleanmatches(String pattern)Does it match the pattern?Stringnid()Get namespace ID.Stringnss()Get namespace specific string.Stringparam(String name)Get query param by name.URNparam(String name, Object value)Add (overwrite) a query param and return a new URN.Map<String,String>params()Get all params.URNpure()Get just body of URN, without params.StringtoString()URItoURI()Convert it to URI.
-
-
-
Constructor Detail
-
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
-
-
Method Detail
-
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
-
compareTo
public int compareTo(URN urn)
- Specified by:
compareToin interfaceComparable<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
-
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 parametervalue- 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?
-
-