1
0
Fork 0
mirror of https://codeberg.org/Mercury-IM/Smack synced 2025-09-10 18:59:41 +02: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:
Florian Schmaus 2014-11-29 13:36:56 +01:00
parent 9286a1decb
commit 252d5172e9
12 changed files with 52 additions and 60 deletions

View file

@ -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);
}
/**

View file

@ -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());
}
/**

View file

@ -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();
}

View file

@ -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();
}

View file

@ -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;