1
0
Fork 0
mirror of https://github.com/vanitasvitae/Smack.git synced 2024-11-29 23:42:06 +01:00

add generics

git-svn-id: http://svn.igniterealtime.org/svn/repos/smack/trunk@11422 b35dd754-fafc-0310-a699-88a17e54d16e
This commit is contained in:
Michael Will 2009-11-26 14:11:19 +00:00 committed by michael.will
parent 0b7421eae3
commit 06805b248d
9 changed files with 52 additions and 51 deletions

View file

@ -39,7 +39,7 @@ public class Agent {
private XMPPConnection connection; private XMPPConnection connection;
private String workgroupJID; private String workgroupJID;
public static Collection getWorkgroups(String serviceJID, String agentJID, XMPPConnection connection) throws XMPPException { public static Collection<String> getWorkgroups(String serviceJID, String agentJID, XMPPConnection connection) throws XMPPException {
AgentWorkgroups request = new AgentWorkgroups(agentJID); AgentWorkgroups request = new AgentWorkgroups(agentJID);
request.setTo(serviceJID); request.setTo(serviceJID);
PacketCollector collector = connection.createPacketCollector(new PacketIDFilter(request.getPacketID())); PacketCollector collector = connection.createPacketCollector(new PacketIDFilter(request.getPacketID()));

View file

@ -52,9 +52,9 @@ public class AgentRoster {
private XMPPConnection connection; private XMPPConnection connection;
private String workgroupJID; private String workgroupJID;
private List entries; private List<String> entries;
private List listeners; private List<AgentRosterListener> listeners;
private Map presenceMap; private Map<String, Map<String, Presence>> presenceMap;
// The roster is marked as initialized when at least a single roster packet // The roster is marked as initialized when at least a single roster packet
// has been recieved and processed. // has been recieved and processed.
boolean rosterInitialized = false; boolean rosterInitialized = false;
@ -67,9 +67,9 @@ public class AgentRoster {
AgentRoster(XMPPConnection connection, String workgroupJID) { AgentRoster(XMPPConnection connection, String workgroupJID) {
this.connection = connection; this.connection = connection;
this.workgroupJID = workgroupJID; this.workgroupJID = workgroupJID;
entries = new ArrayList(); entries = new ArrayList<String>();
listeners = new ArrayList(); listeners = new ArrayList<AgentRosterListener>();
presenceMap = new HashMap(); presenceMap = new HashMap<String, Map<String, Presence>>();
// Listen for any roster packets. // Listen for any roster packets.
PacketFilter rosterFilter = new PacketTypeFilter(AgentStatusRequest.class); PacketFilter rosterFilter = new PacketTypeFilter(AgentStatusRequest.class);
connection.addPacketListener(new AgentStatusListener(), rosterFilter); connection.addPacketListener(new AgentStatusListener(), rosterFilter);
@ -106,19 +106,19 @@ public class AgentRoster {
listeners.add(listener); listeners.add(listener);
// Fire events for the existing entries and presences in the roster // Fire events for the existing entries and presences in the roster
for (Iterator it = getAgents().iterator(); it.hasNext();) { for (Iterator<String> it = getAgents().iterator(); it.hasNext();) {
String jid = (String)it.next(); String jid = it.next();
// Check again in case the agent is no longer in the roster (highly unlikely // Check again in case the agent is no longer in the roster (highly unlikely
// but possible) // but possible)
if (entries.contains(jid)) { if (entries.contains(jid)) {
// Fire the agent added event // Fire the agent added event
listener.agentAdded(jid); listener.agentAdded(jid);
Map userPresences = (Map)presenceMap.get(jid); Map<String,Presence> userPresences = presenceMap.get(jid);
if (userPresences != null) { if (userPresences != null) {
Iterator presences = userPresences.values().iterator(); Iterator<Presence> presences = userPresences.values().iterator();
while (presences.hasNext()) { while (presences.hasNext()) {
// Fire the presence changed event // Fire the presence changed event
listener.presenceChanged((Presence)presences.next()); listener.presenceChanged(presences.next());
} }
} }
} }
@ -153,10 +153,10 @@ public class AgentRoster {
* *
* @return all entries in the roster. * @return all entries in the roster.
*/ */
public Set getAgents() { public Set<String> getAgents() {
Set agents = new HashSet(); Set<String> agents = new HashSet<String>();
synchronized (entries) { synchronized (entries) {
for (Iterator i = entries.iterator(); i.hasNext();) { for (Iterator<String> i = entries.iterator(); i.hasNext();) {
agents.add(i.next()); agents.add(i.next());
} }
} }
@ -176,8 +176,8 @@ public class AgentRoster {
return false; return false;
} }
synchronized (entries) { synchronized (entries) {
for (Iterator i = entries.iterator(); i.hasNext();) { for (Iterator<String> i = entries.iterator(); i.hasNext();) {
String entry = (String)i.next(); String entry = i.next();
if (entry.toLowerCase().equals(jid.toLowerCase())) { if (entry.toLowerCase().equals(jid.toLowerCase())) {
return true; return true;
} }
@ -197,7 +197,7 @@ public class AgentRoster {
*/ */
public Presence getPresence(String user) { public Presence getPresence(String user) {
String key = getPresenceMapKey(user); String key = getPresenceMapKey(user);
Map userPresences = (Map)presenceMap.get(key); Map<String, Presence> userPresences = presenceMap.get(key);
if (userPresences == null) { if (userPresences == null) {
Presence presence = new Presence(Presence.Type.unavailable); Presence presence = new Presence(Presence.Type.unavailable);
presence.setFrom(user); presence.setFrom(user);
@ -206,7 +206,7 @@ public class AgentRoster {
else { else {
// Find the resource with the highest priority // Find the resource with the highest priority
// Might be changed to use the resource with the highest availability instead. // Might be changed to use the resource with the highest availability instead.
Iterator it = userPresences.keySet().iterator(); Iterator<String> it = userPresences.keySet().iterator();
Presence p; Presence p;
Presence presence = null; Presence presence = null;
@ -303,14 +303,14 @@ public class AgentRoster {
else if (!workgroupJID.equals(agentStatus.getWorkgroupJID())) { else if (!workgroupJID.equals(agentStatus.getWorkgroupJID())) {
return; return;
} }
Map userPresences; Map<String, Presence> userPresences;
// Get the user presence map // Get the user presence map
if (presenceMap.get(key) == null) { if (presenceMap.get(key) == null) {
userPresences = new HashMap(); userPresences = new HashMap<String, Presence>();
presenceMap.put(key, userPresences); presenceMap.put(key, userPresences);
} }
else { else {
userPresences = (Map)presenceMap.get(key); userPresences = presenceMap.get(key);
} }
// Add the new presence, using the resources as a key. // Add the new presence, using the resources as a key.
synchronized (userPresences) { synchronized (userPresences) {
@ -329,7 +329,7 @@ public class AgentRoster {
// If an "unavailable" packet, remove any entries in the presence map. // If an "unavailable" packet, remove any entries in the presence map.
else if (presence.getType() == Presence.Type.unavailable) { else if (presence.getType() == Presence.Type.unavailable) {
if (presenceMap.get(key) != null) { if (presenceMap.get(key) != null) {
Map userPresences = (Map)presenceMap.get(key); Map<String,Presence> userPresences = presenceMap.get(key);
synchronized (userPresences) { synchronized (userPresences) {
userPresences.remove(StringUtils.parseResource(from)); userPresences.remove(StringUtils.parseResource(from));
} }
@ -339,7 +339,7 @@ public class AgentRoster {
} }
// Fire an event. // Fire an event.
synchronized (entries) { synchronized (entries) {
for (Iterator i = entries.iterator(); i.hasNext();) { for (Iterator<String> i = entries.iterator(); i.hasNext();) {
String entry = (String)i.next(); String entry = (String)i.next();
if (entry.toLowerCase().equals(StringUtils.parseBareAddress(key).toLowerCase())) { if (entry.toLowerCase().equals(StringUtils.parseBareAddress(key).toLowerCase())) {
fireEvent(EVENT_PRESENCE_CHANGED, packet); fireEvent(EVENT_PRESENCE_CHANGED, packet);

View file

@ -60,7 +60,7 @@ public class AgentSession {
private boolean online = false; private boolean online = false;
private Presence.Mode presenceMode; private Presence.Mode presenceMode;
private int maxChats; private int maxChats;
private final Map metaData; private final Map<String, String> metaData;
private Map<String, WorkgroupQueue> queues; private Map<String, WorkgroupQueue> queues;
@ -96,7 +96,7 @@ public class AgentSession {
this.maxChats = -1; this.maxChats = -1;
this.metaData = new HashMap(); this.metaData = new HashMap<String, String>();
this.queues = new HashMap<String, WorkgroupQueue>(); this.queues = new HashMap<String, WorkgroupQueue>();

View file

@ -50,7 +50,7 @@ public class AgentStatus implements PacketExtension {
public static final String NAMESPACE = "http://jabber.org/protocol/workgroup"; public static final String NAMESPACE = "http://jabber.org/protocol/workgroup";
private String workgroupJID; private String workgroupJID;
private List currentChats = new ArrayList(); private List<ChatInfo> currentChats = new ArrayList<ChatInfo>();
private int maxChats = -1; private int maxChats = -1;
AgentStatus() { AgentStatus() {
@ -67,7 +67,7 @@ public class AgentStatus implements PacketExtension {
* @return a collection of ChatInfo where each ChatInfo represents a Chat where this agent * @return a collection of ChatInfo where each ChatInfo represents a Chat where this agent
* is participating. * is participating.
*/ */
public List getCurrentChats() { public List<ChatInfo> getCurrentChats() {
return Collections.unmodifiableList(currentChats); return Collections.unmodifiableList(currentChats);
} }
@ -96,7 +96,7 @@ public class AgentStatus implements PacketExtension {
} }
if (!currentChats.isEmpty()) { if (!currentChats.isEmpty()) {
buf.append("<current-chats xmlns= \"http://jivesoftware.com/protocol/workgroup\">"); buf.append("<current-chats xmlns= \"http://jivesoftware.com/protocol/workgroup\">");
for (Iterator it = currentChats.iterator(); it.hasNext();) { for (Iterator<ChatInfo> it = currentChats.iterator(); it.hasNext();) {
buf.append(((ChatInfo)it.next()).toXML()); buf.append(((ChatInfo)it.next()).toXML());
} }
buf.append("</current-chats>"); buf.append("</current-chats>");

View file

@ -47,17 +47,17 @@ public class AgentStatusRequest extends IQ {
*/ */
public static final String NAMESPACE = "http://jabber.org/protocol/workgroup"; public static final String NAMESPACE = "http://jabber.org/protocol/workgroup";
private Set agents; private Set<Item> agents;
public AgentStatusRequest() { public AgentStatusRequest() {
agents = new HashSet(); agents = new HashSet<Item>();
} }
public int getAgentCount() { public int getAgentCount() {
return agents.size(); return agents.size();
} }
public Set getAgents() { public Set<Item> getAgents() {
return Collections.unmodifiableSet(agents); return Collections.unmodifiableSet(agents);
} }
@ -73,7 +73,7 @@ public class AgentStatusRequest extends IQ {
StringBuilder buf = new StringBuilder(); StringBuilder buf = new StringBuilder();
buf.append("<").append(ELEMENT_NAME).append(" xmlns=\"").append(NAMESPACE).append("\">"); buf.append("<").append(ELEMENT_NAME).append(" xmlns=\"").append(NAMESPACE).append("\">");
synchronized (agents) { synchronized (agents) {
for (Iterator i=agents.iterator(); i.hasNext(); ) { for (Iterator<Item> i=agents.iterator(); i.hasNext(); ) {
Item item = (Item) i.next(); Item item = (Item) i.next();
buf.append("<agent jid=\"").append(item.getJID()).append("\">"); buf.append("<agent jid=\"").append(item.getJID()).append("\">");
if (item.getName() != null) { if (item.getName() != null) {

View file

@ -38,7 +38,7 @@ import java.util.List;
public class AgentWorkgroups extends IQ { public class AgentWorkgroups extends IQ {
private String agentJID; private String agentJID;
private List workgroups; private List<String> workgroups;
/** /**
* Creates an AgentWorkgroups request for the given agent. This IQ will be sent and an answer * Creates an AgentWorkgroups request for the given agent. This IQ will be sent and an answer
@ -48,7 +48,7 @@ public class AgentWorkgroups extends IQ {
*/ */
public AgentWorkgroups(String agentJID) { public AgentWorkgroups(String agentJID) {
this.agentJID = agentJID; this.agentJID = agentJID;
this.workgroups = new ArrayList(); this.workgroups = new ArrayList<String>();
} }
/** /**
@ -58,7 +58,7 @@ public class AgentWorkgroups extends IQ {
* @param agentJID the id of the agent that can work in the list of workgroups. * @param agentJID the id of the agent that can work in the list of workgroups.
* @param workgroups the list of workgroup JIDs where the agent can work. * @param workgroups the list of workgroup JIDs where the agent can work.
*/ */
public AgentWorkgroups(String agentJID, List workgroups) { public AgentWorkgroups(String agentJID, List<String> workgroups) {
this.agentJID = agentJID; this.agentJID = agentJID;
this.workgroups = workgroups; this.workgroups = workgroups;
} }
@ -72,7 +72,7 @@ public class AgentWorkgroups extends IQ {
* *
* @return a list of workgroup JIDs where the agent can work. * @return a list of workgroup JIDs where the agent can work.
*/ */
public List getWorkgroups() { public List<String> getWorkgroups() {
return Collections.unmodifiableList(workgroups); return Collections.unmodifiableList(workgroups);
} }
@ -83,8 +83,8 @@ public class AgentWorkgroups extends IQ {
.append(agentJID) .append(agentJID)
.append("\">"); .append("\">");
for (Iterator it=workgroups.iterator(); it.hasNext();) { for (Iterator<String> it=workgroups.iterator(); it.hasNext();) {
String workgroupJID = (String) it.next(); String workgroupJID = it.next();
buf.append("<workgroup jid=\"" + workgroupJID + "\"/>"); buf.append("<workgroup jid=\"" + workgroupJID + "\"/>");
} }
@ -106,7 +106,7 @@ public class AgentWorkgroups extends IQ {
public IQ parseIQ(XmlPullParser parser) throws Exception { public IQ parseIQ(XmlPullParser parser) throws Exception {
String agentJID = parser.getAttributeValue("", "jid"); String agentJID = parser.getAttributeValue("", "jid");
List workgroups = new ArrayList(); List<String> workgroups = new ArrayList<String>();
boolean done = false; boolean done = false;
while (!done) { while (!done) {

View file

@ -51,13 +51,13 @@ public class QueueDetails implements PacketExtension {
/** /**
* The list of users in the queue. * The list of users in the queue.
*/ */
private Set users; private Set<QueueUser> users;
/** /**
* Creates a new QueueDetails packet * Creates a new QueueDetails packet
*/ */
private QueueDetails() { private QueueDetails() {
users = new HashSet(); users = new HashSet<QueueUser>();
} }
/** /**
@ -76,7 +76,7 @@ public class QueueDetails implements PacketExtension {
* *
* @return a Set for the users waiting in a queue. * @return a Set for the users waiting in a queue.
*/ */
public Set getUsers() { public Set<QueueUser> getUsers() {
synchronized (users) { synchronized (users) {
return users; return users;
} }
@ -106,7 +106,7 @@ public class QueueDetails implements PacketExtension {
buf.append("<").append(ELEMENT_NAME).append(" xmlns=\"").append(NAMESPACE).append("\">"); buf.append("<").append(ELEMENT_NAME).append(" xmlns=\"").append(NAMESPACE).append("\">");
synchronized (users) { synchronized (users) {
for (Iterator i=users.iterator(); i.hasNext(); ) { for (Iterator<QueueUser> i=users.iterator(); i.hasNext(); ) {
QueueUser user = (QueueUser)i.next(); QueueUser user = (QueueUser)i.next();
int position = user.getQueuePosition(); int position = user.getQueuePosition();
int timeRemaining = user.getEstimatedRemainingTime(); int timeRemaining = user.getEstimatedRemainingTime();

View file

@ -36,7 +36,7 @@ import java.util.List;
*/ */
public class Transcript extends IQ { public class Transcript extends IQ {
private String sessionID; private String sessionID;
private List packets; private List<Packet> packets;
/** /**
* Creates a transcript request for the given sessionID. * Creates a transcript request for the given sessionID.
@ -45,7 +45,7 @@ public class Transcript extends IQ {
*/ */
public Transcript(String sessionID) { public Transcript(String sessionID) {
this.sessionID = sessionID; this.sessionID = sessionID;
this.packets = new ArrayList(); this.packets = new ArrayList<Packet>();
} }
/** /**
@ -55,7 +55,7 @@ public class Transcript extends IQ {
* @param sessionID the id of the session that generated this conversation transcript. * @param sessionID the id of the session that generated this conversation transcript.
* @param packets the list of messages and presences send to the room. * @param packets the list of messages and presences send to the room.
*/ */
public Transcript(String sessionID, List packets) { public Transcript(String sessionID, List<Packet> packets) {
this.sessionID = sessionID; this.sessionID = sessionID;
this.packets = packets; this.packets = packets;
} }
@ -75,7 +75,7 @@ public class Transcript extends IQ {
* *
* @return the list of Messages and Presences that were sent to the room. * @return the list of Messages and Presences that were sent to the room.
*/ */
public List getPackets() { public List<Packet> getPackets() {
return Collections.unmodifiableList(packets); return Collections.unmodifiableList(packets);
} }
@ -86,8 +86,8 @@ public class Transcript extends IQ {
.append(sessionID) .append(sessionID)
.append("\">"); .append("\">");
for (Iterator it=packets.iterator(); it.hasNext();) { for (Iterator<Packet> it=packets.iterator(); it.hasNext();) {
Packet packet = (Packet) it.next(); Packet packet = it.next();
buf.append(packet.toXML()); buf.append(packet.toXML());
} }

View file

@ -21,6 +21,7 @@ package org.jivesoftware.smackx.workgroup.packet;
import org.jivesoftware.smack.provider.IQProvider; import org.jivesoftware.smack.provider.IQProvider;
import org.jivesoftware.smack.packet.IQ; import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smack.packet.Packet;
import org.jivesoftware.smack.util.PacketParserUtils; import org.jivesoftware.smack.util.PacketParserUtils;
import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParser;
@ -40,7 +41,7 @@ public class TranscriptProvider implements IQProvider {
public IQ parseIQ(XmlPullParser parser) throws Exception { public IQ parseIQ(XmlPullParser parser) throws Exception {
String sessionID = parser.getAttributeValue("", "sessionID"); String sessionID = parser.getAttributeValue("", "sessionID");
List packets = new ArrayList(); List<Packet> packets = new ArrayList<Packet>();
boolean done = false; boolean done = false;
while (!done) { while (!done) {