mirror of
https://github.com/Eaglercraft-TeaVM-Fork/eagler-teavm.git
synced 2025-01-09 08:24:10 -08:00
Fixes some tests on java.util.TreeMap. Fixes tests code style
This commit is contained in:
parent
56012d1a9f
commit
6c599c2886
|
@ -75,7 +75,7 @@ public class SystemNativeGenerator implements Generator, DependencyPlugin {
|
||||||
String destPos = context.getParameterName(4);
|
String destPos = context.getParameterName(4);
|
||||||
String length = context.getParameterName(5);
|
String length = context.getParameterName(5);
|
||||||
writer.append("for (var i = 0; i < " + length + "; i = (i + 1) | 0) {").indent().softNewLine();
|
writer.append("for (var i = 0; i < " + length + "; i = (i + 1) | 0) {").indent().softNewLine();
|
||||||
writer.append(dest + ".data[" + srcPos + "++] = " + src + ".data[" + destPos + "++];").softNewLine();
|
writer.append(dest + ".data[" + destPos + "++] = " + src + ".data[" + srcPos + "++];").softNewLine();
|
||||||
writer.outdent().append("}").softNewLine();
|
writer.outdent().append("}").softNewLine();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -34,15 +34,6 @@ package org.teavm.classlib.java.util;
|
||||||
import org.teavm.classlib.java.io.TSerializable;
|
import org.teavm.classlib.java.io.TSerializable;
|
||||||
import org.teavm.classlib.java.lang.*;
|
import org.teavm.classlib.java.lang.*;
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* TreeMap is an implementation of SortedMap. All optional operations (adding
|
|
||||||
* and removing) are supported. The values can be any objects. The keys can be
|
|
||||||
* any objects which are comparable to each other either using their natural
|
|
||||||
* order or a specified Comparator.
|
|
||||||
*
|
|
||||||
* @since 1.2
|
|
||||||
*/
|
|
||||||
public class TTreeMap<K, V> extends TAbstractMap<K, V> implements TSortedMap<K, V>, TCloneable, TSerializable {
|
public class TTreeMap<K, V> extends TAbstractMap<K, V> implements TSortedMap<K, V>, TCloneable, TSerializable {
|
||||||
transient int size;
|
transient int size;
|
||||||
private TComparator<? super K> comparator;
|
private TComparator<? super K> comparator;
|
||||||
|
@ -79,8 +70,7 @@ public class TTreeMap<K, V> extends TAbstractMap<K, V> implements TSortedMap<K,
|
||||||
Entry<?, ?> entry = (Entry<?, ?>) object;
|
Entry<?, ?> entry = (Entry<?, ?>) object;
|
||||||
V value = getValue();
|
V value = getValue();
|
||||||
return (key == null ? entry.getKey() == null : key.equals(entry.getKey()))
|
return (key == null ? entry.getKey() == null : key.equals(entry.getKey()))
|
||||||
&& (value == null ? entry.getValue() == null : value
|
&& (value == null ? entry.getValue() == null : value.equals(entry.getValue()));
|
||||||
.equals(entry.getValue()));
|
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -513,8 +503,7 @@ public class TTreeMap<K, V> extends TAbstractMap<K, V> implements TSortedMap<K,
|
||||||
if (firstKeyModCount == backingMap.modCount) {
|
if (firstKeyModCount == backingMap.modCount) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
TComparable<K> object = backingMap.comparator == null ?
|
TComparable<K> object = backingMap.comparator == null ? toComparable(startKey) : null;
|
||||||
toComparable(startKey) : null;
|
|
||||||
K key = startKey;
|
K key = startKey;
|
||||||
Node<K, V> node = backingMap.root;
|
Node<K, V> node = backingMap.root;
|
||||||
Node<K, V> foundNode = null;
|
Node<K, V> foundNode = null;
|
||||||
|
@ -972,45 +961,17 @@ public class TTreeMap<K, V> extends TAbstractMap<K, V> implements TSortedMap<K,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Constructs a new empty {@code TreeMap} instance.
|
|
||||||
*/
|
|
||||||
public TTreeMap() {
|
public TTreeMap() {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Constructs a new empty {@code TreeMap} instance with the specified
|
|
||||||
* comparator.
|
|
||||||
*
|
|
||||||
* @param comparator
|
|
||||||
* the comparator to compare keys with.
|
|
||||||
*/
|
|
||||||
public TTreeMap(TComparator<? super K> comparator) {
|
public TTreeMap(TComparator<? super K> comparator) {
|
||||||
this.comparator = comparator;
|
this.comparator = comparator;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Constructs a new {@code TreeMap} instance containing the mappings from
|
|
||||||
* the specified map and using natural ordering.
|
|
||||||
*
|
|
||||||
* @param map
|
|
||||||
* the mappings to add.
|
|
||||||
* @throws ClassCastException
|
|
||||||
* if a key in the specified map does not implement the
|
|
||||||
* Comparable interface, or if the keys in the map cannot be
|
|
||||||
* compared.
|
|
||||||
*/
|
|
||||||
public TTreeMap(TMap<? extends K, ? extends V> map) {
|
public TTreeMap(TMap<? extends K, ? extends V> map) {
|
||||||
putAll(map);
|
putAll(map);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Constructs a new {@code TreeMap} instance containing the mappings from
|
|
||||||
* the specified SortedMap and using the same comparator.
|
|
||||||
*
|
|
||||||
* @param map
|
|
||||||
* the mappings to add.
|
|
||||||
*/
|
|
||||||
public TTreeMap(TSortedMap<K, ? extends V> map) {
|
public TTreeMap(TSortedMap<K, ? extends V> map) {
|
||||||
this(map.comparator());
|
this(map.comparator());
|
||||||
Node<K, V> lastNode = null;
|
Node<K, V> lastNode = null;
|
||||||
|
@ -1038,12 +999,6 @@ public class TTreeMap<K, V> extends TAbstractMap<K, V> implements TSortedMap<K,
|
||||||
return last;
|
return last;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Removes all mappings from this TreeMap, leaving it empty.
|
|
||||||
*
|
|
||||||
* @see Map#isEmpty()
|
|
||||||
* @see #size()
|
|
||||||
*/
|
|
||||||
@Override
|
@Override
|
||||||
public void clear() {
|
public void clear() {
|
||||||
root = null;
|
root = null;
|
||||||
|
@ -1051,13 +1006,6 @@ public class TTreeMap<K, V> extends TAbstractMap<K, V> implements TSortedMap<K,
|
||||||
modCount++;
|
modCount++;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns a new {@code TreeMap} with the same mappings, size and comparator
|
|
||||||
* as this instance.
|
|
||||||
*
|
|
||||||
* @return a shallow copy of this instance.
|
|
||||||
* @see java.lang.Cloneable
|
|
||||||
*/
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
@Override
|
@Override
|
||||||
public TObject clone() {
|
public TObject clone() {
|
||||||
|
@ -1095,30 +1043,11 @@ public class TTreeMap<K, V> extends TAbstractMap<K, V> implements TSortedMap<K,
|
||||||
return y;
|
return y;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the comparator used to compare elements in this map.
|
|
||||||
*
|
|
||||||
* @return the comparator or {@code null} if the natural ordering is used.
|
|
||||||
*/
|
|
||||||
@Override
|
@Override
|
||||||
public TComparator<? super K> comparator() {
|
public TComparator<? super K> comparator() {
|
||||||
return comparator;
|
return comparator;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns whether this map contains the specified key.
|
|
||||||
*
|
|
||||||
* @param key
|
|
||||||
* the key to search for.
|
|
||||||
* @return {@code true} if this map contains the specified key,
|
|
||||||
* {@code false} otherwise.
|
|
||||||
* @throws ClassCastException
|
|
||||||
* if the specified key cannot be compared with the keys in this
|
|
||||||
* map.
|
|
||||||
* @throws NullPointerException
|
|
||||||
* if the specified key is {@code null} and the comparator
|
|
||||||
* cannot handle {@code null} keys.
|
|
||||||
*/
|
|
||||||
@Override
|
@Override
|
||||||
public boolean containsKey(Object key) {
|
public boolean containsKey(Object key) {
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
|
@ -1163,14 +1092,6 @@ public class TTreeMap<K, V> extends TAbstractMap<K, V> implements TSortedMap<K,
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns whether this map contains the specified value.
|
|
||||||
*
|
|
||||||
* @param value
|
|
||||||
* the value to search for.
|
|
||||||
* @return {@code true} if this map contains the specified value,
|
|
||||||
* {@code false} otherwise.
|
|
||||||
*/
|
|
||||||
@Override
|
@Override
|
||||||
public boolean containsValue(Object value) {
|
public boolean containsValue(Object value) {
|
||||||
if (root == null) {
|
if (root == null) {
|
||||||
|
@ -1203,14 +1124,6 @@ public class TTreeMap<K, V> extends TAbstractMap<K, V> implements TSortedMap<K,
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns a set containing all of the mappings in this map. Each mapping is
|
|
||||||
* an instance of {@link Map.Entry}. As the set is backed by this map,
|
|
||||||
* changes in one will be reflected in the other. It does not support adding
|
|
||||||
* operations.
|
|
||||||
*
|
|
||||||
* @return a set of the mappings.
|
|
||||||
*/
|
|
||||||
@Override
|
@Override
|
||||||
public TSet<Entry<K, V>> entrySet() {
|
public TSet<Entry<K, V>> entrySet() {
|
||||||
if (entrySet == null) {
|
if (entrySet == null) {
|
||||||
|
@ -1258,13 +1171,6 @@ public class TTreeMap<K, V> extends TAbstractMap<K, V> implements TSortedMap<K,
|
||||||
return entrySet;
|
return entrySet;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the first key in this map.
|
|
||||||
*
|
|
||||||
* @return the first key in this map.
|
|
||||||
* @throws NoSuchElementException
|
|
||||||
* if this map is empty.
|
|
||||||
*/
|
|
||||||
@Override
|
@Override
|
||||||
public K firstKey() {
|
public K firstKey() {
|
||||||
if (root != null) {
|
if (root != null) {
|
||||||
|
@ -1275,18 +1181,6 @@ public class TTreeMap<K, V> extends TAbstractMap<K, V> implements TSortedMap<K,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the value of the mapping with the specified key.
|
|
||||||
*
|
|
||||||
* @param key
|
|
||||||
* the key.
|
|
||||||
* @return the value of the mapping with the specified key.
|
|
||||||
* @throws ClassCastException
|
|
||||||
* if the key cannot be compared with the keys in this map.
|
|
||||||
* @throws NullPointerException
|
|
||||||
* if the key is {@code null} and the comparator cannot handle
|
|
||||||
* {@code null}.
|
|
||||||
*/
|
|
||||||
@Override
|
@Override
|
||||||
public V get(Object key) {
|
public V get(Object key) {
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
|
@ -1332,31 +1226,9 @@ public class TTreeMap<K, V> extends TAbstractMap<K, V> implements TSortedMap<K,
|
||||||
}
|
}
|
||||||
|
|
||||||
private int cmp(TComparable<K> object, K key1, K key2) {
|
private int cmp(TComparable<K> object, K key1, K key2) {
|
||||||
return object != null ?
|
return object != null ? object.compareTo(key2) : comparator.compare(key1, key2);
|
||||||
object.compareTo(key2) : comparator.compare(key1, key2);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns a sorted map over a range of this sorted map with all keys that
|
|
||||||
* are less than the specified {@code endKey}. Changes to the returned
|
|
||||||
* sorted map are reflected in this sorted map and vice versa.
|
|
||||||
* <p>
|
|
||||||
* Note: The returned map will not allow an insertion of a key outside the
|
|
||||||
* specified range.
|
|
||||||
*
|
|
||||||
* @param endKey
|
|
||||||
* the high boundary of the range specified.
|
|
||||||
* @return a sorted map where the keys are less than {@code endKey}.
|
|
||||||
* @throws ClassCastException
|
|
||||||
* if the specified key cannot be compared with the keys in this
|
|
||||||
* map.
|
|
||||||
* @throws NullPointerException
|
|
||||||
* if the specified key is {@code null} and the comparator
|
|
||||||
* cannot handle {@code null} keys.
|
|
||||||
* @throws IllegalArgumentException
|
|
||||||
* if this map is itself a sorted map over a range of another
|
|
||||||
* map and the specified key is outside of its range.
|
|
||||||
*/
|
|
||||||
@Override
|
@Override
|
||||||
public TSortedMap<K, V> headMap(K endKey) {
|
public TSortedMap<K, V> headMap(K endKey) {
|
||||||
// Check for errors
|
// Check for errors
|
||||||
|
@ -1368,13 +1240,6 @@ public class TTreeMap<K, V> extends TAbstractMap<K, V> implements TSortedMap<K,
|
||||||
return new SubMap<>(this, endKey);
|
return new SubMap<>(this, endKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns a set of the keys contained in this map. The set is backed by
|
|
||||||
* this map so changes to one are reflected by the other. The set does not
|
|
||||||
* support adding.
|
|
||||||
*
|
|
||||||
* @return a set of the keys.
|
|
||||||
*/
|
|
||||||
@Override
|
@Override
|
||||||
public TSet<K> keySet() {
|
public TSet<K> keySet() {
|
||||||
if (cachedKeySet == null) {
|
if (cachedKeySet == null) {
|
||||||
|
@ -1412,13 +1277,6 @@ public class TTreeMap<K, V> extends TAbstractMap<K, V> implements TSortedMap<K,
|
||||||
return cachedKeySet;
|
return cachedKeySet;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the last key in this map.
|
|
||||||
*
|
|
||||||
* @return the last key in this map.
|
|
||||||
* @throws NoSuchElementException
|
|
||||||
* if this map is empty.
|
|
||||||
*/
|
|
||||||
@Override
|
@Override
|
||||||
public K lastKey() {
|
public K lastKey() {
|
||||||
if (root != null) {
|
if (root != null) {
|
||||||
|
@ -1448,22 +1306,6 @@ public class TTreeMap<K, V> extends TAbstractMap<K, V> implements TSortedMap<K,
|
||||||
return x;
|
return x;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Maps the specified key to the specified value.
|
|
||||||
*
|
|
||||||
* @param key
|
|
||||||
* the key.
|
|
||||||
* @param value
|
|
||||||
* the value.
|
|
||||||
* @return the value of any previous mapping with the specified key or
|
|
||||||
* {@code null} if there was no mapping.
|
|
||||||
* @throws ClassCastException
|
|
||||||
* if the specified key cannot be compared with the keys in this
|
|
||||||
* map.
|
|
||||||
* @throws NullPointerException
|
|
||||||
* if the specified key is {@code null} and the comparator
|
|
||||||
* cannot handle {@code null} keys.
|
|
||||||
*/
|
|
||||||
@Override
|
@Override
|
||||||
public V put(K key, V value) {
|
public V put(K key, V value) {
|
||||||
if (root == null) {
|
if (root == null) {
|
||||||
|
@ -1827,40 +1669,11 @@ public class TTreeMap<K, V> extends TAbstractMap<K, V> implements TSortedMap<K,
|
||||||
x.parent = y;
|
x.parent = y;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Copies all the mappings in the given map to this map. These mappings will
|
|
||||||
* replace all mappings that this map had for any of the keys currently in
|
|
||||||
* the given map.
|
|
||||||
*
|
|
||||||
* @param map
|
|
||||||
* the map to copy mappings from.
|
|
||||||
* @throws ClassCastException
|
|
||||||
* if a key in the specified map cannot be compared with the
|
|
||||||
* keys in this map.
|
|
||||||
* @throws NullPointerException
|
|
||||||
* if a key in the specified map is {@code null} and the
|
|
||||||
* comparator cannot handle {@code null} keys.
|
|
||||||
*/
|
|
||||||
@Override
|
@Override
|
||||||
public void putAll(TMap<? extends K, ? extends V> map) {
|
public void putAll(TMap<? extends K, ? extends V> map) {
|
||||||
super.putAll(map);
|
super.putAll(map);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Removes the mapping with the specified key from this map.
|
|
||||||
*
|
|
||||||
* @param key
|
|
||||||
* the key of the mapping to remove.
|
|
||||||
* @return the value of the removed mapping or {@code null} if no mapping
|
|
||||||
* for the specified key was found.
|
|
||||||
* @throws ClassCastException
|
|
||||||
* if the specified key cannot be compared with the keys in this
|
|
||||||
* map.
|
|
||||||
* @throws NullPointerException
|
|
||||||
* if the specified key is {@code null} and the comparator
|
|
||||||
* cannot handle {@code null} keys.
|
|
||||||
*/
|
|
||||||
@Override
|
@Override
|
||||||
public V remove(Object key) {
|
public V remove(Object key) {
|
||||||
if (size == 0) {
|
if (size == 0) {
|
||||||
|
@ -2275,42 +2088,11 @@ public class TTreeMap<K, V> extends TAbstractMap<K, V> implements TSortedMap<K,
|
||||||
x.color = false;
|
x.color = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the number of mappings in this map.
|
|
||||||
*
|
|
||||||
* @return the number of mappings in this map.
|
|
||||||
*/
|
|
||||||
@Override
|
@Override
|
||||||
public int size() {
|
public int size() {
|
||||||
return size;
|
return size;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns a sorted map over a range of this sorted map with all keys
|
|
||||||
* greater than or equal to the specified {@code startKey} and less than the
|
|
||||||
* specified {@code endKey}. Changes to the returned sorted map are
|
|
||||||
* reflected in this sorted map and vice versa.
|
|
||||||
* <p>
|
|
||||||
* Note: The returned map will not allow an insertion of a key outside the
|
|
||||||
* specified range.
|
|
||||||
*
|
|
||||||
* @param startKey
|
|
||||||
* the low boundary of the range (inclusive).
|
|
||||||
* @param endKey
|
|
||||||
* the high boundary of the range (exclusive),
|
|
||||||
* @return a sorted map with the key from the specified range.
|
|
||||||
* @throws ClassCastException
|
|
||||||
* if the start or end key cannot be compared with the keys in
|
|
||||||
* this map.
|
|
||||||
* @throws NullPointerException
|
|
||||||
* if the start or end key is {@code null} and the comparator
|
|
||||||
* cannot handle {@code null} keys.
|
|
||||||
* @throws IllegalArgumentException
|
|
||||||
* if the start key is greater than the end key, or if this map
|
|
||||||
* is itself a sorted map over a range of another sorted map and
|
|
||||||
* the specified range is outside of its range.
|
|
||||||
*/
|
|
||||||
@Override
|
@Override
|
||||||
public TSortedMap<K, V> subMap(K startKey, K endKey) {
|
public TSortedMap<K, V> subMap(K startKey, K endKey) {
|
||||||
if (comparator == null) {
|
if (comparator == null) {
|
||||||
|
@ -2325,28 +2107,6 @@ public class TTreeMap<K, V> extends TAbstractMap<K, V> implements TSortedMap<K,
|
||||||
throw new TIllegalArgumentException();
|
throw new TIllegalArgumentException();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns a sorted map over a range of this sorted map with all keys that
|
|
||||||
* are greater than or equal to the specified {@code startKey}. Changes to
|
|
||||||
* the returned sorted map are reflected in this sorted map and vice versa.
|
|
||||||
* <p>
|
|
||||||
* Note: The returned map will not allow an insertion of a key outside the
|
|
||||||
* specified range.
|
|
||||||
*
|
|
||||||
* @param startKey
|
|
||||||
* the low boundary of the range specified.
|
|
||||||
* @return a sorted map where the keys are greater or equal to
|
|
||||||
* {@code startKey}.
|
|
||||||
* @throws ClassCastException
|
|
||||||
* if the specified key cannot be compared with the keys in this
|
|
||||||
* map.
|
|
||||||
* @throws NullPointerException
|
|
||||||
* if the specified key is {@code null} and the comparator
|
|
||||||
* cannot handle {@code null} keys.
|
|
||||||
* @throws IllegalArgumentException
|
|
||||||
* if this map itself a sorted map over a range of another map
|
|
||||||
* and the specified key is outside of its range.
|
|
||||||
*/
|
|
||||||
@Override
|
@Override
|
||||||
public TSortedMap<K, V> tailMap(K startKey) {
|
public TSortedMap<K, V> tailMap(K startKey) {
|
||||||
// Check for errors
|
// Check for errors
|
||||||
|
@ -2358,25 +2118,6 @@ public class TTreeMap<K, V> extends TAbstractMap<K, V> implements TSortedMap<K,
|
||||||
return new SubMap<>(startKey, this);
|
return new SubMap<>(startKey, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns a collection of the values contained in this map. The collection
|
|
||||||
* is backed by this map so changes to one are reflected by the other. The
|
|
||||||
* collection supports remove, removeAll, retainAll and clear operations,
|
|
||||||
* and it does not support add or addAll operations.
|
|
||||||
* <p>
|
|
||||||
* This method returns a collection which is the subclass of
|
|
||||||
* AbstractCollection. The iterator method of this subclass returns a
|
|
||||||
* "wrapper object" over the iterator of map's entrySet(). The {@code size}
|
|
||||||
* method wraps the map's size method and the {@code contains} method wraps
|
|
||||||
* the map's containsValue method.
|
|
||||||
* <p>
|
|
||||||
* The collection is created when this method is called for the first time
|
|
||||||
* and returned in response to all subsequent calls. This method may return
|
|
||||||
* different collections when multiple concurrent calls occur, since no
|
|
||||||
* synchronization is performed.
|
|
||||||
*
|
|
||||||
* @return a collection of the values contained in this map.
|
|
||||||
*/
|
|
||||||
@Override
|
@Override
|
||||||
public TCollection<V> values() {
|
public TCollection<V> values() {
|
||||||
if (cachedValues == null) {
|
if (cachedValues == null) {
|
||||||
|
@ -2405,4 +2146,3 @@ public class TTreeMap<K, V> extends TAbstractMap<K, V> implements TSortedMap<K,
|
||||||
return cachedValues;
|
return cachedValues;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -35,33 +35,27 @@ import static org.junit.Assert.*;
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.text.CollationKey;
|
import java.text.CollationKey;
|
||||||
import java.text.Collator;
|
import java.text.Collator;
|
||||||
import java.util.AbstractMap;
|
import java.util.*;
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.Comparator;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Set;
|
|
||||||
import java.util.SortedMap;
|
|
||||||
import java.util.TreeMap;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
public class TreeMapTest {
|
public class TreeMapTest {
|
||||||
|
|
||||||
public static class ReversedComparator implements Comparator {
|
public static class ReversedComparator implements Comparator<Object> {
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
@Override
|
||||||
public int compare(Object o1, Object o2) {
|
public int compare(Object o1, Object o2) {
|
||||||
return -(((Comparable) o1).compareTo(o2));
|
return -(((Comparable<Object>) o1).compareTo(o2));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
public boolean equals(Object o1, Object o2) {
|
public boolean equals(Object o1, Object o2) {
|
||||||
return (((Comparable) o1).compareTo(o2)) == 0;
|
return (((Comparable<Object>) o1).compareTo(o2)) == 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Regression for Harmony-1026
|
// Regression for Harmony-1026
|
||||||
public static class MockComparator<T extends Comparable<T>> implements
|
public static class MockComparator<T extends Comparable<T>> implements Comparator<T> {
|
||||||
Comparator<T>, Serializable {
|
@Override
|
||||||
|
|
||||||
public int compare(T o1, T o2) {
|
public int compare(T o1, T o2) {
|
||||||
if (o1 == o2) {
|
if (o1 == o2) {
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -77,7 +71,7 @@ public class TreeMapTest {
|
||||||
|
|
||||||
// Regression for Harmony-1161
|
// Regression for Harmony-1161
|
||||||
class MockComparatorNullTolerable implements Comparator<String> {
|
class MockComparatorNullTolerable implements Comparator<String> {
|
||||||
|
@Override
|
||||||
public int compare(String o1, String o2) {
|
public int compare(String o1, String o2) {
|
||||||
if (o1 == o2) {
|
if (o1 == o2) {
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -92,12 +86,12 @@ public class TreeMapTest {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
TreeMap tm;
|
TreeMap<Object, Object> tm;
|
||||||
|
|
||||||
Object objArray[] = new Object[1000];
|
Object objArray[] = new Object[1000];
|
||||||
|
|
||||||
public TreeMapTest() {
|
public TreeMapTest() {
|
||||||
tm = new TreeMap();
|
tm = new TreeMap<>();
|
||||||
for (int i = 0; i < objArray.length; i++) {
|
for (int i = 0; i < objArray.length; i++) {
|
||||||
Object x = objArray[i] = new Integer(i);
|
Object x = objArray[i] = new Integer(i);
|
||||||
tm.put(x.toString(), x);
|
tm.put(x.toString(), x);
|
||||||
|
@ -108,8 +102,8 @@ public class TreeMapTest {
|
||||||
@Test
|
@Test
|
||||||
public void test_ConstructorLjava_util_Comparator() {
|
public void test_ConstructorLjava_util_Comparator() {
|
||||||
// Test for method java.util.TreeMap(java.util.Comparator)
|
// Test for method java.util.TreeMap(java.util.Comparator)
|
||||||
Comparator comp = new ReversedComparator();
|
Comparator<Object> comp = new ReversedComparator();
|
||||||
TreeMap reversedTreeMap = new TreeMap(comp);
|
TreeMap<Object, Object> reversedTreeMap = new TreeMap<>(comp);
|
||||||
assertTrue("TreeMap answered incorrect comparator", reversedTreeMap
|
assertTrue("TreeMap answered incorrect comparator", reversedTreeMap
|
||||||
.comparator() == comp);
|
.comparator() == comp);
|
||||||
reversedTreeMap.put(new Integer(1).toString(), new Integer(1));
|
reversedTreeMap.put(new Integer(1).toString(), new Integer(1));
|
||||||
|
@ -124,22 +118,21 @@ public class TreeMapTest {
|
||||||
@Test
|
@Test
|
||||||
public void test_ConstructorLjava_util_Map() {
|
public void test_ConstructorLjava_util_Map() {
|
||||||
// Test for method java.util.TreeMap(java.util.Map)
|
// Test for method java.util.TreeMap(java.util.Map)
|
||||||
TreeMap myTreeMap = new TreeMap(new HashMap(tm));
|
TreeMap<Object, Object> myTreeMap = new TreeMap<>(new HashMap<>(tm));
|
||||||
assertTrue("Map is incorrect size", myTreeMap.size() == objArray.length);
|
assertTrue("Map is incorrect size", myTreeMap.size() == objArray.length);
|
||||||
for (Object element : objArray) {
|
for (Object element : objArray) {
|
||||||
assertTrue("Map has incorrect mappings", myTreeMap.get(
|
assertTrue("Map has incorrect mappings", myTreeMap.get(element.toString()).equals(element));
|
||||||
element.toString()).equals(element));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test_ConstructorLjava_util_SortedMap() {
|
public void test_ConstructorLjava_util_SortedMap() {
|
||||||
// Test for method java.util.TreeMap(java.util.SortedMap)
|
// Test for method java.util.TreeMap(java.util.SortedMap)
|
||||||
Comparator comp = new ReversedComparator();
|
Comparator<Object> comp = new ReversedComparator();
|
||||||
TreeMap reversedTreeMap = new TreeMap(comp);
|
TreeMap<Object, Object> reversedTreeMap = new TreeMap<>(comp);
|
||||||
reversedTreeMap.put(new Integer(1).toString(), new Integer(1));
|
reversedTreeMap.put(new Integer(1).toString(), new Integer(1));
|
||||||
reversedTreeMap.put(new Integer(2).toString(), new Integer(2));
|
reversedTreeMap.put(new Integer(2).toString(), new Integer(2));
|
||||||
TreeMap anotherTreeMap = new TreeMap(reversedTreeMap);
|
TreeMap<Object, Object> anotherTreeMap = new TreeMap<>(reversedTreeMap);
|
||||||
assertTrue("New tree map does not answer correct comparator",
|
assertTrue("New tree map does not answer correct comparator",
|
||||||
anotherTreeMap.comparator() == comp);
|
anotherTreeMap.comparator() == comp);
|
||||||
assertTrue("TreeMap does not use comparator (firstKey was incorrect)",
|
assertTrue("TreeMap does not use comparator (firstKey was incorrect)",
|
||||||
|
@ -159,34 +152,34 @@ public class TreeMapTest {
|
||||||
@Test
|
@Test
|
||||||
public void test_clone() {
|
public void test_clone() {
|
||||||
// Test for method java.lang.Object java.util.TreeMap.clone()
|
// Test for method java.lang.Object java.util.TreeMap.clone()
|
||||||
TreeMap clonedMap = (TreeMap) tm.clone();
|
@SuppressWarnings("unchecked")
|
||||||
assertTrue("Cloned map does not equal the original map", clonedMap
|
TreeMap<Object, Object> clonedMap = (TreeMap<Object, Object>) tm.clone();
|
||||||
.equals(tm));
|
assertTrue("Cloned map does not equal the original map", clonedMap.equals(tm));
|
||||||
assertTrue("Cloned map is the same reference as the original map",
|
assertTrue("Cloned map is the same reference as the original map", clonedMap != tm);
|
||||||
clonedMap != tm);
|
|
||||||
for (Object element : objArray) {
|
for (Object element : objArray) {
|
||||||
assertTrue("Cloned map contains incorrect elements", clonedMap
|
assertTrue("Cloned map contains incorrect elements", clonedMap
|
||||||
.get(element.toString()) == tm.get(element.toString()));
|
.get(element.toString()) == tm.get(element.toString()));
|
||||||
}
|
}
|
||||||
|
|
||||||
TreeMap map = new TreeMap();
|
TreeMap<Object, Object> map = new TreeMap<>();
|
||||||
map.put("key", "value");
|
map.put("key", "value");
|
||||||
// get the keySet() and values() on the original Map
|
// get the keySet() and values() on the original Map
|
||||||
Set keys = map.keySet();
|
Set<Object> keys = map.keySet();
|
||||||
Collection values = map.values();
|
Collection<Object> values = map.values();
|
||||||
assertEquals("values() does not work", "value", values.iterator()
|
assertEquals("values() does not work", "value", values.iterator()
|
||||||
.next());
|
.next());
|
||||||
assertEquals("keySet() does not work", "key", keys.iterator().next());
|
assertEquals("keySet() does not work", "key", keys.iterator().next());
|
||||||
AbstractMap map2 = (AbstractMap) map.clone();
|
@SuppressWarnings("unchecked")
|
||||||
|
Map<Object, Object> map2 = (Map<Object, Object>) map.clone();
|
||||||
map2.put("key", "value2");
|
map2.put("key", "value2");
|
||||||
Collection values2 = map2.values();
|
Collection<Object> values2 = map2.values();
|
||||||
assertTrue("values() is identical", values2 != values);
|
assertTrue("values() is identical", values2 != values);
|
||||||
// values() and keySet() on the cloned() map should be different
|
// values() and keySet() on the cloned() map should be different
|
||||||
assertEquals("values() was not cloned", "value2", values2.iterator()
|
assertEquals("values() was not cloned", "value2", values2.iterator()
|
||||||
.next());
|
.next());
|
||||||
map2.clear();
|
map2.clear();
|
||||||
map2.put("key2", "value3");
|
map2.put("key2", "value3");
|
||||||
Set key2 = map2.keySet();
|
Set<Object> key2 = map2.keySet();
|
||||||
assertTrue("keySet() is identical", key2 != keys);
|
assertTrue("keySet() is identical", key2 != keys);
|
||||||
assertEquals("keySet() was not cloned", "key2", key2.iterator().next());
|
assertEquals("keySet() was not cloned", "key2", key2.iterator().next());
|
||||||
}
|
}
|
||||||
|
@ -194,10 +187,9 @@ public class TreeMapTest {
|
||||||
@Test
|
@Test
|
||||||
public void test_comparator() {
|
public void test_comparator() {
|
||||||
// Test for method java.util.Comparator java.util.TreeMap.comparator()\
|
// Test for method java.util.Comparator java.util.TreeMap.comparator()\
|
||||||
Comparator comp = new ReversedComparator();
|
Comparator<Object> comp = new ReversedComparator();
|
||||||
TreeMap reversedTreeMap = new TreeMap(comp);
|
TreeMap<Object, Object> reversedTreeMap = new TreeMap<>(comp);
|
||||||
assertTrue("TreeMap answered incorrect comparator", reversedTreeMap
|
assertTrue("TreeMap answered incorrect comparator", reversedTreeMap.comparator() == comp);
|
||||||
.comparator() == comp);
|
|
||||||
reversedTreeMap.put(new Integer(1).toString(), new Integer(1));
|
reversedTreeMap.put(new Integer(1).toString(), new Integer(1));
|
||||||
reversedTreeMap.put(new Integer(2).toString(), new Integer(2));
|
reversedTreeMap.put(new Integer(2).toString(), new Integer(2));
|
||||||
assertTrue("TreeMap does not use comparator (firstKey was incorrect)",
|
assertTrue("TreeMap does not use comparator (firstKey was incorrect)",
|
||||||
|
@ -227,15 +219,13 @@ public class TreeMapTest {
|
||||||
@Test
|
@Test
|
||||||
public void test_entrySet() {
|
public void test_entrySet() {
|
||||||
// Test for method java.util.Set java.util.TreeMap.entrySet()
|
// Test for method java.util.Set java.util.TreeMap.entrySet()
|
||||||
Set anEntrySet = tm.entrySet();
|
Set<Map.Entry<Object, Object>> anEntrySet = tm.entrySet();
|
||||||
Iterator entrySetIterator = anEntrySet.iterator();
|
Iterator<Map.Entry<Object, Object>> entrySetIterator = anEntrySet.iterator();
|
||||||
assertTrue("EntrySet is incorrect size",
|
assertTrue("EntrySet is incorrect size", anEntrySet.size() == objArray.length);
|
||||||
anEntrySet.size() == objArray.length);
|
Map.Entry<Object, Object> entry;
|
||||||
Map.Entry entry;
|
|
||||||
while (entrySetIterator.hasNext()) {
|
while (entrySetIterator.hasNext()) {
|
||||||
entry = (Map.Entry) entrySetIterator.next();
|
entry = entrySetIterator.next();
|
||||||
assertTrue("EntrySet does not contain correct mappings", tm
|
assertTrue("EntrySet does not contain correct mappings", tm.get(entry.getKey()) == entry.getValue());
|
||||||
.get(entry.getKey()) == entry.getValue());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -259,15 +249,14 @@ public class TreeMapTest {
|
||||||
public void test_headMapLjava_lang_Object() {
|
public void test_headMapLjava_lang_Object() {
|
||||||
// Test for method java.util.SortedMap
|
// Test for method java.util.SortedMap
|
||||||
// java.util.TreeMap.headMap(java.lang.Object)
|
// java.util.TreeMap.headMap(java.lang.Object)
|
||||||
Map head = tm.headMap("100");
|
Map<Object, Object> head = tm.headMap("100");
|
||||||
assertEquals("Returned map of incorrect size", 3, head.size());
|
assertEquals("Returned map of incorrect size", 3, head.size());
|
||||||
assertTrue("Returned incorrect elements", head.containsKey("0")
|
assertTrue("Returned incorrect elements", head.containsKey("0")
|
||||||
&& head.containsValue(new Integer("1"))
|
&& head.containsValue(new Integer("1"))
|
||||||
&& head.containsKey("10"));
|
&& head.containsKey("10"));
|
||||||
|
|
||||||
// Regression for Harmony-1026
|
// Regression for Harmony-1026
|
||||||
TreeMap<Integer, Double> map = new TreeMap<Integer, Double>(
|
TreeMap<Integer, Double> map = new TreeMap<>(new MockComparator<Integer>());
|
||||||
new MockComparator());
|
|
||||||
map.put(1, 2.1);
|
map.put(1, 2.1);
|
||||||
map.put(2, 3.1);
|
map.put(2, 3.1);
|
||||||
map.put(3, 4.5);
|
map.put(3, 4.5);
|
||||||
|
@ -310,16 +299,16 @@ public class TreeMapTest {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
TreeMap<String, String> treemap = new TreeMap<String, String>(c);
|
TreeMap<String, String> treemap = new TreeMap<>(c);
|
||||||
assertEquals(0, treemap.headMap(null).size());
|
assertEquals(0, treemap.headMap(null).size());
|
||||||
|
|
||||||
treemap = new TreeMap();
|
treemap = new TreeMap<>();
|
||||||
SortedMap<String, String> headMap = treemap.headMap("100");
|
SortedMap<String, String> headMap = treemap.headMap("100");
|
||||||
headMap.headMap("100");
|
headMap.headMap("100");
|
||||||
|
|
||||||
SortedMap<Integer,Integer> intMap,sub;
|
SortedMap<Integer,Integer> intMap,sub;
|
||||||
int size = 16;
|
int size = 16;
|
||||||
intMap = new TreeMap<Integer,Integer>();
|
intMap = new TreeMap<>();
|
||||||
for(int i=0; i<size; i++) {
|
for(int i=0; i<size; i++) {
|
||||||
intMap.put(i,i);
|
intMap.put(i,i);
|
||||||
}
|
}
|
||||||
|
@ -339,7 +328,7 @@ public class TreeMapTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
size = 256;
|
size = 256;
|
||||||
intMap = new TreeMap<Integer,Integer>();
|
intMap = new TreeMap<>();
|
||||||
for(int i=0; i<size; i++) {
|
for(int i=0; i<size; i++) {
|
||||||
intMap.put(i,i);
|
intMap.put(i,i);
|
||||||
}
|
}
|
||||||
|
@ -363,20 +352,17 @@ public class TreeMapTest {
|
||||||
@Test
|
@Test
|
||||||
public void test_keySet() {
|
public void test_keySet() {
|
||||||
// Test for method java.util.Set java.util.TreeMap.keySet()
|
// Test for method java.util.Set java.util.TreeMap.keySet()
|
||||||
Set ks = tm.keySet();
|
Set<Object> ks = tm.keySet();
|
||||||
assertTrue("Returned set of incorrect size",
|
assertTrue("Returned set of incorrect size",ks.size() == objArray.length);
|
||||||
ks.size() == objArray.length);
|
|
||||||
for (int i = 0; i < tm.size(); i++) {
|
for (int i = 0; i < tm.size(); i++) {
|
||||||
assertTrue("Returned set is missing keys", ks.contains(new Integer(
|
assertTrue("Returned set is missing keys", ks.contains(new Integer(i).toString()));
|
||||||
i).toString()));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test_lastKey() {
|
public void test_lastKey() {
|
||||||
// Test for method java.lang.Object java.util.TreeMap.lastKey()
|
// Test for method java.lang.Object java.util.TreeMap.lastKey()
|
||||||
assertTrue("Returned incorrect last key", tm.lastKey().equals(
|
assertTrue("Returned incorrect last key", tm.lastKey().equals(objArray[objArray.length - 1].toString()));
|
||||||
objArray[objArray.length - 1].toString()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -394,19 +380,18 @@ public class TreeMapTest {
|
||||||
// expected
|
// expected
|
||||||
}
|
}
|
||||||
|
|
||||||
tm = new TreeMap();
|
tm = new TreeMap<>();
|
||||||
assertNull(tm.put(new Integer(1), new Object()));
|
assertNull(tm.put(new Integer(1), new Object()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test_putAllLjava_util_Map() {
|
public void test_putAllLjava_util_Map() {
|
||||||
// Test for method void java.util.TreeMap.putAll(java.util.Map)
|
// Test for method void java.util.TreeMap.putAll(java.util.Map)
|
||||||
TreeMap x = new TreeMap();
|
TreeMap<Object, Object> x = new TreeMap<>();
|
||||||
x.putAll(tm);
|
x.putAll(tm);
|
||||||
assertTrue("Map incorrect size after put", x.size() == tm.size());
|
assertTrue("Map incorrect size after put", x.size() == tm.size());
|
||||||
for (Object element : objArray) {
|
for (Object element : objArray) {
|
||||||
assertTrue("Failed to put all elements", x.get(element.toString())
|
assertTrue("Failed to put all elements", x.get(element.toString()).equals(element));
|
||||||
.equals(element));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -429,8 +414,7 @@ public class TreeMapTest {
|
||||||
public void test_subMapLjava_lang_ObjectLjava_lang_Object() {
|
public void test_subMapLjava_lang_ObjectLjava_lang_Object() {
|
||||||
// Test for method java.util.SortedMap
|
// Test for method java.util.SortedMap
|
||||||
// java.util.TreeMap.subMap(java.lang.Object, java.lang.Object)
|
// java.util.TreeMap.subMap(java.lang.Object, java.lang.Object)
|
||||||
SortedMap subMap = tm.subMap(objArray[100].toString(), objArray[109]
|
SortedMap<Object, Object> subMap = tm.subMap(objArray[100].toString(), objArray[109].toString());
|
||||||
.toString());
|
|
||||||
assertEquals("subMap is of incorrect size", 9, subMap.size());
|
assertEquals("subMap is of incorrect size", 9, subMap.size());
|
||||||
for (int counter = 100; counter < 109; counter++) {
|
for (int counter = 100; counter < 109; counter++) {
|
||||||
assertTrue("SubMap contains incorrect elements", subMap.get(
|
assertTrue("SubMap contains incorrect elements", subMap.get(
|
||||||
|
@ -445,8 +429,7 @@ public class TreeMapTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Regression for Harmony-1161
|
// Regression for Harmony-1161
|
||||||
TreeMap<String, String> treeMapWithNull = new TreeMap<String, String>(
|
TreeMap<String, String> treeMapWithNull = new TreeMap<>(new MockComparatorNullTolerable());
|
||||||
new MockComparatorNullTolerable());
|
|
||||||
treeMapWithNull.put("key1", "value1"); //$NON-NLS-1$ //$NON-NLS-2$
|
treeMapWithNull.put("key1", "value1"); //$NON-NLS-1$ //$NON-NLS-2$
|
||||||
treeMapWithNull.put(null, "value2"); //$NON-NLS-1$
|
treeMapWithNull.put(null, "value2"); //$NON-NLS-1$
|
||||||
SortedMap<String, String> subMapWithNull = treeMapWithNull.subMap(null,
|
SortedMap<String, String> subMapWithNull = treeMapWithNull.subMap(null,
|
||||||
|
@ -454,7 +437,7 @@ public class TreeMapTest {
|
||||||
assertEquals("Size of subMap should be 1:", 1, subMapWithNull.size()); //$NON-NLS-1$
|
assertEquals("Size of subMap should be 1:", 1, subMapWithNull.size()); //$NON-NLS-1$
|
||||||
|
|
||||||
// Regression test for typo in lastKey method
|
// Regression test for typo in lastKey method
|
||||||
SortedMap<String, String> map = new TreeMap<String, String>();
|
SortedMap<String, String> map = new TreeMap<>();
|
||||||
map.put("1", "one"); //$NON-NLS-1$ //$NON-NLS-2$
|
map.put("1", "one"); //$NON-NLS-1$ //$NON-NLS-2$
|
||||||
map.put("2", "two"); //$NON-NLS-1$ //$NON-NLS-2$
|
map.put("2", "two"); //$NON-NLS-1$ //$NON-NLS-2$
|
||||||
map.put("3", "three"); //$NON-NLS-1$ //$NON-NLS-2$
|
map.put("3", "three"); //$NON-NLS-1$ //$NON-NLS-2$
|
||||||
|
@ -466,7 +449,7 @@ public class TreeMapTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test_subMap_Iterator() {
|
public void test_subMap_Iterator() {
|
||||||
TreeMap<String, String> map = new TreeMap<String, String>();
|
TreeMap<String, String> map = new TreeMap<>();
|
||||||
|
|
||||||
String[] keys = { "1", "2", "3" };
|
String[] keys = { "1", "2", "3" };
|
||||||
String[] values = { "one", "two", "three" };
|
String[] values = { "one", "two", "three" };
|
||||||
|
@ -476,15 +459,14 @@ public class TreeMapTest {
|
||||||
|
|
||||||
assertEquals(3, map.size());
|
assertEquals(3, map.size());
|
||||||
|
|
||||||
Map subMap = map.subMap("", "test");
|
Map<String, String> subMap = map.subMap("", "test");
|
||||||
assertEquals(3, subMap.size());
|
assertEquals(3, subMap.size());
|
||||||
|
|
||||||
Set entrySet = subMap.entrySet();
|
Set<Map.Entry<String, String>> entrySet = subMap.entrySet();
|
||||||
Iterator iter = entrySet.iterator();
|
Iterator<Map.Entry<String, String>> iter = entrySet.iterator();
|
||||||
int size = 0;
|
int size = 0;
|
||||||
while (iter.hasNext()) {
|
while (iter.hasNext()) {
|
||||||
Map.Entry<String, String> entry = (Map.Entry<String, String>) iter
|
Map.Entry<String, String> entry = iter.next();
|
||||||
.next();
|
|
||||||
assertTrue(map.containsKey(entry.getKey()));
|
assertTrue(map.containsKey(entry.getKey()));
|
||||||
assertTrue(map.containsValue(entry.getValue()));
|
assertTrue(map.containsValue(entry.getValue()));
|
||||||
size++;
|
size++;
|
||||||
|
@ -492,10 +474,10 @@ public class TreeMapTest {
|
||||||
assertEquals(map.size(), size);
|
assertEquals(map.size(), size);
|
||||||
|
|
||||||
Set<String> keySet = subMap.keySet();
|
Set<String> keySet = subMap.keySet();
|
||||||
iter = keySet.iterator();
|
Iterator<String> keyIter = keySet.iterator();
|
||||||
size = 0;
|
size = 0;
|
||||||
while (iter.hasNext()) {
|
while (keyIter.hasNext()) {
|
||||||
String key = (String) iter.next();
|
String key = keyIter.next();
|
||||||
assertTrue(map.containsKey(key));
|
assertTrue(map.containsKey(key));
|
||||||
size++;
|
size++;
|
||||||
}
|
}
|
||||||
|
@ -507,12 +489,10 @@ public class TreeMapTest {
|
||||||
public void test_tailMapLjava_lang_Object() {
|
public void test_tailMapLjava_lang_Object() {
|
||||||
// Test for method java.util.SortedMap
|
// Test for method java.util.SortedMap
|
||||||
// java.util.TreeMap.tailMap(java.lang.Object)
|
// java.util.TreeMap.tailMap(java.lang.Object)
|
||||||
Map tail = tm.tailMap(objArray[900].toString());
|
Map<Object, Object> tail = tm.tailMap(objArray[900].toString());
|
||||||
assertTrue("Returned map of incorrect size : " + tail.size(), tail
|
assertTrue("Returned map of incorrect size : " + tail.size(), tail.size() == (objArray.length - 900) + 9);
|
||||||
.size() == (objArray.length - 900) + 9);
|
|
||||||
for (int i = 900; i < objArray.length; i++) {
|
for (int i = 900; i < objArray.length; i++) {
|
||||||
assertTrue("Map contains incorrect entries", tail
|
assertTrue("Map contains incorrect entries", tail.containsValue(objArray[i]));
|
||||||
.containsValue(objArray[i]));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Regression for Harmony-1066
|
// Regression for Harmony-1066
|
||||||
|
@ -520,7 +500,7 @@ public class TreeMapTest {
|
||||||
|
|
||||||
SortedMap<Integer,Integer> intMap,sub;
|
SortedMap<Integer,Integer> intMap,sub;
|
||||||
int size = 16;
|
int size = 16;
|
||||||
intMap = new TreeMap<Integer,Integer>();
|
intMap = new TreeMap<>();
|
||||||
for(int i=0; i<size; i++) {
|
for(int i=0; i<size; i++) {
|
||||||
intMap.put(i,i);
|
intMap.put(i,i);
|
||||||
}
|
}
|
||||||
|
@ -540,7 +520,7 @@ public class TreeMapTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
size = 256;
|
size = 256;
|
||||||
intMap = new TreeMap<Integer,Integer>();
|
intMap = new TreeMap<>();
|
||||||
for(int i=0; i<size; i++) {
|
for(int i=0; i<size; i++) {
|
||||||
intMap.put(i,i);
|
intMap.put(i,i);
|
||||||
}
|
}
|
||||||
|
@ -564,31 +544,29 @@ public class TreeMapTest {
|
||||||
@Test
|
@Test
|
||||||
public void test_values() {
|
public void test_values() {
|
||||||
// Test for method java.util.Collection java.util.TreeMap.values()
|
// Test for method java.util.Collection java.util.TreeMap.values()
|
||||||
Collection vals = tm.values();
|
Collection<Object> vals = tm.values();
|
||||||
vals.iterator();
|
vals.iterator();
|
||||||
assertTrue("Returned collection of incorrect size",
|
assertTrue("Returned collection of incorrect size",
|
||||||
vals.size() == objArray.length);
|
vals.size() == objArray.length);
|
||||||
for (Object element : objArray) {
|
for (Object element : objArray) {
|
||||||
assertTrue("Collection contains incorrect elements", vals
|
assertTrue("Collection contains incorrect elements", vals.contains(element));
|
||||||
.contains(element));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TreeMap myTreeMap = new TreeMap();
|
TreeMap<Object, Object> myTreeMap = new TreeMap<>();
|
||||||
for (int i = 0; i < 100; i++) {
|
for (int i = 0; i < 100; i++) {
|
||||||
myTreeMap.put(objArray[i], objArray[i]);
|
myTreeMap.put(objArray[i], objArray[i]);
|
||||||
}
|
}
|
||||||
Collection values = myTreeMap.values();
|
Collection<Object> values = myTreeMap.values();
|
||||||
values.remove(new Integer(0));
|
values.remove(new Integer(0));
|
||||||
assertTrue(
|
assertTrue("Removing from the values collection should remove from the original map",
|
||||||
"Removing from the values collection should remove from the original map",
|
|
||||||
!myTreeMap.containsValue(new Integer(0)));
|
!myTreeMap.containsValue(new Integer(0)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test_equals() throws Exception {
|
public void test_equals() throws Exception {
|
||||||
// comparing TreeMaps with different object types
|
// comparing TreeMaps with different object types
|
||||||
Map m1 = new TreeMap();
|
Map<Object, Object> m1 = new TreeMap<>();
|
||||||
Map m2 = new TreeMap();
|
Map<Object, Object> m2 = new TreeMap<>();
|
||||||
m1.put("key1", "val1");
|
m1.put("key1", "val1");
|
||||||
m1.put("key2", "val2");
|
m1.put("key2", "val2");
|
||||||
m2.put(new Integer(1), "val1");
|
m2.put(new Integer(1), "val1");
|
||||||
|
@ -597,8 +575,8 @@ public class TreeMapTest {
|
||||||
assertFalse("Maps should not be equal 2", m2.equals(m1));
|
assertFalse("Maps should not be equal 2", m2.equals(m1));
|
||||||
|
|
||||||
// comparing TreeMap with HashMap
|
// comparing TreeMap with HashMap
|
||||||
m1 = new TreeMap();
|
m1 = new TreeMap<>();
|
||||||
m2 = new HashMap();
|
m2 = new HashMap<>();
|
||||||
m1.put("key", "val");
|
m1.put("key", "val");
|
||||||
m2.put(new Object(), "val");
|
m2.put(new Object(), "val");
|
||||||
assertFalse("Maps should not be equal 3", m1.equals(m2));
|
assertFalse("Maps should not be equal 3", m1.equals(m2));
|
||||||
|
@ -612,8 +590,8 @@ public class TreeMapTest {
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void test_entrySet_contains() throws Exception {
|
public void test_entrySet_contains() throws Exception {
|
||||||
TreeMap master = new TreeMap<String, String>();
|
TreeMap<String, String> master = new TreeMap<>();
|
||||||
TreeMap test_map = new TreeMap<String, String>();
|
TreeMap<String, String> test_map = new TreeMap<>();
|
||||||
|
|
||||||
master.put("null", null);
|
master.put("null", null);
|
||||||
Object[] entry = master.entrySet().toArray();
|
Object[] entry = master.entrySet().toArray();
|
||||||
|
@ -630,7 +608,7 @@ public class TreeMapTest {
|
||||||
test_map.entrySet().containsAll(master.entrySet()));
|
test_map.entrySet().containsAll(master.entrySet()));
|
||||||
|
|
||||||
master.clear();
|
master.clear();
|
||||||
master.put("null", '0');
|
master.put("null", "0");
|
||||||
entry = master.entrySet().toArray();
|
entry = master.entrySet().toArray();
|
||||||
assertFalse("Null-valued entry should not equal non-null-valued entry",
|
assertFalse("Null-valued entry should not equal non-null-valued entry",
|
||||||
test_map.entrySet().contains(entry[0]));
|
test_map.entrySet().contains(entry[0]));
|
||||||
|
|
Loading…
Reference in New Issue
Block a user