mirror of
https://codeberg.org/Mercury-IM/Smack
synced 2024-11-22 14:22:05 +01:00
Return more specific types (e.g. Collection → List)
be generic as possible in what you accept, but more specific in what you return. Also tweak MultiuserChatManager methods a bit.
This commit is contained in:
parent
9286a1decb
commit
252d5172e9
12 changed files with 52 additions and 60 deletions
|
@ -21,7 +21,6 @@ import org.jivesoftware.smack.SmackException.NotConnectedException;
|
|||
import org.jivesoftware.smack.packet.Message;
|
||||
|
||||
import java.util.Set;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.concurrent.CopyOnWriteArraySet;
|
||||
|
||||
|
@ -141,12 +140,12 @@ public class Chat {
|
|||
}
|
||||
|
||||
/**
|
||||
* Returns an unmodifiable collection of all of the listeners registered with this chat.
|
||||
* Returns an unmodifiable set of all of the listeners registered with this chat.
|
||||
*
|
||||
* @return an unmodifiable collection of all of the listeners registered with this chat.
|
||||
* @return an unmodifiable set of all of the listeners registered with this chat.
|
||||
*/
|
||||
public Collection<ChatMessageListener> getListeners() {
|
||||
return Collections.unmodifiableCollection(listeners);
|
||||
public Set<ChatMessageListener> getListeners() {
|
||||
return Collections.unmodifiableSet(listeners);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -17,7 +17,6 @@
|
|||
|
||||
package org.jivesoftware.smack;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
@ -322,14 +321,14 @@ public class ChatManager extends Manager{
|
|||
}
|
||||
|
||||
/**
|
||||
* Returns an unmodifiable collection of all chat listeners currently registered with this
|
||||
* Returns an unmodifiable set of all chat listeners currently registered with this
|
||||
* manager.
|
||||
*
|
||||
* @return an unmodifiable collection of all chat listeners currently registered with this
|
||||
* manager.
|
||||
*/
|
||||
public Collection<ChatManagerListener> getChatListeners() {
|
||||
return Collections.unmodifiableCollection(chatManagerListeners);
|
||||
public Set<ChatManagerListener> getChatListeners() {
|
||||
return Collections.unmodifiableSet(chatManagerListeners);
|
||||
}
|
||||
|
||||
private void deliverMessage(Chat chat, Message message) {
|
||||
|
|
|
@ -369,12 +369,12 @@ public class Roster {
|
|||
}
|
||||
|
||||
/**
|
||||
* Returns an unmodifiable collection of all entries in the roster, including entries
|
||||
* Returns a set of all entries in the roster, including entries
|
||||
* that don't belong to any groups.
|
||||
*
|
||||
* @return all entries in the roster.
|
||||
*/
|
||||
public Collection<RosterEntry> getEntries() {
|
||||
public Set<RosterEntry> getEntries() {
|
||||
Set<RosterEntry> allEntries = new HashSet<RosterEntry>();
|
||||
// Loop through all roster groups and add their entries to the answer
|
||||
for (RosterGroup rosterGroup : getGroups()) {
|
||||
|
@ -383,7 +383,7 @@ public class Roster {
|
|||
// Add the roster unfiled entries to the answer
|
||||
allEntries.addAll(unfiledEntries);
|
||||
|
||||
return Collections.unmodifiableCollection(allEntries);
|
||||
return allEntries;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -402,7 +402,7 @@ public class Roster {
|
|||
*
|
||||
* @return the unfiled roster entries.
|
||||
*/
|
||||
public Collection<RosterEntry> getUnfiledEntries() {
|
||||
public List<RosterEntry> getUnfiledEntries() {
|
||||
return Collections.unmodifiableList(unfiledEntries);
|
||||
}
|
||||
|
||||
|
|
|
@ -19,7 +19,6 @@ package org.jivesoftware.smack;
|
|||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
|
@ -112,11 +111,11 @@ public class RosterEntry {
|
|||
}
|
||||
|
||||
/**
|
||||
* Returns an unmodifiable collection of the roster groups that this entry belongs to.
|
||||
* Returns an copied list of the roster groups that this entry belongs to.
|
||||
*
|
||||
* @return an iterator for the groups this entry belongs to.
|
||||
*/
|
||||
public Collection<RosterGroup> getGroups() {
|
||||
public List<RosterGroup> getGroups() {
|
||||
List<RosterGroup> results = new ArrayList<RosterGroup>();
|
||||
// Loop through all roster groups and find the ones that contain this
|
||||
// entry. This algorithm should be fine
|
||||
|
@ -125,7 +124,7 @@ public class RosterEntry {
|
|||
results.add(group);
|
||||
}
|
||||
}
|
||||
return Collections.unmodifiableCollection(results);
|
||||
return results;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -18,9 +18,8 @@
|
|||
package org.jivesoftware.smack;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Set;
|
||||
|
||||
|
@ -99,13 +98,13 @@ public class RosterGroup {
|
|||
}
|
||||
|
||||
/**
|
||||
* Returns an unmodifiable collection of all entries in the group.
|
||||
* Returns an copied list of all entries in the group.
|
||||
*
|
||||
* @return all entries in the group.
|
||||
*/
|
||||
public Collection<RosterEntry> getEntries() {
|
||||
public List<RosterEntry> getEntries() {
|
||||
synchronized (entries) {
|
||||
return Collections.unmodifiableList(new ArrayList<RosterEntry>(entries));
|
||||
return new ArrayList<RosterEntry>(entries);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -18,7 +18,6 @@
|
|||
package org.jivesoftware.smack.packet;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
|
@ -154,8 +153,8 @@ public final class Message extends Packet {
|
|||
*
|
||||
* @return a collection of all subjects in this message.
|
||||
*/
|
||||
public Collection<Subject> getSubjects() {
|
||||
return Collections.unmodifiableCollection(subjects);
|
||||
public Set<Subject> getSubjects() {
|
||||
return Collections.unmodifiableSet(subjects);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -218,7 +217,7 @@ public final class Message extends Packet {
|
|||
*
|
||||
* @return the languages being used for the subjects.
|
||||
*/
|
||||
public Collection<String> getSubjectLanguages() {
|
||||
public List<String> getSubjectLanguages() {
|
||||
Subject defaultSubject = getMessageSubject(null);
|
||||
List<String> languages = new ArrayList<String>();
|
||||
for (Subject subject : subjects) {
|
||||
|
@ -226,7 +225,7 @@ public final class Message extends Packet {
|
|||
languages.add(subject.language);
|
||||
}
|
||||
}
|
||||
return Collections.unmodifiableCollection(languages);
|
||||
return Collections.unmodifiableList(languages);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -274,8 +273,8 @@ public final class Message extends Packet {
|
|||
* @return a collection of all bodies in this Message.
|
||||
* @since 3.0.2
|
||||
*/
|
||||
public Collection<Body> getBodies() {
|
||||
return Collections.unmodifiableCollection(bodies);
|
||||
public Set<Body> getBodies() {
|
||||
return Collections.unmodifiableSet(bodies);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -340,7 +339,7 @@ public final class Message extends Packet {
|
|||
* @return the languages being used for the bodies.
|
||||
* @since 3.0.2
|
||||
*/
|
||||
public Collection<String> getBodyLanguages() {
|
||||
public List<String> getBodyLanguages() {
|
||||
Body defaultBody = getMessageBody(null);
|
||||
List<String> languages = new ArrayList<String>();
|
||||
for (Body body : bodies) {
|
||||
|
@ -348,7 +347,7 @@ public final class Message extends Packet {
|
|||
languages.add(body.language);
|
||||
}
|
||||
}
|
||||
return Collections.unmodifiableCollection(languages);
|
||||
return Collections.unmodifiableList(languages);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -20,7 +20,6 @@ package org.jivesoftware.smack.packet;
|
|||
import org.jivesoftware.smack.util.XmlStringBuilder;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
@ -67,13 +66,13 @@ public class RosterPacket extends IQ {
|
|||
}
|
||||
|
||||
/**
|
||||
* Returns an unmodifiable collection for the roster items in the packet.
|
||||
* Returns a copied list of the roster items in the packet.
|
||||
*
|
||||
* @return an unmodifiable collection for the roster items in the packet.
|
||||
* @return a copied list of the roster items in the packet.
|
||||
*/
|
||||
public Collection<Item> getRosterItems() {
|
||||
public List<Item> getRosterItems() {
|
||||
synchronized (rosterItems) {
|
||||
return Collections.unmodifiableList(new ArrayList<Item>(rosterItems));
|
||||
return new ArrayList<Item>(rosterItems);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -16,9 +16,8 @@
|
|||
*/
|
||||
package org.jivesoftware.smackx.amp.packet;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
|
||||
import org.jivesoftware.smack.packet.PacketExtension;
|
||||
|
@ -82,12 +81,12 @@ public class AMPExtension implements PacketExtension {
|
|||
}
|
||||
|
||||
/**
|
||||
* Returns a Collection of the rules in the packet.
|
||||
* Returns a unmodifiable List of the rules in the packet.
|
||||
*
|
||||
* @return a Collection of the rules in the packet.
|
||||
* @return a unmodifiable List of the rules in the packet.
|
||||
*/
|
||||
public Collection<Rule> getRules() {
|
||||
return Collections.unmodifiableList(new ArrayList<Rule>(rules));
|
||||
public List<Rule> getRules() {
|
||||
return Collections.unmodifiableList(rules);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -17,7 +17,6 @@
|
|||
|
||||
package org.jivesoftware.smackx.bookmarks;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
@ -95,9 +94,9 @@ public class BookmarkManager {
|
|||
* @throws NotConnectedException
|
||||
* @see BookmarkedConference
|
||||
*/
|
||||
public Collection<BookmarkedConference> getBookmarkedConferences() throws NoResponseException, XMPPErrorException, NotConnectedException {
|
||||
public List<BookmarkedConference> getBookmarkedConferences() throws NoResponseException, XMPPErrorException, NotConnectedException {
|
||||
retrieveBookmarks();
|
||||
return Collections.unmodifiableCollection(bookmarks.getBookmarkedConferences());
|
||||
return Collections.unmodifiableList(bookmarks.getBookmarkedConferences());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -171,9 +170,9 @@ public class BookmarkManager {
|
|||
* @throws NoResponseException if there was no response from the server.
|
||||
* @throws NotConnectedException
|
||||
*/
|
||||
public Collection<BookmarkedURL> getBookmarkedURLs() throws NoResponseException, XMPPErrorException, NotConnectedException {
|
||||
public List<BookmarkedURL> getBookmarkedURLs() throws NoResponseException, XMPPErrorException, NotConnectedException {
|
||||
retrieveBookmarks();
|
||||
return Collections.unmodifiableCollection(bookmarks.getBookmarkedURLS());
|
||||
return Collections.unmodifiableList(bookmarks.getBookmarkedURLS());
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -17,10 +17,10 @@
|
|||
|
||||
package org.jivesoftware.smackx.iqregister;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.WeakHashMap;
|
||||
|
||||
import org.jivesoftware.smack.Manager;
|
||||
|
@ -141,7 +141,7 @@ public class AccountManager extends Manager {
|
|||
* @throws NoResponseException
|
||||
* @throws NotConnectedException
|
||||
*/
|
||||
public Collection<String> getAccountAttributes() throws NoResponseException, XMPPErrorException, NotConnectedException {
|
||||
public Set<String> getAccountAttributes() throws NoResponseException, XMPPErrorException, NotConnectedException {
|
||||
if (info == null) {
|
||||
getRegistrationInfo();
|
||||
}
|
||||
|
|
|
@ -31,12 +31,11 @@ import org.jivesoftware.smackx.disco.packet.DiscoverItems;
|
|||
*/
|
||||
public class HostedRoom {
|
||||
|
||||
private String jid;
|
||||
private final String jid;
|
||||
|
||||
private String name;
|
||||
private final String name;
|
||||
|
||||
public HostedRoom(DiscoverItems.Item item) {
|
||||
super();
|
||||
jid = item.getEntityID();
|
||||
name = item.getName();
|
||||
}
|
||||
|
|
|
@ -18,7 +18,6 @@ package org.jivesoftware.smackx.muc;
|
|||
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
|
@ -203,11 +202,12 @@ public class MultiUserChatManager extends Manager {
|
|||
*/
|
||||
public List<String> getJoinedRooms(String user) throws NoResponseException, XMPPErrorException,
|
||||
NotConnectedException {
|
||||
ArrayList<String> answer = new ArrayList<String>();
|
||||
// Send the disco packet to the user
|
||||
DiscoverItems result = ServiceDiscoveryManager.getInstanceFor(connection()).discoverItems(user, DISCO_NODE);
|
||||
List<DiscoverItems.Item> items = result.getItems();
|
||||
List<String> answer = new ArrayList<String>(items.size());
|
||||
// Collect the entityID for each returned item
|
||||
for (DiscoverItems.Item item : result.getItems()) {
|
||||
for (DiscoverItems.Item item : items) {
|
||||
answer.add(item.getEntityID());
|
||||
}
|
||||
return answer;
|
||||
|
@ -242,7 +242,7 @@ public class MultiUserChatManager extends Manager {
|
|||
}
|
||||
|
||||
/**
|
||||
* Returns a collection of HostedRooms where each HostedRoom has the XMPP address of the room and the room's name.
|
||||
* Returns a List of HostedRooms where each HostedRoom has the XMPP address of the room and the room's name.
|
||||
* Once discovered the rooms hosted by a chat service it is possible to discover more detailed room information or
|
||||
* join the room.
|
||||
*
|
||||
|
@ -252,12 +252,13 @@ public class MultiUserChatManager extends Manager {
|
|||
* @throws NoResponseException
|
||||
* @throws NotConnectedException
|
||||
*/
|
||||
public Collection<HostedRoom> getHostedRooms(String serviceName) throws NoResponseException, XMPPErrorException,
|
||||
public List<HostedRoom> getHostedRooms(String serviceName) throws NoResponseException, XMPPErrorException,
|
||||
NotConnectedException {
|
||||
List<HostedRoom> answer = new ArrayList<HostedRoom>();
|
||||
ServiceDiscoveryManager discoManager = ServiceDiscoveryManager.getInstanceFor(connection());
|
||||
DiscoverItems items = discoManager.discoverItems(serviceName);
|
||||
for (DiscoverItems.Item item : items.getItems()) {
|
||||
DiscoverItems discoverItems = discoManager.discoverItems(serviceName);
|
||||
List<DiscoverItems.Item> items = discoverItems.getItems();
|
||||
List<HostedRoom> answer = new ArrayList<HostedRoom>(items.size());
|
||||
for (DiscoverItems.Item item : items) {
|
||||
answer.add(new HostedRoom(item));
|
||||
}
|
||||
return answer;
|
||||
|
|
Loading…
Reference in a new issue