public interface Jid extends Comparable<Jid>, CharSequence, Serializable
JIDs are created from String
or CharSequence
with the JidCreate
utility.
Jid jid = JidCreate.from("juliet@capulet.org/balcony"); EntityBareJid bareJid = JidCreate.entityBareFrom("romeo@montague.net");
This is the super interface for all JID types, which are constructed from two dimensions: Bare/Full and
Domain/Entity. Every JID consists at least of a Domainpart
. Bare JID types do not come with a
Resourcepart
, full JID types always have a Resourcepart
. Domain JID types do not possess a
Localpart
, whereas entity JID types always do.
The following table shows a few examples of JID types.
Example | Type |
example.org |
DomainBareJid |
example.org/resource |
DomainFullJid |
user@example.org |
EntityBareJid |
user@example.org/resource |
EntityFullJid |
You can retrieve the escaped String representing the Jid with toString()
or the unsecaped String of the JID
with asUnescapedString()
.
Modifier and Type | Method and Description |
---|---|
BareJid |
asBareJid()
Return a JID created by removing the Resourcepart from this JID.
|
DomainBareJid |
asDomainBareJid()
Convert this Jid to a
DomainBareJid . |
DomainFullJid |
asDomainFullJidIfPossible()
Convert this Jid to a
DomainFullJid if possible. |
DomainFullJid |
asDomainFullJidOrThrow()
Convert this Jid to a
DomainFullJid or throw an IllegalStateException if this is not possible. |
EntityBareJid |
asEntityBareJidIfPossible()
Convert this Jid to a
EntityBareJid if possible. |
EntityBareJid |
asEntityBareJidOrThrow()
Convert this Jid to a
EntityBareJid or throw an IllegalStateException if this is not possible. |
EntityFullJid |
asEntityFullJidIfPossible()
Convert this Jid to a
EntityFullJid if possible. |
EntityFullJid |
asEntityFullJidOrThrow()
Convert this Jid to a
EntityFullJid or throw an IllegalStateException if this is not possible. |
EntityJid |
asEntityJidIfPossible()
Convert this Jid to a
EntityJid if possible. |
EntityJid |
asEntityJidOrThrow()
Convert this Jid to a
EntityJid or throw an IllegalStateException if this is not possible. |
FullJid |
asFullJidIfPossible()
Convert this Jid to a
FullJid if possible. |
EntityFullJid |
asFullJidOrThrow()
Convert this Jid to a
FullJid or throw an IllegalStateException if this is not possible. |
String |
asUnescapedString()
Return the unescaped String representation of this JID.
|
<T extends Jid> |
downcast(Class<T> jidClass)
Return the downcasted instance of this Jid.
|
boolean |
equals(CharSequence charSequence)
Compares the given CharSequence with this JID.
|
boolean |
equals(String string)
Compares the given String wit this JID.
|
Domainpart |
getDomain()
Get the
Domainpart of this Jid. |
Localpart |
getLocalpartOrNull()
Get the localpart of this JID or null.
|
Localpart |
getLocalpartOrThrow()
Get the localpart of this JID or throw an
IllegalStateException . |
Resourcepart |
getResourceOrEmpty()
Get the resourcepart of this JID or return the empty resourcepart.
|
Resourcepart |
getResourceOrNull()
Get the resourcepart of this JID or null.
|
Resourcepart |
getResourceOrThrow()
Get the resourcepart of this JID or throw an
IllegalStateException . |
boolean |
hasLocalpart()
Check if this is a Jid with a
Localpart . |
boolean |
hasNoResource()
Check if this is an instance of
EntityBareJid or DomainBareJid . |
boolean |
hasResource()
Check if this is a Jid with a
Resourcepart . |
String |
intern()
Returns the canonical String representation of this JID.
|
boolean |
isDomainBareJid()
Check if this is an instance of
DomainBareJid . |
boolean |
isDomainFullJid()
Check if this is an instance of
DomainFullJid . |
boolean |
isEntityBareJid()
Check if this is an instance of
EntityBareJid . |
boolean |
isEntityFullJid()
Check if this is an instance of
EntityFullJid . |
boolean |
isEntityJid()
Check if this is a
EntityBareJid or EntityFullJid . |
boolean |
isParentOf(DomainBareJid domainBareJid)
See
isParentOf(Jid) . |
boolean |
isParentOf(DomainFullJid domainFullJid)
See
isParentOf(Jid) . |
boolean |
isParentOf(EntityBareJid bareJid)
See
isParentOf(Jid) . |
boolean |
isParentOf(EntityFullJid fullJid)
See
isParentOf(Jid) . |
boolean |
isParentOf(Jid jid)
Check if this JID is the parent of another JID.
|
String |
toString()
Returns the String representation of this JID.
|
compareTo
charAt, chars, codePoints, length, subSequence
Domainpart getDomain()
Domainpart
of this Jid.String toString()
toString
in interface CharSequence
toString
in class Object
String asUnescapedString()
Since certain Unicode code points are disallowed in the localpart of a JID by the required stringprep profile, those need to get escaped when used in a real JID. The unescaped representation of the JID is only for presentation to a human user or for gatewaying to a non-XMPP system.
For example, if the users inputs'at&t guy@example.com'
, the escaped real JID created with
JidCreate
will be 'at\26t\20guy@example.com'
, which is what
toString()
will return. But asUnescapedString()
will return again
'at&t guy@example.com'
.boolean isEntityJid()
EntityBareJid
or EntityFullJid
.boolean isEntityBareJid()
EntityBareJid
.boolean isEntityFullJid()
EntityFullJid
.boolean isDomainBareJid()
DomainBareJid
.boolean isDomainFullJid()
DomainFullJid
.boolean hasNoResource()
EntityBareJid
or DomainBareJid
.boolean hasResource()
Resourcepart
.boolean hasLocalpart()
Localpart
.BareJid asBareJid()
EntityBareJid asEntityBareJidIfPossible()
EntityBareJid
if possible.EntityBareJid
or null.EntityBareJid asEntityBareJidOrThrow()
EntityBareJid
or throw an IllegalStateException
if this is not possible.EntityBareJid
.EntityFullJid asEntityFullJidIfPossible()
EntityFullJid
if possible.EntityFullJid
or null.EntityFullJid asEntityFullJidOrThrow()
EntityFullJid
or throw an IllegalStateException
if this is not possible.EntityFullJid
.EntityJid asEntityJidIfPossible()
EntityJid
if possible.EntityJid
or null.EntityJid asEntityJidOrThrow()
EntityJid
or throw an IllegalStateException
if this is not possible.EntityJid
.FullJid asFullJidIfPossible()
FullJid
if possible.FullJid
or null.EntityFullJid asFullJidOrThrow()
FullJid
or throw an IllegalStateException
if this is not possible.FullJid
.DomainBareJid asDomainBareJid()
DomainBareJid
.
Note that it is always possible to convert a Jid to a DomainBareJid, since every Jid has a domain part.
DomainFullJid asDomainFullJidIfPossible()
DomainFullJid
if possible.DomainFullJid asDomainFullJidOrThrow()
DomainFullJid
or throw an IllegalStateException
if this is not possible.DomainFullJid
.Resourcepart getResourceOrNull()
If the JID is of form <localpart@domain.example/resource>
then this method returns 'resource'. If the JID no
resourcepart, then null
is returned.
Resourcepart getResourceOrEmpty()
If the JID is of form <localpart@domain.example/resource>
then this method returns 'resource'. If the JID no
resourcepart, then Resourcepart.EMPTY
is returned.
Resourcepart getResourceOrThrow()
IllegalStateException
.
If the JID is of form <localpart@domain.example/resource>
then this method returns 'resource'. If the JID no
resourcepart, then an IllegalStateException
is thrown.
Localpart getLocalpartOrNull()
If the JID is of form <localpart@domain.example>
then this method returns 'localpart'. If the JID has no
localpart, then null
is returned.
Localpart getLocalpartOrThrow()
IllegalStateException
.
If the JID is of form <localpart@domain.example>
then this method returns 'localpart'. If the JID has no
localpart, then null
is returned.
boolean isParentOf(Jid jid)
| this JID (parentOf) | other JID | result | |---------------------+---------------------+--------| | dom.example | dom.example | true | | dom.example | dom.example/res | true | | dom.example | loc@dom.example | true | | dom.example | loc@dom.example/res | true | | dom.example/res | dom.exmple | false | | dom.example/res | dom.example/res | true | | dom.example/res | loc@dom.example | false | | dom.example/res | loc@dom.example/res | false | | loc@dom.example | dom.example | false | | loc@dom.example | dom.example/res | false | | loc@dom.example | loc@dom.example | true | | loc@dom.example | loc@dom.example/res | true | | loc@dom.example/res | dom.example | false | | loc@dom.example/res | dom.example/res | false | | loc@dom.example/res | loc@dom.example | false | | loc@dom.example/res | loc@dom.example/res | true |
jid
- the other JID to compare withboolean isParentOf(EntityBareJid bareJid)
isParentOf(Jid)
.bareJid
- the bare JID.boolean isParentOf(EntityFullJid fullJid)
isParentOf(Jid)
.fullJid
- the full JID.boolean isParentOf(DomainBareJid domainBareJid)
isParentOf(Jid)
.domainBareJid
- the domain bare JID.boolean isParentOf(DomainFullJid domainFullJid)
isParentOf(Jid)
.domainFullJid
- the domain full JID.<T extends Jid> T downcast(Class<T> jidClass) throws ClassCastException
T
- the Jid type to downcast to.jidClass
- the class of JID to downcast too.ClassCastException
- if this JID is not assignable to the type T.boolean equals(CharSequence charSequence)
equals(charSequence.toString()
would
return true.charSequence
- the CharSequence to compare this JID with.equals(charSequence.toString()
would return true.equals(String)
boolean equals(String string)
Returns true if toString().equals(string)
, that is if the String representation of this JID matches the given string.
string
- the String to compare this JID with.toString().equals(string)
.String intern()
String.intern()
for details.