From 8aa7029b385b88b1b26c2b70dc7c7c367163e39c Mon Sep 17 00:00:00 2001 From: Florian Schmaus Date: Sun, 3 Jun 2018 21:19:04 +0200 Subject: [PATCH] Add DataForm.addFields() --- .../smackx/xdata/packet/DataForm.java | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/xdata/packet/DataForm.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/xdata/packet/DataForm.java index 5315c6d49..326a3a248 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/xdata/packet/DataForm.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/xdata/packet/DataForm.java @@ -18,6 +18,7 @@ package org.jivesoftware.smackx.xdata.packet; import java.util.ArrayList; +import java.util.Collection; import java.util.Collections; import java.util.LinkedHashMap; import java.util.List; @@ -234,6 +235,26 @@ public class DataForm implements ExtensionElement { } } + /** + * Add the given fields to this form. + * + * @param fieldsToAdd + * @return true if a field was overridden. + * @since 4.3.0 + */ + public boolean addFields(Collection fieldsToAdd) { + boolean fieldOverridden = false; + synchronized (fields) { + for (FormField field : fieldsToAdd) { + FormField previousField = fields.put(field.getVariable(), field); + if (previousField != null) { + fieldOverridden = true; + } + } + } + return fieldOverridden; + } + /** * Adds a new instruction to the list of instructions that explain how to fill out the form * and what the form is about. The dataform could include multiple instructions since each