From b3662c0682c0df338f02cf4e20f707ab9604daa7 Mon Sep 17 00:00:00 2001 From: Florian Schmaus Date: Fri, 20 Jan 2017 08:52:37 +0100 Subject: [PATCH] Make UnblockContactsIQ immutable and make the serialization function idiomatic. --- .../blocking/element/UnblockContactsIQ.java | 29 ++++++++++++------- .../blocking/UnblockContactsIQTest.java | 2 +- 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/blocking/element/UnblockContactsIQ.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/blocking/element/UnblockContactsIQ.java index 5b2260b37..73d36ff9e 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/blocking/element/UnblockContactsIQ.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/blocking/element/UnblockContactsIQ.java @@ -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"); * you may not use this file except in compliance with the License. @@ -16,6 +16,7 @@ */ package org.jivesoftware.smackx.blocking.element; +import java.util.Collections; import java.util.List; import org.jivesoftware.smack.packet.IQ; @@ -52,7 +53,11 @@ public class UnblockContactsIQ extends IQ { public UnblockContactsIQ(List jids) { super(ELEMENT, NAMESPACE); 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 null. */ public List getJids() { return jids; @@ -73,14 +78,16 @@ public class UnblockContactsIQ extends IQ { @Override protected IQChildElementXmlStringBuilder getIQChildElementBuilder(IQChildElementXmlStringBuilder xml) { - xml.rightAngleBracket(); + if (jids == null) { + xml.setEmptyElement(); + return xml; + } - if (jids != null) { - for (Jid jid : jids) { - xml.halfOpenElement("item"); - xml.attribute("jid", jid); - xml.closeEmptyElement(); - } + xml.rightAngleBracket(); + for (Jid jid : jids) { + xml.halfOpenElement("item"); + xml.attribute("jid", jid); + xml.closeEmptyElement(); } return xml; diff --git a/smack-extensions/src/test/java/org/jivesoftware/smackx/blocking/UnblockContactsIQTest.java b/smack-extensions/src/test/java/org/jivesoftware/smackx/blocking/UnblockContactsIQTest.java index 3d4f8a943..4145e60fa 100644 --- a/smack-extensions/src/test/java/org/jivesoftware/smackx/blocking/UnblockContactsIQTest.java +++ b/smack-extensions/src/test/java/org/jivesoftware/smackx/blocking/UnblockContactsIQTest.java @@ -36,7 +36,7 @@ public class UnblockContactsIQTest { + "" + "" + "" + "" + ""; - String unblockAllIQExample = "" + "" + String unblockAllIQExample = "" + "" + ""; String unblockAllPushIQExample = ""