Interface Jid
-
- All Superinterfaces:
java.lang.CharSequence,java.lang.Comparable<Jid>,java.io.Serializable
- All Known Subinterfaces:
BareJid,DomainBareJid,DomainFullJid,DomainJid,EntityBareJid,EntityFullJid,EntityJid,FullJid
- All Known Implementing Classes:
AbstractJid,DomainAndResourcepartJid,DomainpartJid,LocalAndDomainpartJid,LocalDomainAndResourcepartJid
public interface Jid extends java.lang.Comparable<Jid>, java.lang.CharSequence, java.io.Serializable
An XMPP address, also known as JID (formerly for "Jabber Identifier"), which acts as globally unique address within the XMPP network.JIDs are created from
StringorCharSequencewith theJidCreateutility.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 aResourcepart, full JID types always have aResourcepart. Domain JID types do not possess aLocalpart, whereas entity JID types always do.The following table shows a few examples of JID types.
XMPP Address Types Example Type example.orgDomainBareJidexample.org/resourceDomainFullJiduser@example.orgEntityBareJiduser@example.org/resourceEntityFullJidYou can retrieve the escaped String representing the Jid with
toString()or the unescaped String of the JID withasUnescapedString().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 likeJidCreate.fromUrlEncoded(CharSequence).
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description BareJidasBareJid()Return a JID created by removing the Resourcepart from this JID.DomainBareJidasDomainBareJid()Convert this Jid to aDomainBareJid.DomainFullJidasDomainFullJidIfPossible()Convert this Jid to aDomainFullJidif possible.DomainFullJidasDomainFullJidOrThrow()Convert this Jid to aDomainFullJidor throw anIllegalStateExceptionif this is not possible.EntityBareJidasEntityBareJidIfPossible()Convert this Jid to aEntityBareJidif possible.EntityBareJidasEntityBareJidOrThrow()Convert this Jid to aEntityBareJidor throw anIllegalStateExceptionif this is not possible.EntityFullJidasEntityFullJidIfPossible()Convert this Jid to aEntityFullJidif possible.EntityFullJidasEntityFullJidOrThrow()Convert this Jid to aEntityFullJidor throw anIllegalStateExceptionif this is not possible.EntityJidasEntityJidIfPossible()Convert this Jid to aEntityJidif possible.EntityJidasEntityJidOrThrow()Convert this Jid to aEntityJidor throw anIllegalStateExceptionif this is not possible.FullJidasFullJidIfPossible()Convert this Jid to aFullJidif possible.EntityFullJidasFullJidOrThrow()Convert this Jid to aFullJidor throw anIllegalStateExceptionif this is not possible.java.lang.StringasUnescapedString()Return the unescaped String representation of this JID.java.lang.StringasUrlEncodedString()Get the URL encoded version of this JID.<T extends Jid>
Tdowncast(java.lang.Class<T> jidClass)Return the downcasted instance of this Jid.booleanequals(java.lang.CharSequence charSequence)Compares the given CharSequence with this JID.booleanequals(java.lang.String string)Compares the given String wit this JID.DomainpartgetDomain()Get theDomainpartof this Jid.LocalpartgetLocalpartOrNull()Get the localpart of this JID or null.LocalpartgetLocalpartOrThrow()Get the localpart of this JID or throw anIllegalStateException.ResourcepartgetResourceOrEmpty()Get the resourcepart of this JID or return the empty resourcepart.ResourcepartgetResourceOrNull()Get the resourcepart of this JID or null.ResourcepartgetResourceOrThrow()Get the resourcepart of this JID or throw anIllegalStateException.booleanhasLocalpart()Check if this is a Jid with aLocalpart.booleanhasNoResource()Check if this is an instance ofEntityBareJidorDomainBareJid.booleanhasResource()Check if this is a Jid with aResourcepart.java.lang.Stringintern()Returns the canonical String representation of this JID.booleanisDomainBareJid()Check if this is an instance ofDomainBareJid.booleanisDomainFullJid()Check if this is an instance ofDomainFullJid.booleanisEntityBareJid()Check if this is an instance ofEntityBareJid.booleanisEntityFullJid()Check if this is an instance ofEntityFullJid.booleanisEntityJid()Check if this is aEntityBareJidorEntityFullJid.booleanisParentOf(DomainBareJid domainBareJid)SeeisParentOf(Jid).booleanisParentOf(DomainFullJid domainFullJid)SeeisParentOf(Jid).booleanisParentOf(EntityBareJid bareJid)SeeisParentOf(Jid).booleanisParentOf(EntityFullJid fullJid)SeeisParentOf(Jid).booleanisParentOf(Jid jid)Check if this JID is the parent of another JID.java.lang.StringtoString()Returns the String representation of this JID.
-
-
-
Method Detail
-
getDomain
Domainpart getDomain()
Get theDomainpartof this Jid.- Returns:
- the domainpart.
-
toString
java.lang.String toString()
Returns the String representation of this JID.- Specified by:
toStringin interfacejava.lang.CharSequence- Overrides:
toStringin classjava.lang.Object- Returns:
- the String representation of this JID.
-
asUnescapedString
java.lang.String 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 withJidCreatewill 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
java.lang.String 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 aEntityBareJidorEntityFullJid.- 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 ofEntityBareJidorDomainBareJid.- 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
BareJid asBareJid()
Return a JID created by removing the Resourcepart from this JID.- Returns:
- this Jid without a Resourcepart.
-
asEntityBareJidIfPossible
EntityBareJid asEntityBareJidIfPossible()
Convert this Jid to aEntityBareJidif possible.- Returns:
- the corresponding
EntityBareJidor null.
-
asEntityBareJidOrThrow
EntityBareJid asEntityBareJidOrThrow()
Convert this Jid to aEntityBareJidor throw anIllegalStateExceptionif this is not possible.- Returns:
- the corresponding
EntityBareJid.
-
asEntityFullJidIfPossible
EntityFullJid asEntityFullJidIfPossible()
Convert this Jid to aEntityFullJidif possible.- Returns:
- the corresponding
EntityFullJidor null.
-
asEntityFullJidOrThrow
EntityFullJid asEntityFullJidOrThrow()
Convert this Jid to aEntityFullJidor throw anIllegalStateExceptionif this is not possible.- Returns:
- the corresponding
EntityFullJid.
-
asEntityJidIfPossible
EntityJid asEntityJidIfPossible()
Convert this Jid to aEntityJidif possible.- Returns:
- the corresponding
EntityJidor null.
-
asEntityJidOrThrow
EntityJid asEntityJidOrThrow()
Convert this Jid to aEntityJidor throw anIllegalStateExceptionif this is not possible.- Returns:
- the corresponding
EntityJid.
-
asFullJidIfPossible
FullJid asFullJidIfPossible()
Convert this Jid to aFullJidif possible.- Returns:
- the corresponding
FullJidor null.
-
asFullJidOrThrow
EntityFullJid asFullJidOrThrow()
Convert this Jid to aFullJidor throw anIllegalStateExceptionif this is not possible.- Returns:
- the corresponding
FullJid.
-
asDomainBareJid
DomainBareJid 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
DomainFullJid asDomainFullJidIfPossible()
Convert this Jid to aDomainFullJidif possible.- Returns:
- the corresponding DomainFullJid or null.
-
asDomainFullJidOrThrow
DomainFullJid asDomainFullJidOrThrow()
Convert this Jid to aDomainFullJidor throw anIllegalStateExceptionif this is not possible.- Returns:
- the corresponding
DomainFullJid.
-
getResourceOrNull
Resourcepart 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, thennullis returned.- Returns:
- the resource of this JID or null.
-
getResourceOrEmpty
Resourcepart 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.EMPTYis returned.- Returns:
- the resource of this JID or the empty resourcepart.
-
getResourceOrThrow
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 anIllegalStateExceptionis thrown.- Returns:
- the resource of this JID.
-
getLocalpartOrNull
Localpart 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, thennullis returned.- Returns:
- the localpart of this JID or null.
-
getLocalpartOrThrow
Localpart 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, thennullis returned.- Returns:
- the localpart of this JID.
-
isParentOf
boolean isParentOf(Jid jid)
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
boolean isParentOf(EntityBareJid bareJid)
SeeisParentOf(Jid).- Parameters:
bareJid- the bare JID.- Returns:
- true if this JID is a parent of the given JID.
-
isParentOf
boolean isParentOf(EntityFullJid fullJid)
SeeisParentOf(Jid).- Parameters:
fullJid- the full JID.- Returns:
- true if this JID is a parent of the given JID.
-
isParentOf
boolean isParentOf(DomainBareJid domainBareJid)
SeeisParentOf(Jid).- Parameters:
domainBareJid- the domain bare JID.- Returns:
- true if this JID is a parent of the given JID.
-
isParentOf
boolean isParentOf(DomainFullJid domainFullJid)
SeeisParentOf(Jid).- Parameters:
domainFullJid- the domain full JID.- Returns:
- true if this JID is a parent of the given JID.
-
downcast
<T extends Jid> T downcast(java.lang.Class<T> jidClass) throws java.lang.ClassCastException
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:
java.lang.ClassCastException- if this JID is not assignable to the type T.
-
equals
boolean equals(java.lang.CharSequence charSequence)
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(String)
-
equals
boolean equals(java.lang.String string)
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
java.lang.String intern()
Returns the canonical String representation of this JID. SeeString.intern()for details.- Returns:
- the canonical String representation.
-
-