aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/de/pixart/messenger/xmpp/jid/Jid.java
diff options
context:
space:
mode:
authorChristian Schneppe <christian@pix-art.de>2016-10-26 22:13:24 +0200
committerChristian Schneppe <christian@pix-art.de>2016-10-26 22:13:24 +0200
commit1052af9276e4c660b95b7b7fecfc8f40fe28c485 (patch)
treeba42fb45167b7bfb15188265e4e49b47b5857b2d /src/main/java/de/pixart/messenger/xmpp/jid/Jid.java
parenta404e06944817335a81c84b86012aa1715df75bc (diff)
write prepped string to db. use display version everywhere else
Diffstat (limited to '')
-rw-r--r--src/main/java/de/pixart/messenger/xmpp/jid/Jid.java19
1 files changed, 18 insertions, 1 deletions
diff --git a/src/main/java/de/pixart/messenger/xmpp/jid/Jid.java b/src/main/java/de/pixart/messenger/xmpp/jid/Jid.java
index ffbd754ee..c596367ca 100644
--- a/src/main/java/de/pixart/messenger/xmpp/jid/Jid.java
+++ b/src/main/java/de/pixart/messenger/xmpp/jid/Jid.java
@@ -21,6 +21,10 @@ public final class Jid {
private final String domainpart;
private final String resourcepart;
+ // It's much more efficient to store the full JID as well as the parts instead of figuring them
+ // all out every time (since some characters are displayed but aren't used for comparisons).
+ private final String displayjid;
+
public String getLocalpart() {
return localpart;
}
@@ -69,6 +73,7 @@ public final class Jid {
Jid fromCache = Jid.cache.get(jid);
if (fromCache != null) {
+ displayjid = fromCache.displayjid;
localpart = fromCache.localpart;
domainpart = fromCache.domainpart;
resourcepart = fromCache.resourcepart;
@@ -89,6 +94,8 @@ public final class Jid {
throw new InvalidJidException(InvalidJidException.INVALID_CHARACTER);
}
+ String finaljid;
+
final int domainpartStart;
final int atLoc = jid.indexOf("@");
final int slashLoc = jid.indexOf("/");
@@ -96,6 +103,7 @@ public final class Jid {
// or there are one or more "@" signs but they're all in the resourcepart (eg. "example.net/@/rp@"):
if (atCount == 0 || (atCount > 0 && slashLoc != -1 && atLoc > slashLoc)) {
localpart = "";
+ finaljid = "";
domainpartStart = 0;
} else {
final String lp = jid.substring(0, atLoc);
@@ -108,6 +116,7 @@ public final class Jid {
throw new InvalidJidException(InvalidJidException.INVALID_PART_LENGTH);
}
domainpartStart = atLoc + 1;
+ finaljid = lp + "@";
}
final String dp;
@@ -126,6 +135,7 @@ public final class Jid {
} catch (final StringprepException e) {
throw new InvalidJidException(InvalidJidException.STRINGPREP_FAIL, e);
}
+ finaljid = finaljid + dp + "/" + rp;
} else {
resourcepart = "";
try{
@@ -133,7 +143,8 @@ public final class Jid {
} catch (final StringprepException e) {
throw new InvalidJidException(InvalidJidException.STRINGPREP_FAIL, e);
}
- }
+ finaljid = finaljid + dp;
+ }
// Remove trailing "." before storing the domain part.
if (dp.endsWith(".")) {
@@ -156,6 +167,8 @@ public final class Jid {
}
Jid.cache.put(jid, this);
+
+ this.displayjid = finaljid;
}
public Jid toBareJid() {
@@ -178,6 +191,10 @@ public final class Jid {
@Override
public String toString() {
+ return displayjid;
+ }
+
+ public String toPreppedString() {
String out;
if (hasLocalpart()) {
out = localpart + '@' + domainpart;