From 4cff0087087f20378e4c96647a67a3dc088efc42 Mon Sep 17 00:00:00 2001 From: Florian Schmaus Date: Wed, 9 Apr 2014 08:26:28 +0200 Subject: [PATCH] Return Collections (or sublcasses) instead of Iterators This allows us to exploid Java 8 streams and Java 5 for-each loops. The returned Collections are usually unmodifiable. We decided against returning Iterable because this would mean determining the size in O(n) compared to Collection.size() which is often faster (e.g. O(1)). --- .../java/org/jivesoftware/smack/Roster.java | 13 +++-- .../jivesoftware/smack/packet/XMPPError.java | 4 +- documentation/extensions/disco.html | 6 +- .../smackx/amp/packet/AMPExtension.java | 12 ++-- .../smackx/bookmarks/Bookmarks.java | 9 +-- .../smackx/caps/EntityCapsManager.java | 19 +++---- .../smackx/disco/ServiceDiscoveryManager.java | 11 ++-- .../filetransfer/FileTransferNegotiator.java | 18 ++---- .../iqprivate/packet/DefaultPrivateData.java | 15 +++-- .../smackx/muc/MultiUserChat.java | 41 +++++++------- .../org/jivesoftware/smackx/muc/RoomInfo.java | 6 +- .../smackx/muc/packet/MUCAdmin.java | 10 ++-- .../smackx/muc/packet/MUCOwner.java | 10 ++-- .../smackx/offline/OfflineMessageManager.java | 25 ++++----- .../offline/packet/OfflineMessageRequest.java | 10 ++-- .../smackx/pubsub/ConfigureForm.java | 32 +++++------ .../org/jivesoftware/smackx/pubsub/Node.java | 7 +-- .../smackx/pubsub/PubSubManager.java | 2 +- .../smackx/pubsub/SubscribeForm.java | 16 +++--- .../smackx/search/ReportedData.java | 46 +++++++--------- .../smackx/search/SimpleUserSearch.java | 19 +++---- .../sharedgroups/packet/SharedGroupsInfo.java | 5 +- .../smackx/vcardtemp/packet/VCard.java | 17 ++---- .../org/jivesoftware/smackx/xdata/Form.java | 30 +++++----- .../jivesoftware/smackx/xdata/FormField.java | 27 +++++---- .../smackx/xdata/packet/DataForm.java | 55 +++++++++---------- .../smackx/xevent/MessageEventManager.java | 9 ++- .../smackx/xevent/packet/MessageEvent.java | 8 +-- .../smackx/xhtmlim/XHTMLManager.java | 4 +- .../smackx/xhtmlim/packet/XHTMLExtension.java | 13 ++--- .../provider/XHTMLExtensionProviderTest.java | 2 +- 31 files changed, 219 insertions(+), 282 deletions(-) diff --git a/core/src/main/java/org/jivesoftware/smack/Roster.java b/core/src/main/java/org/jivesoftware/smack/Roster.java index 34753ba9a..03b72c992 100644 --- a/core/src/main/java/org/jivesoftware/smack/Roster.java +++ b/core/src/main/java/org/jivesoftware/smack/Roster.java @@ -22,7 +22,6 @@ import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.HashSet; -import java.util.Iterator; import java.util.List; import java.util.Locale; import java.util.Map; @@ -583,17 +582,18 @@ public class Roster { * updates. * * @param user a XMPP ID, e.g. jdoe@example.com. - * @return an iterator (of Presence objects) for all the user's current presences, + * @return an Collection (of Presence objects) for all the user's current presences, * or an unavailable presence if the user is offline or if no presence information * is available. */ - public Iterator getPresences(String user) { + public Collection getPresences(String user) { + Collection res; String key = getPresenceMapKey(user); Map userPresences = presenceMap.get(key); if (userPresences == null) { Presence presence = new Presence(Presence.Type.unavailable); presence.setFrom(user); - return Arrays.asList(presence).iterator(); + res = Arrays.asList(presence); } else { Collection answer = new ArrayList(); @@ -603,14 +603,15 @@ public class Roster { } } if (!answer.isEmpty()) { - return answer.iterator(); + res = answer; } else { Presence presence = new Presence(Presence.Type.unavailable); presence.setFrom(user); - return Arrays.asList(presence).iterator(); + res = Arrays.asList(presence); } } + return Collections.unmodifiableCollection(res); } /** diff --git a/core/src/main/java/org/jivesoftware/smack/packet/XMPPError.java b/core/src/main/java/org/jivesoftware/smack/packet/XMPPError.java index 3ac70af49..a11c98d32 100644 --- a/core/src/main/java/org/jivesoftware/smack/packet/XMPPError.java +++ b/core/src/main/java/org/jivesoftware/smack/packet/XMPPError.java @@ -190,11 +190,11 @@ public class XMPPError { } /** - * Returns an Iterator for the error extensions attached to the xmppError. + * Returns a List of the error extensions attached to the xmppError. * An application MAY provide application-specific error information by including a * properly-namespaced child in the error element. * - * @return an Iterator for the error extensions. + * @return a List of the error extensions. */ public synchronized List getExtensions() { if (applicationExtensions == null) { diff --git a/documentation/extensions/disco.html b/documentation/extensions/disco.html index 6f8058dd9..40a612bcb 100644 --- a/documentation/extensions/disco.html +++ b/documentation/extensions/disco.html @@ -93,13 +93,13 @@ information concerning a node named "http://jabber.org/protocol/muc#rooms":
ServiceDiscoveryManager.getInstanceFor(connection).setNodeInformationProvider( "http://jabber.org/protocol/muc#rooms", new NodeInformationProvider() { - public Iterator getNodeItems() { + public List getNodeItems() { ArrayList answer = new ArrayList(); Iterator rooms = MultiUserChat.getJoinedRooms(connection); while (rooms.hasNext()) { answer.add(new DiscoverItems.Item((String)rooms.next())); } - return answer.iterator(); + return answer; } }); @@ -233,4 +233,4 @@ In this example we can see how to publish new items:
- \ No newline at end of file + diff --git a/extensions/src/main/java/org/jivesoftware/smackx/amp/packet/AMPExtension.java b/extensions/src/main/java/org/jivesoftware/smackx/amp/packet/AMPExtension.java index d80d0a359..d3a01bded 100644 --- a/extensions/src/main/java/org/jivesoftware/smackx/amp/packet/AMPExtension.java +++ b/extensions/src/main/java/org/jivesoftware/smackx/amp/packet/AMPExtension.java @@ -80,12 +80,12 @@ public class AMPExtension implements PacketExtension { } /** - * Returns an Iterator for the rules in the packet. + * Returns a Collection of the rules in the packet. * - * @return an Iterator for the rules in the packet. + * @return a Collection of the rules in the packet. */ - public Iterator getRules() { - return Collections.unmodifiableList(new ArrayList(rules)).iterator(); + public Collection getRules() { + return Collections.unmodifiableList(new ArrayList(rules)); } /** @@ -168,8 +168,8 @@ public class AMPExtension implements PacketExtension { buf.append(">"); // Loop through all the rules and append them to the string buffer - for (Iterator i = getRules(); i.hasNext();) { - buf.append(i.next().toXML()); + for (Rule rule : getRules()) { + buf.append(rule.toXML()); } buf.append(""); diff --git a/extensions/src/main/java/org/jivesoftware/smackx/bookmarks/Bookmarks.java b/extensions/src/main/java/org/jivesoftware/smackx/bookmarks/Bookmarks.java index af484c3b5..f70de8a99 100644 --- a/extensions/src/main/java/org/jivesoftware/smackx/bookmarks/Bookmarks.java +++ b/extensions/src/main/java/org/jivesoftware/smackx/bookmarks/Bookmarks.java @@ -23,7 +23,6 @@ import org.xmlpull.v1.XmlPullParserException; import java.io.IOException; import java.util.ArrayList; -import java.util.Iterator; import java.util.List; /** @@ -167,9 +166,7 @@ public class Bookmarks implements PrivateData { StringBuilder buf = new StringBuilder(); buf.append(""); - final Iterator urls = getBookmarkedURLS().iterator(); - while (urls.hasNext()) { - BookmarkedURL urlStorage = urls.next(); + for (BookmarkedURL urlStorage : getBookmarkedURLS()) { if(urlStorage.isShared()) { continue; } @@ -182,9 +179,7 @@ public class Bookmarks implements PrivateData { } // Add Conference additions - final Iterator conferences = getBookmarkedConferences().iterator(); - while (conferences.hasNext()) { - BookmarkedConference conference = conferences.next(); + for (BookmarkedConference conference : getBookmarkedConferences()) { if(conference.isShared()) { continue; } diff --git a/extensions/src/main/java/org/jivesoftware/smackx/caps/EntityCapsManager.java b/extensions/src/main/java/org/jivesoftware/smackx/caps/EntityCapsManager.java index a4a217fb3..7ef889874 100644 --- a/extensions/src/main/java/org/jivesoftware/smackx/caps/EntityCapsManager.java +++ b/extensions/src/main/java/org/jivesoftware/smackx/caps/EntityCapsManager.java @@ -51,7 +51,6 @@ import org.jivesoftware.smackx.xdata.packet.DataForm; import java.util.Collections; import java.util.Comparator; import java.util.HashMap; -import java.util.Iterator; import java.util.LinkedList; import java.util.List; import java.util.Locale; @@ -528,12 +527,10 @@ public class EntityCapsManager extends Manager { */ protected static boolean verifyPacketExtensions(DiscoverInfo info) { List foundFormTypes = new LinkedList(); - for (Iterator i = info.getExtensions().iterator(); i.hasNext();) { - PacketExtension pe = i.next(); + for (PacketExtension pe : info.getExtensions()) { if (pe.getNamespace().equals(Form.NAMESPACE)) { DataForm df = (DataForm) pe; - for (Iterator it = df.getFields(); it.hasNext();) { - FormField f = it.next(); + for (FormField f : df.getFields()) { if (f.getVariable().equals("FORM_TYPE")) { for (FormField fft : foundFormTypes) { if (f.equals(fft)) @@ -583,8 +580,7 @@ public class EntityCapsManager extends Manager { // 3. For each identity, append the 'category/type/lang/name' to S, // followed by the '<' character. - for (Iterator it = sortedIdentities.iterator(); it.hasNext();) { - DiscoverInfo.Identity identity = it.next(); + for (DiscoverInfo.Identity identity : sortedIdentities) { sb.append(identity.getCategory()); sb.append("/"); sb.append(identity.getType()); @@ -623,8 +619,7 @@ public class EntityCapsManager extends Manager { FormField ft = null; - for (Iterator i = extendedInfo.getFields(); i.hasNext();) { - FormField f = i.next(); + for (FormField f : extendedInfo.getFields()) { if (!f.getVariable().equals("FORM_TYPE")) { fs.add(f); } else { @@ -664,10 +659,10 @@ public class EntityCapsManager extends Manager { return Base64.encodeBytes(digest); } - private static void formFieldValuesToCaps(Iterator i, StringBuilder sb) { + private static void formFieldValuesToCaps(List i, StringBuilder sb) { SortedSet fvs = new TreeSet(); - while (i.hasNext()) { - fvs.add(i.next()); + for (String s : i) { + fvs.add(s); } for (String fv : fvs) { sb.append(fv); diff --git a/extensions/src/main/java/org/jivesoftware/smackx/disco/ServiceDiscoveryManager.java b/extensions/src/main/java/org/jivesoftware/smackx/disco/ServiceDiscoveryManager.java index 8dbe98bfc..8e31230f8 100644 --- a/extensions/src/main/java/org/jivesoftware/smackx/disco/ServiceDiscoveryManager.java +++ b/extensions/src/main/java/org/jivesoftware/smackx/disco/ServiceDiscoveryManager.java @@ -38,7 +38,6 @@ import org.jivesoftware.smackx.xdata.packet.DataForm; import java.util.ArrayList; import java.util.Collections; import java.util.HashSet; -import java.util.Iterator; import java.util.LinkedList; import java.util.List; import java.util.Map; @@ -314,8 +313,8 @@ public class ServiceDiscoveryManager extends Manager { // Add the registered features to the response synchronized (features) { - for (Iterator it = getFeatures(); it.hasNext();) { - response.addFeature(it.next()); + for (String feature : getFeatures()) { + response.addFeature(feature); } response.addExtension(extendedInfo); } @@ -373,11 +372,11 @@ public class ServiceDiscoveryManager extends Manager { /** * Returns the supported features by this XMPP entity. * - * @return an Iterator on the supported features by this XMPP entity. + * @return a List of the supported features by this XMPP entity. */ - public Iterator getFeatures() { + public List getFeatures() { synchronized (features) { - return Collections.unmodifiableList(new ArrayList(features)).iterator(); + return Collections.unmodifiableList(new ArrayList(features)); } } diff --git a/extensions/src/main/java/org/jivesoftware/smackx/filetransfer/FileTransferNegotiator.java b/extensions/src/main/java/org/jivesoftware/smackx/filetransfer/FileTransferNegotiator.java index 337ad00a8..6b1c4cc16 100644 --- a/extensions/src/main/java/org/jivesoftware/smackx/filetransfer/FileTransferNegotiator.java +++ b/extensions/src/main/java/org/jivesoftware/smackx/filetransfer/FileTransferNegotiator.java @@ -21,7 +21,6 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.Collections; -import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Random; @@ -280,15 +279,12 @@ public class FileTransferNegotiator { } private FormField getStreamMethodField(DataForm form) { - FormField field = null; - for (Iterator it = form.getFields(); it.hasNext();) { - field = it.next(); + for (FormField field : form.getFields()) { if (field.getVariable().equals(STREAM_DATA_FIELD_NAME)) { - break; + return field; } - field = null; } - return field; + return null; } private StreamNegotiator getNegotiator(final FormField field) @@ -296,8 +292,8 @@ public class FileTransferNegotiator { String variable; boolean isByteStream = false; boolean isIBB = false; - for (Iterator it = field.getOptions(); it.hasNext();) { - variable = it.next().getValue(); + for (FormField.Option option : field.getOptions()) { + variable = option.getValue(); if (variable.equals(Socks5BytestreamManager.NAMESPACE) && !IBB_ONLY) { isByteStream = true; } @@ -425,11 +421,9 @@ public class FileTransferNegotiator { private StreamNegotiator getOutgoingNegotiator(final FormField field) throws XMPPErrorException { - String variable; boolean isByteStream = false; boolean isIBB = false; - for (Iterator it = field.getValues(); it.hasNext();) { - variable = it.next(); + for (String variable : field.getValues()) { if (variable.equals(Socks5BytestreamManager.NAMESPACE) && !IBB_ONLY) { isByteStream = true; } diff --git a/extensions/src/main/java/org/jivesoftware/smackx/iqprivate/packet/DefaultPrivateData.java b/extensions/src/main/java/org/jivesoftware/smackx/iqprivate/packet/DefaultPrivateData.java index f6ccba0b3..2aa4ca3ba 100644 --- a/extensions/src/main/java/org/jivesoftware/smackx/iqprivate/packet/DefaultPrivateData.java +++ b/extensions/src/main/java/org/jivesoftware/smackx/iqprivate/packet/DefaultPrivateData.java @@ -19,8 +19,8 @@ package org.jivesoftware.smackx.iqprivate.packet; import java.util.Collections; import java.util.HashMap; -import java.util.Iterator; import java.util.Map; +import java.util.Set; /** * Default implementation of the PrivateData interface. Unless a PrivateDataProvider @@ -82,8 +82,7 @@ public class DefaultPrivateData implements PrivateData { public String toXML() { StringBuilder buf = new StringBuilder(); buf.append("<").append(elementName).append(" xmlns=\"").append(namespace).append("\">"); - for (Iterator i=getNames(); i.hasNext(); ) { - String name = i.next(); + for (String name : getNames()) { String value = getValue(name); buf.append("<").append(name).append(">"); buf.append(value); @@ -94,16 +93,16 @@ public class DefaultPrivateData implements PrivateData { } /** - * Returns an Iterator for the names that can be used to get + * Returns a Set of the names that can be used to get * values of the private data. * - * @return an Iterator for the names. + * @return a Set of the names. */ - public synchronized Iterator getNames() { + public synchronized Set getNames() { if (map == null) { - return Collections.emptyList().iterator(); + return Collections.emptySet(); } - return Collections.unmodifiableSet(map.keySet()).iterator(); + return Collections.unmodifiableSet(map.keySet()); } /** diff --git a/extensions/src/main/java/org/jivesoftware/smackx/muc/MultiUserChat.java b/extensions/src/main/java/org/jivesoftware/smackx/muc/MultiUserChat.java index 95d09daa2..0f789a5d2 100644 --- a/extensions/src/main/java/org/jivesoftware/smackx/muc/MultiUserChat.java +++ b/extensions/src/main/java/org/jivesoftware/smackx/muc/MultiUserChat.java @@ -23,7 +23,6 @@ import java.lang.reflect.Method; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; -import java.util.Iterator; import java.util.LinkedList; import java.util.List; import java.util.Locale; @@ -129,9 +128,8 @@ public class MultiUserChat { XMPPConnection connection = weakRefConnection.get(); if (connection == null) return new LinkedList(); List answer = new ArrayList(); - Iterator rooms=MultiUserChat.getJoinedRooms(connection); - while (rooms.hasNext()) { - answer.add(new DiscoverItems.Item(rooms.next())); + for (String room : MultiUserChat.getJoinedRooms(connection)) { + answer.add(new DiscoverItems.Item(room)); } return answer; } @@ -191,34 +189,34 @@ public class MultiUserChat { } /** - * Returns an Iterator on the rooms where the user has joined using a given connection. + * Returns a List of the rooms where the user has joined using a given connection. * The Iterator will contain Strings where each String represents a room * (e.g. room@muc.jabber.org). * * @param connection the connection used to join the rooms. - * @return an Iterator on the rooms where the user has joined using a given connection. + * @return a List of the rooms where the user has joined using a given connection. */ - private static Iterator getJoinedRooms(XMPPConnection connection) { + private static List getJoinedRooms(XMPPConnection connection) { List rooms = joinedRooms.get(connection); if (rooms != null) { - return rooms.iterator(); + return rooms; } - // Return an iterator on an empty collection (i.e. the user never joined a room) - return new ArrayList().iterator(); + // Return an empty collection (i.e. the user never joined a room) + return Collections.emptyList(); } /** - * Returns an Iterator on the rooms where the requested user has joined. The Iterator will + * Returns a List of the rooms where the requested user has joined. The Iterator will * contain Strings where each String represents a room (e.g. room@muc.jabber.org). * * @param connection the connection to use to perform the service discovery. * @param user the user to check. A fully qualified xmpp ID, e.g. jdoe@example.com. - * @return an Iterator on the rooms where the requested user has joined. + * @return a List of the rooms where the requested user has joined. * @throws XMPPErrorException * @throws NoResponseException * @throws NotConnectedException */ - public static Iterator getJoinedRooms(XMPPConnection connection, String user) + public static List getJoinedRooms(XMPPConnection connection, String user) throws NoResponseException, XMPPErrorException, NotConnectedException { ArrayList answer = new ArrayList(); // Send the disco packet to the user @@ -228,7 +226,7 @@ public class MultiUserChat { for (DiscoverItems.Item item : result.getItems()) { answer.add(item.getEntityID()); } - return answer.iterator(); + return answer; } /** @@ -1463,11 +1461,10 @@ public class MultiUserChat { * Note: this value will only be accurate after joining the group chat, and may * fluctuate over time. * - * @return an Iterator for the occupants in the group chat. + * @return a List of the occupants in the group chat. */ - public Iterator getOccupants() { - return Collections.unmodifiableList(new ArrayList(occupantsMap.keySet())) - .iterator(); + public List getOccupants() { + return Collections.unmodifiableList(new ArrayList(occupantsMap.keySet())); } /** @@ -1595,8 +1592,8 @@ public class MultiUserChat { // Get the list of affiliates from the server's answer List affiliates = new ArrayList(); - for (Iterator it = answer.getItems(); it.hasNext();) { - affiliates.add(new Affiliate(it.next())); + for (MUCAdmin.Item mucadminItem : answer.getItems()) { + affiliates.add(new Affiliate(mucadminItem)); } return affiliates; } @@ -1646,8 +1643,8 @@ public class MultiUserChat { MUCAdmin answer = (MUCAdmin) connection.createPacketCollectorAndSend(iq).nextResultOrThrow(); // Get the list of participants from the server's answer List participants = new ArrayList(); - for (Iterator it = answer.getItems(); it.hasNext();) { - participants.add(new Occupant(it.next())); + for (MUCAdmin.Item mucadminItem : answer.getItems()) { + participants.add(new Occupant(mucadminItem)); } return participants; } diff --git a/extensions/src/main/java/org/jivesoftware/smackx/muc/RoomInfo.java b/extensions/src/main/java/org/jivesoftware/smackx/muc/RoomInfo.java index b6e9c8724..4c8996c1e 100644 --- a/extensions/src/main/java/org/jivesoftware/smackx/muc/RoomInfo.java +++ b/extensions/src/main/java/org/jivesoftware/smackx/muc/RoomInfo.java @@ -85,14 +85,14 @@ public class RoomInfo { Form form = Form.getFormFrom(info); if (form != null) { FormField descField = form.getField("muc#roominfo_description"); - this.description = ( descField == null || !(descField.getValues().hasNext()) )? "" : descField.getValues().next(); + this.description = ( descField == null || descField.getValues().isEmpty() ) ? "" : descField.getValues().get(0); FormField subjField = form.getField("muc#roominfo_subject"); - this.subject = ( subjField == null || !(subjField.getValues().hasNext()) ) ? "" : subjField.getValues().next(); + this.subject = ( subjField == null || subjField.getValues().isEmpty() ) ? "" : subjField.getValues().get(0); FormField occCountField = form.getField("muc#roominfo_occupants"); this.occupantsCount = occCountField == null ? -1 : Integer.parseInt(occCountField.getValues() - .next()); + .get(0)); } } diff --git a/extensions/src/main/java/org/jivesoftware/smackx/muc/packet/MUCAdmin.java b/extensions/src/main/java/org/jivesoftware/smackx/muc/packet/MUCAdmin.java index ae63d21cd..bf6c0459a 100644 --- a/extensions/src/main/java/org/jivesoftware/smackx/muc/packet/MUCAdmin.java +++ b/extensions/src/main/java/org/jivesoftware/smackx/muc/packet/MUCAdmin.java @@ -17,8 +17,8 @@ package org.jivesoftware.smackx.muc.packet; import java.util.ArrayList; +import java.util.Collection; import java.util.Collections; -import java.util.Iterator; import java.util.List; import org.jivesoftware.smack.packet.IQ; @@ -36,15 +36,15 @@ public class MUCAdmin extends IQ { private List items = new ArrayList(); /** - * Returns an Iterator for item childs that holds information about roles, affiliation, + * Returns a Collection of item childs that holds information about roles, affiliation, * jids and nicks. * - * @return an Iterator for item childs that holds information about roles, affiliation, + * @return a Collection of item childs that holds information about roles, affiliation, * jids and nicks. */ - public Iterator getItems() { + public Collection getItems() { synchronized (items) { - return Collections.unmodifiableList(new ArrayList(items)).iterator(); + return Collections.unmodifiableList(new ArrayList(items)); } } diff --git a/extensions/src/main/java/org/jivesoftware/smackx/muc/packet/MUCOwner.java b/extensions/src/main/java/org/jivesoftware/smackx/muc/packet/MUCOwner.java index 3c33c4368..ceb14df58 100644 --- a/extensions/src/main/java/org/jivesoftware/smackx/muc/packet/MUCOwner.java +++ b/extensions/src/main/java/org/jivesoftware/smackx/muc/packet/MUCOwner.java @@ -19,8 +19,8 @@ package org.jivesoftware.smackx.muc.packet; import org.jivesoftware.smack.packet.IQ; import java.util.ArrayList; +import java.util.Collection; import java.util.Collections; -import java.util.Iterator; import java.util.List; /** @@ -36,15 +36,15 @@ public class MUCOwner extends IQ { private Destroy destroy; /** - * Returns an Iterator for item childs that holds information about affiliation, + * Returns a Collection of item childs that holds information about affiliation, * jids and nicks. * - * @return an Iterator for item childs that holds information about affiliation, + * @return a Collection of item childs that holds information about affiliation, * jids and nicks. */ - public Iterator getItems() { + public Collection getItems() { synchronized (items) { - return Collections.unmodifiableList(new ArrayList(items)).iterator(); + return Collections.unmodifiableList(new ArrayList(items)); } } diff --git a/extensions/src/main/java/org/jivesoftware/smackx/offline/OfflineMessageManager.java b/extensions/src/main/java/org/jivesoftware/smackx/offline/OfflineMessageManager.java index c08676bdc..78310fdef 100644 --- a/extensions/src/main/java/org/jivesoftware/smackx/offline/OfflineMessageManager.java +++ b/extensions/src/main/java/org/jivesoftware/smackx/offline/OfflineMessageManager.java @@ -37,7 +37,6 @@ import org.jivesoftware.smackx.offline.packet.OfflineMessageRequest; import org.jivesoftware.smackx.xdata.Form; import java.util.ArrayList; -import java.util.Iterator; import java.util.List; /** @@ -99,49 +98,49 @@ public class OfflineMessageManager { namespace); Form extendedInfo = Form.getFormFrom(info); if (extendedInfo != null) { - String value = extendedInfo.getField("number_of_messages").getValues().next(); + String value = extendedInfo.getField("number_of_messages").getValues().get(0); return Integer.parseInt(value); } return 0; } /** - * Returns an iterator on OfflineMessageHeader that keep information about the + * Returns a List of OfflineMessageHeader that keep information about the * offline message. The OfflineMessageHeader includes a stamp that could be used to retrieve * the complete message or delete the specific message. * - * @return an iterator on OfflineMessageHeader that keep information about the offline + * @return a List of OfflineMessageHeader that keep information about the offline * message. * @throws XMPPErrorException If the user is not allowed to make this request or the server does * not support offline message retrieval. * @throws NoResponseException if there was no response from the server. * @throws NotConnectedException */ - public Iterator getHeaders() throws NoResponseException, XMPPErrorException, NotConnectedException { + public List getHeaders() throws NoResponseException, XMPPErrorException, NotConnectedException { List answer = new ArrayList(); DiscoverItems items = ServiceDiscoveryManager.getInstanceFor(connection).discoverItems( null, namespace); for (DiscoverItems.Item item : items.getItems()) { answer.add(new OfflineMessageHeader(item)); } - return answer.iterator(); + return answer; } /** - * Returns an Iterator with the offline Messages whose stamp matches the specified + * Returns a List of the offline Messages whose stamp matches the specified * request. The request will include the list of stamps that uniquely identifies * the offline messages to retrieve. The returned offline messages will not be deleted * from the server. Use {@link #deleteMessages(java.util.List)} to delete the messages. * * @param nodes the list of stamps that uniquely identifies offline message. - * @return an Iterator with the offline Messages that were received as part of + * @return a List with the offline Messages that were received as part of * this request. * @throws XMPPErrorException If the user is not allowed to make this request or the server does * not support offline message retrieval. * @throws NoResponseException if there was no response from the server. * @throws NotConnectedException */ - public Iterator getMessages(final List nodes) throws NoResponseException, XMPPErrorException, NotConnectedException { + public List getMessages(final List nodes) throws NoResponseException, XMPPErrorException, NotConnectedException { List messages = new ArrayList(); OfflineMessageRequest request = new OfflineMessageRequest(); for (String node : nodes) { @@ -169,7 +168,7 @@ public class OfflineMessageManager { } // Stop queuing offline messages messageCollector.cancel(); - return messages.iterator(); + return messages; } /** @@ -177,13 +176,13 @@ public class OfflineMessageManager { * messages will not be deleted from the server. Use {@link #deleteMessages(java.util.List)} * to delete the messages. * - * @return an Iterator with all the offline Messages of the user. + * @return a List with all the offline Messages of the user. * @throws XMPPErrorException If the user is not allowed to make this request or the server does * not support offline message retrieval. * @throws NoResponseException if there was no response from the server. * @throws NotConnectedException */ - public Iterator getMessages() throws NoResponseException, XMPPErrorException, NotConnectedException { + public List getMessages() throws NoResponseException, XMPPErrorException, NotConnectedException { List messages = new ArrayList(); OfflineMessageRequest request = new OfflineMessageRequest(); request.setFetch(true); @@ -200,7 +199,7 @@ public class OfflineMessageManager { } // Stop queuing offline messages messageCollector.cancel(); - return messages.iterator(); + return messages; } /** diff --git a/extensions/src/main/java/org/jivesoftware/smackx/offline/packet/OfflineMessageRequest.java b/extensions/src/main/java/org/jivesoftware/smackx/offline/packet/OfflineMessageRequest.java index 2ab8e06c5..3cf1fca67 100644 --- a/extensions/src/main/java/org/jivesoftware/smackx/offline/packet/OfflineMessageRequest.java +++ b/extensions/src/main/java/org/jivesoftware/smackx/offline/packet/OfflineMessageRequest.java @@ -22,8 +22,8 @@ import org.jivesoftware.smack.provider.IQProvider; import org.xmlpull.v1.XmlPullParser; import java.util.ArrayList; +import java.util.Collection; import java.util.Collections; -import java.util.Iterator; import java.util.List; /** @@ -39,15 +39,15 @@ public class OfflineMessageRequest extends IQ { private boolean fetch = false; /** - * Returns an Iterator for item childs that holds information about offline messages to + * Returns a Collection of item childs that holds information about offline messages to * view or delete. * - * @return an Iterator for item childs that holds information about offline messages to + * @return a Collection of item childs that holds information about offline messages to * view or delete. */ - public Iterator getItems() { + public Collection getItems() { synchronized (items) { - return Collections.unmodifiableList(new ArrayList(items)).iterator(); + return Collections.unmodifiableList(new ArrayList(items)); } } diff --git a/extensions/src/main/java/org/jivesoftware/smackx/pubsub/ConfigureForm.java b/extensions/src/main/java/org/jivesoftware/smackx/pubsub/ConfigureForm.java index 7c70333bb..f6f6cb76a 100644 --- a/extensions/src/main/java/org/jivesoftware/smackx/pubsub/ConfigureForm.java +++ b/extensions/src/main/java/org/jivesoftware/smackx/pubsub/ConfigureForm.java @@ -17,7 +17,6 @@ package org.jivesoftware.smackx.pubsub; import java.util.ArrayList; -import java.util.Iterator; import java.util.List; import org.jivesoftware.smackx.xdata.Form; @@ -123,9 +122,9 @@ public class ConfigureForm extends Form /** * The id's of the child nodes associated with a collection node (both leaf and collection). * - * @return Iterator over the list of child nodes. + * @return list of child nodes. */ - public Iterator getChildren() + public List getChildren() { return getFieldValues(ConfigureNodeFields.children); } @@ -170,13 +169,13 @@ public class ConfigureForm extends Form } /** - * Iterator of JID's that are on the whitelist that determines who can associate child nodes + * List of JID's that are on the whitelist that determines who can associate child nodes * with the collection node. This is only relevant if {@link #getChildrenAssociationPolicy()} is set to * {@link ChildrenAssociationPolicy#whitelist}. * - * @return Iterator over whitelist + * @return List of the whitelist */ - public Iterator getChildrenAssociationWhitelist() + public List getChildrenAssociationWhitelist() { return getFieldValues(ConfigureNodeFields.children_association_whitelist); } @@ -512,11 +511,11 @@ public class ConfigureForm extends Form } /** - * Iterator over the multi user chat rooms that are specified as reply rooms. + * List of the multi user chat rooms that are specified as reply rooms. * * @return The reply room JID's */ - public Iterator getReplyRoom() + public List getReplyRoom() { return getFieldValues(ConfigureNodeFields.replyroom); } @@ -537,7 +536,7 @@ public class ConfigureForm extends Form * * @return The JID's */ - public Iterator getReplyTo() + public List getReplyTo() { return getFieldValues(ConfigureNodeFields.replyto); } @@ -558,7 +557,7 @@ public class ConfigureForm extends Form * * @return The roster groups */ - public Iterator getRosterGroupsAllowed() + public List getRosterGroupsAllowed() { return getFieldValues(ConfigureNodeFields.roster_groups_allowed); } @@ -642,23 +641,18 @@ public class ConfigureForm extends Form { StringBuilder result = new StringBuilder(getClass().getName() + " Content ["); - Iterator fields = getFields(); - - while (fields.hasNext()) + for (FormField formField : getFields()) { - FormField formField = fields.next(); result.append('('); result.append(formField.getVariable()); result.append(':'); - Iterator values = formField.getValues(); StringBuilder valuesBuilder = new StringBuilder(); - while (values.hasNext()) + for (String value : formField.getValues()) { if (valuesBuilder.length() > 0) result.append(','); - String value = (String)values.next(); valuesBuilder.append(value); } @@ -680,10 +674,10 @@ public class ConfigureForm extends Form { FormField formField = getField(field.getFieldName()); - return (formField.getValues().hasNext()) ? formField.getValues().next() : null; + return (formField.getValues().isEmpty()) ? null : formField.getValues().get(0); } - private Iterator getFieldValues(ConfigureNodeFields field) + private List getFieldValues(ConfigureNodeFields field) { FormField formField = getField(field.getFieldName()); diff --git a/extensions/src/main/java/org/jivesoftware/smackx/pubsub/Node.java b/extensions/src/main/java/org/jivesoftware/smackx/pubsub/Node.java index a8dd2c692..a5a052d55 100644 --- a/extensions/src/main/java/org/jivesoftware/smackx/pubsub/Node.java +++ b/extensions/src/main/java/org/jivesoftware/smackx/pubsub/Node.java @@ -18,7 +18,6 @@ package org.jivesoftware.smackx.pubsub; import java.util.ArrayList; import java.util.Collection; -import java.util.Iterator; import java.util.List; import java.util.concurrent.ConcurrentHashMap; @@ -450,14 +449,12 @@ abstract public class Node else { ItemsExtension itemsElem = (ItemsExtension)event.getEvent(); - Collection pubItems = itemsElem.getItems(); @SuppressWarnings("unchecked") - Iterator it = (Iterator)pubItems.iterator(); + Collection pubItems = (Collection) itemsElem.getItems(); List items = new ArrayList(pubItems.size()); - while (it.hasNext()) + for (RetractItem item : pubItems) { - RetractItem item = it.next(); items.add(item.getId()); } diff --git a/extensions/src/main/java/org/jivesoftware/smackx/pubsub/PubSubManager.java b/extensions/src/main/java/org/jivesoftware/smackx/pubsub/PubSubManager.java index c528cce81..9ac1cbee9 100644 --- a/extensions/src/main/java/org/jivesoftware/smackx/pubsub/PubSubManager.java +++ b/extensions/src/main/java/org/jivesoftware/smackx/pubsub/PubSubManager.java @@ -135,7 +135,7 @@ final public class PubSubManager FormField nodeTypeField = config.getField(ConfigureNodeFields.node_type.getFieldName()); if (nodeTypeField != null) - isLeafNode = nodeTypeField.getValues().next().equals(NodeType.leaf.toString()); + isLeafNode = nodeTypeField.getValues().get(0).equals(NodeType.leaf.toString()); } // Errors will cause exceptions in getReply, so it only returns diff --git a/extensions/src/main/java/org/jivesoftware/smackx/pubsub/SubscribeForm.java b/extensions/src/main/java/org/jivesoftware/smackx/pubsub/SubscribeForm.java index d031d61e5..9208b783e 100644 --- a/extensions/src/main/java/org/jivesoftware/smackx/pubsub/SubscribeForm.java +++ b/extensions/src/main/java/org/jivesoftware/smackx/pubsub/SubscribeForm.java @@ -20,7 +20,7 @@ import java.text.ParseException; import java.util.ArrayList; import java.util.Collection; import java.util.Date; -import java.util.Iterator; +import java.util.List; import java.util.UnknownFormatConversionException; import org.jivesoftware.smack.util.XmppDateTime; @@ -176,19 +176,17 @@ public class SubscribeForm extends Form * Gets the {@link PresenceState} for which an entity wants to receive * notifications. * - * @return iterator over the list of states + * @return the list of states */ - public Iterator getShowValues() + public List getShowValues() { ArrayList result = new ArrayList(5); - Iterator it = getFieldValues(SubscribeOptionFields.show_values); - while (it.hasNext()) + for (String state : getFieldValues(SubscribeOptionFields.show_values)) { - String state = it.next(); result.add(PresenceState.valueOf(state)); } - return result.iterator(); + return result; } /** @@ -219,10 +217,10 @@ public class SubscribeForm extends Form { FormField formField = getField(field.getFieldName()); - return formField.getValues().next(); + return formField.getValues().get(0); } - private Iterator getFieldValues(SubscribeOptionFields field) + private List getFieldValues(SubscribeOptionFields field) { FormField formField = getField(field.getFieldName()); diff --git a/extensions/src/main/java/org/jivesoftware/smackx/search/ReportedData.java b/extensions/src/main/java/org/jivesoftware/smackx/search/ReportedData.java index cbc2d5663..dbb553f36 100644 --- a/extensions/src/main/java/org/jivesoftware/smackx/search/ReportedData.java +++ b/extensions/src/main/java/org/jivesoftware/smackx/search/ReportedData.java @@ -24,7 +24,6 @@ import org.jivesoftware.smackx.xdata.packet.DataForm.Item; import java.util.ArrayList; import java.util.Collections; -import java.util.Iterator; import java.util.List; /** @@ -67,22 +66,18 @@ public class ReportedData { */ private ReportedData(DataForm dataForm) { // Add the columns to the report based on the reported data fields - for (Iterator fields = dataForm.getReportedData().getFields(); fields.hasNext();) { - FormField field = fields.next(); + for (FormField field : dataForm.getReportedData().getFields()) { columns.add(new Column(field.getLabel(), field.getVariable(), field.getType())); } // Add the rows to the report based on the form's items - for (Iterator items = dataForm.getItems(); items.hasNext();) { - Item item = items.next(); + for (Item item : dataForm.getItems()) { List fieldList = new ArrayList(columns.size()); - FormField field; - for (Iterator fields = item.getFields(); fields.hasNext();) { - field = fields.next(); + for (FormField field : item.getFields()) { // The field is created with all the values of the data form's field List values = new ArrayList(); - for (Iterator it=field.getValues(); it.hasNext();) { - values.add(it.next()); + for (String value : field.getValues()) { + values.add(value); } fieldList.add(new Field(field.getVariable(), values)); } @@ -116,21 +111,21 @@ public class ReportedData { /** - * Returns an Iterator for the rows returned from a search. + * Returns a List of the rows returned from a search. * - * @return an Iterator for the rows returned from a search. + * @return a List of the rows returned from a search. */ - public Iterator getRows() { - return Collections.unmodifiableList(new ArrayList(rows)).iterator(); + public List getRows() { + return Collections.unmodifiableList(new ArrayList(rows)); } /** - * Returns an Iterator for the columns returned from a search. + * Returns a List of the columns returned from a search. * - * @return an Iterator for the columns returned from a search. + * @return a List of the columns returned from a search. */ - public Iterator getColumns() { - return Collections.unmodifiableList(new ArrayList(columns)).iterator(); + public List getColumns() { + return Collections.unmodifiableList(new ArrayList(columns)); } @@ -229,9 +224,8 @@ public class ReportedData { * @param variable the variable to match. * @return the values of the field whose variable matches the requested variable. */ - public Iterator getValues(String variable) { - for(Iterator it=getFields();it.hasNext();) { - Field field = it.next(); + public List getValues(String variable) { + for(Field field : getFields()) { if (variable.equalsIgnoreCase(field.getVariable())) { return field.getValues(); } @@ -244,8 +238,8 @@ public class ReportedData { * * @return the fields that define the data that goes with the item. */ - private Iterator getFields() { - return Collections.unmodifiableList(new ArrayList(fields)).iterator(); + private List getFields() { + return Collections.unmodifiableList(new ArrayList(fields)); } } @@ -268,12 +262,12 @@ public class ReportedData { } /** - * Returns an iterator on the values reported as part of the search. + * Returns a List of the values reported as part of the search. * * @return the returned values of the search. */ - public Iterator getValues() { - return Collections.unmodifiableList(values).iterator(); + public List getValues() { + return Collections.unmodifiableList(values); } } } diff --git a/extensions/src/main/java/org/jivesoftware/smackx/search/SimpleUserSearch.java b/extensions/src/main/java/org/jivesoftware/smackx/search/SimpleUserSearch.java index dba3ef10d..675bac4f2 100644 --- a/extensions/src/main/java/org/jivesoftware/smackx/search/SimpleUserSearch.java +++ b/extensions/src/main/java/org/jivesoftware/smackx/search/SimpleUserSearch.java @@ -22,7 +22,6 @@ import org.jivesoftware.smackx.xdata.FormField; import org.xmlpull.v1.XmlPullParser; import java.util.ArrayList; -import java.util.Iterator; import java.util.List; /** @@ -65,9 +64,7 @@ class SimpleUserSearch extends IQ { return ""; } - Iterator fields = form.getFields(); - while (fields.hasNext()) { - FormField field = fields.next(); + for (FormField field : form.getFields()) { String name = field.getVariable(); String value = getSingleValue(field); if (value.trim().length() > 0) { @@ -79,11 +76,12 @@ class SimpleUserSearch extends IQ { } private static String getSingleValue(FormField formField) { - Iterator values = formField.getValues(); - while (values.hasNext()) { - return values.next(); + List values = formField.getValues(); + if (values.isEmpty()) { + return ""; + } else { + return values.get(0); } - return ""; } protected void parseItems(XmlPullParser parser) throws Exception { @@ -121,11 +119,10 @@ class SimpleUserSearch extends IQ { fields.add(field); boolean exists = false; - Iterator cols = data.getColumns(); - while (cols.hasNext()) { - ReportedData.Column column = cols.next(); + for (ReportedData.Column column : data.getColumns()) { if (column.getVariable().equals(name)) { exists = true; + break; } } diff --git a/extensions/src/main/java/org/jivesoftware/smackx/sharedgroups/packet/SharedGroupsInfo.java b/extensions/src/main/java/org/jivesoftware/smackx/sharedgroups/packet/SharedGroupsInfo.java index afc21af7f..4bde6e8c2 100644 --- a/extensions/src/main/java/org/jivesoftware/smackx/sharedgroups/packet/SharedGroupsInfo.java +++ b/extensions/src/main/java/org/jivesoftware/smackx/sharedgroups/packet/SharedGroupsInfo.java @@ -21,7 +21,6 @@ import org.jivesoftware.smack.provider.IQProvider; import org.xmlpull.v1.XmlPullParser; import java.util.ArrayList; -import java.util.Iterator; import java.util.List; /** @@ -49,8 +48,8 @@ public class SharedGroupsInfo extends IQ { public String getChildElementXML() { StringBuilder buf = new StringBuilder(); buf.append(""); - for (Iterator it=groups.iterator(); it.hasNext();) { - buf.append("").append(it.next()).append(""); + for (String group : groups) { + buf.append("").append(group).append(""); } buf.append(""); return buf.toString(); diff --git a/extensions/src/main/java/org/jivesoftware/smackx/vcardtemp/packet/VCard.java b/extensions/src/main/java/org/jivesoftware/smackx/vcardtemp/packet/VCard.java index 2bd287d51..0a368fb38 100644 --- a/extensions/src/main/java/org/jivesoftware/smackx/vcardtemp/packet/VCard.java +++ b/extensions/src/main/java/org/jivesoftware/smackx/vcardtemp/packet/VCard.java @@ -27,7 +27,6 @@ import java.net.URL; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; import java.util.HashMap; -import java.util.Iterator; import java.util.Map; import java.util.Map.Entry; import java.util.logging.Level; @@ -754,9 +753,7 @@ public class VCard extends IQ { } private void appendPhones(Map phones, final String code) { - Iterator> it = phones.entrySet().iterator(); - while (it.hasNext()) { - final Map.Entry entry = it.next(); + for (final Map.Entry entry : phones.entrySet()) { appendTag("TEL", true, new ContentBuilder() { public void addTagContent() { appendEmptyTag(entry.getKey()); @@ -773,9 +770,7 @@ public class VCard extends IQ { public void addTagContent() { appendEmptyTag(code); - Iterator> it = addr.entrySet().iterator(); - while (it.hasNext()) { - final Entry entry = it.next(); + for (final Entry entry : addr.entrySet()) { appendTag(entry.getKey(), StringUtils.escapeForXML(entry.getValue())); } } @@ -788,16 +783,12 @@ public class VCard extends IQ { } private void appendGenericFields() { - Iterator> it = otherSimpleFields.entrySet().iterator(); - while (it.hasNext()) { - Map.Entry entry = it.next(); + for (Map.Entry entry : otherSimpleFields.entrySet()) { appendTag(entry.getKey().toString(), StringUtils.escapeForXML(entry.getValue())); } - it = otherUnescapableFields.entrySet().iterator(); - while (it.hasNext()) { - Map.Entry entry = it.next(); + for (Map.Entry entry : otherUnescapableFields.entrySet()) { appendTag(entry.getKey().toString(),entry.getValue()); } } diff --git a/extensions/src/main/java/org/jivesoftware/smackx/xdata/Form.java b/extensions/src/main/java/org/jivesoftware/smackx/xdata/Form.java index 18831aee6..2cfc311ac 100644 --- a/extensions/src/main/java/org/jivesoftware/smackx/xdata/Form.java +++ b/extensions/src/main/java/org/jivesoftware/smackx/xdata/Form.java @@ -342,8 +342,8 @@ public class Form { // Clear the old values field.resetValues(); // Set the default value - for (Iterator it = field.getValues(); it.hasNext();) { - field.addValue(it.next()); + for (String value : field.getValues()) { + field.addValue(value); } } else { @@ -352,11 +352,11 @@ public class Form { } /** - * Returns an Iterator for the fields that are part of the form. + * Returns a List of the fields that are part of the form. * - * @return an Iterator for the fields that are part of the form. + * @return a List of the fields that are part of the form. */ - public Iterator getFields() { + public List getFields() { return dataForm.getFields(); } @@ -373,9 +373,7 @@ public class Form { throw new IllegalArgumentException("Variable must not be null or blank."); } // Look for the field whose variable matches the requested variable - FormField field; - for (Iterator it=getFields();it.hasNext();) { - field = it.next(); + for (FormField field : getFields()) { if (variable.equals(field.getVariable())) { return field; } @@ -391,7 +389,7 @@ public class Form { public String getInstructions() { StringBuilder sb = new StringBuilder(); // Join the list of instructions together separated by newlines - for (Iterator it = dataForm.getInstructions(); it.hasNext();) { + for (Iterator it = dataForm.getInstructions().iterator(); it.hasNext();) { sb.append(it.next()); // If this is not the last instruction then append a newline if (it.hasNext()) { @@ -472,9 +470,8 @@ public class Form { if (isSubmitType()) { // Create a new DataForm that contains only the answered fields DataForm dataFormToSend = new DataForm(getType()); - for(Iterator it=getFields();it.hasNext();) { - FormField field = it.next(); - if (field.getValues().hasNext()) { + for(FormField field : getFields()) { + if (!field.getValues().isEmpty()) { dataFormToSend.addField(field); } } @@ -521,8 +518,7 @@ public class Form { } // Create a new Form Form form = new Form(TYPE_SUBMIT); - for (Iterator fields=getFields(); fields.hasNext();) { - FormField field = fields.next(); + for (FormField field : getFields()) { // Add to the new form any type of field that includes a variable. // Note: The fields of type FIXED are the only ones that don't specify a variable if (field.getVariable() != null) { @@ -534,11 +530,11 @@ public class Form { // Since a hidden field could have many values we need to collect them // in a list List values = new ArrayList(); - for (Iterator it=field.getValues();it.hasNext();) { - values.add(it.next()); + for (String value : field.getValues()) { + values.add(value); } form.setAnswer(field.getVariable(), values); - } + } } } return form; diff --git a/extensions/src/main/java/org/jivesoftware/smackx/xdata/FormField.java b/extensions/src/main/java/org/jivesoftware/smackx/xdata/FormField.java index d6166366e..1d40525cc 100644 --- a/extensions/src/main/java/org/jivesoftware/smackx/xdata/FormField.java +++ b/extensions/src/main/java/org/jivesoftware/smackx/xdata/FormField.java @@ -22,7 +22,6 @@ import org.jivesoftware.smack.util.XmlStringBuilder; import java.util.ArrayList; import java.util.Collections; -import java.util.Iterator; import java.util.List; /** @@ -95,14 +94,14 @@ public class FormField { } /** - * Returns an Iterator for the available options that the user has in order to answer + * Returns a List of the available options that the user has in order to answer * the question. * - * @return Iterator for the available options. + * @return List of the available options. */ - public Iterator"); return buf.toString(); diff --git a/extensions/src/main/java/org/jivesoftware/smackx/xdata/packet/DataForm.java b/extensions/src/main/java/org/jivesoftware/smackx/xdata/packet/DataForm.java index c10b5c424..6ee3d80b6 100644 --- a/extensions/src/main/java/org/jivesoftware/smackx/xdata/packet/DataForm.java +++ b/extensions/src/main/java/org/jivesoftware/smackx/xdata/packet/DataForm.java @@ -23,7 +23,6 @@ import org.jivesoftware.smackx.xdata.FormField; import java.util.ArrayList; import java.util.Collections; -import java.util.Iterator; import java.util.List; /** @@ -76,16 +75,16 @@ public class DataForm implements PacketExtension { } /** - * Returns an Iterator for the list of instructions that explain how to fill out the form and + * Returns a List of 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 * instruction could not contain newlines characters. Join the instructions together in order - * to show them to the user. + * to show them to the user. * - * @return an Iterator for the list of instructions that explain how to fill out the form. + * @return a List of the list of instructions that explain how to fill out the form. */ - public Iterator getInstructions() { + public List getInstructions() { synchronized (instructions) { - return Collections.unmodifiableList(new ArrayList(instructions)).iterator(); + return Collections.unmodifiableList(new ArrayList(instructions)); } } @@ -99,24 +98,24 @@ public class DataForm implements PacketExtension { } /** - * Returns an Iterator for the items returned from a search. + * Returns a List of the items returned from a search. * - * @return an Iterator for the items returned from a search. + * @return a List of the items returned from a search. */ - public Iterator getItems() { + public List getItems() { synchronized (items) { - return Collections.unmodifiableList(new ArrayList(items)).iterator(); + return Collections.unmodifiableList(new ArrayList(items)); } } /** - * Returns an Iterator for the fields that are part of the form. + * Returns a List of the fields that are part of the form. * - * @return an Iterator for the fields that are part of the form. + * @return a List of the fields that are part of the form. */ - public Iterator getFields() { + public List getFields() { synchronized (fields) { - return Collections.unmodifiableList(new ArrayList(fields)).iterator(); + return Collections.unmodifiableList(new ArrayList(fields)); } } @@ -215,21 +214,19 @@ public class DataForm implements PacketExtension { if (getTitle() != null) { buf.append("").append(getTitle()).append(""); } - for (Iterator it=getInstructions(); it.hasNext();) { - buf.append("").append(it.next()).append(""); + for (String instruction : getInstructions()) { + buf.append("").append(instruction).append(""); } // Append the list of fields returned from a search if (getReportedData() != null) { buf.append(getReportedData().toXML()); } // Loop through all the items returned from a search and append them to the string buffer - for (Iterator i = getItems(); i.hasNext();) { - Item item = i.next(); + for (Item item : getItems()) { buf.append(item.toXML()); } // Loop through all the form fields and append them to the string buffer - for (Iterator i = getFields(); i.hasNext();) { - FormField field = i.next(); + for (FormField field : getFields()) { buf.append(field.toXML()); } buf.append(""); @@ -249,22 +246,21 @@ public class DataForm implements PacketExtension { public ReportedData(List fields) { this.fields = fields; } - + /** * Returns the fields returned from a search. * * @return the fields returned from a search. */ - public Iterator getFields() { - return Collections.unmodifiableList(new ArrayList(fields)).iterator(); + public List getFields() { + return Collections.unmodifiableList(new ArrayList(fields)); } - + public String toXML() { StringBuilder buf = new StringBuilder(); buf.append(""); // Loop through all the form items and append them to the string buffer - for (Iterator i = getFields(); i.hasNext();) { - FormField field = i.next(); + for (FormField field : getFields()) { buf.append(field.toXML()); } buf.append(""); @@ -290,16 +286,15 @@ public class DataForm implements PacketExtension { * * @return the fields that define the data that goes with the item. */ - public Iterator getFields() { - return Collections.unmodifiableList(new ArrayList(fields)).iterator(); + public List getFields() { + return Collections.unmodifiableList(new ArrayList(fields)); } public String toXML() { StringBuilder buf = new StringBuilder(); buf.append(""); // Loop through all the form items and append them to the string buffer - for (Iterator i = getFields(); i.hasNext();) { - FormField field = i.next(); + for (FormField field : getFields()) { buf.append(field.toXML()); } buf.append(""); diff --git a/extensions/src/main/java/org/jivesoftware/smackx/xevent/MessageEventManager.java b/extensions/src/main/java/org/jivesoftware/smackx/xevent/MessageEventManager.java index 006e5c91c..42ef462d7 100644 --- a/extensions/src/main/java/org/jivesoftware/smackx/xevent/MessageEventManager.java +++ b/extensions/src/main/java/org/jivesoftware/smackx/xevent/MessageEventManager.java @@ -19,7 +19,6 @@ package org.jivesoftware.smackx.xevent; import java.lang.reflect.Method; import java.util.ArrayList; -import java.util.Iterator; import java.util.List; import java.util.logging.Level; import java.util.logging.Logger; @@ -198,18 +197,18 @@ public class MessageEventManager { (MessageEvent) message.getExtension("x", "jabber:x:event"); if (messageEvent.isMessageEventRequest()) { // Fire event for requests of message events - for (Iterator it = messageEvent.getEventTypes(); it.hasNext();) + for (String eventType : messageEvent.getEventTypes()) fireMessageEventRequestListeners( message.getFrom(), message.getPacketID(), - it.next().concat("NotificationRequested")); + eventType.concat("NotificationRequested")); } else // Fire event for notifications of message events - for (Iterator it = messageEvent.getEventTypes(); it.hasNext();) + for (String eventType : messageEvent.getEventTypes()) fireMessageEventNotificationListeners( message.getFrom(), messageEvent.getPacketID(), - it.next().concat("Notification")); + eventType.concat("Notification")); }; diff --git a/extensions/src/main/java/org/jivesoftware/smackx/xevent/packet/MessageEvent.java b/extensions/src/main/java/org/jivesoftware/smackx/xevent/packet/MessageEvent.java index 708ee2151..5e0df59dc 100644 --- a/extensions/src/main/java/org/jivesoftware/smackx/xevent/packet/MessageEvent.java +++ b/extensions/src/main/java/org/jivesoftware/smackx/xevent/packet/MessageEvent.java @@ -20,7 +20,7 @@ package org.jivesoftware.smackx.xevent.packet; import org.jivesoftware.smack.packet.PacketExtension; import java.util.ArrayList; -import java.util.Iterator; +import java.util.List; /** * Represents message events relating to the delivery, display, composition and cancellation of @@ -162,9 +162,9 @@ public class MessageEvent implements PacketExtension { * Returns the types of events. The type of event could be: * "offline", "composing","delivered","displayed", "offline" * - * @return an iterator over all the types of events of the MessageEvent. + * @return a List of all the types of events of the MessageEvent. */ - public Iterator getEventTypes() { + public List getEventTypes() { ArrayList allEvents = new ArrayList(); if (isDelivered()) { allEvents.add(MessageEvent.DELIVERED); @@ -181,7 +181,7 @@ public class MessageEvent implements PacketExtension { if (isOffline()) { allEvents.add(MessageEvent.OFFLINE); } - return allEvents.iterator(); + return allEvents; } /** diff --git a/extensions/src/main/java/org/jivesoftware/smackx/xhtmlim/XHTMLManager.java b/extensions/src/main/java/org/jivesoftware/smackx/xhtmlim/XHTMLManager.java index 3c0751cd9..51340145b 100644 --- a/extensions/src/main/java/org/jivesoftware/smackx/xhtmlim/XHTMLManager.java +++ b/extensions/src/main/java/org/jivesoftware/smackx/xhtmlim/XHTMLManager.java @@ -26,7 +26,7 @@ import org.jivesoftware.smack.packet.Message; import org.jivesoftware.smackx.disco.ServiceDiscoveryManager; import org.jivesoftware.smackx.xhtmlim.packet.XHTMLExtension; -import java.util.Iterator; +import java.util.List; /** * Manages XHTML formatted texts within messages. A XHTMLManager provides a high level access to @@ -55,7 +55,7 @@ public class XHTMLManager { * @param message an XHTML message * @return an Iterator for the bodies in the message or null if none. */ - public static Iterator getBodies(Message message) { + public static List getBodies(Message message) { XHTMLExtension xhtmlExtension = (XHTMLExtension) message.getExtension("html", namespace); if (xhtmlExtension != null) return xhtmlExtension.getBodies(); diff --git a/extensions/src/main/java/org/jivesoftware/smackx/xhtmlim/packet/XHTMLExtension.java b/extensions/src/main/java/org/jivesoftware/smackx/xhtmlim/packet/XHTMLExtension.java index f5701c201..30903dfda 100644 --- a/extensions/src/main/java/org/jivesoftware/smackx/xhtmlim/packet/XHTMLExtension.java +++ b/extensions/src/main/java/org/jivesoftware/smackx/xhtmlim/packet/XHTMLExtension.java @@ -21,7 +21,6 @@ import org.jivesoftware.smack.packet.PacketExtension; import java.util.ArrayList; import java.util.Collections; -import java.util.Iterator; import java.util.List; /** @@ -82,21 +81,21 @@ public class XHTMLExtension implements PacketExtension { buf.append("<").append(getElementName()).append(" xmlns=\"").append(getNamespace()).append( "\">"); // Loop through all the bodies and append them to the string buffer - for (Iterator i = getBodies(); i.hasNext();) { - buf.append(i.next()); + for (String body : getBodies()) { + buf.append(body); } buf.append(""); return buf.toString(); } /** - * Returns an Iterator for the bodies in the packet. + * Returns a List of the bodies in the packet. * - * @return an Iterator for the bodies in the packet. + * @return a List of the bodies in the packet. */ - public Iterator getBodies() { + public List getBodies() { synchronized (bodies) { - return Collections.unmodifiableList(new ArrayList(bodies)).iterator(); + return Collections.unmodifiableList(new ArrayList(bodies)); } } diff --git a/extensions/src/test/java/org/jivesoftware/smackx/xhtmlim/provider/XHTMLExtensionProviderTest.java b/extensions/src/test/java/org/jivesoftware/smackx/xhtmlim/provider/XHTMLExtensionProviderTest.java index 23b94d831..31227808c 100644 --- a/extensions/src/test/java/org/jivesoftware/smackx/xhtmlim/provider/XHTMLExtensionProviderTest.java +++ b/extensions/src/test/java/org/jivesoftware/smackx/xhtmlim/provider/XHTMLExtensionProviderTest.java @@ -47,7 +47,7 @@ public class XHTMLExtensionProviderTest { assertThat(extension, is(instanceOf(XHTMLExtension.class))); XHTMLExtension attachmentsInfo = (XHTMLExtension) extension; - assertEquals(sampleXhtml(), attachmentsInfo.getBodies().next()); + assertEquals(sampleXhtml(), attachmentsInfo.getBodies().get(0)); } private String sampleXhtml() {