From 7d59df9eed803d9448f1ee21c9620ac0c4f3a143 Mon Sep 17 00:00:00 2001 From: Florian Schmaus Date: Mon, 10 Jun 2019 23:22:28 +0200 Subject: [PATCH] Change type of presence priority to 'Byte' --- .../jivesoftware/smack/packet/Presence.java | 18 ++++++++++-------- .../smack/util/PacketParserUtils.java | 2 +- .../jivesoftware/smack/util/ParserUtils.java | 5 +++++ 3 files changed, 16 insertions(+), 9 deletions(-) diff --git a/smack-core/src/main/java/org/jivesoftware/smack/packet/Presence.java b/smack-core/src/main/java/org/jivesoftware/smack/packet/Presence.java index 2279cde26..114cef1b1 100644 --- a/smack-core/src/main/java/org/jivesoftware/smack/packet/Presence.java +++ b/smack-core/src/main/java/org/jivesoftware/smack/packet/Presence.java @@ -68,12 +68,12 @@ public final class Presence extends Stanza implements TypedCloneable { private String status = null; /** - * The priority of the presence. The magic value {@link Integer#MIN_VALUE} is used to indicate that the original + * The priority of the presence. It is null to indicate that the original * presence stanza did not had an explicit priority set. In which case the priority defaults to 0. * * @see RFC 6121 § 4.7.2.3. */ - private int priority = Integer.MIN_VALUE; + private Byte priority; private Mode mode = null; @@ -203,13 +203,13 @@ public final class Presence extends Stanza implements TypedCloneable { } /** - * Returns the priority of the presence, or Integer.MIN_VALUE if no priority has been set. + * Returns the priority of the presence. * * @return the priority. * @see RFC 6121 § 4.7.2.3. Priority Element */ public int getPriority() { - if (priority == Integer.MIN_VALUE) { + if (priority == null) { return 0; } return priority; @@ -227,6 +227,10 @@ public final class Presence extends Stanza implements TypedCloneable { throw new IllegalArgumentException("Priority value " + priority + " is not valid. Valid range is -128 through 127."); } + setPriority((byte) priority); + } + + public void setPriority(byte priority) { this.priority = priority; } @@ -264,7 +268,7 @@ public final class Presence extends Stanza implements TypedCloneable { if (!StringUtils.isNullOrEmpty(status)) { sb.append("status=").append(status).append(','); } - if (priority != Integer.MIN_VALUE) { + if (priority != null) { sb.append("prio=").append(priority).append(','); } sb.append(']'); @@ -282,9 +286,7 @@ public final class Presence extends Stanza implements TypedCloneable { buf.rightAngleBracket(); buf.optElement("status", status); - if (priority != Integer.MIN_VALUE) { - buf.element("priority", Integer.toString(priority)); - } + buf.optElement("priority", priority); if (mode != null && mode != Mode.available) { buf.element("show", mode); } diff --git a/smack-core/src/main/java/org/jivesoftware/smack/util/PacketParserUtils.java b/smack-core/src/main/java/org/jivesoftware/smack/util/PacketParserUtils.java index 520e4ee87..178932554 100644 --- a/smack-core/src/main/java/org/jivesoftware/smack/util/PacketParserUtils.java +++ b/smack-core/src/main/java/org/jivesoftware/smack/util/PacketParserUtils.java @@ -454,7 +454,7 @@ public class PacketParserUtils { presence.setStatus(parser.nextText()); break; case "priority": - int priority = Integer.parseInt(parser.nextText()); + Byte priority = ParserUtils.getByteAttributeFromNextText(parser); presence.setPriority(priority); break; case "show": diff --git a/smack-core/src/main/java/org/jivesoftware/smack/util/ParserUtils.java b/smack-core/src/main/java/org/jivesoftware/smack/util/ParserUtils.java index feeba45ab..86d091841 100644 --- a/smack-core/src/main/java/org/jivesoftware/smack/util/ParserUtils.java +++ b/smack-core/src/main/java/org/jivesoftware/smack/util/ParserUtils.java @@ -179,6 +179,11 @@ public class ParserUtils { } } + public static Byte getByteAttributeFromNextText(XmlPullParser parser) throws IOException, XmlPullParserException { + String nextText = parser.nextText(); + return Byte.valueOf(nextText); + } + public static int getIntegerAttributeOrThrow(XmlPullParser parser, String name, String throwMessage) throws IOException { Integer res = getIntegerAttribute(parser, name);