mirror of
https://github.com/vanitasvitae/Smack.git
synced 2024-10-04 21:49:33 +02:00
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)).
This commit is contained in:
parent
6ea1d65e73
commit
4cff008708
|
@ -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<Presence> getPresences(String user) {
|
||||
public Collection<Presence> getPresences(String user) {
|
||||
Collection<Presence> res;
|
||||
String key = getPresenceMapKey(user);
|
||||
Map<String, Presence> 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<Presence> answer = new ArrayList<Presence>();
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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<PacketExtension> getExtensions() {
|
||||
if (applicationExtensions == null) {
|
||||
|
|
|
@ -93,13 +93,13 @@ information concerning a node named "http://jabber.org/protocol/muc#rooms": <br>
|
|||
ServiceDiscoveryManager.getInstanceFor(connection).setNodeInformationProvider(
|
||||
<font color="#0000FF">"http://jabber.org/protocol/muc#rooms"</font>,
|
||||
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;
|
||||
}
|
||||
});
|
||||
</pre>
|
||||
|
@ -233,4 +233,4 @@ In this example we can see how to publish new items: <br>
|
|||
</blockquote>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
</html>
|
||||
|
|
|
@ -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<Rule> getRules() {
|
||||
return Collections.unmodifiableList(new ArrayList<Rule>(rules)).iterator();
|
||||
public Collection<Rule> getRules() {
|
||||
return Collections.unmodifiableList(new ArrayList<Rule>(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<Rule> i = getRules(); i.hasNext();) {
|
||||
buf.append(i.next().toXML());
|
||||
for (Rule rule : getRules()) {
|
||||
buf.append(rule.toXML());
|
||||
}
|
||||
|
||||
buf.append("</").append(getElementName()).append(">");
|
||||
|
|
|
@ -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("<storage xmlns=\"storage:bookmarks\">");
|
||||
|
||||
final Iterator<BookmarkedURL> 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<BookmarkedConference> conferences = getBookmarkedConferences().iterator();
|
||||
while (conferences.hasNext()) {
|
||||
BookmarkedConference conference = conferences.next();
|
||||
for (BookmarkedConference conference : getBookmarkedConferences()) {
|
||||
if(conference.isShared()) {
|
||||
continue;
|
||||
}
|
||||
|
|
|
@ -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<FormField> foundFormTypes = new LinkedList<FormField>();
|
||||
for (Iterator<PacketExtension> 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<FormField> 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<DiscoverInfo.Identity> 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<FormField> 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<String> i, StringBuilder sb) {
|
||||
private static void formFieldValuesToCaps(List<String> i, StringBuilder sb) {
|
||||
SortedSet<String> fvs = new TreeSet<String>();
|
||||
while (i.hasNext()) {
|
||||
fvs.add(i.next());
|
||||
for (String s : i) {
|
||||
fvs.add(s);
|
||||
}
|
||||
for (String fv : fvs) {
|
||||
sb.append(fv);
|
||||
|
|
|
@ -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<String> 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<String> getFeatures() {
|
||||
public List<String> getFeatures() {
|
||||
synchronized (features) {
|
||||
return Collections.unmodifiableList(new ArrayList<String>(features)).iterator();
|
||||
return Collections.unmodifiableList(new ArrayList<String>(features));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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<FormField> 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<FormField.Option> 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<String> it = field.getValues(); it.hasNext();) {
|
||||
variable = it.next();
|
||||
for (String variable : field.getValues()) {
|
||||
if (variable.equals(Socks5BytestreamManager.NAMESPACE) && !IBB_ONLY) {
|
||||
isByteStream = true;
|
||||
}
|
||||
|
|
|
@ -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<String> 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<String> getNames() {
|
||||
public synchronized Set<String> getNames() {
|
||||
if (map == null) {
|
||||
return Collections.<String>emptyList().iterator();
|
||||
return Collections.<String>emptySet();
|
||||
}
|
||||
return Collections.unmodifiableSet(map.keySet()).iterator();
|
||||
return Collections.unmodifiableSet(map.keySet());
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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<DiscoverItems.Item>();
|
||||
List<DiscoverItems.Item> answer = new ArrayList<DiscoverItems.Item>();
|
||||
Iterator<String> 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<String> getJoinedRooms(XMPPConnection connection) {
|
||||
private static List<String> getJoinedRooms(XMPPConnection connection) {
|
||||
List<String> 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<String>().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<String> getJoinedRooms(XMPPConnection connection, String user)
|
||||
public static List<String> getJoinedRooms(XMPPConnection connection, String user)
|
||||
throws NoResponseException, XMPPErrorException, NotConnectedException {
|
||||
ArrayList<String> answer = new ArrayList<String>();
|
||||
// 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<String> getOccupants() {
|
||||
return Collections.unmodifiableList(new ArrayList<String>(occupantsMap.keySet()))
|
||||
.iterator();
|
||||
public List<String> getOccupants() {
|
||||
return Collections.unmodifiableList(new ArrayList<String>(occupantsMap.keySet()));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1595,8 +1592,8 @@ public class MultiUserChat {
|
|||
|
||||
// Get the list of affiliates from the server's answer
|
||||
List<Affiliate> affiliates = new ArrayList<Affiliate>();
|
||||
for (Iterator<MUCAdmin.Item> 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<Occupant> participants = new ArrayList<Occupant>();
|
||||
for (Iterator<MUCAdmin.Item> it = answer.getItems(); it.hasNext();) {
|
||||
participants.add(new Occupant(it.next()));
|
||||
for (MUCAdmin.Item mucadminItem : answer.getItems()) {
|
||||
participants.add(new Occupant(mucadminItem));
|
||||
}
|
||||
return participants;
|
||||
}
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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<Item> items = new ArrayList<Item>();
|
||||
|
||||
/**
|
||||
* 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<Item> getItems() {
|
||||
public Collection<Item> getItems() {
|
||||
synchronized (items) {
|
||||
return Collections.unmodifiableList(new ArrayList<Item>(items)).iterator();
|
||||
return Collections.unmodifiableList(new ArrayList<Item>(items));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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<Item> getItems() {
|
||||
public Collection<Item> getItems() {
|
||||
synchronized (items) {
|
||||
return Collections.unmodifiableList(new ArrayList<Item>(items)).iterator();
|
||||
return Collections.unmodifiableList(new ArrayList<Item>(items));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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 <tt>OfflineMessageHeader</tt> that keep information about the
|
||||
* Returns a List of <tt>OfflineMessageHeader</tt> 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 <tt>OfflineMessageHeader</tt> that keep information about the offline
|
||||
* @return a List of <tt>OfflineMessageHeader</tt> 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<OfflineMessageHeader> getHeaders() throws NoResponseException, XMPPErrorException, NotConnectedException {
|
||||
public List<OfflineMessageHeader> getHeaders() throws NoResponseException, XMPPErrorException, NotConnectedException {
|
||||
List<OfflineMessageHeader> answer = new ArrayList<OfflineMessageHeader>();
|
||||
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 <tt>Messages</tt> whose stamp matches the specified
|
||||
* Returns a List of the offline <tt>Messages</tt> 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 <tt>Messages</tt> that were received as part of
|
||||
* @return a List with the offline <tt>Messages</tt> 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<Message> getMessages(final List<String> nodes) throws NoResponseException, XMPPErrorException, NotConnectedException {
|
||||
public List<Message> getMessages(final List<String> nodes) throws NoResponseException, XMPPErrorException, NotConnectedException {
|
||||
List<Message> messages = new ArrayList<Message>();
|
||||
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 <tt>Messages</tt> of the user.
|
||||
* @return a List with all the offline <tt>Messages</tt> 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<Message> getMessages() throws NoResponseException, XMPPErrorException, NotConnectedException {
|
||||
public List<Message> getMessages() throws NoResponseException, XMPPErrorException, NotConnectedException {
|
||||
List<Message> messages = new ArrayList<Message>();
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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<Item> getItems() {
|
||||
public Collection<Item> getItems() {
|
||||
synchronized (items) {
|
||||
return Collections.unmodifiableList(new ArrayList<Item>(items)).iterator();
|
||||
return Collections.unmodifiableList(new ArrayList<Item>(items));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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<String> getChildren()
|
||||
public List<String> 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<String> getChildrenAssociationWhitelist()
|
||||
public List<String> 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<String> getReplyRoom()
|
||||
public List<String> getReplyRoom()
|
||||
{
|
||||
return getFieldValues(ConfigureNodeFields.replyroom);
|
||||
}
|
||||
|
@ -537,7 +536,7 @@ public class ConfigureForm extends Form
|
|||
*
|
||||
* @return The JID's
|
||||
*/
|
||||
public Iterator<String> getReplyTo()
|
||||
public List<String> getReplyTo()
|
||||
{
|
||||
return getFieldValues(ConfigureNodeFields.replyto);
|
||||
}
|
||||
|
@ -558,7 +557,7 @@ public class ConfigureForm extends Form
|
|||
*
|
||||
* @return The roster groups
|
||||
*/
|
||||
public Iterator<String> getRosterGroupsAllowed()
|
||||
public List<String> getRosterGroupsAllowed()
|
||||
{
|
||||
return getFieldValues(ConfigureNodeFields.roster_groups_allowed);
|
||||
}
|
||||
|
@ -642,23 +641,18 @@ public class ConfigureForm extends Form
|
|||
{
|
||||
StringBuilder result = new StringBuilder(getClass().getName() + " Content [");
|
||||
|
||||
Iterator<FormField> fields = getFields();
|
||||
|
||||
while (fields.hasNext())
|
||||
for (FormField formField : getFields())
|
||||
{
|
||||
FormField formField = fields.next();
|
||||
result.append('(');
|
||||
result.append(formField.getVariable());
|
||||
result.append(':');
|
||||
|
||||
Iterator<String> 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<String> getFieldValues(ConfigureNodeFields field)
|
||||
private List<String> getFieldValues(ConfigureNodeFields field)
|
||||
{
|
||||
FormField formField = getField(field.getFieldName());
|
||||
|
||||
|
|
|
@ -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<? extends PacketExtension> pubItems = itemsElem.getItems();
|
||||
@SuppressWarnings("unchecked")
|
||||
Iterator<RetractItem> it = (Iterator<RetractItem>)pubItems.iterator();
|
||||
Collection<RetractItem> pubItems = (Collection<RetractItem>) itemsElem.getItems();
|
||||
List<String> items = new ArrayList<String>(pubItems.size());
|
||||
|
||||
while (it.hasNext())
|
||||
for (RetractItem item : pubItems)
|
||||
{
|
||||
RetractItem item = it.next();
|
||||
items.add(item.getId());
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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<PresenceState> getShowValues()
|
||||
public List<PresenceState> getShowValues()
|
||||
{
|
||||
ArrayList<PresenceState> result = new ArrayList<PresenceState>(5);
|
||||
Iterator<String > 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<String> getFieldValues(SubscribeOptionFields field)
|
||||
private List<String> getFieldValues(SubscribeOptionFields field)
|
||||
{
|
||||
FormField formField = getField(field.getFieldName());
|
||||
|
||||
|
|
|
@ -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<FormField> 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<Item> items = dataForm.getItems(); items.hasNext();) {
|
||||
Item item = items.next();
|
||||
for (Item item : dataForm.getItems()) {
|
||||
List<Field> fieldList = new ArrayList<Field>(columns.size());
|
||||
FormField field;
|
||||
for (Iterator<FormField> 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<String> values = new ArrayList<String>();
|
||||
for (Iterator<String> 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<Row> getRows() {
|
||||
return Collections.unmodifiableList(new ArrayList<Row>(rows)).iterator();
|
||||
public List<Row> getRows() {
|
||||
return Collections.unmodifiableList(new ArrayList<Row>(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<Column> getColumns() {
|
||||
return Collections.unmodifiableList(new ArrayList<Column>(columns)).iterator();
|
||||
public List<Column> getColumns() {
|
||||
return Collections.unmodifiableList(new ArrayList<Column>(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<String> getValues(String variable) {
|
||||
for(Iterator<Field> it=getFields();it.hasNext();) {
|
||||
Field field = it.next();
|
||||
public List<String> 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<Field> getFields() {
|
||||
return Collections.unmodifiableList(new ArrayList<Field>(fields)).iterator();
|
||||
private List<Field> getFields() {
|
||||
return Collections.unmodifiableList(new ArrayList<Field>(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<String> getValues() {
|
||||
return Collections.unmodifiableList(values).iterator();
|
||||
public List<String> getValues() {
|
||||
return Collections.unmodifiableList(values);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<FormField> 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<String> values = formField.getValues();
|
||||
while (values.hasNext()) {
|
||||
return values.next();
|
||||
List<String> 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<ReportedData.Column> 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;
|
||||
}
|
||||
}
|
||||
|
||||
|
|