diff options
| -rw-r--r-- | src/com/isode/stroke/jid/JID.java | 36 | ||||
| -rw-r--r-- | test/com/isode/stroke/jid/JIDTest.java | 2 |
2 files changed, 14 insertions, 24 deletions
diff --git a/src/com/isode/stroke/jid/JID.java b/src/com/isode/stroke/jid/JID.java index 8b62ca1..07b2084 100644 --- a/src/com/isode/stroke/jid/JID.java +++ b/src/com/isode/stroke/jid/JID.java | |||
| @@ -46,10 +46,9 @@ public class JID implements Comparable<JID> { | |||
| 46 | }; | 46 | }; |
| 47 | 47 | ||
| 48 | private boolean valid_ = true; | 48 | private boolean valid_ = true; |
| 49 | private boolean hasResource_ = true; | ||
| 50 | private String node_ = ""; | 49 | private String node_ = ""; |
| 51 | private String domain_ = ""; | 50 | private String domain_ = ""; |
| 52 | private String resource_ = ""; | 51 | private String resource_ = null; |
| 53 | private static IDNConverter idnConverter = new ICUConverter(); | 52 | private static IDNConverter idnConverter = new ICUConverter(); |
| 54 | 53 | ||
| 55 | /** | 54 | /** |
| @@ -81,8 +80,7 @@ public class JID implements Comparable<JID> { | |||
| 81 | * @param jid String representation. Invalid JID if null or invalid. | 80 | * @param jid String representation. Invalid JID if null or invalid. |
| 82 | */ | 81 | */ |
| 83 | public JID(String jid) { | 82 | public JID(String jid) { |
| 84 | NotNull.exceptIfNull(jid, "jid"); | 83 | NotNull.exceptIfNull(jid, "jid"); |
| 85 | valid_ = true; | ||
| 86 | initializeFromString(jid); | 84 | initializeFromString(jid); |
| 87 | } | 85 | } |
| 88 | 86 | ||
| @@ -91,7 +89,7 @@ public class JID implements Comparable<JID> { | |||
| 91 | valid_ = false; | 89 | valid_ = false; |
| 92 | node_ = ""; | 90 | node_ = ""; |
| 93 | domain_ = ""; | 91 | domain_ = ""; |
| 94 | resource_ = ""; | 92 | resource_ = null; |
| 95 | return; | 93 | return; |
| 96 | } | 94 | } |
| 97 | 95 | ||
| @@ -102,7 +100,6 @@ public class JID implements Comparable<JID> { | |||
| 102 | bare = parts[0]; | 100 | bare = parts[0]; |
| 103 | resource = parts[1]; | 101 | resource = parts[1]; |
| 104 | } else { | 102 | } else { |
| 105 | hasResource_ = false; | ||
| 106 | resource = null; | 103 | resource = null; |
| 107 | bare = jid; | 104 | bare = jid; |
| 108 | } | 105 | } |
| @@ -145,11 +142,6 @@ public class JID implements Comparable<JID> { | |||
| 145 | public JID(String node, String domain, String resource) { | 142 | public JID(String node, String domain, String resource) { |
| 146 | NotNull.exceptIfNull(node, "node"); | 143 | NotNull.exceptIfNull(node, "node"); |
| 147 | NotNull.exceptIfNull(domain, "domain"); | 144 | NotNull.exceptIfNull(domain, "domain"); |
| 148 | valid_ = true; | ||
| 149 | hasResource_ = (resource != null); | ||
| 150 | if (hasResource_ && resource.isEmpty()) { | ||
| 151 | valid_ = false; | ||
| 152 | } | ||
| 153 | nameprepAndSetComponents(node, domain, resource); | 145 | nameprepAndSetComponents(node, domain, resource); |
| 154 | } | 146 | } |
| 155 | 147 | ||
| @@ -167,12 +159,15 @@ public class JID implements Comparable<JID> { | |||
| 167 | valid_ = false; | 159 | valid_ = false; |
| 168 | return; | 160 | return; |
| 169 | } | 161 | } |
| 162 | if (resource_ != null && resource_.isEmpty()) { | ||
| 163 | valid_ = false; | ||
| 164 | } | ||
| 170 | if (domain_.isEmpty()) { | 165 | if (domain_.isEmpty()) { |
| 171 | valid_ = false; | 166 | valid_ = false; |
| 172 | return; | 167 | return; |
| 173 | } | 168 | } |
| 174 | } | 169 | } |
| 175 | 170 | ||
| 176 | /** | 171 | /** |
| 177 | * @return Is a correctly-formatted JID. | 172 | * @return Is a correctly-formatted JID. |
| 178 | */ | 173 | */ |
| @@ -209,7 +204,7 @@ public class JID implements Comparable<JID> { | |||
| 209 | * @return true if the resource part of JID is null, false if not | 204 | * @return true if the resource part of JID is null, false if not |
| 210 | */ | 205 | */ |
| 211 | public boolean isBare() { | 206 | public boolean isBare() { |
| 212 | return !hasResource_; | 207 | return resource_ == null; |
| 213 | } | 208 | } |
| 214 | 209 | ||
| 215 | /** | 210 | /** |
| @@ -309,9 +304,6 @@ public class JID implements Comparable<JID> { | |||
| 309 | 304 | ||
| 310 | @Override | 305 | @Override |
| 311 | public String toString() { | 306 | public String toString() { |
| 312 | if (!valid_) { | ||
| 313 | return ""; | ||
| 314 | } | ||
| 315 | String string = new String(); | 307 | String string = new String(); |
| 316 | if (node_.length()!=0) { | 308 | if (node_.length()!=0) { |
| 317 | string += node_ + "@"; | 309 | string += node_ + "@"; |
| @@ -348,14 +340,12 @@ public class JID implements Comparable<JID> { | |||
| 348 | return domain_.compareTo(o.domain_); | 340 | return domain_.compareTo(o.domain_); |
| 349 | } | 341 | } |
| 350 | if (compareType == CompareType.WithResource) { | 342 | if (compareType == CompareType.WithResource) { |
| 351 | String res1 = resource_; | 343 | if (isBare() != o.isBare()) { |
| 352 | String res2 = o.resource_; | 344 | return !isBare() ? 1 : -1; |
| 353 | if(res1 != null && res2 != null) { | 345 | } |
| 354 | return res1.compareTo(res2); | 346 | if (!isBare()) { |
| 347 | return resource_.compareTo(o.resource_); | ||
| 355 | } | 348 | } |
| 356 | if(res1 == null && res2 == null) { return 0; } | ||
| 357 | if (res1 == null) { return -1; } | ||
| 358 | if (res2 == null) { return 1; } | ||
| 359 | } | 349 | } |
| 360 | return 0; | 350 | return 0; |
| 361 | } | 351 | } |
diff --git a/test/com/isode/stroke/jid/JIDTest.java b/test/com/isode/stroke/jid/JIDTest.java index 69bee05..758bd5f 100644 --- a/test/com/isode/stroke/jid/JIDTest.java +++ b/test/com/isode/stroke/jid/JIDTest.java | |||
| @@ -51,7 +51,7 @@ public class JIDTest { | |||
| 51 | public void testConstructorWithString_EmptyResource() { | 51 | public void testConstructorWithString_EmptyResource() { |
| 52 | JID testling = new JID("bar/"); | 52 | JID testling = new JID("bar/"); |
| 53 | 53 | ||
| 54 | assertTrue(testling.isValid()); | 54 | assertFalse(testling.isValid()); |
| 55 | assertFalse(testling.isBare()); | 55 | assertFalse(testling.isBare()); |
| 56 | } | 56 | } |
| 57 | 57 | ||
Swift