Commit 336313bb authored by Dave Cridland's avatar Dave Cridland

Merge pull request #338 from sco0ter/arraylist

Use Collections.singleton() where ArrayList has only one element.
parents 7a7db14a b90b9cab
......@@ -22,6 +22,7 @@ package org.jivesoftware.openfire;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
......@@ -396,9 +397,7 @@ public class MulticastRouter extends BasicModule implements ServerFeaturesProvid
}
public Iterator<String> getFeatures() {
ArrayList<String> features = new ArrayList<String>();
features.add(NAMESPACE);
return features.iterator();
return Collections.singleton(NAMESPACE).iterator();
}
@Override
......
......@@ -96,18 +96,14 @@ public class AdHocCommandHandler extends IQHandler
}
public Iterator<String> getFeatures() {
ArrayList<String> features = new ArrayList<String>();
features.add(NAMESPACE);
return features.iterator();
return Collections.singleton(NAMESPACE).iterator();
}
public Iterator<Element> getIdentities(String name, String node, JID senderJID) {
ArrayList<Element> identities = new ArrayList<Element>();
Element identity = DocumentHelper.createElement("identity");
identity.addAttribute("category", "automation");
identity.addAttribute("type", NAMESPACE.equals(node) ? "command-list" : "command-node");
identities.add(identity);
return identities.iterator();
return Collections.singleton(identity).iterator();
}
public Iterator<String> getFeatures(String name, String node, JID senderJID) {
......
......@@ -413,11 +413,7 @@ public class IQDiscoItemsHandler extends IQHandler implements ServerFeaturesProv
}
public Iterator<String> getFeatures() {
List<String> features = new ArrayList<String>();
features.add("http://jabber.org/protocol/disco#items");
// TODO Comment out this line when publishing of client items is implemented
//features.add("http://jabber.org/protocol/disco#publish");
return features.iterator();
return Collections.singleton(NAMESPACE_DISCO_ITEMS).iterator();
}
public void joinedCluster() {
......
......@@ -24,8 +24,8 @@ import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import org.dom4j.DocumentHelper;
......@@ -306,30 +306,25 @@ public class FileTransferProxy extends BasicModule
}
public Iterator<DiscoServerItem> getItems() {
List<DiscoServerItem> items = new ArrayList<DiscoServerItem>();
if(!isEnabled()) {
return items.iterator();
return Collections.emptyIterator();
}
final DiscoServerItem item = new DiscoServerItem(new JID(
getServiceDomain()), "Socks 5 Bytestreams Proxy", null, null, this,
this);
items.add(item);
return items.iterator();
return Collections.singleton(item).iterator();
}
public Iterator<Element> getIdentities(String name, String node, JID senderJID) {
List<Element> identities = new ArrayList<Element>();
// Answer the identity of the proxy
Element identity = DocumentHelper.createElement("identity");
identity.addAttribute("category", "proxy");
identity.addAttribute("name", "SOCKS5 Bytestreams Service");
identity.addAttribute("type", "bytestreams");
identities.add(identity);
return identities.iterator();
return Collections.singleton(identity).iterator();
}
public Iterator<String> getFeatures(String name, String node, JID senderJID) {
......
......@@ -30,7 +30,7 @@ import org.jivesoftware.openfire.user.UserNotFoundException;
import org.xmpp.packet.IQ;
import org.xmpp.packet.PacketError;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
/**
......@@ -116,9 +116,7 @@ public class IQLastActivityHandler extends IQHandler implements ServerFeaturesPr
}
public Iterator<String> getFeatures() {
ArrayList<String> features = new ArrayList<String>();
features.add("jabber:iq:last");
return features.iterator();
return Collections.singleton("jabber:iq:last").iterator();
}
@Override
......
......@@ -141,22 +141,18 @@ public class IQOfflineMessagesHandler extends IQHandler implements ServerFeature
}
public Iterator<String> getFeatures() {
ArrayList<String> features = new ArrayList<String>();
features.add(NAMESPACE);
return features.iterator();
return Collections.singleton(NAMESPACE).iterator();
}
public Iterator<Element> getIdentities(String name, String node, JID senderJID) {
ArrayList<Element> identities = new ArrayList<Element>();
Element identity = DocumentHelper.createElement("identity");
identity.addAttribute("category", "automation");
identity.addAttribute("type", "message-list");
identities.add(identity);
return identities.iterator();
return Collections.singleton(identity).iterator();
}
public Iterator<String> getFeatures(String name, String node, JID senderJID) {
return Collections.singletonList(NAMESPACE).iterator();
return Collections.singleton(NAMESPACE).iterator();
}
public DataForm getExtendedInfo(String name, String node, JID senderJID) {
......
......@@ -36,7 +36,7 @@ import org.xmpp.packet.IQ;
import org.xmpp.packet.JID;
import org.xmpp.packet.PacketError;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
......@@ -416,9 +416,7 @@ public class IQPrivacyHandler extends IQHandler
}
public Iterator<String> getFeatures() {
ArrayList<String> features = new ArrayList<String>();
features.add("jabber:iq:privacy");
return features.iterator();
return Collections.singleton("jabber:iq:privacy").iterator();
}
public void userCreated(User user, Map params) {
......
......@@ -30,9 +30,8 @@ import org.jivesoftware.openfire.disco.ServerFeaturesProvider;
import org.xmpp.packet.IQ;
import org.xmpp.packet.PacketError;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
/**
* Implements the TYPE_IQ jabber:iq:private protocol. Clients
......@@ -117,8 +116,6 @@ public class IQPrivateHandler extends IQHandler implements ServerFeaturesProvide
}
public Iterator<String> getFeatures() {
List<String> features = new ArrayList<String>();
features.add("jabber:iq:private");
return features.iterator();
return Collections.singleton("jabber:iq:private").iterator();
}
}
......@@ -23,7 +23,7 @@ package org.jivesoftware.openfire.handler;
import gnu.inet.encoding.Stringprep;
import gnu.inet.encoding.StringprepException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
......@@ -470,8 +470,6 @@ public class IQRegisterHandler extends IQHandler implements ServerFeaturesProvid
}
public Iterator<String> getFeatures() {
ArrayList<String> features = new ArrayList<String>();
features.add("jabber:iq:register");
return features.iterator();
return Collections.singleton("jabber:iq:register").iterator();
}
}
......@@ -22,7 +22,7 @@ package org.jivesoftware.openfire.handler;
import gnu.inet.encoding.IDNAException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
......@@ -345,8 +345,6 @@ public class IQRosterHandler extends IQHandler implements ServerFeaturesProvider
@Override
public Iterator<String> getFeatures() {
ArrayList<String> features = new ArrayList<String>();
features.add("jabber:iq:roster");
return features.iterator();
return Collections.singleton("jabber:iq:roster").iterator();
}
}
\ No newline at end of file
......@@ -30,9 +30,8 @@ import org.jivesoftware.openfire.disco.ServerFeaturesProvider;
import org.xmpp.packet.IQ;
import org.xmpp.packet.PacketError;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
/**
* Implements the TYPE_IQ jabber:iq:version protocol (version info). Allows
......@@ -92,8 +91,6 @@ public class IQVersionHandler extends IQHandler implements ServerFeaturesProvide
}
public Iterator<String> getFeatures() {
List<String> features = new ArrayList<String>();
features.add("jabber:iq:version");
return features.iterator();
return Collections.singleton("jabber:iq:version").iterator();
}
}
\ No newline at end of file
......@@ -976,9 +976,7 @@ public class MultiUserChatServiceImpl implements Component, MultiUserChatService
}
public void removeUserAllowedToCreate(JID userJID) {
List<JID> asList = new ArrayList<JID>();
asList.add(userJID);
removeUsersAllowedToCreate(asList);
removeUsersAllowedToCreate(Collections.singleton(userJID));
}
public void initialize(XMPPServer server) {
......
......@@ -194,7 +194,7 @@ public class DNSUtil {
Attribute srvRecords = dnsLookup.get("SRV");
if (srvRecords == null) {
logger.debug("No SRV record found for domain: " + lookup);
return new ArrayList<HostAddress>();
return Collections.emptyList();
}
WeightedHostAddress[] hosts = new WeightedHostAddress[srvRecords.size()];
for (int i = 0; i < srvRecords.size(); i++) {
......@@ -209,7 +209,7 @@ public class DNSUtil {
catch (NamingException e) {
logger.error("Can't process DNS lookup!", e);
}
return new ArrayList<HostAddress>();
return Collections.emptyList();
}
/**
......
......@@ -21,7 +21,7 @@
package org.jivesoftware.openfire.pep;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Iterator;
import java.util.Map;
import java.util.concurrent.ExecutorService;
......@@ -266,12 +266,10 @@ public class IQPEPHandler extends IQHandler implements ServerIdentitiesProvider,
* the PEP identity to the respective disco#info results.
*/
public Iterator<Element> getIdentities() {
ArrayList<Element> identities = new ArrayList<Element>();
Element identity = DocumentHelper.createElement("identity");
identity.addAttribute("category", "pubsub");
identity.addAttribute("type", "pep");
identities.add(identity);
return identities.iterator();
return Collections.singleton(identity).iterator();
}
/**
......
......@@ -20,7 +20,7 @@
package org.jivesoftware.openfire.vcard;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.Map;
import java.util.StringTokenizer;
......@@ -310,9 +310,7 @@ public class VCardManager extends BasicModule implements ServerFeaturesProvider
}
public Iterator<String> getFeatures() {
ArrayList<String> features = new ArrayList<String>();
features.add("vcard-temp");
return features.iterator();
return Collections.singleton("vcard-temp").iterator();
}
private class EventHandler extends UserEventAdapter {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment