1111 */
1212public class GlobalItemIDImpl implements GlobalItemID {
1313
14- private static final Pattern STRING_PATTERN = Pattern .compile ("^tag:([^,]+),([^,]+),([^,]+)$" );
15-
14+ private static final Pattern STRING_PATTERN = Pattern
15+ .compile ("^tag:([^,]+),([^,]+),([^,]+)$" );
16+
1617 /**
1718 * Creates a new global item ID
18- * @param service the JID of the pubsub service hosting the node
19- * @param nodeID the id of the node containing the item
20- * @param itemID the id of the item
19+ *
20+ * @param service
21+ * the JID of the pubsub service hosting the node
22+ * @param nodeID
23+ * the id of the node containing the item
24+ * @param itemID
25+ * the id of the item
2126 */
2227 public GlobalItemIDImpl (JID service , String nodeID , String itemID ) {
2328 this .service = service ;
@@ -28,26 +33,26 @@ public GlobalItemIDImpl(JID service, String nodeID, String itemID) {
2833 private JID service ;
2934 private String nodeID ;
3035 private String itemID ;
31-
36+
3237 @ Override
3338 public JID getService () {
3439 return service ;
3540 }
36-
41+
3742 @ Override
3843 public String getNodeID () {
3944 return nodeID ;
4045 }
41-
46+
4247 @ Override
4348 public String getItemID () {
4449 return itemID ;
4550 }
46-
51+
4752 @ Override
4853 public String toString () {
4954 StringBuilder builder = new StringBuilder ();
50-
55+
5156 if (service != null ) {
5257 builder .append ("tag:" );
5358 builder .append (service .toString ());
@@ -56,40 +61,46 @@ public String toString() {
5661 builder .append (nodeID );
5762 builder .append ("," );
5863 builder .append (itemID );
59-
64+
6065 return builder .toString ();
6166 }
62-
67+
6368 /**
64- * Creates a new {@link GlobalItemID} from a tag string which looks a bit like:
65- * <blockquote><code>tag:pubsub.server.com,a/node/id,an/item/id</code></blockquote>
66- * @param str The tag string
69+ * Creates a new {@link GlobalItemID} from a tag string which looks a bit
70+ * like: <blockquote><code>tag:pubsub.server.com,a/node/id,an/item/id</code>
71+ * </blockquote>
72+ *
73+ * @param str
74+ * The tag string
6775 * @return the {@link GlobalItemID}
6876 */
6977 public static GlobalItemID fromString (final String str ) {
7078 Matcher matcher = STRING_PATTERN .matcher (str );
71-
72- if (!matcher .matches ()) {
73- throw new IllegalArgumentException (str + " is not a valid GlobalItemID String. Expected something like 'tag:example.com,node,item'." );
79+
80+ if (!matcher .matches ()) {
81+ throw new IllegalArgumentException (
82+ str
83+ + " is not a valid GlobalItemID String. Expected something like 'tag:example.com,node,item'." );
7484 }
75-
85+
7686 JID service = new JID (matcher .group (1 ));
77-
87+
7888 // Handle an issue with certain clients
79- if ((service .getNode () != null ) && service .getNode ().equals ("null" )) {
89+ if ((service .getNode () != null ) && service .getNode ().equals ("null" )) {
8090 service = new JID (null , service .getDomain (), service .getResource ());
8191 }
82-
92+
8393 return new GlobalItemIDImpl (service , matcher .group (2 ), matcher .group (3 ));
8494 }
85-
95+
8696 /**
8797 *
8898 */
8999 public static GlobalItemID fromBuddycloudString (String itemId ) {
90100 String [] splittedItemId = itemId .split ("," );
91101 if (splittedItemId .length < 2 ) {
92- throw new IllegalArgumentException ("Illegal format for buddycloud global id" );
102+ throw new IllegalArgumentException (
103+ "Illegal format for buddycloud global id" );
93104 }
94105 if (splittedItemId .length == 3 ) {
95106 return fromString (itemId );
@@ -108,7 +119,7 @@ public static String toLocalId(String itemId) {
108119 }
109120 return fromBuddycloudString (itemId ).getItemID ();
110121 }
111-
122+
112123 @ Override
113124 public int hashCode () {
114125 final int prime = 31 ;
@@ -145,4 +156,13 @@ public boolean equals(Object obj) {
145156 return false ;
146157 return true ;
147158 }
159+
160+ public static boolean isGlobalId (String id ) {
161+ Matcher matcher = STRING_PATTERN .matcher (id );
162+
163+ if (!matcher .matches ()) {
164+ return false ;
165+ }
166+ return true ;
167+ }
148168}
0 commit comments