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