1
0
Fork 0
mirror of https://github.com/vanitasvitae/Smack.git synced 2025-09-10 09:39:39 +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

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

View file

@ -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) {

View file

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

View file

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

View file

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

View file

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

View file

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