mirror of
https://github.com/vanitasvitae/Smack.git
synced 2024-12-22 18:48:00 +01:00
Remove old Apache commons collections from codebase
ChatManager's Chat instances are now removed by Chat.close(), removing the need for a Map with Hard to Weak references. ChatStateManager can simply use WeakHashMap.
This commit is contained in:
parent
f73a3afbca
commit
a46d02ca32
17 changed files with 72 additions and 3224 deletions
|
@ -99,9 +99,8 @@ public class Chat {
|
|||
* and message type of the message will automatically set to those of this chat.
|
||||
*
|
||||
* @param message the message to send.
|
||||
* @throws XMPPException if an error occurs sending the message.
|
||||
*/
|
||||
public void sendMessage(Message message) throws XMPPException {
|
||||
public void sendMessage(Message message) {
|
||||
// Force the recipient, message type, and thread ID since the user elected
|
||||
// to send the message through this chat object.
|
||||
message.setTo(participant);
|
||||
|
|
|
@ -19,6 +19,7 @@ package org.jivesoftware.smack;
|
|||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
@ -33,7 +34,6 @@ import org.jivesoftware.smack.packet.Message;
|
|||
import org.jivesoftware.smack.packet.Message.Type;
|
||||
import org.jivesoftware.smack.packet.Packet;
|
||||
import org.jivesoftware.smack.util.StringUtils;
|
||||
import org.jivesoftware.smack.util.collections.ReferenceMap;
|
||||
|
||||
/**
|
||||
* The chat manager keeps track of references to all current chats. It will not hold any references
|
||||
|
@ -87,20 +87,17 @@ public class ChatManager {
|
|||
/**
|
||||
* Maps thread ID to chat.
|
||||
*/
|
||||
private Map<String, Chat> threadChats = Collections.synchronizedMap(new ReferenceMap<String, Chat>(ReferenceMap.HARD,
|
||||
ReferenceMap.WEAK));
|
||||
private Map<String, Chat> threadChats = Collections.synchronizedMap(new HashMap<String, Chat>());
|
||||
|
||||
/**
|
||||
* Maps jids to chats
|
||||
*/
|
||||
private Map<String, Chat> jidChats = Collections.synchronizedMap(new ReferenceMap<String, Chat>(ReferenceMap.HARD,
|
||||
ReferenceMap.WEAK));
|
||||
private Map<String, Chat> jidChats = Collections.synchronizedMap(new HashMap<String, Chat>());
|
||||
|
||||
/**
|
||||
* Maps base jids to chats
|
||||
*/
|
||||
private Map<String, Chat> baseJidChats = Collections.synchronizedMap(new ReferenceMap<String, Chat>(ReferenceMap.HARD,
|
||||
ReferenceMap.WEAK));
|
||||
private Map<String, Chat> baseJidChats = Collections.synchronizedMap(new HashMap<String, Chat>());
|
||||
|
||||
private Set<ChatManagerListener> chatManagerListeners
|
||||
= new CopyOnWriteArraySet<ChatManagerListener>();
|
||||
|
|
|
@ -16,8 +16,6 @@
|
|||
*/
|
||||
package org.jivesoftware.smack.util;
|
||||
|
||||
import org.jivesoftware.smack.util.collections.AbstractMapEntry;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
|
@ -675,4 +673,67 @@ public class Cache<K, V> implements Map<K, V> {
|
|||
return object.toString();
|
||||
}
|
||||
}
|
||||
|
||||
static class AbstractMapEntry<K, V> implements Map.Entry<K, V> {
|
||||
final K key;
|
||||
V value;
|
||||
|
||||
AbstractMapEntry(K key, V value) {
|
||||
this.key = key;
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public K getKey() {
|
||||
return key;
|
||||
}
|
||||
|
||||
@Override
|
||||
public V getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public V setValue(V value) {
|
||||
V answer = this.value;
|
||||
this.value = value;
|
||||
return answer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compares this Map Entry with another Map Entry.
|
||||
* <p/>
|
||||
* Implemented per API documentation of {@link java.util.Map.Entry#equals(Object)}
|
||||
*
|
||||
* @param obj the object to compare to
|
||||
* @return true if equal key and value
|
||||
*/
|
||||
@SuppressWarnings("rawtypes")
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (obj == this) {
|
||||
return true;
|
||||
}
|
||||
if (obj instanceof Map.Entry == false) {
|
||||
return false;
|
||||
}
|
||||
Map.Entry other = (Map.Entry) obj;
|
||||
return (getKey() == null ? other.getKey() == null : getKey().equals(other.getKey()))
|
||||
&& (getValue() == null ? other.getValue() == null : getValue().equals(
|
||||
other.getValue()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a hashCode compatible with the equals method.
|
||||
* <p/>
|
||||
* Implemented per API documentation of {@link java.util.Map.Entry#hashCode()}
|
||||
*
|
||||
* @return a suitable hash code
|
||||
*/
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return (getKey() == null ? 0 : getKey().hashCode())
|
||||
^ (getValue() == null ? 0 : getValue().hashCode());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,89 +0,0 @@
|
|||
/**
|
||||
*
|
||||
* Copyright 2004 The Apache Software Foundation
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jivesoftware.smack.util.collections;
|
||||
|
||||
import java.util.NoSuchElementException;
|
||||
|
||||
/**
|
||||
* Provides an implementation of an empty iterator.
|
||||
*
|
||||
* @author Matt Hall, John Watkinson, Stephen Colebourne
|
||||
* @version $Revision: 1.1 $ $Date: 2005/10/11 17:05:24 $
|
||||
* @since Commons Collections 3.1
|
||||
*/
|
||||
abstract class AbstractEmptyIterator <E> {
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
protected AbstractEmptyIterator() {
|
||||
super();
|
||||
}
|
||||
|
||||
public boolean hasNext() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public E next() {
|
||||
throw new NoSuchElementException("Iterator contains no elements");
|
||||
}
|
||||
|
||||
public boolean hasPrevious() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public E previous() {
|
||||
throw new NoSuchElementException("Iterator contains no elements");
|
||||
}
|
||||
|
||||
public int nextIndex() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public int previousIndex() {
|
||||
return -1;
|
||||
}
|
||||
|
||||
public void add(E obj) {
|
||||
throw new UnsupportedOperationException("add() not supported for empty Iterator");
|
||||
}
|
||||
|
||||
public void set(E obj) {
|
||||
throw new IllegalStateException("Iterator contains no elements");
|
||||
}
|
||||
|
||||
public void remove() {
|
||||
throw new IllegalStateException("Iterator contains no elements");
|
||||
}
|
||||
|
||||
public E getKey() {
|
||||
throw new IllegalStateException("Iterator contains no elements");
|
||||
}
|
||||
|
||||
public E getValue() {
|
||||
throw new IllegalStateException("Iterator contains no elements");
|
||||
}
|
||||
|
||||
public E setValue(E value) {
|
||||
throw new IllegalStateException("Iterator contains no elements");
|
||||
}
|
||||
|
||||
public void reset() {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
}
|
File diff suppressed because it is too large
Load diff
|
@ -1,80 +0,0 @@
|
|||
/**
|
||||
*
|
||||
* Copyright 2003-2004 The Apache Software Foundation
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jivesoftware.smack.util.collections;
|
||||
|
||||
|
||||
/**
|
||||
* Abstract pair class to assist with creating KeyValue and MapEntry implementations.
|
||||
*
|
||||
* @author James Strachan
|
||||
* @author Michael A. Smith
|
||||
* @author Neil O'Toole
|
||||
* @author Matt Hall, John Watkinson, Stephen Colebourne
|
||||
* @version $Revision: 1.1 $ $Date: 2005/10/11 17:05:32 $
|
||||
* @since Commons Collections 3.0
|
||||
*/
|
||||
public abstract class AbstractKeyValue <K,V> implements KeyValue<K, V> {
|
||||
|
||||
/**
|
||||
* The key
|
||||
*/
|
||||
protected K key;
|
||||
/**
|
||||
* The value
|
||||
*/
|
||||
protected V value;
|
||||
|
||||
/**
|
||||
* Constructs a new pair with the specified key and given value.
|
||||
*
|
||||
* @param key the key for the entry, may be null
|
||||
* @param value the value for the entry, may be null
|
||||
*/
|
||||
protected AbstractKeyValue(K key, V value) {
|
||||
super();
|
||||
this.key = key;
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the key from the pair.
|
||||
*
|
||||
* @return the key
|
||||
*/
|
||||
public K getKey() {
|
||||
return key;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the value from the pair.
|
||||
*
|
||||
* @return the value
|
||||
*/
|
||||
public V getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a debugging String view of the pair.
|
||||
*
|
||||
* @return a String view of the entry
|
||||
*/
|
||||
public String toString() {
|
||||
return new StringBuilder().append(getKey()).append('=').append(getValue()).toString();
|
||||
}
|
||||
|
||||
}
|
|
@ -1,89 +0,0 @@
|
|||
/**
|
||||
*
|
||||
* Copyright 2003-2004 The Apache Software Foundation
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jivesoftware.smack.util.collections;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Abstract Pair class to assist with creating correct Map Entry implementations.
|
||||
*
|
||||
* @author James Strachan
|
||||
* @author Michael A. Smith
|
||||
* @author Neil O'Toole
|
||||
* @author Matt Hall, John Watkinson, Stephen Colebourne
|
||||
* @version $Revision: 1.1 $ $Date: 2005/10/11 17:05:32 $
|
||||
* @since Commons Collections 3.0
|
||||
*/
|
||||
public abstract class AbstractMapEntry <K,V> extends AbstractKeyValue<K, V> implements Map.Entry<K, V> {
|
||||
|
||||
/**
|
||||
* Constructs a new entry with the given key and given value.
|
||||
*
|
||||
* @param key the key for the entry, may be null
|
||||
* @param value the value for the entry, may be null
|
||||
*/
|
||||
protected AbstractMapEntry(K key, V value) {
|
||||
super(key, value);
|
||||
}
|
||||
|
||||
// Map.Entry interface
|
||||
//-------------------------------------------------------------------------
|
||||
/**
|
||||
* Sets the value stored in this Map Entry.
|
||||
* <p/>
|
||||
* This Map Entry is not connected to a Map, so only the local data is changed.
|
||||
*
|
||||
* @param value the new value
|
||||
* @return the previous value
|
||||
*/
|
||||
public V setValue(V value) {
|
||||
V answer = this.value;
|
||||
this.value = value;
|
||||
return answer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compares this Map Entry with another Map Entry.
|
||||
* <p/>
|
||||
* Implemented per API documentation of {@link java.util.Map.Entry#equals(Object)}
|
||||
*
|
||||
* @param obj the object to compare to
|
||||
* @return true if equal key and value
|
||||
*/
|
||||
public boolean equals(Object obj) {
|
||||
if (obj == this) {
|
||||
return true;
|
||||
}
|
||||
if (obj instanceof Map.Entry == false) {
|
||||
return false;
|
||||
}
|
||||
Map.Entry other = (Map.Entry) obj;
|
||||
return (getKey() == null ? other.getKey() == null : getKey().equals(other.getKey())) && (getValue() == null ? other.getValue() == null : getValue().equals(other.getValue()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a hashCode compatible with the equals method.
|
||||
* <p/>
|
||||
* Implemented per API documentation of {@link java.util.Map.Entry#hashCode()}
|
||||
*
|
||||
* @return a suitable hash code
|
||||
*/
|
||||
public int hashCode() {
|
||||
return (getKey() == null ? 0 : getKey().hashCode()) ^ (getValue() == null ? 0 : getValue().hashCode());
|
||||
}
|
||||
|
||||
}
|
File diff suppressed because it is too large
Load diff
|
@ -1,65 +0,0 @@
|
|||
/**
|
||||
*
|
||||
* Copyright 2001-2004 The Apache Software Foundation
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jivesoftware.smack.util.collections;
|
||||
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* A restricted implementation of {@link java.util.Map.Entry} that prevents
|
||||
* the MapEntry contract from being broken.
|
||||
*
|
||||
* @author James Strachan
|
||||
* @author Michael A. Smith
|
||||
* @author Neil O'Toole
|
||||
* @author Matt Hall, John Watkinson, Stephen Colebourne
|
||||
* @version $Revision: 1.1 $ $Date: 2005/10/11 17:05:32 $
|
||||
* @since Commons Collections 3.0
|
||||
*/
|
||||
public final class DefaultMapEntry <K,V> extends AbstractMapEntry<K, V> {
|
||||
|
||||
/**
|
||||
* Constructs a new entry with the specified key and given value.
|
||||
*
|
||||
* @param key the key for the entry, may be null
|
||||
* @param value the value for the entry, may be null
|
||||
*/
|
||||
public DefaultMapEntry(final K key, final V value) {
|
||||
super(key, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a new entry from the specified KeyValue.
|
||||
*
|
||||
* @param pair the pair to copy, must not be null
|
||||
* @throws NullPointerException if the entry is null
|
||||
*/
|
||||
public DefaultMapEntry(final KeyValue<K, V> pair) {
|
||||
super(pair.getKey(), pair.getValue());
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a new entry from the specified MapEntry.
|
||||
*
|
||||
* @param entry the entry to copy, must not be null
|
||||
* @throws NullPointerException if the entry is null
|
||||
*/
|
||||
public DefaultMapEntry(final Map.Entry<K, V> entry) {
|
||||
super(entry.getKey(), entry.getValue());
|
||||
}
|
||||
|
||||
}
|
|
@ -1,58 +0,0 @@
|
|||
/**
|
||||
*
|
||||
* Copyright 2004 The Apache Software Foundation
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jivesoftware.smack.util.collections;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
/**
|
||||
* Provides an implementation of an empty iterator.
|
||||
* <p/>
|
||||
* This class provides an implementation of an empty iterator.
|
||||
* This class provides for binary compatability between Commons Collections
|
||||
* 2.1.1 and 3.1 due to issues with <code>IteratorUtils</code>.
|
||||
*
|
||||
* @author Matt Hall, John Watkinson, Stephen Colebourne
|
||||
* @version $Revision: 1.1 $ $Date: 2005/10/11 17:05:24 $
|
||||
* @since Commons Collections 2.1.1 and 3.1
|
||||
*/
|
||||
public class EmptyIterator <E> extends AbstractEmptyIterator<E> implements ResettableIterator<E> {
|
||||
|
||||
/**
|
||||
* Singleton instance of the iterator.
|
||||
*
|
||||
* @since Commons Collections 3.1
|
||||
*/
|
||||
public static final ResettableIterator RESETTABLE_INSTANCE = new EmptyIterator();
|
||||
/**
|
||||
* Singleton instance of the iterator.
|
||||
*
|
||||
* @since Commons Collections 2.1.1 and 3.1
|
||||
*/
|
||||
public static final Iterator INSTANCE = RESETTABLE_INSTANCE;
|
||||
|
||||
public static <T> Iterator<T> getInstance() {
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
protected EmptyIterator() {
|
||||
super();
|
||||
}
|
||||
|
||||
}
|
|
@ -1,42 +0,0 @@
|
|||
/**
|
||||
*
|
||||
* Copyright 2004 The Apache Software Foundation
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jivesoftware.smack.util.collections;
|
||||
|
||||
/**
|
||||
* Provides an implementation of an empty map iterator.
|
||||
*
|
||||
* @author Matt Hall, John Watkinson, Stephen Colebourne
|
||||
* @version $Revision: 1.1 $ $Date: 2005/10/11 17:05:24 $
|
||||
* @since Commons Collections 3.1
|
||||
*/
|
||||
public class EmptyMapIterator extends AbstractEmptyIterator implements MapIterator, ResettableIterator {
|
||||
|
||||
/**
|
||||
* Singleton instance of the iterator.
|
||||
*
|
||||
* @since Commons Collections 3.1
|
||||
*/
|
||||
public static final MapIterator INSTANCE = new EmptyMapIterator();
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
protected EmptyMapIterator() {
|
||||
super();
|
||||
}
|
||||
|
||||
}
|
|
@ -1,61 +0,0 @@
|
|||
/**
|
||||
*
|
||||
* Copyright 2003-2004 The Apache Software Foundation
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jivesoftware.smack.util.collections;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Defines a map that can be iterated directly without needing to create an entry set.
|
||||
* <p/>
|
||||
* A map iterator is an efficient way of iterating over maps.
|
||||
* There is no need to access the entry set or cast to Map Entry objects.
|
||||
* <pre>
|
||||
* IterableMap map = new HashedMap();
|
||||
* MapIterator it = map.mapIterator();
|
||||
* while (it.hasNext()) {
|
||||
* Object key = it.next();
|
||||
* Object value = it.getValue();
|
||||
* it.setValue("newValue");
|
||||
* }
|
||||
* </pre>
|
||||
*
|
||||
* @author Matt Hall, John Watkinson, Stephen Colebourne
|
||||
* @version $Revision: 1.1 $ $Date: 2005/10/11 17:05:19 $
|
||||
* @since Commons Collections 3.0
|
||||
*/
|
||||
public interface IterableMap <K,V> extends Map<K, V> {
|
||||
|
||||
/**
|
||||
* Obtains a <code>MapIterator</code> over the map.
|
||||
* <p/>
|
||||
* A map iterator is an efficient way of iterating over maps.
|
||||
* There is no need to access the entry set or cast to Map Entry objects.
|
||||
* <pre>
|
||||
* IterableMap map = new HashedMap();
|
||||
* MapIterator it = map.mapIterator();
|
||||
* while (it.hasNext()) {
|
||||
* Object key = it.next();
|
||||
* Object value = it.getValue();
|
||||
* it.setValue("newValue");
|
||||
* }
|
||||
* </pre>
|
||||
*
|
||||
* @return a map iterator
|
||||
*/
|
||||
MapIterator<K, V> mapIterator();
|
||||
|
||||
}
|
|
@ -1,46 +0,0 @@
|
|||
/**
|
||||
*
|
||||
* Copyright 2003-2004 The Apache Software Foundation
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jivesoftware.smack.util.collections;
|
||||
|
||||
/**
|
||||
* Defines a simple key value pair.
|
||||
* <p/>
|
||||
* A Map Entry has considerable additional semantics over and above a simple
|
||||
* key-value pair. This interface defines the minimum key value, with just the
|
||||
* two get methods.
|
||||
*
|
||||
* @author Matt Hall, John Watkinson, Stephen Colebourne
|
||||
* @version $Revision: 1.1 $ $Date: 2005/10/11 17:05:19 $
|
||||
* @since Commons Collections 3.0
|
||||
*/
|
||||
public interface KeyValue <K,V> {
|
||||
|
||||
/**
|
||||
* Gets the key from the pair.
|
||||
*
|
||||
* @return the key
|
||||
*/
|
||||
K getKey();
|
||||
|
||||
/**
|
||||
* Gets the value from the pair.
|
||||
*
|
||||
* @return the value
|
||||
*/
|
||||
V getValue();
|
||||
|
||||
}
|
|
@ -1,109 +0,0 @@
|
|||
/**
|
||||
*
|
||||
* Copyright 2003-2004 The Apache Software Foundation
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jivesoftware.smack.util.collections;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
/**
|
||||
* Defines an iterator that operates over a <code>Map</code>.
|
||||
* <p/>
|
||||
* This iterator is a special version designed for maps. It can be more
|
||||
* efficient to use this rather than an entry set iterator where the option
|
||||
* is available, and it is certainly more convenient.
|
||||
* <p/>
|
||||
* A map that provides this interface may not hold the data internally using
|
||||
* Map Entry objects, thus this interface can avoid lots of object creation.
|
||||
* <p/>
|
||||
* In use, this iterator iterates through the keys in the map. After each call
|
||||
* to <code>next()</code>, the <code>getValue()</code> method provides direct
|
||||
* access to the value. The value can also be set using <code>setValue()</code>.
|
||||
* <pre>
|
||||
* MapIterator it = map.mapIterator();
|
||||
* while (it.hasNext()) {
|
||||
* Object key = it.next();
|
||||
* Object value = it.getValue();
|
||||
* it.setValue(newValue);
|
||||
* }
|
||||
* </pre>
|
||||
*
|
||||
* @author Matt Hall, John Watkinson, Stephen Colebourne
|
||||
* @version $Revision: 1.1 $ $Date: 2005/10/11 17:05:19 $
|
||||
* @since Commons Collections 3.0
|
||||
*/
|
||||
public interface MapIterator <K,V> extends Iterator<K> {
|
||||
|
||||
/**
|
||||
* Checks to see if there are more entries still to be iterated.
|
||||
*
|
||||
* @return <code>true</code> if the iterator has more elements
|
||||
*/
|
||||
boolean hasNext();
|
||||
|
||||
/**
|
||||
* Gets the next <em>key</em> from the <code>Map</code>.
|
||||
*
|
||||
* @return the next key in the iteration
|
||||
* @throws java.util.NoSuchElementException
|
||||
* if the iteration is finished
|
||||
*/
|
||||
K next();
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
/**
|
||||
* Gets the current key, which is the key returned by the last call
|
||||
* to <code>next()</code>.
|
||||
*
|
||||
* @return the current key
|
||||
* @throws IllegalStateException if <code>next()</code> has not yet been called
|
||||
*/
|
||||
K getKey();
|
||||
|
||||
/**
|
||||
* Gets the current value, which is the value associated with the last key
|
||||
* returned by <code>next()</code>.
|
||||
*
|
||||
* @return the current value
|
||||
* @throws IllegalStateException if <code>next()</code> has not yet been called
|
||||
*/
|
||||
V getValue();
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
/**
|
||||
* Removes the last returned key from the underlying <code>Map</code> (optional operation).
|
||||
* <p/>
|
||||
* This method can be called once per call to <code>next()</code>.
|
||||
*
|
||||
* @throws UnsupportedOperationException if remove is not supported by the map
|
||||
* @throws IllegalStateException if <code>next()</code> has not yet been called
|
||||
* @throws IllegalStateException if <code>remove()</code> has already been called
|
||||
* since the last call to <code>next()</code>
|
||||
*/
|
||||
void remove();
|
||||
|
||||
/**
|
||||
* Sets the value associated with the current key (optional operation).
|
||||
*
|
||||
* @param value the new value
|
||||
* @return the previous value
|
||||
* @throws UnsupportedOperationException if setValue is not supported by the map
|
||||
* @throws IllegalStateException if <code>next()</code> has not yet been called
|
||||
* @throws IllegalStateException if <code>remove()</code> has been called since the
|
||||
* last call to <code>next()</code>
|
||||
*/
|
||||
V setValue(V value);
|
||||
|
||||
}
|
|
@ -1,161 +0,0 @@
|
|||
/**
|
||||
*
|
||||
* Copyright 2002-2004 The Apache Software Foundation
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jivesoftware.smack.util.collections;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.io.ObjectOutputStream;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* A <code>Map</code> implementation that allows mappings to be
|
||||
* removed by the garbage collector.
|
||||
* <p/>
|
||||
* When you construct a <code>ReferenceMap</code>, you can specify what kind
|
||||
* of references are used to store the map's keys and values.
|
||||
* If non-hard references are used, then the garbage collector can remove
|
||||
* mappings if a key or value becomes unreachable, or if the JVM's memory is
|
||||
* running low. For information on how the different reference types behave,
|
||||
* see {@link java.lang.ref.Reference}.
|
||||
* <p/>
|
||||
* Different types of references can be specified for keys and values.
|
||||
* The keys can be configured to be weak but the values hard,
|
||||
* in which case this class will behave like a
|
||||
* <a href="http://java.sun.com/j2se/1.4/docs/api/java/util/WeakHashMap.html">
|
||||
* <code>WeakHashMap</code></a>. However, you can also specify hard keys and
|
||||
* weak values, or any other combination. The default constructor uses
|
||||
* hard keys and soft values, providing a memory-sensitive cache.
|
||||
* <p/>
|
||||
* This map is similar to ReferenceIdentityMap.
|
||||
* It differs in that keys and values in this class are compared using <code>equals()</code>.
|
||||
* <p/>
|
||||
* This {@link java.util.Map} implementation does <i>not</i> allow null elements.
|
||||
* Attempting to add a null key or value to the map will raise a <code>NullPointerException</code>.
|
||||
* <p/>
|
||||
* This implementation is not synchronized.
|
||||
* You can use {@link java.util.Collections#synchronizedMap} to
|
||||
* provide synchronized access to a <code>ReferenceMap</code>.
|
||||
* Remember that synchronization will not stop the garbage collecter removing entries.
|
||||
* <p/>
|
||||
* All the available iterators can be reset back to the start by casting to
|
||||
* <code>ResettableIterator</code> and calling <code>reset()</code>.
|
||||
* <p/>
|
||||
* NOTE: As from Commons Collections 3.1 this map extends <code>AbstractReferenceMap</code>
|
||||
* (previously it extended AbstractMap). As a result, the implementation is now
|
||||
* extensible and provides a <code>MapIterator</code>.
|
||||
*
|
||||
* @author Paul Jack
|
||||
* @author Matt Hall, John Watkinson, Stephen Colebourne
|
||||
* @version $Revision: 1.1 $ $Date: 2005/10/11 17:05:32 $
|
||||
* @see java.lang.ref.Reference
|
||||
* @since Commons Collections 3.0 (previously in main package v2.1)
|
||||
*/
|
||||
public class ReferenceMap <K,V> extends AbstractReferenceMap<K, V> implements Serializable {
|
||||
|
||||
/**
|
||||
* Serialization version
|
||||
*/
|
||||
private static final long serialVersionUID = 1555089888138299607L;
|
||||
|
||||
/**
|
||||
* Constructs a new <code>ReferenceMap</code> that will
|
||||
* use hard references to keys and soft references to values.
|
||||
*/
|
||||
public ReferenceMap() {
|
||||
super(HARD, SOFT, DEFAULT_CAPACITY, DEFAULT_LOAD_FACTOR, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a new <code>ReferenceMap</code> that will
|
||||
* use the specified types of references.
|
||||
*
|
||||
* @param keyType the type of reference to use for keys;
|
||||
* must be {@link #HARD}, {@link #SOFT}, {@link #WEAK}
|
||||
* @param valueType the type of reference to use for values;
|
||||
* must be {@link #HARD}, {@link #SOFT}, {@link #WEAK}
|
||||
*/
|
||||
public ReferenceMap(int keyType, int valueType) {
|
||||
super(keyType, valueType, DEFAULT_CAPACITY, DEFAULT_LOAD_FACTOR, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a new <code>ReferenceMap</code> that will
|
||||
* use the specified types of references.
|
||||
*
|
||||
* @param keyType the type of reference to use for keys;
|
||||
* must be {@link #HARD}, {@link #SOFT}, {@link #WEAK}
|
||||
* @param valueType the type of reference to use for values;
|
||||
* must be {@link #HARD}, {@link #SOFT}, {@link #WEAK}
|
||||
* @param purgeValues should the value be automatically purged when the
|
||||
* key is garbage collected
|
||||
*/
|
||||
public ReferenceMap(int keyType, int valueType, boolean purgeValues) {
|
||||
super(keyType, valueType, DEFAULT_CAPACITY, DEFAULT_LOAD_FACTOR, purgeValues);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a new <code>ReferenceMap</code> with the
|
||||
* specified reference types, load factor and initial
|
||||
* capacity.
|
||||
*
|
||||
* @param keyType the type of reference to use for keys;
|
||||
* must be {@link #HARD}, {@link #SOFT}, {@link #WEAK}
|
||||
* @param valueType the type of reference to use for values;
|
||||
* must be {@link #HARD}, {@link #SOFT}, {@link #WEAK}
|
||||
* @param capacity the initial capacity for the map
|
||||
* @param loadFactor the load factor for the map
|
||||
*/
|
||||
public ReferenceMap(int keyType, int valueType, int capacity, float loadFactor) {
|
||||
super(keyType, valueType, capacity, loadFactor, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a new <code>ReferenceMap</code> with the
|
||||
* specified reference types, load factor and initial
|
||||
* capacity.
|
||||
*
|
||||
* @param keyType the type of reference to use for keys;
|
||||
* must be {@link #HARD}, {@link #SOFT}, {@link #WEAK}
|
||||
* @param valueType the type of reference to use for values;
|
||||
* must be {@link #HARD}, {@link #SOFT}, {@link #WEAK}
|
||||
* @param capacity the initial capacity for the map
|
||||
* @param loadFactor the load factor for the map
|
||||
* @param purgeValues should the value be automatically purged when the
|
||||
* key is garbage collected
|
||||
*/
|
||||
public ReferenceMap(int keyType, int valueType, int capacity, float loadFactor, boolean purgeValues) {
|
||||
super(keyType, valueType, capacity, loadFactor, purgeValues);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
/**
|
||||
* Write the map out using a custom routine.
|
||||
*/
|
||||
private void writeObject(ObjectOutputStream out) throws IOException {
|
||||
out.defaultWriteObject();
|
||||
doWriteObject(out);
|
||||
}
|
||||
|
||||
/**
|
||||
* Read the map in using a custom routine.
|
||||
*/
|
||||
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
|
||||
in.defaultReadObject();
|
||||
doReadObject(in);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,38 +0,0 @@
|
|||
/**
|
||||
*
|
||||
* Copyright 2003-2004 The Apache Software Foundation
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jivesoftware.smack.util.collections;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
/**
|
||||
* Defines an iterator that can be reset back to an initial state.
|
||||
* <p/>
|
||||
* This interface allows an iterator to be repeatedly reused.
|
||||
*
|
||||
* @author Matt Hall, John Watkinson, Stephen Colebourne
|
||||
* @version $Revision: 1.1 $ $Date: 2005/10/11 17:05:19 $
|
||||
* @since Commons Collections 3.0
|
||||
*/
|
||||
public interface ResettableIterator <E> extends Iterator<E> {
|
||||
|
||||
/**
|
||||
* Resets the iterator back to the position at which the iterator
|
||||
* was created.
|
||||
*/
|
||||
public void reset();
|
||||
|
||||
}
|
|
@ -26,20 +26,18 @@ import org.jivesoftware.smack.XMPPConnection;
|
|||
import org.jivesoftware.smack.Manager;
|
||||
import org.jivesoftware.smack.MessageListener;
|
||||
import org.jivesoftware.smack.PacketInterceptor;
|
||||
import org.jivesoftware.smack.XMPPException;
|
||||
import org.jivesoftware.smack.filter.NotFilter;
|
||||
import org.jivesoftware.smack.filter.PacketExtensionFilter;
|
||||
import org.jivesoftware.smack.filter.PacketFilter;
|
||||
import org.jivesoftware.smack.packet.Message;
|
||||
import org.jivesoftware.smack.packet.Packet;
|
||||
import org.jivesoftware.smack.packet.PacketExtension;
|
||||
import org.jivesoftware.smack.util.collections.ReferenceMap;
|
||||
import org.jivesoftware.smackx.chatstates.packet.ChatStateExtension;
|
||||
import org.jivesoftware.smackx.disco.ServiceDiscoveryManager;
|
||||
|
||||
/**
|
||||
* Handles chat state for all chats on a particular XMPPConnection. This class manages both the
|
||||
* packet extensions and the disco response neccesary for compliance with
|
||||
* packet extensions and the disco response necessary for compliance with
|
||||
* <a href="http://www.xmpp.org/extensions/xep-0085.html">XEP-0085</a>.
|
||||
*
|
||||
* NOTE: {@link org.jivesoftware.smackx.chatstates.ChatStateManager#getInstance(org.jivesoftware.smack.XMPPConnection)}
|
||||
|
@ -80,8 +78,7 @@ public class ChatStateManager extends Manager {
|
|||
/**
|
||||
* Maps chat to last chat state.
|
||||
*/
|
||||
private final Map<Chat, ChatState> chatStates =
|
||||
new ReferenceMap<Chat, ChatState>(ReferenceMap.WEAK, ReferenceMap.HARD);
|
||||
private final Map<Chat, ChatState> chatStates = new WeakHashMap<Chat, ChatState>();
|
||||
|
||||
private ChatStateManager(XMPPConnection connection) {
|
||||
super(connection);
|
||||
|
@ -100,11 +97,8 @@ public class ChatStateManager extends Manager {
|
|||
*
|
||||
* @param newState the new state of the chat
|
||||
* @param chat the chat.
|
||||
* @throws org.jivesoftware.smack.XMPPException
|
||||
* when there is an error sending the message
|
||||
* packet.
|
||||
*/
|
||||
public void setCurrentState(ChatState newState, Chat chat) throws XMPPException {
|
||||
public void setCurrentState(ChatState newState, Chat chat) {
|
||||
if(chat == null || newState == null) {
|
||||
throw new IllegalArgumentException("Arguments cannot be null.");
|
||||
}
|
||||
|
@ -133,7 +127,7 @@ public class ChatStateManager extends Manager {
|
|||
return connection().hashCode();
|
||||
}
|
||||
|
||||
private boolean updateChatState(Chat chat, ChatState newState) {
|
||||
private synchronized boolean updateChatState(Chat chat, ChatState newState) {
|
||||
ChatState lastChatState = chatStates.get(chat);
|
||||
if (lastChatState != newState) {
|
||||
chatStates.put(chat, newState);
|
||||
|
|
Loading…
Reference in a new issue