Interface Jid
- All Superinterfaces:
CharSequence
,Comparable<Jid>
,Serializable
- All Known Subinterfaces:
BareJid
,DomainBareJid
,DomainFullJid
,DomainJid
,EntityBareJid
,EntityFullJid
,EntityJid
,FullJid
- All Known Implementing Classes:
AbstractJid
,DomainAndResourcepartJid
,DomainpartJid
,LocalAndDomainpartJid
,LocalDomainAndResourcepartJid
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 unescaped String of the JID
with asUnescapedString()
.
URL Encoded JIDs
The URL encoded representation of a JID is ideal if a JID should be stored as part of a path name, e.g. as file name.
You can retrieve this information using asUrlEncodedString()
. The JidCreate API provides methods to create
JIDs from URL encoded Strings like JidCreate.fromUrlEncoded(CharSequence)
.
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionReturn a JID created by removing the Resourcepart from this JID.Convert this Jid to aDomainBareJid
.Convert this Jid to aDomainFullJid
if possible.Convert this Jid to aDomainFullJid
or throw anIllegalStateException
if this is not possible.Convert this Jid to aEntityBareJid
if possible.Convert this Jid to aEntityBareJid
or throw anIllegalStateException
if this is not possible.Convert this Jid to aEntityFullJid
if possible.Convert this Jid to aEntityFullJid
or throw anIllegalStateException
if this is not possible.Convert this Jid to aEntityJid
if possible.Convert this Jid to aEntityJid
or throw anIllegalStateException
if this is not possible.Convert this Jid to aFullJid
if possible.Convert this Jid to aFullJid
or throw anIllegalStateException
if this is not possible.Return the unescaped String representation of this JID.Get the URL encoded version of this JID.<T extends Jid>
TReturn the downcasted instance of this Jid.boolean
equals
(CharSequence charSequence) Compares the given CharSequence with this JID.boolean
Compares the given String wit this JID.Get theDomainpart
of this Jid.Get the localpart of this JID or null.Get the localpart of this JID or throw anIllegalStateException
.Get the resourcepart of this JID or return the empty resourcepart.Get the resourcepart of this JID or null.Get the resourcepart of this JID or throw anIllegalStateException
.boolean
Check if this is a Jid with aLocalpart
.boolean
Check if this is an instance ofEntityBareJid
orDomainBareJid
.boolean
Check if this is a Jid with aResourcepart
.intern()
Returns the canonical String representation of this JID.boolean
Check if this is an instance ofDomainBareJid
.boolean
Check if this is an instance ofDomainFullJid
.boolean
Check if this is an instance ofEntityBareJid
.boolean
Check if this is an instance ofEntityFullJid
.boolean
Check if this is aEntityBareJid
orEntityFullJid
.boolean
isParentOf
(DomainBareJid domainBareJid) SeeisParentOf(Jid)
.boolean
isParentOf
(DomainFullJid domainFullJid) SeeisParentOf(Jid)
.boolean
isParentOf
(EntityBareJid bareJid) SeeisParentOf(Jid)
.boolean
isParentOf
(EntityFullJid fullJid) SeeisParentOf(Jid)
.boolean
isParentOf
(Jid jid) Check if this JID is the parent of another JID.boolean
isStrictParentOf
(DomainBareJid domainBareJid) boolean
isStrictParentOf
(DomainFullJid domainFullJid) boolean
isStrictParentOf
(EntityBareJid bareJid) SeeisParentOf(Jid)
.boolean
isStrictParentOf
(EntityFullJid fullJid) boolean
isStrictParentOf
(Jid jid) Check if this JID is the strict parent of another JID.toString()
Returns the String representation of this JID.Methods inherited from interface java.lang.CharSequence
charAt, chars, codePoints, length, subSequence
Methods inherited from interface java.lang.Comparable
compareTo
-
Method Details
-
getDomain
Get theDomainpart
of this Jid.- Returns:
- the domainpart.
-
toString
Returns the String representation of this JID.- Specified by:
toString
in interfaceCharSequence
- Overrides:
toString
in classObject
- Returns:
- the String representation of this JID.
-
asUnescapedString
Return the unescaped String representation of this JID.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 withJidCreate
will be'at\26t\20guy@example.com'
, which is whattoString()
will return. ButasUnescapedString()
will return again'at&t guy@example.com'
.- Returns:
- the unescaped String representation of this JID.
-
asUrlEncodedString
Get the URL encoded version of this JID.- Returns:
- the URL encoded version of this JID.
- Since:
- 0.7.0
-
isEntityJid
boolean isEntityJid()Check if this is aEntityBareJid
orEntityFullJid
.- Returns:
- true if this is an instance of BareJid or FullJid.
-
isEntityBareJid
boolean isEntityBareJid()Check if this is an instance ofEntityBareJid
.- Returns:
- true if this is an instance of EntityBareJid
-
isEntityFullJid
boolean isEntityFullJid()Check if this is an instance ofEntityFullJid
.- Returns:
- true if this is an instance of EntityFullJid
-
isDomainBareJid
boolean isDomainBareJid()Check if this is an instance ofDomainBareJid
.- Returns:
- true if this is an instance of DomainBareJid
-
isDomainFullJid
boolean isDomainFullJid()Check if this is an instance ofDomainFullJid
.- Returns:
- true if this is an instance of DomainFullJid
-
hasNoResource
boolean hasNoResource()Check if this is an instance ofEntityBareJid
orDomainBareJid
.- Returns:
- true if this is an instance of BareJid or DomainBareJid
-
hasResource
boolean hasResource()Check if this is a Jid with aResourcepart
.- Returns:
- true if this Jid has a resourcepart.
-
hasLocalpart
boolean hasLocalpart()Check if this is a Jid with aLocalpart
.- Returns:
- true if this Jid has a localpart.
-
asBareJid
Return a JID created by removing the Resourcepart from this JID.- Returns:
- this Jid without a Resourcepart.
-
asEntityBareJidIfPossible
Convert this Jid to aEntityBareJid
if possible.- Returns:
- the corresponding
EntityBareJid
or null.
-
asEntityBareJidOrThrow
Convert this Jid to aEntityBareJid
or throw anIllegalStateException
if this is not possible.- Returns:
- the corresponding
EntityBareJid
.
-
asEntityFullJidIfPossible
Convert this Jid to aEntityFullJid
if possible.- Returns:
- the corresponding
EntityFullJid
or null.
-
asEntityFullJidOrThrow
Convert this Jid to aEntityFullJid
or throw anIllegalStateException
if this is not possible.- Returns:
- the corresponding
EntityFullJid
.
-
asEntityJidIfPossible
Convert this Jid to aEntityJid
if possible.- Returns:
- the corresponding
EntityJid
or null.
-
asEntityJidOrThrow
Convert this Jid to aEntityJid
or throw anIllegalStateException
if this is not possible.- Returns:
- the corresponding
EntityJid
.
-
asFullJidIfPossible
Convert this Jid to aFullJid
if possible.- Returns:
- the corresponding
FullJid
or null.
-
asFullJidOrThrow
Convert this Jid to aFullJid
or throw anIllegalStateException
if this is not possible.- Returns:
- the corresponding
FullJid
.
-
asDomainBareJid
Convert this Jid to aDomainBareJid
.Note that it is always possible to convert a Jid to a DomainBareJid, since every Jid has a domain part.
- Returns:
- the corresponding DomainBareJid.
-
asDomainFullJidIfPossible
Convert this Jid to aDomainFullJid
if possible.- Returns:
- the corresponding DomainFullJid or null.
-
asDomainFullJidOrThrow
Convert this Jid to aDomainFullJid
or throw anIllegalStateException
if this is not possible.- Returns:
- the corresponding
DomainFullJid
.
-
getResourceOrNull
Get the resourcepart of this JID or null.If the JID is of form
<localpart@domain.example/resource>
then this method returns 'resource'. If the JID no resourcepart, thennull
is returned.- Returns:
- the resource of this JID or null.
-
getResourceOrEmpty
Get the resourcepart of this JID or return the empty resourcepart.If the JID is of form
<localpart@domain.example/resource>
then this method returns 'resource'. If the JID no resourcepart, thenResourcepart.EMPTY
is returned.- Returns:
- the resource of this JID or the empty resourcepart.
-
getResourceOrThrow
Get the resourcepart of this JID or throw anIllegalStateException
.If the JID is of form
<localpart@domain.example/resource>
then this method returns 'resource'. If the JID no resourcepart, then anIllegalStateException
is thrown.- Returns:
- the resource of this JID.
-
getLocalpartOrNull
Get the localpart of this JID or null.If the JID is of form
<localpart@domain.example>
then this method returns 'localpart'. If the JID has no localpart, thennull
is returned.- Returns:
- the localpart of this JID or null.
-
getLocalpartOrThrow
Get the localpart of this JID or throw anIllegalStateException
.If the JID is of form
<localpart@domain.example>
then this method returns 'localpart'. If the JID has no localpart, thennull
is returned.- Returns:
- the localpart of this JID.
-
isParentOf
Check if this JID is the parent of another JID. The parent of relation is defined, under the precondition that the JID parts (localpart, domainpart and resourcepart) are equal, as follows:| 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 |
- Parameters:
jid
- the other JID to compare with- Returns:
- true if this JID is a parent of the given JID.
-
isParentOf
SeeisParentOf(Jid)
.- Parameters:
bareJid
- the bare JID.- Returns:
- true if this JID is a parent of the given JID.
-
isParentOf
SeeisParentOf(Jid)
.- Parameters:
fullJid
- the full JID.- Returns:
- true if this JID is a parent of the given JID.
-
isParentOf
SeeisParentOf(Jid)
.- Parameters:
domainBareJid
- the domain bare JID.- Returns:
- true if this JID is a parent of the given JID.
-
isParentOf
SeeisParentOf(Jid)
.- Parameters:
domainFullJid
- the domain full JID.- Returns:
- true if this JID is a parent of the given JID.
-
isStrictParentOf
Check if this JID is the strict parent of another JID. In other words, all parts of this JID must exist on the other JID, and match this JID's values. Furthermore, and this is what makes this method different fromisParentOf(Jid)
, the other JID must have one additional part, that this JID does not have. The parent of relation is defined, under the precondition that the JID parts (localpart, domainpart and resourcepart) are equal, as follows:| this JID | other JID | result | |---------------------+---------------------+--------| | dom.example | dom.example | false | (different from isParentOf) | 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 | false | (different from isParentOf) | 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 | false | (different from isParentOf) | 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 | false | (different from isParentOf)
- Parameters:
jid
- the other JID to compare with- Returns:
- true if this JID is a parent of the given JID.
-
isStrictParentOf
SeeisParentOf(Jid)
.- Parameters:
bareJid
- the bare JID.- Returns:
- true if this JID is a parent of the given JID.
-
isStrictParentOf
- Parameters:
fullJid
- the full JID.- Returns:
- true if this JID is a parent of the given JID.
-
isStrictParentOf
- Parameters:
domainBareJid
- the domain bare JID.- Returns:
- true if this JID is a parent of the given JID.
-
isStrictParentOf
- Parameters:
domainFullJid
- the domain full JID.- Returns:
- true if this JID is a parent of the given JID.
-
downcast
Return the downcasted instance of this Jid. This method is unsafe, make sure to check that this is actually of the type of are casting to.- Type Parameters:
T
- the Jid type to downcast to.- Parameters:
jidClass
- the class of JID to downcast too.- Returns:
- the downcasted instanced of this
- Throws:
ClassCastException
- if this JID is not assignable to the type T.
-
equals
Compares the given CharSequence with this JID. Returns true ifequals(charSequence.toString()
would return true.- Parameters:
charSequence
- the CharSequence to compare this JID with.- Returns:
- true if if
equals(charSequence.toString()
would return true. - See Also:
-
equals
Compares the given String wit this JID.Returns true if
toString().equals(string)
, that is if the String representation of this JID matches the given string.- Parameters:
string
- the String to compare this JID with.- Returns:
- true if
toString().equals(string)
.
-
intern
Returns the canonical String representation of this JID. SeeString.intern()
for details.- Returns:
- the canonical String representation.
-