Change type of presence priority to 'Byte'

This commit is contained in:
Florian Schmaus 2019-06-10 23:22:28 +02:00
parent e911874e72
commit 7d59df9eed
3 changed files with 16 additions and 9 deletions

View File

@ -68,12 +68,12 @@ public final class Presence extends Stanza implements TypedCloneable<Presence> {
private String status = null; 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 <code>null</code> to indicate that the original
* presence stanza did not had an explicit priority set. In which case the priority defaults to 0. * presence stanza did not had an explicit priority set. In which case the priority defaults to 0.
* *
* @see <a href="https://tools.ietf.org/html/rfc6121#section-4.7.2.3">RFC 6121 § 4.7.2.3.</a> * @see <a href="https://tools.ietf.org/html/rfc6121#section-4.7.2.3">RFC 6121 § 4.7.2.3.</a>
*/ */
private int priority = Integer.MIN_VALUE; private Byte priority;
private Mode mode = null; private Mode mode = null;
@ -203,13 +203,13 @@ public final class Presence extends Stanza implements TypedCloneable<Presence> {
} }
/** /**
* 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. * @return the priority.
* @see <a href="https://tools.ietf.org/html/rfc6121#section-4.7.2.3">RFC 6121 § 4.7.2.3. Priority Element</a> * @see <a href="https://tools.ietf.org/html/rfc6121#section-4.7.2.3">RFC 6121 § 4.7.2.3. Priority Element</a>
*/ */
public int getPriority() { public int getPriority() {
if (priority == Integer.MIN_VALUE) { if (priority == null) {
return 0; return 0;
} }
return priority; return priority;
@ -227,6 +227,10 @@ public final class Presence extends Stanza implements TypedCloneable<Presence> {
throw new IllegalArgumentException("Priority value " + priority + throw new IllegalArgumentException("Priority value " + priority +
" is not valid. Valid range is -128 through 127."); " is not valid. Valid range is -128 through 127.");
} }
setPriority((byte) priority);
}
public void setPriority(byte priority) {
this.priority = priority; this.priority = priority;
} }
@ -264,7 +268,7 @@ public final class Presence extends Stanza implements TypedCloneable<Presence> {
if (!StringUtils.isNullOrEmpty(status)) { if (!StringUtils.isNullOrEmpty(status)) {
sb.append("status=").append(status).append(','); sb.append("status=").append(status).append(',');
} }
if (priority != Integer.MIN_VALUE) { if (priority != null) {
sb.append("prio=").append(priority).append(','); sb.append("prio=").append(priority).append(',');
} }
sb.append(']'); sb.append(']');
@ -282,9 +286,7 @@ public final class Presence extends Stanza implements TypedCloneable<Presence> {
buf.rightAngleBracket(); buf.rightAngleBracket();
buf.optElement("status", status); buf.optElement("status", status);
if (priority != Integer.MIN_VALUE) { buf.optElement("priority", priority);
buf.element("priority", Integer.toString(priority));
}
if (mode != null && mode != Mode.available) { if (mode != null && mode != Mode.available) {
buf.element("show", mode); buf.element("show", mode);
} }

View File

@ -454,7 +454,7 @@ public class PacketParserUtils {
presence.setStatus(parser.nextText()); presence.setStatus(parser.nextText());
break; break;
case "priority": case "priority":
int priority = Integer.parseInt(parser.nextText()); Byte priority = ParserUtils.getByteAttributeFromNextText(parser);
presence.setPriority(priority); presence.setPriority(priority);
break; break;
case "show": case "show":

View File

@ -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) public static int getIntegerAttributeOrThrow(XmlPullParser parser, String name, String throwMessage)
throws IOException { throws IOException {
Integer res = getIntegerAttribute(parser, name); Integer res = getIntegerAttribute(parser, name);