Package tigase.xmpp.jid
Class BareJID
- java.lang.Object
-
- tigase.xmpp.jid.BareJID
-
- All Implemented Interfaces:
java.lang.Comparable<BareJID>
public final class BareJID extends java.lang.Object implements java.lang.Comparable<BareJID>
Instance of theBareJID
class holds a single, bare JID. When the object is created the parameters are checked and processed through the stringprep. An exception is throw in case of stringprep processing error. The instances of the class are immutable objects.
There are planed various optimisations for the class implementation, one of them is to allow for comparing the instanced by references ('==') instead of of equals() method. This is to improve the performance and lower memory usage. Other improvements and optimisations are also planed.
Some of the optimisations require that the instances are created in strictly controlled way, hence there is no public constructor and you have to use factory methods to create a new instance of theBareJID
class.
The class also offers a few utility methods for parsing and constructing JID strings. Please see JavaDoc documentation for more details.
Created: Dec 28, 2009 10:47:51 PM- Version:
- $Rev$
- Author:
- Artur Hefczyc
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static BareJID
bareJIDInstance(java.lang.String jid)
The method creates an instance of theBareJID
class.static BareJID
bareJIDInstance(java.lang.String p_localpart, java.lang.String p_domain)
The method creates an instance of theBareJID
class.static BareJID
bareJIDInstanceNS(java.lang.String jid)
The method creates an instance of theBareJID
class.static BareJID
bareJIDInstanceNS(java.lang.String p_localpart, java.lang.String p_domain)
The method creates an instance of theBareJID
class.int
compareTo(BareJID o)
Method compares theBareJID
instance to the object given as a parameter.boolean
equals(java.lang.Object b)
Method compares whether thisBareJID
instance represents the same user bare JID as the one given in parameter.java.lang.String
getDomain()
Method returns a domain part of theBareJID
.java.lang.String
getLocalpart()
Method returns a localpart (nickname) of theBareJID
.int
hashCode()
Method returns a hash code calculated for theBareJID
instance.static java.lang.String
jidToBareJID(java.lang.String jid)
A utility method to strip the resource part from the given JID string.static java.lang.String[]
parseJID(java.lang.String jid)
A utility method to parse and split the given JID string into separate parts.java.lang.String
toString()
Method returns aString
representation of theBareJID
instance.static java.lang.String
toString(java.lang.String p_localpart, java.lang.String p_domain)
A utility method to construct aString
representing user JID from given parameters.static java.lang.String
toString(java.lang.String p_localpart, java.lang.String p_domain, java.lang.String p_resource)
A utility method to construct aString
representing user JID from given parameters.static java.lang.String
toString(BareJID bareJid, java.lang.String p_resource)
A utility method to construct aString
representing user JID from given parameters.static void
useStringprepProcessor(java.lang.String stringprepProcessor)
Changes stringprep processor implementation used for the JID checking.
-
-
-
Method Detail
-
bareJIDInstance
public static BareJID bareJIDInstance(java.lang.String jid) throws TigaseStringprepException
The method creates an instance of theBareJID
class. The bare JID is parsed and constructed from theString
parameter.
The localpart (nick name) and the domain part of the JID are parsed and processed through the stringprep. If a strngprep parsing error occurs an exception is thrown.
The resource part, if provided in the JID paramater, is thrown away.
Please note, the method does not necessarily has to return a new instance of the class. It may return the same exact object every time you pass parameters which refer to the same bare JID identifier.- Parameters:
jid
- is aString
parameter used to create the bare JID instance.- Returns:
- an instance of the
BareJID
class which corresponds to the JID given as the parameter. - Throws:
TigaseStringprepException
- if the stringprep processing fails for any JID part used to create the instance.
-
bareJIDInstance
public static BareJID bareJIDInstance(java.lang.String p_localpart, java.lang.String p_domain) throws TigaseStringprepException
The method creates an instance of theBareJID
class. The bare JID is parsed and constructed from twoString
parameters.
The localpart (nick name) and the domain part of the JID are parsed and processed through the stringprep. If a strngprep parsing error occurs an exception is thrown.
Please note, the method does not necessarily has to return a new instance of the class. It may return the same exact object every time you pass parameters which refer to the same bare JID identifier.- Parameters:
p_localpart
- is aString
parameter assumed to be a JID localpart (nickname) and used to create the bare JID instance. The localpart parameter can be null.p_domain
- is aString
parameter assumed to be a JID domain part and used to create the bare JID instance. This parameter must not be null.- Returns:
- an instance of the
BareJID
class which corresponds to the JID given as the parameter. - Throws:
TigaseStringprepException
- if the stringprep processing fails for any JID part used to create the instance.
-
bareJIDInstanceNS
public static BareJID bareJIDInstanceNS(java.lang.String jid)
The method creates an instance of theBareJID
class. The bare JID is parsed and constructed from theString
parameter. Note, this method does not perform stringprep processing on input parameters.
The resource part, if provided in the JID paramater, is thrown away.
Please note, the method does not necessarily has to return a new instance of the class. It may return the same exact object every time you pass parameters which refer to the same bare JID identifier.- Parameters:
jid
- is aString
parameter used to create the bare JID instance.- Returns:
- an instance of the
BareJID
class which corresponds to the JID given as the parameter or null if passed string/domain was null or effectively empty.
-
bareJIDInstanceNS
public static BareJID bareJIDInstanceNS(java.lang.String p_localpart, java.lang.String p_domain)
The method creates an instance of theBareJID
class. The bare JID is parsed and constructed from twoString
parameters. Note, this method does not perform stringprep processing on input parameters.
Please note, the method does not necessarily has to return a new instance of the class. It may return the same exact object every time you pass parameters which refer to the same bare JID identifier.- Parameters:
p_localpart
- is aString
parameter assumed to be a JID localpart (nickname) and used to create the bare JID instance. The localpart parameter can be null.p_domain
- is aString
parameter assumed to be a JID domain part and used to create the bare JID instance. This parameter must not be null.- Returns:
- an instance of the
BareJID
class which corresponds to the JID given as the parameter or null if passed domain was null or effectively empty.
-
jidToBareJID
public static java.lang.String jidToBareJID(java.lang.String jid)
A utility method to strip the resource part from the given JID string. The method doesn't perform any checkings and it doesn't run stringprep processing on the given parameter. This is a pure string manipulation utility method.- Parameters:
jid
- is aString
representing user full JID.- Returns:
- a new
String
instance of the JID wihout resource part.
-
parseJID
public static java.lang.String[] parseJID(java.lang.String jid)
A utility method to parse and split the given JID string into separate parts. The result is returned as a three elements'String
array:- The first element (index 0) of the array is the JID's localpart (nickname). Can be null.
- The second element (index 1) of the array is the JID's domain part.
- The third element (index 2) of the array is the JID's resource part. Can be null.
- Parameters:
jid
- is aString
representing user full JID.- Returns:
- a three element
String
array with parsed JID parts. The array may contain null elements.
-
toString
public static java.lang.String toString(java.lang.String p_localpart, java.lang.String p_domain)
A utility method to construct aString
representing user JID from given parameters. The method doesn't perform any checkings and it doesn't run stringprep processing on the given parameter. This is a pure string manipulation utility method.- Parameters:
p_localpart
- is a JID's localpart (nickname)p_domain
- is a JID's domain part.- Returns:
- a new
String
representing user's JID build from given parameters. If the localpart is null then the method simply returns parameter given as domain part.
-
toString
public static java.lang.String toString(java.lang.String p_localpart, java.lang.String p_domain, java.lang.String p_resource)
A utility method to construct aString
representing user JID from given parameters. The method doesn't perform any checkings and it doesn't run stringprep processing on the given parameter. This is a pure string manipulation utility method.- Parameters:
p_localpart
- is a JID's localpart (nickname)p_domain
- is a JID's domain part.p_resource
- is a JID's resource part.- Returns:
- a new
String
representing user's JID build from given parameters. If the localpart and resource part is null then the method simply returns parameter given as domain part.
-
toString
public static java.lang.String toString(BareJID bareJid, java.lang.String p_resource)
A utility method to construct aString
representing user JID from given parameters. The method doesn't perform any checkings and it doesn't run stringprep processing on the resource parameter.- Parameters:
bareJid
- is aBareJID
instance.p_resource
- is a JID's resource part.- Returns:
- a new
String
representing user's JID build from given parameters.
-
useStringprepProcessor
public static void useStringprepProcessor(java.lang.String stringprepProcessor)
Changes stringprep processor implementation used for the JID checking. The method can be called at any time to change used processor. All subsequentJID
andBareJID
instances are created using a new processor.- Parameters:
stringprepProcessor
- is aString
value with stringprep processor name or class name implementing stringprep processing interface.
-
compareTo
public int compareTo(BareJID o)
Method compares theBareJID
instance to the object given as a parameter. The method implements thecompareTo
specification contract and returns values as we would expect from the call:bareJID_1.toString().compareTo(bareJID_2.toString())
- Specified by:
compareTo
in interfacejava.lang.Comparable<BareJID>
- Parameters:
o
- is anBareJID
instance with which the comparision is performed.- Returns:
- values as we would expect from the call:
bareJID_1.toString().compareTo(bareJID_2.toString())
-
equals
public boolean equals(java.lang.Object b)
Method compares whether thisBareJID
instance represents the same user bare JID as the one given in parameter. It returnstrue
of both the localpart (nickname) and domain part are the same for both objects.- Overrides:
equals
in classjava.lang.Object
- Parameters:
b
- is aBareJID
object to which the instance is compared.- Returns:
- a
boolean
value oftrue
if both instances represent the same bare JID andfalse
otherwise.
-
getDomain
public java.lang.String getDomain()
Method returns a domain part of theBareJID
. Please note theString
returned is parsed, checked and processed via stringprep, hence it represents a valid domain name as defined in XMPP RFC.- Returns:
- a domain part of the
BareJID
instance.
-
getLocalpart
public java.lang.String getLocalpart()
Method returns a localpart (nickname) of theBareJID
. Please note theString
returned is parsed, checked and processed via stringprep, hence it represents a valid localpart as defined in XMPP RFC.- Returns:
- a localpart (nickname) of the
BareJID
instance.
-
hashCode
public int hashCode()
Method returns a hash code calculated for theBareJID
instance.- Overrides:
hashCode
in classjava.lang.Object
- Returns:
- an object hash code.
-
toString
public java.lang.String toString()
Method returns aString
representation of theBareJID
instance.- Overrides:
toString
in classjava.lang.Object
- Returns:
- a
String
representation of theBareJID
instance.
-
-