[COLLECTIONS-312] Apply remaining changes from patch.

git-svn-id: https://svn.apache.org/repos/asf/commons/proper/collections/trunk@1443602 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Thomas Neidhart 2013-02-07 17:00:23 +00:00
parent 8411797028
commit c6f0df6546
9 changed files with 28 additions and 26 deletions

View File

@ -370,15 +370,13 @@ public class ClosureUtils {
*/
@SuppressWarnings("unchecked")
public static <E> Closure<E> switchMapClosure(final Map<? extends E, Closure<E>> objectsAndClosures) {
Closure<? super E>[] trs = null;
Predicate<E>[] preds = null;
if (objectsAndClosures == null) {
throw new IllegalArgumentException("The object and closure map must not be null");
}
final Closure<? super E> def = objectsAndClosures.remove(null);
final int size = objectsAndClosures.size();
trs = new Closure[size];
preds = new Predicate[size];
final Closure<? super E>[] trs = new Closure[size];
final Predicate<E>[] preds = new Predicate[size];
int i = 0;
for (final Map.Entry<? extends E, Closure<E>> entry : objectsAndClosures.entrySet()) {
preds[i] = EqualPredicate.<E>equalPredicate(entry.getKey());

View File

@ -97,7 +97,8 @@ public class CollectionUtils {
elements = new HashSet<O>();
addAll(elements, a);
addAll(elements, b);
newList = new ArrayList<O>();
// the resulting list must contain at least each unique element, but may grow
newList = new ArrayList<O>(elements.size());
}
public Iterator<O> iterator() {

View File

@ -1071,7 +1071,7 @@ public class ExtendedProperties extends Hashtable<String, Object> {
if (defaults != null) {
return defaults.getVector(key, defaultValue);
} else {
return defaultValue == null ? new Vector<String>() : defaultValue;
return defaultValue == null ? new Vector<String>(1) : defaultValue;
}
} else {
throw new ClassCastException('\'' + key + "' doesn't map to a Vector object");
@ -1125,7 +1125,7 @@ public class ExtendedProperties extends Hashtable<String, Object> {
if (defaults != null) {
return defaults.getList(key, defaultValue);
} else {
return defaultValue == null ? new ArrayList<String>() : defaultValue;
return defaultValue == null ? new ArrayList<String>(1) : defaultValue;
}
} else {
throw new ClassCastException('\'' + key + "' doesn't map to a List object");

View File

@ -342,15 +342,13 @@ public class TransformerUtils {
public static <I, O> Transformer<I, O> switchMapTransformer(
final Map<I, Transformer<I, O>> objectsAndTransformers) {
Transformer<? super I, ? extends O>[] trs = null;
Predicate<I>[] preds = null;
if (objectsAndTransformers == null) {
throw new IllegalArgumentException("The object and transformer map must not be null");
}
final Transformer<? super I, ? extends O> def = objectsAndTransformers.remove(null);
final int size = objectsAndTransformers.size();
trs = new Transformer[size];
preds = new Predicate[size];
final Transformer<? super I, ? extends O>[] trs = new Transformer[size];
final Predicate<I>[] preds = new Predicate[size];
int i = 0;
for (final Map.Entry<I, Transformer<I, O>> entry : objectsAndTransformers.entrySet()) {
preds[i] = EqualPredicate.<I>equalPredicate(entry.getKey());

View File

@ -661,8 +661,7 @@ public abstract class AbstractDualBidiMap<K, V> implements BidiMap<K, V> {
"Cannot use setValue() when the object being set is already in the map");
}
parent.put(key, value);
final V oldValue = super.setValue(value);
return oldValue;
return super.setValue(value);
}
}

View File

@ -100,8 +100,7 @@ public class DualHashBidiMap<K, V> extends AbstractDualBidiMap<K, V> implements
normalMap = new HashMap<K, V>();
reverseMap = new HashMap<V, K>();
@SuppressWarnings("unchecked") // will fail at runtime if stream is incorrect
final
Map<K, V> map = (Map<K, V>) in.readObject();
final Map<K, V> map = (Map<K, V>) in.readObject();
putAll(map);
}

View File

@ -193,7 +193,7 @@ public class SynchronizedCollection<E> implements Collection<E>, Serializable {
if (object == this) {
return true;
}
return decorated().equals(object);
return object == this || decorated().equals(object);
}
}

View File

@ -386,7 +386,7 @@ public abstract class AbstractLinkedList<E> implements List<E> {
return "[]";
}
final StringBuilder buf = new StringBuilder(16 * size());
buf.append("[");
buf.append('[');
final Iterator<E> it = iterator();
boolean hasNext = it.hasNext();
@ -398,7 +398,7 @@ public abstract class AbstractLinkedList<E> implements List<E> {
buf.append(", ");
}
}
buf.append("]");
buf.append(']');
return buf.toString();
}

View File

@ -420,8 +420,6 @@ public class TreeList<E> extends AbstractList<E> {
}
private AVLNode<E> insertOnLeft(final int indexRelativeToMe, final E obj) {
AVLNode<E> ret = this;
if (getLeftSubTree() == null) {
setLeft(new AVLNode<E>(-1, obj, this, left), null);
} else {
@ -431,14 +429,12 @@ public class TreeList<E> extends AbstractList<E> {
if (relativePosition >= 0) {
relativePosition++;
}
ret = balance();
AVLNode<E> ret = balance();
recalcHeight();
return ret;
}
private AVLNode<E> insertOnRight(final int indexRelativeToMe, final E obj) {
AVLNode<E> ret = this;
if (getRightSubTree() == null) {
setRight(new AVLNode<E>(+1, obj, right, this), null);
} else {
@ -447,7 +443,7 @@ public class TreeList<E> extends AbstractList<E> {
if (relativePosition < 0) {
relativePosition--;
}
ret = balance();
AVLNode<E> ret = balance();
recalcHeight();
return ret;
}
@ -777,8 +773,19 @@ public class TreeList<E> extends AbstractList<E> {
*/
@Override
public String toString() {
return "AVLNode(" + relativePosition + "," + (left != null) + "," + value +
"," + (getRightSubTree() != null) + ", faedelung " + rightIsNext + " )";
return new StringBuilder()
.append("AVLNode(")
.append(relativePosition)
.append(',')
.append(left != null)
.append(',')
.append(value)
.append(',')
.append(getRightSubTree() != null)
.append(", faedelung ")
.append(rightIsNext)
.append(" )")
.toString();
}
}