Fix up generics and other warnings
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/collections/trunk@966368 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
fb3daab4fd
commit
2d2aefe361
|
@ -127,7 +127,6 @@ public class CollectionUtils {
|
|||
* this purpose. However they could be cast to Set or List which might be
|
||||
* undesirable. This implementation only implements Collection.
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public static final Collection EMPTY_COLLECTION = UnmodifiableCollection.decorate(new ArrayList<Object>());
|
||||
|
||||
/**
|
||||
|
|
|
@ -876,35 +876,34 @@ public class IteratorUtils {
|
|||
* @param obj the object to convert to an iterator
|
||||
* @return a suitable iterator, never null
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public static Iterator<?> getIterator(Object obj) {
|
||||
if (obj == null) {
|
||||
return emptyIterator();
|
||||
}
|
||||
if (obj instanceof Iterator) {
|
||||
return (Iterator) obj;
|
||||
return (Iterator<?>) obj;
|
||||
}
|
||||
if (obj instanceof Collection) {
|
||||
return ((Collection) obj).iterator();
|
||||
return ((Collection<?>) obj).iterator();
|
||||
}
|
||||
if (obj instanceof Object[]) {
|
||||
return new ObjectArrayIterator((Object[]) obj);
|
||||
return new ObjectArrayIterator<Object>((Object[]) obj);
|
||||
}
|
||||
if (obj instanceof Enumeration) {
|
||||
return new EnumerationIterator((Enumeration) obj);
|
||||
return new EnumerationIterator<Object>((Enumeration<?>) obj);
|
||||
}
|
||||
if (obj instanceof Map) {
|
||||
return ((Map) obj).values().iterator();
|
||||
return ((Map<?, ?>) obj).values().iterator();
|
||||
}
|
||||
if (obj instanceof Dictionary) {
|
||||
return new EnumerationIterator(((Dictionary) obj).elements());
|
||||
return new EnumerationIterator<Object>(((Dictionary<?, ?>) obj).elements());
|
||||
} else if (obj.getClass().isArray()) {
|
||||
return new ArrayIterator(obj);
|
||||
return new ArrayIterator<Object>(obj);
|
||||
}
|
||||
try {
|
||||
Method method = obj.getClass().getMethod("iterator", (Class[]) null);
|
||||
if (Iterator.class.isAssignableFrom(method.getReturnType())) {
|
||||
Iterator it = (Iterator) method.invoke(obj, (Object[]) null);
|
||||
Iterator<?> it = (Iterator<?>) method.invoke(obj, (Object[]) null);
|
||||
if (it != null) {
|
||||
return it;
|
||||
}
|
||||
|
|
|
@ -138,12 +138,11 @@ public abstract class AbstractMapBag<E> implements Bag<E> {
|
|||
* @param coll the collection to check against
|
||||
* @return <code>true</code> if the Bag contains all the collection
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public boolean containsAll(Collection<?> coll) {
|
||||
if (coll instanceof Bag) {
|
||||
return containsAll((Bag<?>) coll);
|
||||
}
|
||||
return containsAll(new HashBag<Object>((Collection<Object>) coll));
|
||||
return containsAll(new HashBag<Object>(coll));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -208,7 +207,7 @@ public abstract class AbstractMapBag<E> implements Bag<E> {
|
|||
throw new ConcurrentModificationException();
|
||||
}
|
||||
if (itemCount == 0) {
|
||||
current = (Map.Entry<E, MutableInteger>) entryIterator.next();
|
||||
current = entryIterator.next();
|
||||
itemCount = current.getValue().value;
|
||||
}
|
||||
canRemove = true;
|
||||
|
@ -365,12 +364,11 @@ public abstract class AbstractMapBag<E> implements Bag<E> {
|
|||
* @param coll the collection to retain
|
||||
* @return true if this call changed the collection
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public boolean retainAll(Collection<?> coll) {
|
||||
if (coll instanceof Bag) {
|
||||
return retainAll((Bag<?>) coll);
|
||||
}
|
||||
return retainAll(new HashBag<Object>((Collection<Object>) coll));
|
||||
return retainAll(new HashBag<Object>(coll));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -190,11 +190,11 @@ public class DualTreeBidiMap<K, V> extends AbstractDualBidiMap<K, V> implements
|
|||
}
|
||||
|
||||
public SortedBidiMap<V, K> inverseSortedBidiMap() {
|
||||
return (SortedBidiMap<V, K>) inverseBidiMap();
|
||||
return inverseBidiMap();
|
||||
}
|
||||
|
||||
public OrderedBidiMap<V, K> inverseOrderedBidiMap() {
|
||||
return (OrderedBidiMap<V, K>) inverseBidiMap();
|
||||
return inverseBidiMap();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
@ -239,7 +239,7 @@ public class DualTreeBidiMap<K, V> extends AbstractDualBidiMap<K, V> implements
|
|||
// use the normalMap as the filtered map, but reverseMap as the full map
|
||||
// this forces containsValue and clear to be overridden
|
||||
super(new DualTreeBidiMap<K, V>(sm, bidi.reverseMap, bidi.inverseBidiMap));
|
||||
this.bidi = (DualTreeBidiMap<K, V>) decorated();
|
||||
this.bidi = decorated();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -280,12 +280,12 @@ public class DualTreeBidiMap<K, V> extends AbstractDualBidiMap<K, V> implements
|
|||
@Override
|
||||
public K previousKey(K key) {
|
||||
return decorated().previousKey(key);
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public K nextKey(K key) {
|
||||
return decorated().nextKey(key);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
|
|
@ -71,7 +71,6 @@ public class BlockingBuffer<E> extends SynchronizedBuffer<E> {
|
|||
/**
|
||||
* Factory method to create a blocking buffer with a timeout value.
|
||||
*
|
||||
* @param <t> the type of the elements in the buffer
|
||||
* @param buffer the buffer to decorate, must not be null
|
||||
* @param timeoutMillis the timeout value in milliseconds, zero or less for no timeout
|
||||
* @return a new blocking buffer
|
||||
|
|
|
@ -46,7 +46,6 @@ public class ComparableComparator<E extends Comparable<? super E>> implements Co
|
|||
private static final long serialVersionUID=-291439688585137865L;
|
||||
|
||||
/** The singleton instance. */
|
||||
@SuppressWarnings("unchecked")
|
||||
public static final ComparableComparator<?> INSTANCE = new ComparableComparator();
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
|
|
@ -220,7 +220,7 @@ public class FixedOrderComparator<T> implements Comparator<T> {
|
|||
* @return negative if obj1 is less, positive if greater, zero if equal
|
||||
* @throws IllegalArgumentException if obj1 or obj2 are not known
|
||||
* to this Comparator and an alternative behavior has not been set
|
||||
* via {@link #setUnknownObjectBehavior(int)}.
|
||||
* via {@link #setUnknownObjectBehavior(UnknownObjectBehavior)}.
|
||||
*/
|
||||
public int compare(T obj1, T obj2) {
|
||||
isLocked = true;
|
||||
|
|
|
@ -76,7 +76,7 @@ public class ChainedClosure<E> implements Closure<E>, Serializable {
|
|||
Closure<? super E>[] cmds = new Closure[closures.size()];
|
||||
int i = 0;
|
||||
for (Closure<? super E> closure : closures) {
|
||||
cmds[i++] = (Closure<E>) closure;
|
||||
cmds[i++] = closure;
|
||||
}
|
||||
FunctorUtils.validate(cmds);
|
||||
return new ChainedClosure<E>(cmds);
|
||||
|
|
|
@ -70,8 +70,8 @@ public class InstantiateTransformer<T> implements Transformer<Class<? extends T>
|
|||
if (paramTypes == null || paramTypes.length == 0) {
|
||||
return new InstantiateTransformer<T>();
|
||||
}
|
||||
paramTypes = (Class[]) paramTypes.clone();
|
||||
args = (Object[]) args.clone();
|
||||
paramTypes = paramTypes.clone();
|
||||
args = args.clone();
|
||||
return new InstantiateTransformer<T>(paramTypes, args);
|
||||
}
|
||||
|
||||
|
|
|
@ -77,8 +77,8 @@ public class InvokerTransformer<I, O> implements Transformer<I, O>, Serializable
|
|||
if (paramTypes == null || paramTypes.length == 0) {
|
||||
return new InvokerTransformer<I, O>(methodName);
|
||||
} else {
|
||||
paramTypes = (Class[]) paramTypes.clone();
|
||||
args = (Object[]) args.clone();
|
||||
paramTypes = paramTypes.clone();
|
||||
args = args.clone();
|
||||
return new InvokerTransformer<I, O>(methodName, paramTypes, args);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -74,7 +74,7 @@ public class EntrySetMapIterator<K, V> implements MapIterator<K, V>, ResettableI
|
|||
* @throws java.util.NoSuchElementException if the iteration is finished
|
||||
*/
|
||||
public K next() {
|
||||
last = (Map.Entry<K, V>) iterator.next();
|
||||
last = iterator.next();
|
||||
canRemove = true;
|
||||
return last.getKey();
|
||||
}
|
||||
|
|
|
@ -125,8 +125,7 @@ public class ListIteratorWrapper<E> implements ResettableListIterator<E> {
|
|||
*/
|
||||
public boolean hasPrevious() {
|
||||
if (iterator instanceof ListIterator) {
|
||||
@SuppressWarnings("unchecked")
|
||||
ListIterator li = (ListIterator) iterator;
|
||||
ListIterator<?> li = (ListIterator<?>) iterator;
|
||||
return li.hasPrevious();
|
||||
}
|
||||
return currentIndex > 0;
|
||||
|
@ -163,8 +162,7 @@ public class ListIteratorWrapper<E> implements ResettableListIterator<E> {
|
|||
*/
|
||||
public int nextIndex() {
|
||||
if (iterator instanceof ListIterator) {
|
||||
@SuppressWarnings("unchecked")
|
||||
ListIterator li = (ListIterator) iterator;
|
||||
ListIterator<?> li = (ListIterator<?>) iterator;
|
||||
return li.nextIndex();
|
||||
}
|
||||
return currentIndex;
|
||||
|
@ -197,8 +195,7 @@ public class ListIteratorWrapper<E> implements ResettableListIterator<E> {
|
|||
*/
|
||||
public int previousIndex() {
|
||||
if (iterator instanceof ListIterator) {
|
||||
@SuppressWarnings("unchecked")
|
||||
ListIterator li = (ListIterator) iterator;
|
||||
ListIterator<?> li = (ListIterator<?>) iterator;
|
||||
return li.previousIndex();
|
||||
}
|
||||
return currentIndex - 1;
|
||||
|
@ -255,8 +252,7 @@ public class ListIteratorWrapper<E> implements ResettableListIterator<E> {
|
|||
*/
|
||||
public void reset() {
|
||||
if (iterator instanceof ListIterator) {
|
||||
@SuppressWarnings("unchecked")
|
||||
ListIterator li = (ListIterator) iterator;
|
||||
ListIterator<?> li = (ListIterator<?>) iterator;
|
||||
while (li.previousIndex() >= 0) {
|
||||
li.previous();
|
||||
}
|
||||
|
|
|
@ -68,7 +68,6 @@ public abstract class AbstractMapEntry<K, V> extends AbstractKeyValue<K, V> impl
|
|||
* @return true if equal key and value
|
||||
*/
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public boolean equals(Object obj) {
|
||||
if (obj == this) {
|
||||
return true;
|
||||
|
@ -76,7 +75,7 @@ public abstract class AbstractMapEntry<K, V> extends AbstractKeyValue<K, V> impl
|
|||
if (obj instanceof Map.Entry == false) {
|
||||
return false;
|
||||
}
|
||||
Map.Entry other = (Map.Entry) obj;
|
||||
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()));
|
||||
|
|
|
@ -130,7 +130,6 @@ public class DefaultKeyValue<K, V> extends AbstractKeyValue<K, V> {
|
|||
* @return true if equal key and value
|
||||
*/
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public boolean equals(final Object obj) {
|
||||
if (obj == this) {
|
||||
return true;
|
||||
|
@ -139,7 +138,7 @@ public class DefaultKeyValue<K, V> extends AbstractKeyValue<K, V> {
|
|||
return false;
|
||||
}
|
||||
|
||||
DefaultKeyValue other = (DefaultKeyValue) obj;
|
||||
DefaultKeyValue<?, ?> other = (DefaultKeyValue<?, ?>) obj;
|
||||
return
|
||||
(getKey() == null ? other.getKey() == null : getKey().equals(other.getKey())) &&
|
||||
(getValue() == null ? other.getValue() == null : getValue().equals(other.getValue()));
|
||||
|
|
|
@ -174,7 +174,7 @@ public abstract class AbstractLinkedList<E> implements List<E> {
|
|||
public <T> T[] toArray(T[] array) {
|
||||
// Extend the array if needed
|
||||
if (array.length < size) {
|
||||
Class componentType = array.getClass().getComponentType();
|
||||
Class<?> componentType = array.getClass().getComponentType();
|
||||
array = (T[]) Array.newInstance(componentType, size);
|
||||
}
|
||||
// Copy the values into the array
|
||||
|
@ -326,7 +326,6 @@ public abstract class AbstractLinkedList<E> implements List<E> {
|
|||
|
||||
//-----------------------------------------------------------------------
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public boolean equals(Object obj) {
|
||||
if (obj == this) {
|
||||
return true;
|
||||
|
@ -334,12 +333,12 @@ public abstract class AbstractLinkedList<E> implements List<E> {
|
|||
if (obj instanceof List == false) {
|
||||
return false;
|
||||
}
|
||||
List other = (List) obj;
|
||||
List<?> other = (List<?>) obj;
|
||||
if (other.size() != size()) {
|
||||
return false;
|
||||
}
|
||||
ListIterator it1 = listIterator();
|
||||
ListIterator it2 = other.listIterator();
|
||||
ListIterator<?> it1 = listIterator();
|
||||
ListIterator<?> it2 = other.listIterator();
|
||||
while (it1.hasNext() && it2.hasNext()) {
|
||||
Object o1 = it1.next();
|
||||
Object o2 = it2.next();
|
||||
|
|
|
@ -307,7 +307,7 @@ public class SetUniqueList<E> extends AbstractSerializableListDecorator<E> {
|
|||
subSet = new HashSet<E>(list.size());
|
||||
} else {
|
||||
try {
|
||||
subSet = (Set<E>) set.getClass().newInstance();
|
||||
subSet = set.getClass().newInstance();
|
||||
} catch (InstantiationException ie) {
|
||||
subSet = new HashSet<E>();
|
||||
} catch (IllegalAccessException iae) {
|
||||
|
|
|
@ -634,16 +634,16 @@ public class AbstractHashedMap<K, V> extends AbstractMap<K, V> implements Iterab
|
|||
threshold = calculateThreshold(newCapacity, loadFactor);
|
||||
data = new HashEntry[newCapacity];
|
||||
} else {
|
||||
HashEntry oldEntries[] = data;
|
||||
HashEntry newEntries[] = new HashEntry[newCapacity];
|
||||
HashEntry<K, V> oldEntries[] = data;
|
||||
HashEntry<K, V> newEntries[] = new HashEntry[newCapacity];
|
||||
|
||||
modCount++;
|
||||
for (int i = oldCapacity - 1; i >= 0; i--) {
|
||||
HashEntry entry = oldEntries[i];
|
||||
HashEntry<K, V> entry = oldEntries[i];
|
||||
if (entry != null) {
|
||||
oldEntries[i] = null; // gc
|
||||
do {
|
||||
HashEntry next = entry.next;
|
||||
HashEntry<K, V> next = entry.next;
|
||||
int index = hashIndex(entry.hashCode, newCapacity);
|
||||
entry.next = newEntries[index];
|
||||
newEntries[index] = entry;
|
||||
|
@ -1305,7 +1305,6 @@ public class AbstractHashedMap<K, V> extends AbstractMap<K, V> implements Iterab
|
|||
* @return true if equal
|
||||
*/
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public boolean equals(Object obj) {
|
||||
if (obj == this) {
|
||||
return true;
|
||||
|
|
|
@ -658,7 +658,6 @@ public abstract class AbstractReferenceMap<K, V> extends AbstractHashedMap<K, V>
|
|||
* @return true if equal, false if not
|
||||
*/
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public boolean equals(Object obj) {
|
||||
if (obj == this) {
|
||||
return true;
|
||||
|
@ -667,7 +666,7 @@ public abstract class AbstractReferenceMap<K, V> extends AbstractHashedMap<K, V>
|
|||
return false;
|
||||
}
|
||||
|
||||
Map.Entry entry = (Map.Entry)obj;
|
||||
Map.Entry<?, ?> entry = (Map.Entry<?, ?>)obj;
|
||||
Object entryKey = entry.getKey(); // convert to hard reference
|
||||
Object entryValue = entry.getValue(); // convert to hard reference
|
||||
if ((entryKey == null) || (entryValue == null)) {
|
||||
|
|
|
@ -105,13 +105,13 @@ public abstract class AbstractSortedMapDecorator<K, V> extends AbstractMapDecora
|
|||
public K previousKey(K key) {
|
||||
SortedMap<K, V> headMap = headMap(key);
|
||||
return headMap.isEmpty() ? null : headMap.lastKey();
|
||||
};
|
||||
}
|
||||
|
||||
public K nextKey(K key) {
|
||||
Iterator<K> it = tailMap(key).keySet().iterator();
|
||||
it.next();
|
||||
return it.hasNext() ? it.next() : null;
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
|
|
|
@ -464,10 +464,9 @@ public class CompositeMap<K, V> extends AbstractIterableMap<K, V> implements Ser
|
|||
* @return true if the maps are equal
|
||||
*/
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public boolean equals(Object obj) {
|
||||
if (obj instanceof Map) {
|
||||
Map map = (Map) obj;
|
||||
Map<?, ?> map = (Map<?, ?>) obj;
|
||||
return (this.entrySet().equals(map.entrySet()));
|
||||
}
|
||||
return false;
|
||||
|
|
|
@ -179,7 +179,7 @@ public class DefaultedMap<K, V> extends AbstractMapDecorator<K, V> implements Se
|
|||
@SuppressWarnings("unchecked")
|
||||
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
|
||||
in.defaultReadObject();
|
||||
map = (Map) in.readObject();
|
||||
map = (Map<K, V>) in.readObject();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
|
|
@ -69,7 +69,7 @@ public class EntrySetToMapIteratorAdapter<K, V> implements MapIterator<K, V>, Re
|
|||
*/
|
||||
public V setValue(V value) {
|
||||
return current().setValue(value);
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
|
|
|
@ -1053,7 +1053,7 @@ public class Flat3Map<K, V> implements IterableMap<K, V>, Serializable, Cloneabl
|
|||
try {
|
||||
Flat3Map<K, V> cloned = (Flat3Map<K, V>) super.clone();
|
||||
if (cloned.delegateMap != null) {
|
||||
cloned.delegateMap = (HashedMap<K, V>) cloned.delegateMap.clone();
|
||||
cloned.delegateMap = cloned.delegateMap.clone();
|
||||
}
|
||||
return cloned;
|
||||
} catch (CloneNotSupportedException ex) {
|
||||
|
|
|
@ -173,7 +173,7 @@ public class LazyMap<K, V> extends AbstractMapDecorator<K, V> implements Map<K,
|
|||
@SuppressWarnings("unchecked")
|
||||
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
|
||||
in.defaultReadObject();
|
||||
map = (Map) in.readObject();
|
||||
map = (Map<K, V>) in.readObject();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
|
|
@ -279,7 +279,7 @@ public class MultiValueMap<K, V> extends AbstractMapDecorator<K, Object> impleme
|
|||
}
|
||||
} else {
|
||||
for (Map.Entry<? extends K, ?> entry : map.entrySet()) {
|
||||
put(entry.getKey(), (V) entry.getValue());
|
||||
put(entry.getKey(), entry.getValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -197,7 +197,7 @@ public class TransformedMap<K, V>
|
|||
Map<K, V> result = new LinkedMap<K, V>(map.size());
|
||||
|
||||
for (Map.Entry<? extends K, ? extends V> entry : map.entrySet()) {
|
||||
result.put((K) transformKey(entry.getKey()), transformValue(entry.getValue()));
|
||||
result.put(transformKey(entry.getKey()), transformValue(entry.getValue()));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
|
|
@ -164,10 +164,9 @@ public class CompositeSet<E> extends CompositeCollection<E> implements Set<E> {
|
|||
* @see Set#equals
|
||||
*/
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public boolean equals(Object obj) {
|
||||
if (obj instanceof Set) {
|
||||
Set set = (Set) obj;
|
||||
Set<?> set = (Set<?>) obj;
|
||||
return set.containsAll(this) && set.size() == this.size();
|
||||
}
|
||||
return false;
|
||||
|
|
|
@ -184,7 +184,7 @@ public class TransformedMap<J, K, U, V> extends AbstractIterableGetMapDecorator<
|
|||
Map<K, V> result = new LinkedMap<K, V>(map.size());
|
||||
|
||||
for (Map.Entry<? extends J, ? extends U> entry : map.entrySet()) {
|
||||
result.put((K) transformKey(entry.getKey()), transformValue(entry.getValue()));
|
||||
result.put(transformKey(entry.getKey()), transformValue(entry.getValue()));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue