1
0
Fork 0
mirror of https://github.com/vanitasvitae/Smack.git synced 2025-09-09 09:09:38 +02:00

Add Stanza.setNewStanzaId() and ensureStanzaIdSet()

Also deprecate setStanzaId() since it was not clear if this would
create a new stanza ID or just ensure that one is set.
This commit is contained in:
Florian Schmaus 2019-10-05 23:14:41 +02:00
parent 133ee29150
commit e23babf147
4 changed files with 39 additions and 9 deletions

View file

@ -138,9 +138,43 @@ public abstract class Stanza implements TopLevelStreamElement {
*
* @return the stanza id.
* @since 4.2
* @deprecated use {@link #setNewStanzaId()} instead.
*/
@Deprecated
// TODO: Remove in Smack 4.5.
public String setStanzaId() {
if (!hasStanzaIdSet()) {
return ensureStanzaIdSet();
}
/**
* Set a new stanza ID even if there is already one set.
*
* @return the stanza id.
* @since 4.4
*/
public String setNewStanzaId() {
return ensureStanzaIdSet(true);
}
/**
* Ensure a stanza id is set.
*
* @return the stanza id.
* @since 4.4
*/
public String ensureStanzaIdSet() {
return ensureStanzaIdSet(false);
}
/**
* Ensure that a stanza ID is set.
*
* @param forceNew force a new ID even if there is already one set.
* @return the stanza ID.
* @since 4.4
*/
private String ensureStanzaIdSet(boolean forceNew) {
if (forceNew || !hasStanzaIdSet()) {
setStanzaId(StanzaIdUtil.newStanzaId());
}
return getStanzaId();