mirror of
https://github.com/vanitasvitae/Smack.git
synced 2024-11-29 15:32:06 +01:00
Make UnblockContactsIQ immutable
and make the serialization function idiomatic.
This commit is contained in:
parent
07cba5b974
commit
b3662c0682
2 changed files with 19 additions and 12 deletions
|
@ -1,6 +1,6 @@
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* Copyright 2016 Fernando Ramirez, Florian Schmaus
|
* Copyright 2016-2017 Fernando Ramirez, Florian Schmaus
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -16,6 +16,7 @@
|
||||||
*/
|
*/
|
||||||
package org.jivesoftware.smackx.blocking.element;
|
package org.jivesoftware.smackx.blocking.element;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.jivesoftware.smack.packet.IQ;
|
import org.jivesoftware.smack.packet.IQ;
|
||||||
|
@ -52,7 +53,11 @@ public class UnblockContactsIQ extends IQ {
|
||||||
public UnblockContactsIQ(List<Jid> jids) {
|
public UnblockContactsIQ(List<Jid> jids) {
|
||||||
super(ELEMENT, NAMESPACE);
|
super(ELEMENT, NAMESPACE);
|
||||||
this.setType(Type.set);
|
this.setType(Type.set);
|
||||||
this.jids = jids;
|
if (jids != null) {
|
||||||
|
this.jids = Collections.unmodifiableList(jids);
|
||||||
|
} else {
|
||||||
|
this.jids = null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -63,9 +68,9 @@ public class UnblockContactsIQ extends IQ {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the JIDs.
|
* Get the JIDs. This may return null, which means that all JIDs should be or where unblocked.
|
||||||
*
|
*
|
||||||
* @return the list of JIDs
|
* @return the list of JIDs or <code>null</code>.
|
||||||
*/
|
*/
|
||||||
public List<Jid> getJids() {
|
public List<Jid> getJids() {
|
||||||
return jids;
|
return jids;
|
||||||
|
@ -73,15 +78,17 @@ public class UnblockContactsIQ extends IQ {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected IQChildElementXmlStringBuilder getIQChildElementBuilder(IQChildElementXmlStringBuilder xml) {
|
protected IQChildElementXmlStringBuilder getIQChildElementBuilder(IQChildElementXmlStringBuilder xml) {
|
||||||
xml.rightAngleBracket();
|
if (jids == null) {
|
||||||
|
xml.setEmptyElement();
|
||||||
|
return xml;
|
||||||
|
}
|
||||||
|
|
||||||
if (jids != null) {
|
xml.rightAngleBracket();
|
||||||
for (Jid jid : jids) {
|
for (Jid jid : jids) {
|
||||||
xml.halfOpenElement("item");
|
xml.halfOpenElement("item");
|
||||||
xml.attribute("jid", jid);
|
xml.attribute("jid", jid);
|
||||||
xml.closeEmptyElement();
|
xml.closeEmptyElement();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return xml;
|
return xml;
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,7 +36,7 @@ public class UnblockContactsIQTest {
|
||||||
+ "<unblock xmlns='urn:xmpp:blocking'>" + "<item jid='romeo@montague.net'/>"
|
+ "<unblock xmlns='urn:xmpp:blocking'>" + "<item jid='romeo@montague.net'/>"
|
||||||
+ "<item jid='pepe@montague.net'/>" + "</unblock>" + "</iq>";
|
+ "<item jid='pepe@montague.net'/>" + "</unblock>" + "</iq>";
|
||||||
|
|
||||||
String unblockAllIQExample = "<iq id='unblock2' type='set'>" + "<unblock xmlns='urn:xmpp:blocking'></unblock>"
|
String unblockAllIQExample = "<iq id='unblock2' type='set'>" + "<unblock xmlns='urn:xmpp:blocking'/>"
|
||||||
+ "</iq>";
|
+ "</iq>";
|
||||||
|
|
||||||
String unblockAllPushIQExample = "<iq to='juliet@capulet.com/chamber' type='set' id='push5'>"
|
String unblockAllPushIQExample = "<iq to='juliet@capulet.com/chamber' type='set' id='push5'>"
|
||||||
|
|
Loading…
Reference in a new issue