From e0a2441c62d68ffb0b078d3712727439956ef3a6 Mon Sep 17 00:00:00 2001 From: Florian Schmaus Date: Sun, 8 Feb 2015 11:50:07 +0100 Subject: [PATCH] Add Stanza.hasStanzaIdSet() --- .../org/jivesoftware/smack/packet/Stanza.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/smack-core/src/main/java/org/jivesoftware/smack/packet/Stanza.java b/smack-core/src/main/java/org/jivesoftware/smack/packet/Stanza.java index b7226a965..4e341b023 100644 --- a/smack-core/src/main/java/org/jivesoftware/smack/packet/Stanza.java +++ b/smack-core/src/main/java/org/jivesoftware/smack/packet/Stanza.java @@ -119,6 +119,9 @@ public abstract class Stanza implements TopLevelStreamElement, Packet { * @param id the unique ID for the packet. */ public void setStanzaId(String id) { + if (id != null) { + requireNotNullOrEmpty(id, "id must either be null or not the empty String"); + } this.id = id; } @@ -132,6 +135,18 @@ public abstract class Stanza implements TopLevelStreamElement, Packet { setStanzaId(packetID); } + /** + * Check if this stanza has an ID set. + * + * @return true if the stanza ID is set, false otherwise. + * @since 4.1 + */ + public boolean hasStanzaIdSet() { + // setStanzaId ensures that the id is either null or not empty, + // so we can assume that it is set if it's not null. + return id != null; + } + /** * Returns who the packet is being sent "to", or null if * the value is not set. The XMPP protocol often makes the "to"