mirror of
https://github.com/apache/commons-collections.git
synced 2025-02-26 04:35:47 +00:00
Use final for locals.
This commit is contained in:
parent
cefe846e3e
commit
712ddb1e19
@ -1245,7 +1245,7 @@ public class CollectionUtils {
|
|||||||
* @throws IllegalArgumentException if the object type is invalid
|
* @throws IllegalArgumentException if the object type is invalid
|
||||||
*/
|
*/
|
||||||
public static Object get(final Object object, final int index) {
|
public static Object get(final Object object, final int index) {
|
||||||
int i = index;
|
final int i = index;
|
||||||
if (i < 0) {
|
if (i < 0) {
|
||||||
throw new IndexOutOfBoundsException("Index cannot be negative: " + i);
|
throw new IndexOutOfBoundsException("Index cannot be negative: " + i);
|
||||||
}
|
}
|
||||||
|
@ -548,6 +548,7 @@ public class IterableUtils {
|
|||||||
@Override
|
@Override
|
||||||
public Iterator<E> iterator() {
|
public Iterator<E> iterator() {
|
||||||
@SuppressWarnings("unchecked") // safe
|
@SuppressWarnings("unchecked") // safe
|
||||||
|
final
|
||||||
Iterator<? extends E>[] iterators = new Iterator[others.length + 1];
|
Iterator<? extends E>[] iterators = new Iterator[others.length + 1];
|
||||||
iterators[0] = first.iterator();
|
iterators[0] = first.iterator();
|
||||||
for (int i = 0; i < others.length; i++) {
|
for (int i = 0; i < others.length; i++) {
|
||||||
@ -920,7 +921,7 @@ public class IterableUtils {
|
|||||||
throw new NullPointerException("Predicates must not be null.");
|
throw new NullPointerException("Predicates must not be null.");
|
||||||
}
|
}
|
||||||
|
|
||||||
for (Predicate<?> p : predicates) {
|
for (final Predicate<?> p : predicates) {
|
||||||
if (p == null) {
|
if (p == null) {
|
||||||
throw new NullPointerException("Predicate must not be null.");
|
throw new NullPointerException("Predicate must not be null.");
|
||||||
}
|
}
|
||||||
|
@ -569,7 +569,7 @@ public class ListUtils {
|
|||||||
}
|
}
|
||||||
final List<Character> lcs = longestCommonSubsequence(new CharSequenceAsList( a ), new CharSequenceAsList( b ));
|
final List<Character> lcs = longestCommonSubsequence(new CharSequenceAsList( a ), new CharSequenceAsList( b ));
|
||||||
final StringBuilder sb = new StringBuilder();
|
final StringBuilder sb = new StringBuilder();
|
||||||
for ( Character ch : lcs ) {
|
for ( final Character ch : lcs ) {
|
||||||
sb.append(ch);
|
sb.append(ch);
|
||||||
}
|
}
|
||||||
return sb.toString();
|
return sb.toString();
|
||||||
|
@ -127,7 +127,7 @@ public class MultiMapUtils {
|
|||||||
*/
|
*/
|
||||||
public static <K, V> List<V> getValuesAsList(final MultiValuedMap<K, V> map, final K key) {
|
public static <K, V> List<V> getValuesAsList(final MultiValuedMap<K, V> map, final K key) {
|
||||||
if (map != null) {
|
if (map != null) {
|
||||||
Collection<V> col = map.get(key);
|
final Collection<V> col = map.get(key);
|
||||||
if (col instanceof List) {
|
if (col instanceof List) {
|
||||||
return (List<V>) col;
|
return (List<V>) col;
|
||||||
}
|
}
|
||||||
@ -147,7 +147,7 @@ public class MultiMapUtils {
|
|||||||
*/
|
*/
|
||||||
public static <K, V> Set<V> getValuesAsSet(final MultiValuedMap<K, V> map, final K key) {
|
public static <K, V> Set<V> getValuesAsSet(final MultiValuedMap<K, V> map, final K key) {
|
||||||
if (map != null) {
|
if (map != null) {
|
||||||
Collection<V> col = map.get(key);
|
final Collection<V> col = map.get(key);
|
||||||
if (col instanceof Set) {
|
if (col instanceof Set) {
|
||||||
return (Set<V>) col;
|
return (Set<V>) col;
|
||||||
}
|
}
|
||||||
@ -167,7 +167,7 @@ public class MultiMapUtils {
|
|||||||
*/
|
*/
|
||||||
public static <K, V> Bag<V> getValuesAsBag(final MultiValuedMap<K, V> map, final K key) {
|
public static <K, V> Bag<V> getValuesAsBag(final MultiValuedMap<K, V> map, final K key) {
|
||||||
if (map != null) {
|
if (map != null) {
|
||||||
Collection<V> col = map.get(key);
|
final Collection<V> col = map.get(key);
|
||||||
if (col instanceof Bag) {
|
if (col instanceof Bag) {
|
||||||
return (Bag<V>) col;
|
return (Bag<V>) col;
|
||||||
}
|
}
|
||||||
|
@ -1439,10 +1439,10 @@ public class TreeBidiMap<K extends Comparable<K>, V extends Comparable<V>>
|
|||||||
private void readObject(final ObjectInputStream stream) throws IOException, ClassNotFoundException{
|
private void readObject(final ObjectInputStream stream) throws IOException, ClassNotFoundException{
|
||||||
stream.defaultReadObject();
|
stream.defaultReadObject();
|
||||||
rootNode = new Node[2];
|
rootNode = new Node[2];
|
||||||
int size = stream.readInt();
|
final int size = stream.readInt();
|
||||||
for(int i = 0; i < size; i++){
|
for(int i = 0; i < size; i++){
|
||||||
K k =(K) stream.readObject();
|
final K k =(K) stream.readObject();
|
||||||
V v =(V) stream.readObject();
|
final V v =(V) stream.readObject();
|
||||||
put(k, v);
|
put(k, v);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -256,7 +256,7 @@ public class PredicatedCollection<E> extends AbstractCollectionDecorator<E> {
|
|||||||
*/
|
*/
|
||||||
public Builder<E> addAll(final Collection<? extends E> items) {
|
public Builder<E> addAll(final Collection<? extends E> items) {
|
||||||
if (items != null) {
|
if (items != null) {
|
||||||
for (E item : items) {
|
for (final E item : items) {
|
||||||
add(item);
|
add(item);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -82,7 +82,7 @@ public class PermutationIterator<E> implements Iterator<List<E>> {
|
|||||||
Arrays.fill(direction, false);
|
Arrays.fill(direction, false);
|
||||||
int value = 1;
|
int value = 1;
|
||||||
objectMap = new HashMap<>();
|
objectMap = new HashMap<>();
|
||||||
for (E e : coll) {
|
for (final E e : coll) {
|
||||||
objectMap.put(Integer.valueOf(value), e);
|
objectMap.put(Integer.valueOf(value), e);
|
||||||
keys[value - 1] = value;
|
keys[value - 1] = value;
|
||||||
value++;
|
value++;
|
||||||
@ -123,7 +123,7 @@ public class PermutationIterator<E> implements Iterator<List<E>> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (largestKey == -1) {
|
if (largestKey == -1) {
|
||||||
List<E> toReturn = nextPermutation;
|
final List<E> toReturn = nextPermutation;
|
||||||
nextPermutation = null;
|
nextPermutation = null;
|
||||||
return toReturn;
|
return toReturn;
|
||||||
}
|
}
|
||||||
@ -133,7 +133,7 @@ public class PermutationIterator<E> implements Iterator<List<E>> {
|
|||||||
final int tmpKey = keys[indexOfLargestMobileInteger];
|
final int tmpKey = keys[indexOfLargestMobileInteger];
|
||||||
keys[indexOfLargestMobileInteger] = keys[indexOfLargestMobileInteger + offset];
|
keys[indexOfLargestMobileInteger] = keys[indexOfLargestMobileInteger + offset];
|
||||||
keys[indexOfLargestMobileInteger + offset] = tmpKey;
|
keys[indexOfLargestMobileInteger + offset] = tmpKey;
|
||||||
boolean tmpDirection = direction[indexOfLargestMobileInteger];
|
final boolean tmpDirection = direction[indexOfLargestMobileInteger];
|
||||||
direction[indexOfLargestMobileInteger] = direction[indexOfLargestMobileInteger + offset];
|
direction[indexOfLargestMobileInteger] = direction[indexOfLargestMobileInteger + offset];
|
||||||
direction[indexOfLargestMobileInteger + offset] = tmpDirection;
|
direction[indexOfLargestMobileInteger + offset] = tmpDirection;
|
||||||
|
|
||||||
|
@ -261,7 +261,7 @@ public class SetUniqueList<E> extends AbstractSerializableListDecorator<E> {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public boolean retainAll(final Collection<?> coll) {
|
public boolean retainAll(final Collection<?> coll) {
|
||||||
boolean result = set.retainAll(coll);
|
final boolean result = set.retainAll(coll);
|
||||||
if (result == false) {
|
if (result == false) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -130,7 +130,7 @@ public abstract class AbstractListValuedMap<K, V> extends AbstractMultiValuedMap
|
|||||||
List<V> list = getMapping();
|
List<V> list = getMapping();
|
||||||
if (list == null) {
|
if (list == null) {
|
||||||
list = createCollection();
|
list = createCollection();
|
||||||
boolean changed = list.addAll(index, c);
|
final boolean changed = list.addAll(index, c);
|
||||||
if (changed) {
|
if (changed) {
|
||||||
getMap().put(key, list);
|
getMap().put(key, list);
|
||||||
}
|
}
|
||||||
@ -170,7 +170,7 @@ public abstract class AbstractListValuedMap<K, V> extends AbstractMultiValuedMap
|
|||||||
@Override
|
@Override
|
||||||
public V remove(final int index) {
|
public V remove(final int index) {
|
||||||
final List<V> list = ListUtils.emptyIfNull(getMapping());
|
final List<V> list = ListUtils.emptyIfNull(getMapping());
|
||||||
V value = list.remove(index);
|
final V value = list.remove(index);
|
||||||
if (list.isEmpty()) {
|
if (list.isEmpty()) {
|
||||||
AbstractListValuedMap.this.remove(key);
|
AbstractListValuedMap.this.remove(key);
|
||||||
}
|
}
|
||||||
@ -198,7 +198,7 @@ public abstract class AbstractListValuedMap<K, V> extends AbstractMultiValuedMap
|
|||||||
if (!(other instanceof List)) {
|
if (!(other instanceof List)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
List<?> otherList = (List<?>) other;
|
final List<?> otherList = (List<?>) other;
|
||||||
return ListUtils.isEqualList(list, otherList);
|
return ListUtils.isEqualList(list, otherList);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -232,7 +232,7 @@ public abstract class AbstractListValuedMap<K, V> extends AbstractMultiValuedMap
|
|||||||
@Override
|
@Override
|
||||||
public void add(final V value) {
|
public void add(final V value) {
|
||||||
if (getMap().get(key) == null) {
|
if (getMap().get(key) == null) {
|
||||||
List<V> list = createCollection();
|
final List<V> list = createCollection();
|
||||||
getMap().put(key, list);
|
getMap().put(key, list);
|
||||||
this.values = list;
|
this.values = list;
|
||||||
this.iterator = list.listIterator();
|
this.iterator = list.listIterator();
|
||||||
|
@ -128,7 +128,7 @@ public abstract class AbstractMultiValuedMap<K, V> implements MultiValuedMap<K,
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean containsMapping(final Object key, final Object value) {
|
public boolean containsMapping(final Object key, final Object value) {
|
||||||
Collection<V> coll = getMap().get(key);
|
final Collection<V> coll = getMap().get(key);
|
||||||
return coll != null && coll.contains(value);
|
return coll != null && coll.contains(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -186,7 +186,7 @@ public abstract class AbstractMultiValuedMap<K, V> implements MultiValuedMap<K,
|
|||||||
if (coll == null) {
|
if (coll == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
boolean changed = coll.remove(value);
|
final boolean changed = coll.remove(value);
|
||||||
if (coll.isEmpty()) {
|
if (coll.isEmpty()) {
|
||||||
getMap().remove(key);
|
getMap().remove(key);
|
||||||
}
|
}
|
||||||
@ -285,7 +285,7 @@ public abstract class AbstractMultiValuedMap<K, V> implements MultiValuedMap<K,
|
|||||||
throw new NullPointerException("Map must not be null.");
|
throw new NullPointerException("Map must not be null.");
|
||||||
}
|
}
|
||||||
boolean changed = false;
|
boolean changed = false;
|
||||||
for (Map.Entry<? extends K, ? extends V> entry : map.entrySet()) {
|
for (final Map.Entry<? extends K, ? extends V> entry : map.entrySet()) {
|
||||||
changed |= put(entry.getKey(), entry.getValue());
|
changed |= put(entry.getKey(), entry.getValue());
|
||||||
}
|
}
|
||||||
return changed;
|
return changed;
|
||||||
@ -309,7 +309,7 @@ public abstract class AbstractMultiValuedMap<K, V> implements MultiValuedMap<K,
|
|||||||
throw new NullPointerException("Map must not be null.");
|
throw new NullPointerException("Map must not be null.");
|
||||||
}
|
}
|
||||||
boolean changed = false;
|
boolean changed = false;
|
||||||
for (Map.Entry<? extends K, ? extends V> entry : map.entries()) {
|
for (final Map.Entry<? extends K, ? extends V> entry : map.entries()) {
|
||||||
changed |= put(entry.getKey(), entry.getValue());
|
changed |= put(entry.getKey(), entry.getValue());
|
||||||
}
|
}
|
||||||
return changed;
|
return changed;
|
||||||
@ -353,10 +353,10 @@ public abstract class AbstractMultiValuedMap<K, V> implements MultiValuedMap<K,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (values instanceof Collection<?>) {
|
if (values instanceof Collection<?>) {
|
||||||
Collection<? extends V> valueCollection = (Collection<? extends V>) values;
|
final Collection<? extends V> valueCollection = (Collection<? extends V>) values;
|
||||||
return !valueCollection.isEmpty() && get(key).addAll(valueCollection);
|
return !valueCollection.isEmpty() && get(key).addAll(valueCollection);
|
||||||
} else {
|
} else {
|
||||||
Iterator<? extends V> it = values.iterator();
|
final Iterator<? extends V> it = values.iterator();
|
||||||
return it.hasNext() && CollectionUtils.addAll(get(key), it);
|
return it.hasNext() && CollectionUtils.addAll(get(key), it);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -484,7 +484,7 @@ public abstract class AbstractMultiValuedMap<K, V> implements MultiValuedMap<K,
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean result = coll.remove(item);
|
final boolean result = coll.remove(item);
|
||||||
if (coll.isEmpty()) {
|
if (coll.isEmpty()) {
|
||||||
AbstractMultiValuedMap.this.remove(key);
|
AbstractMultiValuedMap.this.remove(key);
|
||||||
}
|
}
|
||||||
@ -498,7 +498,7 @@ public abstract class AbstractMultiValuedMap<K, V> implements MultiValuedMap<K,
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean result = coll.removeAll(c);
|
final boolean result = coll.removeAll(c);
|
||||||
if (coll.isEmpty()) {
|
if (coll.isEmpty()) {
|
||||||
AbstractMultiValuedMap.this.remove(key);
|
AbstractMultiValuedMap.this.remove(key);
|
||||||
}
|
}
|
||||||
@ -512,7 +512,7 @@ public abstract class AbstractMultiValuedMap<K, V> implements MultiValuedMap<K,
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean result = coll.retainAll(c);
|
final boolean result = coll.retainAll(c);
|
||||||
if (coll.isEmpty()) {
|
if (coll.isEmpty()) {
|
||||||
AbstractMultiValuedMap.this.remove(key);
|
AbstractMultiValuedMap.this.remove(key);
|
||||||
}
|
}
|
||||||
@ -577,7 +577,7 @@ public abstract class AbstractMultiValuedMap<K, V> implements MultiValuedMap<K,
|
|||||||
@Override
|
@Override
|
||||||
public int getCount(final Object object) {
|
public int getCount(final Object object) {
|
||||||
int count = 0;
|
int count = 0;
|
||||||
Collection<V> col = AbstractMultiValuedMap.this.getMap().get(object);
|
final Collection<V> col = AbstractMultiValuedMap.this.getMap().get(object);
|
||||||
if (col != null) {
|
if (col != null) {
|
||||||
count = col.size();
|
count = col.size();
|
||||||
}
|
}
|
||||||
@ -797,11 +797,12 @@ public abstract class AbstractMultiValuedMap<K, V> implements MultiValuedMap<K,
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Collection<V> get(final Object key) {
|
public Collection<V> get(final Object key) {
|
||||||
Collection<V> collection = decoratedMap.get(key);
|
final Collection<V> collection = decoratedMap.get(key);
|
||||||
if (collection == null) {
|
if (collection == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
|
final
|
||||||
K k = (K) key;
|
K k = (K) key;
|
||||||
return wrappedCollection(k);
|
return wrappedCollection(k);
|
||||||
}
|
}
|
||||||
@ -818,7 +819,7 @@ public abstract class AbstractMultiValuedMap<K, V> implements MultiValuedMap<K,
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Collection<V> remove(final Object key) {
|
public Collection<V> remove(final Object key) {
|
||||||
Collection<V> collection = decoratedMap.remove(key);
|
final Collection<V> collection = decoratedMap.remove(key);
|
||||||
if (collection == null) {
|
if (collection == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -876,7 +877,7 @@ public abstract class AbstractMultiValuedMap<K, V> implements MultiValuedMap<K,
|
|||||||
if (!contains(o)) {
|
if (!contains(o)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
Map.Entry<?, ?> entry = (Map.Entry<?, ?>) o;
|
final Map.Entry<?, ?> entry = (Map.Entry<?, ?>) o;
|
||||||
AbstractMultiValuedMap.this.remove(entry.getKey());
|
AbstractMultiValuedMap.this.remove(entry.getKey());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -934,6 +935,7 @@ public abstract class AbstractMultiValuedMap<K, V> implements MultiValuedMap<K,
|
|||||||
final int valueSize = in.readInt();
|
final int valueSize = in.readInt();
|
||||||
for (int j = 0; j < valueSize; j++) {
|
for (int j = 0; j < valueSize; j++) {
|
||||||
@SuppressWarnings("unchecked") // see above
|
@SuppressWarnings("unchecked") // see above
|
||||||
|
final
|
||||||
V value = (V) in.readObject();
|
V value = (V) in.readObject();
|
||||||
values.add(value);
|
values.add(value);
|
||||||
}
|
}
|
||||||
|
@ -119,7 +119,7 @@ public abstract class AbstractSetValuedMap<K, V> extends AbstractMultiValuedMap<
|
|||||||
if (!(other instanceof Set)) {
|
if (!(other instanceof Set)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
Set<?> otherSet = (Set<?>) other;
|
final Set<?> otherSet = (Set<?>) other;
|
||||||
return SetUtils.isEqualSet(set, otherSet);
|
return SetUtils.isEqualSet(set, otherSet);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -121,7 +121,7 @@ public class ArrayListValuedHashMap<K, V> extends AbstractListValuedMap<K, V>
|
|||||||
* Trims the capacity of all value collections to their current size.
|
* Trims the capacity of all value collections to their current size.
|
||||||
*/
|
*/
|
||||||
public void trimToSize() {
|
public void trimToSize() {
|
||||||
for (Collection<V> coll : getMap().values()) {
|
for (final Collection<V> coll : getMap().values()) {
|
||||||
final ArrayList<V> list = (ArrayList<V>) coll;
|
final ArrayList<V> list = (ArrayList<V>) coll;
|
||||||
list.trimToSize();
|
list.trimToSize();
|
||||||
}
|
}
|
||||||
|
@ -169,7 +169,7 @@ public class TransformedMultiValuedMap<K, V> extends AbstractMultiValuedMapDecor
|
|||||||
throw new NullPointerException("Map must not be null.");
|
throw new NullPointerException("Map must not be null.");
|
||||||
}
|
}
|
||||||
boolean changed = false;
|
boolean changed = false;
|
||||||
for (Map.Entry<? extends K, ? extends V> entry : map.entrySet()) {
|
for (final Map.Entry<? extends K, ? extends V> entry : map.entrySet()) {
|
||||||
changed |= put(entry.getKey(), entry.getValue());
|
changed |= put(entry.getKey(), entry.getValue());
|
||||||
}
|
}
|
||||||
return changed;
|
return changed;
|
||||||
@ -181,7 +181,7 @@ public class TransformedMultiValuedMap<K, V> extends AbstractMultiValuedMapDecor
|
|||||||
throw new NullPointerException("Map must not be null.");
|
throw new NullPointerException("Map must not be null.");
|
||||||
}
|
}
|
||||||
boolean changed = false;
|
boolean changed = false;
|
||||||
for (Map.Entry<? extends K, ? extends V> entry : map.entries()) {
|
for (final Map.Entry<? extends K, ? extends V> entry : map.entries()) {
|
||||||
changed |= put(entry.getKey(), entry.getValue());
|
changed |= put(entry.getKey(), entry.getValue());
|
||||||
}
|
}
|
||||||
return changed;
|
return changed;
|
||||||
|
@ -220,7 +220,7 @@ public abstract class AbstractMapMultiSet<E> extends AbstractMultiSet<E> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
final MutableInteger mut = map.get(object);
|
final MutableInteger mut = map.get(object);
|
||||||
int oldCount = mut != null ? mut.value : 0;
|
final int oldCount = mut != null ? mut.value : 0;
|
||||||
|
|
||||||
if (occurrences > 0) {
|
if (occurrences > 0) {
|
||||||
modCount++;
|
modCount++;
|
||||||
@ -255,7 +255,7 @@ public abstract class AbstractMapMultiSet<E> extends AbstractMultiSet<E> {
|
|||||||
if (mut == null) {
|
if (mut == null) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
int oldCount = mut.value;
|
final int oldCount = mut.value;
|
||||||
if (occurrences > 0) {
|
if (occurrences > 0) {
|
||||||
modCount++;
|
modCount++;
|
||||||
if (occurrences < mut.value) {
|
if (occurrences < mut.value) {
|
||||||
|
@ -58,7 +58,7 @@ public abstract class AbstractMultiSet<E> extends AbstractCollection<E> implemen
|
|||||||
@Override
|
@Override
|
||||||
public int size() {
|
public int size() {
|
||||||
int totalSize = 0;
|
int totalSize = 0;
|
||||||
for (Entry<E> entry : entrySet()) {
|
for (final Entry<E> entry : entrySet()) {
|
||||||
totalSize += entry.getCount();
|
totalSize += entry.getCount();
|
||||||
}
|
}
|
||||||
return totalSize;
|
return totalSize;
|
||||||
@ -73,7 +73,7 @@ public abstract class AbstractMultiSet<E> extends AbstractCollection<E> implemen
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public int getCount(final Object object) {
|
public int getCount(final Object object) {
|
||||||
for (Entry<E> entry : entrySet()) {
|
for (final Entry<E> entry : entrySet()) {
|
||||||
final E element = entry.getElement();
|
final E element = entry.getElement();
|
||||||
if (element == object ||
|
if (element == object ||
|
||||||
element != null && element.equals(object)) {
|
element != null && element.equals(object)) {
|
||||||
@ -89,7 +89,7 @@ public abstract class AbstractMultiSet<E> extends AbstractCollection<E> implemen
|
|||||||
throw new IllegalArgumentException("Count must not be negative.");
|
throw new IllegalArgumentException("Count must not be negative.");
|
||||||
}
|
}
|
||||||
|
|
||||||
int oldCount = getCount(object);
|
final int oldCount = getCount(object);
|
||||||
if (oldCount < count) {
|
if (oldCount < count) {
|
||||||
add(object, count - oldCount);
|
add(object, count - oldCount);
|
||||||
} else {
|
} else {
|
||||||
@ -196,7 +196,7 @@ public abstract class AbstractMultiSet<E> extends AbstractCollection<E> implemen
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void clear() {
|
public void clear() {
|
||||||
Iterator<Entry<E>> it = entrySet().iterator();
|
final Iterator<Entry<E>> it = entrySet().iterator();
|
||||||
while (it.hasNext()) {
|
while (it.hasNext()) {
|
||||||
it.next();
|
it.next();
|
||||||
it.remove();
|
it.remove();
|
||||||
|
@ -387,7 +387,7 @@ public class CompositeSet<E> implements Set<E>, Serializable {
|
|||||||
* @param sets the Sets to be appended to the composite
|
* @param sets the Sets to be appended to the composite
|
||||||
*/
|
*/
|
||||||
public void addComposited(final Set<E>... sets) {
|
public void addComposited(final Set<E>... sets) {
|
||||||
for (Set<E> set : sets) {
|
for (final Set<E> set : sets) {
|
||||||
addComposited(set);
|
addComposited(set);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -235,14 +235,14 @@ public class ListOrderedSet<E>
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public boolean retainAll(final Collection<?> coll) {
|
public boolean retainAll(final Collection<?> coll) {
|
||||||
boolean result = decorated().retainAll(coll);
|
final boolean result = decorated().retainAll(coll);
|
||||||
if (result == false) {
|
if (result == false) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (decorated().size() == 0) {
|
if (decorated().size() == 0) {
|
||||||
setOrder.clear();
|
setOrder.clear();
|
||||||
} else {
|
} else {
|
||||||
for (Iterator<E> it = setOrder.iterator(); it.hasNext();) {
|
for (final Iterator<E> it = setOrder.iterator(); it.hasNext();) {
|
||||||
if (!decorated().contains(it.next())) {
|
if (!decorated().contains(it.next())) {
|
||||||
it.remove();
|
it.remove();
|
||||||
}
|
}
|
||||||
|
@ -2260,8 +2260,8 @@ abstract class AbstractPatriciaTrie<K, V> extends AbstractBitwiseTrie<K, V> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void clear() {
|
public void clear() {
|
||||||
Iterator<Map.Entry<K, V>> it = AbstractPatriciaTrie.this.entrySet().iterator();
|
final Iterator<Map.Entry<K, V>> it = AbstractPatriciaTrie.this.entrySet().iterator();
|
||||||
Set<K> currentKeys = keySet();
|
final Set<K> currentKeys = keySet();
|
||||||
while (it.hasNext()) {
|
while (it.hasNext()) {
|
||||||
if (currentKeys.contains(it.next().getKey())) {
|
if (currentKeys.contains(it.next().getKey())) {
|
||||||
it.remove();
|
it.remove();
|
||||||
@ -2427,10 +2427,10 @@ abstract class AbstractPatriciaTrie<K, V> extends AbstractBitwiseTrie<K, V> {
|
|||||||
private void readObject(final ObjectInputStream stream) throws IOException, ClassNotFoundException{
|
private void readObject(final ObjectInputStream stream) throws IOException, ClassNotFoundException{
|
||||||
stream.defaultReadObject();
|
stream.defaultReadObject();
|
||||||
root = new TrieEntry<>(null, null, -1);
|
root = new TrieEntry<>(null, null, -1);
|
||||||
int size = stream.readInt();
|
final int size = stream.readInt();
|
||||||
for(int i = 0; i < size; i++){
|
for(int i = 0; i < size; i++){
|
||||||
K k = (K) stream.readObject();
|
final K k = (K) stream.readObject();
|
||||||
V v = (V) stream.readObject();
|
final V v = (V) stream.readObject();
|
||||||
put(k, v);
|
put(k, v);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -44,7 +44,7 @@ public class BagUtilsTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSynchronizedBag() {
|
public void testSynchronizedBag() {
|
||||||
Bag<Object> bag = BagUtils.synchronizedBag(new HashBag<>());
|
final Bag<Object> bag = BagUtils.synchronizedBag(new HashBag<>());
|
||||||
assertTrue("Returned object should be a SynchronizedBag.",
|
assertTrue("Returned object should be a SynchronizedBag.",
|
||||||
bag instanceof SynchronizedBag);
|
bag instanceof SynchronizedBag);
|
||||||
try {
|
try {
|
||||||
@ -57,7 +57,7 @@ public class BagUtilsTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testUnmodifiableBag() {
|
public void testUnmodifiableBag() {
|
||||||
Bag<Object> bag = BagUtils.unmodifiableBag(new HashBag<>());
|
final Bag<Object> bag = BagUtils.unmodifiableBag(new HashBag<>());
|
||||||
assertTrue("Returned object should be an UnmodifiableBag.",
|
assertTrue("Returned object should be an UnmodifiableBag.",
|
||||||
bag instanceof UnmodifiableBag);
|
bag instanceof UnmodifiableBag);
|
||||||
try {
|
try {
|
||||||
@ -72,7 +72,7 @@ public class BagUtilsTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPredicatedBag() {
|
public void testPredicatedBag() {
|
||||||
Bag<Object> bag = BagUtils.predicatedBag(new HashBag<>(), truePredicate);
|
final Bag<Object> bag = BagUtils.predicatedBag(new HashBag<>(), truePredicate);
|
||||||
assertTrue("Returned object should be a PredicatedBag.",
|
assertTrue("Returned object should be a PredicatedBag.",
|
||||||
bag instanceof PredicatedBag);
|
bag instanceof PredicatedBag);
|
||||||
try {
|
try {
|
||||||
@ -91,7 +91,7 @@ public class BagUtilsTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testTransformedBag() {
|
public void testTransformedBag() {
|
||||||
Bag<Object> bag = BagUtils.transformingBag(new HashBag<>(), nopTransformer);
|
final Bag<Object> bag = BagUtils.transformingBag(new HashBag<>(), nopTransformer);
|
||||||
assertTrue("Returned object should be an TransformedBag.",
|
assertTrue("Returned object should be an TransformedBag.",
|
||||||
bag instanceof TransformedBag);
|
bag instanceof TransformedBag);
|
||||||
try {
|
try {
|
||||||
@ -110,7 +110,7 @@ public class BagUtilsTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSynchronizedSortedBag() {
|
public void testSynchronizedSortedBag() {
|
||||||
Bag<Object> bag = BagUtils.synchronizedSortedBag(new TreeBag<>());
|
final Bag<Object> bag = BagUtils.synchronizedSortedBag(new TreeBag<>());
|
||||||
assertTrue("Returned object should be a SynchronizedSortedBag.",
|
assertTrue("Returned object should be a SynchronizedSortedBag.",
|
||||||
bag instanceof SynchronizedSortedBag);
|
bag instanceof SynchronizedSortedBag);
|
||||||
try {
|
try {
|
||||||
@ -123,7 +123,7 @@ public class BagUtilsTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testUnmodifiableSortedBag() {
|
public void testUnmodifiableSortedBag() {
|
||||||
SortedBag<Object> bag = BagUtils.unmodifiableSortedBag(new TreeBag<>());
|
final SortedBag<Object> bag = BagUtils.unmodifiableSortedBag(new TreeBag<>());
|
||||||
assertTrue("Returned object should be an UnmodifiableSortedBag.",
|
assertTrue("Returned object should be an UnmodifiableSortedBag.",
|
||||||
bag instanceof UnmodifiableSortedBag);
|
bag instanceof UnmodifiableSortedBag);
|
||||||
try {
|
try {
|
||||||
@ -138,7 +138,7 @@ public class BagUtilsTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPredicatedSortedBag() {
|
public void testPredicatedSortedBag() {
|
||||||
Bag<Object> bag = BagUtils.predicatedSortedBag(new TreeBag<>(), truePredicate);
|
final Bag<Object> bag = BagUtils.predicatedSortedBag(new TreeBag<>(), truePredicate);
|
||||||
assertTrue("Returned object should be a PredicatedSortedBag.",
|
assertTrue("Returned object should be a PredicatedSortedBag.",
|
||||||
bag instanceof PredicatedSortedBag);
|
bag instanceof PredicatedSortedBag);
|
||||||
try {
|
try {
|
||||||
@ -157,7 +157,7 @@ public class BagUtilsTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testTransformedSortedBag() {
|
public void testTransformedSortedBag() {
|
||||||
Bag<Object> bag = BagUtils.transformingSortedBag(new TreeBag<>(), nopTransformer);
|
final Bag<Object> bag = BagUtils.transformingSortedBag(new TreeBag<>(), nopTransformer);
|
||||||
assertTrue("Returned object should be an TransformedSortedBag",
|
assertTrue("Returned object should be an TransformedSortedBag",
|
||||||
bag instanceof TransformedSortedBag);
|
bag instanceof TransformedSortedBag);
|
||||||
try {
|
try {
|
||||||
|
@ -698,7 +698,7 @@ public class CollectionUtilsTest extends MockTestCase {
|
|||||||
lastElement = CollectionUtils.forAllButLastDo(col, testClosure);
|
lastElement = CollectionUtils.forAllButLastDo(col, testClosure);
|
||||||
assertNull(lastElement);
|
assertNull(lastElement);
|
||||||
|
|
||||||
Collection<String> strings = Arrays.asList("a", "b", "c");
|
final Collection<String> strings = Arrays.asList("a", "b", "c");
|
||||||
final StringBuffer result = new StringBuffer();
|
final StringBuffer result = new StringBuffer();
|
||||||
result.append(CollectionUtils.forAllButLastDo(strings, new Closure<String>() {
|
result.append(CollectionUtils.forAllButLastDo(strings, new Closure<String>() {
|
||||||
@Override
|
@Override
|
||||||
@ -708,7 +708,7 @@ public class CollectionUtilsTest extends MockTestCase {
|
|||||||
}));
|
}));
|
||||||
assertEquals("a;b;c", result.toString());
|
assertEquals("a;b;c", result.toString());
|
||||||
|
|
||||||
Collection<String> oneString = Arrays.asList("a");
|
final Collection<String> oneString = Arrays.asList("a");
|
||||||
final StringBuffer resultOne = new StringBuffer();
|
final StringBuffer resultOne = new StringBuffer();
|
||||||
resultOne.append(CollectionUtils.forAllButLastDo(oneString, new Closure<String>() {
|
resultOne.append(CollectionUtils.forAllButLastDo(oneString, new Closure<String>() {
|
||||||
@Override
|
@Override
|
||||||
@ -728,7 +728,7 @@ public class CollectionUtilsTest extends MockTestCase {
|
|||||||
final Collection<List<? extends Number>> col = new ArrayList<>();
|
final Collection<List<? extends Number>> col = new ArrayList<>();
|
||||||
col.add(collectionA);
|
col.add(collectionA);
|
||||||
col.add(collectionB);
|
col.add(collectionB);
|
||||||
List<? extends Number> lastElement = CollectionUtils.forAllButLastDo(col.iterator(), testClosure);
|
final List<? extends Number> lastElement = CollectionUtils.forAllButLastDo(col.iterator(), testClosure);
|
||||||
assertSame(lastElement, collectionB);
|
assertSame(lastElement, collectionB);
|
||||||
assertTrue(collectionA.isEmpty() && !collectionB.isEmpty());
|
assertTrue(collectionA.isEmpty() && !collectionB.isEmpty());
|
||||||
|
|
||||||
@ -1178,14 +1178,14 @@ public class CollectionUtilsTest extends MockTestCase {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void selectWithOutputCollections() {
|
public void selectWithOutputCollections() {
|
||||||
List<Integer> input = new ArrayList<>();
|
final List<Integer> input = new ArrayList<>();
|
||||||
input.add(1);
|
input.add(1);
|
||||||
input.add(2);
|
input.add(2);
|
||||||
input.add(3);
|
input.add(3);
|
||||||
input.add(4);
|
input.add(4);
|
||||||
|
|
||||||
List<Integer> output = new ArrayList<>();
|
final List<Integer> output = new ArrayList<>();
|
||||||
List<Integer> rejected = new ArrayList<>();
|
final List<Integer> rejected = new ArrayList<>();
|
||||||
|
|
||||||
CollectionUtils.select(input, EQUALS_TWO, output, rejected);
|
CollectionUtils.select(input, EQUALS_TWO, output, rejected);
|
||||||
|
|
||||||
@ -1194,7 +1194,7 @@ public class CollectionUtilsTest extends MockTestCase {
|
|||||||
assertEquals(2, CollectionUtils.extractSingleton(output).intValue());
|
assertEquals(2, CollectionUtils.extractSingleton(output).intValue());
|
||||||
|
|
||||||
// rejected contains 1, 3, and 4
|
// rejected contains 1, 3, and 4
|
||||||
Integer[] expected = {1, 3, 4};
|
final Integer[] expected = {1, 3, 4};
|
||||||
Assert.assertArrayEquals(expected, rejected.toArray());
|
Assert.assertArrayEquals(expected, rejected.toArray());
|
||||||
|
|
||||||
output.clear();
|
output.clear();
|
||||||
@ -1330,7 +1330,7 @@ public class CollectionUtilsTest extends MockTestCase {
|
|||||||
@Test
|
@Test
|
||||||
public void predicatedCollection() {
|
public void predicatedCollection() {
|
||||||
final Predicate<Object> predicate = PredicateUtils.instanceofPredicate(Integer.class);
|
final Predicate<Object> predicate = PredicateUtils.instanceofPredicate(Integer.class);
|
||||||
Collection<Number> collection = CollectionUtils.predicatedCollection(new ArrayList<Number>(), predicate);
|
final Collection<Number> collection = CollectionUtils.predicatedCollection(new ArrayList<Number>(), predicate);
|
||||||
assertTrue("returned object should be a PredicatedCollection", collection instanceof PredicatedCollection);
|
assertTrue("returned object should be a PredicatedCollection", collection instanceof PredicatedCollection);
|
||||||
try {
|
try {
|
||||||
CollectionUtils.predicatedCollection(new ArrayList<Number>(), null);
|
CollectionUtils.predicatedCollection(new ArrayList<Number>(), null);
|
||||||
@ -1505,7 +1505,7 @@ public class CollectionUtilsTest extends MockTestCase {
|
|||||||
@Test
|
@Test
|
||||||
public void testTransformedCollection() {
|
public void testTransformedCollection() {
|
||||||
final Transformer<Object, Object> transformer = TransformerUtils.nopTransformer();
|
final Transformer<Object, Object> transformer = TransformerUtils.nopTransformer();
|
||||||
Collection<Object> collection = CollectionUtils.transformingCollection(new ArrayList<>(), transformer);
|
final Collection<Object> collection = CollectionUtils.transformingCollection(new ArrayList<>(), transformer);
|
||||||
assertTrue("returned object should be a TransformedCollection", collection instanceof TransformedCollection);
|
assertTrue("returned object should be a TransformedCollection", collection instanceof TransformedCollection);
|
||||||
try {
|
try {
|
||||||
CollectionUtils.transformingCollection(new ArrayList<>(), null);
|
CollectionUtils.transformingCollection(new ArrayList<>(), null);
|
||||||
@ -1536,7 +1536,7 @@ public class CollectionUtilsTest extends MockTestCase {
|
|||||||
@Test
|
@Test
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public void testSynchronizedCollection() {
|
public void testSynchronizedCollection() {
|
||||||
Collection<Object> col = CollectionUtils.synchronizedCollection(new ArrayList<>());
|
final Collection<Object> col = CollectionUtils.synchronizedCollection(new ArrayList<>());
|
||||||
assertTrue("Returned object should be a SynchronizedCollection.", col instanceof SynchronizedCollection);
|
assertTrue("Returned object should be a SynchronizedCollection.", col instanceof SynchronizedCollection);
|
||||||
try {
|
try {
|
||||||
CollectionUtils.synchronizedCollection(null);
|
CollectionUtils.synchronizedCollection(null);
|
||||||
@ -1549,7 +1549,7 @@ public class CollectionUtilsTest extends MockTestCase {
|
|||||||
@Test
|
@Test
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public void testUnmodifiableCollection() {
|
public void testUnmodifiableCollection() {
|
||||||
Collection<Object> col = CollectionUtils.unmodifiableCollection(new ArrayList<>());
|
final Collection<Object> col = CollectionUtils.unmodifiableCollection(new ArrayList<>());
|
||||||
assertTrue("Returned object should be a UnmodifiableCollection.", col instanceof UnmodifiableCollection);
|
assertTrue("Returned object should be a UnmodifiableCollection.", col instanceof UnmodifiableCollection);
|
||||||
try {
|
try {
|
||||||
CollectionUtils.unmodifiableCollection(null);
|
CollectionUtils.unmodifiableCollection(null);
|
||||||
@ -1735,7 +1735,7 @@ public class CollectionUtilsTest extends MockTestCase {
|
|||||||
List<Integer> result2 = CollectionUtils.collate(collectionE, collectionD);
|
List<Integer> result2 = CollectionUtils.collate(collectionE, collectionD);
|
||||||
assertEquals("Merge two lists 1", result1, result2);
|
assertEquals("Merge two lists 1", result1, result2);
|
||||||
|
|
||||||
List<Integer> combinedList = new ArrayList<>();
|
final List<Integer> combinedList = new ArrayList<>();
|
||||||
combinedList.addAll(collectionD);
|
combinedList.addAll(collectionD);
|
||||||
combinedList.addAll(collectionE);
|
combinedList.addAll(collectionE);
|
||||||
Collections.sort(combinedList);
|
Collections.sort(combinedList);
|
||||||
@ -1760,14 +1760,14 @@ public class CollectionUtilsTest extends MockTestCase {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCollateIgnoreDuplicates() {
|
public void testCollateIgnoreDuplicates() {
|
||||||
List<Integer> result1 = CollectionUtils.collate(collectionD, collectionE, false);
|
final List<Integer> result1 = CollectionUtils.collate(collectionD, collectionE, false);
|
||||||
List<Integer> result2 = CollectionUtils.collate(collectionE, collectionD, false);
|
final List<Integer> result2 = CollectionUtils.collate(collectionE, collectionD, false);
|
||||||
assertEquals("Merge two lists 1 - ignore duplicates", result1, result2);
|
assertEquals("Merge two lists 1 - ignore duplicates", result1, result2);
|
||||||
|
|
||||||
Set<Integer> combinedSet = new HashSet<>();
|
final Set<Integer> combinedSet = new HashSet<>();
|
||||||
combinedSet.addAll(collectionD);
|
combinedSet.addAll(collectionD);
|
||||||
combinedSet.addAll(collectionE);
|
combinedSet.addAll(collectionE);
|
||||||
List<Integer> combinedList = new ArrayList<>(combinedSet);
|
final List<Integer> combinedList = new ArrayList<>(combinedSet);
|
||||||
Collections.sort(combinedList);
|
Collections.sort(combinedList);
|
||||||
|
|
||||||
assertEquals("Merge two lists 2 - ignore duplicates", combinedList, result2);
|
assertEquals("Merge two lists 2 - ignore duplicates", combinedList, result2);
|
||||||
@ -1780,11 +1780,11 @@ public class CollectionUtilsTest extends MockTestCase {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPermutations() {
|
public void testPermutations() {
|
||||||
List<Integer> sample = collectionA.subList(0, 5);
|
final List<Integer> sample = collectionA.subList(0, 5);
|
||||||
Collection<List<Integer>> permutations = CollectionUtils.permutations(sample);
|
final Collection<List<Integer>> permutations = CollectionUtils.permutations(sample);
|
||||||
|
|
||||||
// result size = n!
|
// result size = n!
|
||||||
int collSize = sample.size();
|
final int collSize = sample.size();
|
||||||
int factorial = 1;
|
int factorial = 1;
|
||||||
for (int i = 1; i <= collSize; i++) {
|
for (int i = 1; i <= collSize; i++) {
|
||||||
factorial *= i;
|
factorial *= i;
|
||||||
@ -1798,7 +1798,7 @@ public class CollectionUtilsTest extends MockTestCase {
|
|||||||
assertFalse(CollectionUtils.matchesAll(null, null));
|
assertFalse(CollectionUtils.matchesAll(null, null));
|
||||||
assertFalse(CollectionUtils.matchesAll(collectionA, null));
|
assertFalse(CollectionUtils.matchesAll(collectionA, null));
|
||||||
|
|
||||||
Predicate<Integer> lessThanFive = new Predicate<Integer>() {
|
final Predicate<Integer> lessThanFive = new Predicate<Integer>() {
|
||||||
@Override
|
@Override
|
||||||
public boolean evaluate(final Integer object) {
|
public boolean evaluate(final Integer object) {
|
||||||
return object < 5;
|
return object < 5;
|
||||||
@ -1806,7 +1806,7 @@ public class CollectionUtilsTest extends MockTestCase {
|
|||||||
};
|
};
|
||||||
assertTrue(CollectionUtils.matchesAll(collectionA, lessThanFive));
|
assertTrue(CollectionUtils.matchesAll(collectionA, lessThanFive));
|
||||||
|
|
||||||
Predicate<Integer> lessThanFour = new Predicate<Integer>() {
|
final Predicate<Integer> lessThanFour = new Predicate<Integer>() {
|
||||||
@Override
|
@Override
|
||||||
public boolean evaluate(final Integer object) {
|
public boolean evaluate(final Integer object) {
|
||||||
return object < 4;
|
return object < 4;
|
||||||
|
@ -46,7 +46,7 @@ public class ComparatorUtilsTest {
|
|||||||
@Test
|
@Test
|
||||||
public void chainedComparator() {
|
public void chainedComparator() {
|
||||||
// simple test: chain 2 natural comparators
|
// simple test: chain 2 natural comparators
|
||||||
Comparator<Integer> comp = ComparatorUtils.chainedComparator(ComparatorUtils.<Integer>naturalComparator(),
|
final Comparator<Integer> comp = ComparatorUtils.chainedComparator(ComparatorUtils.<Integer>naturalComparator(),
|
||||||
ComparatorUtils.<Integer>naturalComparator());
|
ComparatorUtils.<Integer>naturalComparator());
|
||||||
assertTrue(comp.compare(1, 2) < 0);
|
assertTrue(comp.compare(1, 2) < 0);
|
||||||
assertTrue(comp.compare(1, 1) == 0);
|
assertTrue(comp.compare(1, 1) == 0);
|
||||||
@ -55,7 +55,7 @@ public class ComparatorUtilsTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void max() {
|
public void max() {
|
||||||
Comparator<Integer> reversed =
|
final Comparator<Integer> reversed =
|
||||||
ComparatorUtils.reversedComparator(ComparatorUtils.<Integer>naturalComparator());
|
ComparatorUtils.reversedComparator(ComparatorUtils.<Integer>naturalComparator());
|
||||||
|
|
||||||
assertEquals(Integer.valueOf(10), ComparatorUtils.max(1, 10, null));
|
assertEquals(Integer.valueOf(10), ComparatorUtils.max(1, 10, null));
|
||||||
@ -67,21 +67,21 @@ public class ComparatorUtilsTest {
|
|||||||
try {
|
try {
|
||||||
ComparatorUtils.max(1, null, null);
|
ComparatorUtils.max(1, null, null);
|
||||||
fail("expecting NullPointerException");
|
fail("expecting NullPointerException");
|
||||||
} catch (NullPointerException npe) {
|
} catch (final NullPointerException npe) {
|
||||||
// expected
|
// expected
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
ComparatorUtils.max(null, 10, null);
|
ComparatorUtils.max(null, 10, null);
|
||||||
fail("expecting NullPointerException");
|
fail("expecting NullPointerException");
|
||||||
} catch (NullPointerException npe) {
|
} catch (final NullPointerException npe) {
|
||||||
// expected
|
// expected
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void min() {
|
public void min() {
|
||||||
Comparator<Integer> reversed =
|
final Comparator<Integer> reversed =
|
||||||
ComparatorUtils.reversedComparator(ComparatorUtils.<Integer>naturalComparator());
|
ComparatorUtils.reversedComparator(ComparatorUtils.<Integer>naturalComparator());
|
||||||
|
|
||||||
assertEquals(Integer.valueOf(1), ComparatorUtils.min(1, 10, null));
|
assertEquals(Integer.valueOf(1), ComparatorUtils.min(1, 10, null));
|
||||||
@ -93,21 +93,21 @@ public class ComparatorUtilsTest {
|
|||||||
try {
|
try {
|
||||||
ComparatorUtils.min(1, null, null);
|
ComparatorUtils.min(1, null, null);
|
||||||
fail("expecting NullPointerException");
|
fail("expecting NullPointerException");
|
||||||
} catch (NullPointerException npe) {
|
} catch (final NullPointerException npe) {
|
||||||
// expected
|
// expected
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
ComparatorUtils.min(null, 10, null);
|
ComparatorUtils.min(null, 10, null);
|
||||||
fail("expecting NullPointerException");
|
fail("expecting NullPointerException");
|
||||||
} catch (NullPointerException npe) {
|
} catch (final NullPointerException npe) {
|
||||||
// expected
|
// expected
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void nullLowComparator() {
|
public void nullLowComparator() {
|
||||||
Comparator<Integer> comp = ComparatorUtils.nullLowComparator(null);
|
final Comparator<Integer> comp = ComparatorUtils.nullLowComparator(null);
|
||||||
assertTrue(comp.compare(null, 10) < 0);
|
assertTrue(comp.compare(null, 10) < 0);
|
||||||
assertTrue(comp.compare(null, null) == 0);
|
assertTrue(comp.compare(null, null) == 0);
|
||||||
assertTrue(comp.compare(10, null) > 0);
|
assertTrue(comp.compare(10, null) > 0);
|
||||||
@ -115,7 +115,7 @@ public class ComparatorUtilsTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void nullHighComparator() {
|
public void nullHighComparator() {
|
||||||
Comparator<Integer> comp = ComparatorUtils.nullHighComparator(null);
|
final Comparator<Integer> comp = ComparatorUtils.nullHighComparator(null);
|
||||||
assertTrue(comp.compare(null, 10) > 0);
|
assertTrue(comp.compare(null, 10) > 0);
|
||||||
assertTrue(comp.compare(null, null) == 0);
|
assertTrue(comp.compare(null, null) == 0);
|
||||||
assertTrue(comp.compare(10, null) < 0);
|
assertTrue(comp.compare(10, null) < 0);
|
||||||
|
@ -110,7 +110,7 @@ public class FactoryUtilsTest {
|
|||||||
@Test
|
@Test
|
||||||
public void testPrototypeFactoryPublicCopyConstructor() throws Exception {
|
public void testPrototypeFactoryPublicCopyConstructor() throws Exception {
|
||||||
final Mock1 proto = new Mock1(6);
|
final Mock1 proto = new Mock1(6);
|
||||||
Factory<Object> factory = FactoryUtils.<Object>prototypeFactory(proto);
|
final Factory<Object> factory = FactoryUtils.<Object>prototypeFactory(proto);
|
||||||
assertNotNull(factory);
|
assertNotNull(factory);
|
||||||
final Object created = factory.create();
|
final Object created = factory.create();
|
||||||
assertTrue(proto != created);
|
assertTrue(proto != created);
|
||||||
|
@ -71,7 +71,7 @@ public class FluentIterableTest {
|
|||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
Collection<Integer> collectionA = new ArrayList<>();
|
final Collection<Integer> collectionA = new ArrayList<>();
|
||||||
collectionA.add(1);
|
collectionA.add(1);
|
||||||
collectionA.add(2);
|
collectionA.add(2);
|
||||||
collectionA.add(2);
|
collectionA.add(2);
|
||||||
@ -84,7 +84,7 @@ public class FluentIterableTest {
|
|||||||
collectionA.add(4);
|
collectionA.add(4);
|
||||||
iterableA = collectionA;
|
iterableA = collectionA;
|
||||||
|
|
||||||
Collection<Long> collectionB = new LinkedList<>();
|
final Collection<Long> collectionB = new LinkedList<>();
|
||||||
collectionB.add(5L);
|
collectionB.add(5L);
|
||||||
collectionB.add(4L);
|
collectionB.add(4L);
|
||||||
collectionB.add(4L);
|
collectionB.add(4L);
|
||||||
@ -129,14 +129,14 @@ public class FluentIterableTest {
|
|||||||
try {
|
try {
|
||||||
FluentIterable.of(it).toList();
|
FluentIterable.of(it).toList();
|
||||||
fail("expecting NullPointerException");
|
fail("expecting NullPointerException");
|
||||||
} catch (NullPointerException npe) {
|
} catch (final NullPointerException npe) {
|
||||||
// expected
|
// expected
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void appendElements() {
|
public void appendElements() {
|
||||||
FluentIterable<Integer> it = FluentIterable.of(iterableA).append(10, 20, 30);
|
final FluentIterable<Integer> it = FluentIterable.of(iterableA).append(10, 20, 30);
|
||||||
assertEquals(IterableUtils.size(iterableA) + 3, IterableUtils.size(it));
|
assertEquals(IterableUtils.size(iterableA) + 3, IterableUtils.size(it));
|
||||||
assertTrue(IterableUtils.contains(it, 1));
|
assertTrue(IterableUtils.contains(it, 1));
|
||||||
assertTrue(IterableUtils.contains(it, 10));
|
assertTrue(IterableUtils.contains(it, 10));
|
||||||
@ -144,14 +144,14 @@ public class FluentIterableTest {
|
|||||||
assertTrue(IterableUtils.contains(it, 30));
|
assertTrue(IterableUtils.contains(it, 30));
|
||||||
assertFalse(IterableUtils.contains(it, 40));
|
assertFalse(IterableUtils.contains(it, 40));
|
||||||
|
|
||||||
FluentIterable<Integer> empty = FluentIterable.of(emptyIterable).append();
|
final FluentIterable<Integer> empty = FluentIterable.of(emptyIterable).append();
|
||||||
assertTrue(IterableUtils.isEmpty(empty));
|
assertTrue(IterableUtils.isEmpty(empty));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void appendIterable() {
|
public void appendIterable() {
|
||||||
List<Integer> listB = Arrays.asList(10, 20, 30);
|
final List<Integer> listB = Arrays.asList(10, 20, 30);
|
||||||
FluentIterable<Integer> it = FluentIterable.of(iterableA).append(listB);
|
final FluentIterable<Integer> it = FluentIterable.of(iterableA).append(listB);
|
||||||
assertEquals(IterableUtils.size(iterableA) + listB.size(), IterableUtils.size(it));
|
assertEquals(IterableUtils.size(iterableA) + listB.size(), IterableUtils.size(it));
|
||||||
assertTrue(IterableUtils.contains(it, 1));
|
assertTrue(IterableUtils.contains(it, 1));
|
||||||
assertTrue(IterableUtils.contains(it, 10));
|
assertTrue(IterableUtils.contains(it, 10));
|
||||||
@ -162,8 +162,8 @@ public class FluentIterableTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void collate() {
|
public void collate() {
|
||||||
List<Integer> result = FluentIterable.of(iterableOdd).collate(iterableEven).toList();
|
final List<Integer> result = FluentIterable.of(iterableOdd).collate(iterableEven).toList();
|
||||||
List<Integer> combinedList = new ArrayList<>();
|
final List<Integer> combinedList = new ArrayList<>();
|
||||||
CollectionUtils.addAll(combinedList, iterableOdd);
|
CollectionUtils.addAll(combinedList, iterableOdd);
|
||||||
CollectionUtils.addAll(combinedList, iterableEven);
|
CollectionUtils.addAll(combinedList, iterableEven);
|
||||||
Collections.sort(combinedList);
|
Collections.sort(combinedList);
|
||||||
@ -172,7 +172,7 @@ public class FluentIterableTest {
|
|||||||
try {
|
try {
|
||||||
FluentIterable.of(iterableOdd).collate(null).toList();
|
FluentIterable.of(iterableOdd).collate(null).toList();
|
||||||
fail("expecting NullPointerException");
|
fail("expecting NullPointerException");
|
||||||
} catch (NullPointerException npe) {
|
} catch (final NullPointerException npe) {
|
||||||
// expected
|
// expected
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -185,7 +185,7 @@ public class FluentIterableTest {
|
|||||||
.collate(iterableEven, ComparatorUtils.<Integer>naturalComparator())
|
.collate(iterableEven, ComparatorUtils.<Integer>naturalComparator())
|
||||||
.toList();
|
.toList();
|
||||||
|
|
||||||
List<Integer> combinedList = new ArrayList<>();
|
final List<Integer> combinedList = new ArrayList<>();
|
||||||
CollectionUtils.addAll(combinedList, iterableOdd);
|
CollectionUtils.addAll(combinedList, iterableOdd);
|
||||||
CollectionUtils.addAll(combinedList, iterableEven);
|
CollectionUtils.addAll(combinedList, iterableEven);
|
||||||
Collections.sort(combinedList);
|
Collections.sort(combinedList);
|
||||||
@ -198,7 +198,7 @@ public class FluentIterableTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void filter() {
|
public void filter() {
|
||||||
Predicate<Integer> smallerThan3 = new Predicate<Integer>() {
|
final Predicate<Integer> smallerThan3 = new Predicate<Integer>() {
|
||||||
@Override
|
@Override
|
||||||
public boolean evaluate(final Integer object) {
|
public boolean evaluate(final Integer object) {
|
||||||
return object.intValue() < 3;
|
return object.intValue() < 3;
|
||||||
@ -215,7 +215,7 @@ public class FluentIterableTest {
|
|||||||
try {
|
try {
|
||||||
FluentIterable.of(iterableA).filter(null).toList();
|
FluentIterable.of(iterableA).filter(null).toList();
|
||||||
fail("expecting NullPointerException");
|
fail("expecting NullPointerException");
|
||||||
} catch (NullPointerException npe) {
|
} catch (final NullPointerException npe) {
|
||||||
// expected
|
// expected
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -223,7 +223,7 @@ public class FluentIterableTest {
|
|||||||
@Test
|
@Test
|
||||||
public void forEach() {
|
public void forEach() {
|
||||||
final AtomicInteger sum = new AtomicInteger(0);
|
final AtomicInteger sum = new AtomicInteger(0);
|
||||||
Closure<Integer> closure = new Closure<Integer>() {
|
final Closure<Integer> closure = new Closure<Integer>() {
|
||||||
@Override
|
@Override
|
||||||
public void execute(final Integer input) {
|
public void execute(final Integer input) {
|
||||||
sum.addAndGet(input);
|
sum.addAndGet(input);
|
||||||
@ -232,7 +232,7 @@ public class FluentIterableTest {
|
|||||||
|
|
||||||
FluentIterable.of(iterableA).forEach(closure);
|
FluentIterable.of(iterableA).forEach(closure);
|
||||||
int expectedSum = 0;
|
int expectedSum = 0;
|
||||||
for (Integer i : iterableA) {
|
for (final Integer i : iterableA) {
|
||||||
expectedSum += i;
|
expectedSum += i;
|
||||||
}
|
}
|
||||||
assertEquals(expectedSum, sum.get());
|
assertEquals(expectedSum, sum.get());
|
||||||
@ -240,7 +240,7 @@ public class FluentIterableTest {
|
|||||||
try {
|
try {
|
||||||
FluentIterable.of(iterableA).forEach((Closure<Integer>) null);
|
FluentIterable.of(iterableA).forEach((Closure<Integer>) null);
|
||||||
fail("expecting NullPointerException");
|
fail("expecting NullPointerException");
|
||||||
} catch (NullPointerException npe) {
|
} catch (final NullPointerException npe) {
|
||||||
// expected
|
// expected
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -253,7 +253,7 @@ public class FluentIterableTest {
|
|||||||
|
|
||||||
// limit larger than input
|
// limit larger than input
|
||||||
result = FluentIterable.of(iterableA).limit(100).toList();
|
result = FluentIterable.of(iterableA).limit(100).toList();
|
||||||
List<Integer> expected = IterableUtils.toList(iterableA);
|
final List<Integer> expected = IterableUtils.toList(iterableA);
|
||||||
assertEquals(expected.size(), result.size());
|
assertEquals(expected.size(), result.size());
|
||||||
assertEquals(expected, result);
|
assertEquals(expected, result);
|
||||||
|
|
||||||
@ -268,7 +268,7 @@ public class FluentIterableTest {
|
|||||||
try {
|
try {
|
||||||
FluentIterable.of(iterableA).limit(-2).toList();
|
FluentIterable.of(iterableA).limit(-2).toList();
|
||||||
fail("expecting IllegalArgumentException");
|
fail("expecting IllegalArgumentException");
|
||||||
} catch (IllegalArgumentException iae) {
|
} catch (final IllegalArgumentException iae) {
|
||||||
// expected
|
// expected
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -276,7 +276,7 @@ public class FluentIterableTest {
|
|||||||
@Test
|
@Test
|
||||||
public void reverse() {
|
public void reverse() {
|
||||||
List<Integer> result = FluentIterable.of(iterableA).reverse().toList();
|
List<Integer> result = FluentIterable.of(iterableA).reverse().toList();
|
||||||
List<Integer> expected = IterableUtils.toList(iterableA);
|
final List<Integer> expected = IterableUtils.toList(iterableA);
|
||||||
Collections.reverse(expected);
|
Collections.reverse(expected);
|
||||||
assertEquals(expected, result);
|
assertEquals(expected, result);
|
||||||
|
|
||||||
@ -297,7 +297,7 @@ public class FluentIterableTest {
|
|||||||
|
|
||||||
// skip 0 elements
|
// skip 0 elements
|
||||||
result = FluentIterable.of(iterableA).skip(0).toList();
|
result = FluentIterable.of(iterableA).skip(0).toList();
|
||||||
List<Integer> expected = IterableUtils.toList(iterableA);
|
final List<Integer> expected = IterableUtils.toList(iterableA);
|
||||||
assertEquals(expected.size(), result.size());
|
assertEquals(expected.size(), result.size());
|
||||||
assertEquals(expected, result);
|
assertEquals(expected, result);
|
||||||
|
|
||||||
@ -308,14 +308,14 @@ public class FluentIterableTest {
|
|||||||
try {
|
try {
|
||||||
FluentIterable.of(iterableA).skip(-4).toList();
|
FluentIterable.of(iterableA).skip(-4).toList();
|
||||||
fail("expecting IllegalArgumentException");
|
fail("expecting IllegalArgumentException");
|
||||||
} catch (IllegalArgumentException iae) {
|
} catch (final IllegalArgumentException iae) {
|
||||||
// expected
|
// expected
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void transform() {
|
public void transform() {
|
||||||
Transformer<Integer, Integer> squared = new Transformer<Integer, Integer>() {
|
final Transformer<Integer, Integer> squared = new Transformer<Integer, Integer>() {
|
||||||
@Override
|
@Override
|
||||||
public Integer transform(final Integer object) {
|
public Integer transform(final Integer object) {
|
||||||
return object * object;
|
return object * object;
|
||||||
@ -332,7 +332,7 @@ public class FluentIterableTest {
|
|||||||
try {
|
try {
|
||||||
FluentIterable.of(iterableA).transform(null).toList();
|
FluentIterable.of(iterableA).transform(null).toList();
|
||||||
fail("expecting NullPointerException");
|
fail("expecting NullPointerException");
|
||||||
} catch (NullPointerException npe) {
|
} catch (final NullPointerException npe) {
|
||||||
// expected
|
// expected
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -350,18 +350,18 @@ public class FluentIterableTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void unmodifiable() {
|
public void unmodifiable() {
|
||||||
FluentIterable<Integer> iterable1 = FluentIterable.of(iterableA).unmodifiable();
|
final FluentIterable<Integer> iterable1 = FluentIterable.of(iterableA).unmodifiable();
|
||||||
Iterator<Integer> it = iterable1.iterator();
|
final Iterator<Integer> it = iterable1.iterator();
|
||||||
assertEquals(1, it.next().intValue());
|
assertEquals(1, it.next().intValue());
|
||||||
try {
|
try {
|
||||||
it.remove();
|
it.remove();
|
||||||
fail("expecting UnsupportedOperationException");
|
fail("expecting UnsupportedOperationException");
|
||||||
} catch (UnsupportedOperationException ise) {
|
} catch (final UnsupportedOperationException ise) {
|
||||||
// expected
|
// expected
|
||||||
}
|
}
|
||||||
|
|
||||||
// calling unmodifiable on an already unmodifiable iterable shall return the same instance
|
// calling unmodifiable on an already unmodifiable iterable shall return the same instance
|
||||||
FluentIterable<Integer> iterable2 = iterable1.unmodifiable();
|
final FluentIterable<Integer> iterable2 = iterable1.unmodifiable();
|
||||||
assertSame(iterable1, iterable2);
|
assertSame(iterable1, iterable2);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -378,7 +378,7 @@ public class FluentIterableTest {
|
|||||||
try {
|
try {
|
||||||
FluentIterable.of(iterableOdd).zip((Iterable<Integer>) null).toList();
|
FluentIterable.of(iterableOdd).zip((Iterable<Integer>) null).toList();
|
||||||
fail("expecting NullPointerException");
|
fail("expecting NullPointerException");
|
||||||
} catch (NullPointerException npe) {
|
} catch (final NullPointerException npe) {
|
||||||
// expected
|
// expected
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -393,7 +393,7 @@ public class FluentIterableTest {
|
|||||||
@Test
|
@Test
|
||||||
public void asEnumeration() {
|
public void asEnumeration() {
|
||||||
Enumeration<Long> enumeration = FluentIterable.of(iterableB).asEnumeration();
|
Enumeration<Long> enumeration = FluentIterable.of(iterableB).asEnumeration();
|
||||||
List<Long> result = EnumerationUtils.toList(enumeration);
|
final List<Long> result = EnumerationUtils.toList(enumeration);
|
||||||
assertEquals(iterableB, result);
|
assertEquals(iterableB, result);
|
||||||
|
|
||||||
enumeration = FluentIterable.<Long>empty().asEnumeration();
|
enumeration = FluentIterable.<Long>empty().asEnumeration();
|
||||||
@ -409,7 +409,7 @@ public class FluentIterableTest {
|
|||||||
try {
|
try {
|
||||||
FluentIterable.of(iterableEven).allMatch(null);
|
FluentIterable.of(iterableEven).allMatch(null);
|
||||||
fail("expecting NullPointerException");
|
fail("expecting NullPointerException");
|
||||||
} catch (NullPointerException npe) {
|
} catch (final NullPointerException npe) {
|
||||||
// expected
|
// expected
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -423,7 +423,7 @@ public class FluentIterableTest {
|
|||||||
try {
|
try {
|
||||||
FluentIterable.of(iterableEven).anyMatch(null);
|
FluentIterable.of(iterableEven).anyMatch(null);
|
||||||
fail("expecting NullPointerException");
|
fail("expecting NullPointerException");
|
||||||
} catch (NullPointerException npe) {
|
} catch (final NullPointerException npe) {
|
||||||
// expected
|
// expected
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -439,7 +439,7 @@ public class FluentIterableTest {
|
|||||||
try {
|
try {
|
||||||
FluentIterable.of((Iterable<?>) null).size();
|
FluentIterable.of((Iterable<?>) null).size();
|
||||||
fail("expecting NullPointerException");
|
fail("expecting NullPointerException");
|
||||||
} catch (NullPointerException npe) {
|
} catch (final NullPointerException npe) {
|
||||||
// expected
|
// expected
|
||||||
}
|
}
|
||||||
assertEquals(0, FluentIterable.of(emptyIterable).size());
|
assertEquals(0, FluentIterable.of(emptyIterable).size());
|
||||||
@ -448,10 +448,10 @@ public class FluentIterableTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void eval() {
|
public void eval() {
|
||||||
List<Integer> listNumbers = new ArrayList<>();
|
final List<Integer> listNumbers = new ArrayList<>();
|
||||||
listNumbers.addAll(Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10));
|
listNumbers.addAll(Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10));
|
||||||
FluentIterable<Integer> iterable = FluentIterable.of(listNumbers).filter(EVEN);
|
final FluentIterable<Integer> iterable = FluentIterable.of(listNumbers).filter(EVEN);
|
||||||
FluentIterable<Integer> materialized = iterable.eval();
|
final FluentIterable<Integer> materialized = iterable.eval();
|
||||||
|
|
||||||
listNumbers.addAll(Arrays.asList(11, 12, 13, 14, 15, 16, 17, 18, 19, 20));
|
listNumbers.addAll(Arrays.asList(11, 12, 13, 14, 15, 16, 17, 18, 19, 20));
|
||||||
assertEquals(5, materialized.size());
|
assertEquals(5, materialized.size());
|
||||||
@ -493,7 +493,7 @@ public class FluentIterableTest {
|
|||||||
try {
|
try {
|
||||||
FluentIterable.of(iterableA).copyInto(null);
|
FluentIterable.of(iterableA).copyInto(null);
|
||||||
fail("expecting NullPointerException");
|
fail("expecting NullPointerException");
|
||||||
} catch (NullPointerException npe) {
|
} catch (final NullPointerException npe) {
|
||||||
// expected
|
// expected
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -514,14 +514,14 @@ public class FluentIterableTest {
|
|||||||
try {
|
try {
|
||||||
FluentIterable.of(iterableEven).get(-1);
|
FluentIterable.of(iterableEven).get(-1);
|
||||||
fail("expecting IndexOutOfBoundsException");
|
fail("expecting IndexOutOfBoundsException");
|
||||||
} catch (IndexOutOfBoundsException ioe) {
|
} catch (final IndexOutOfBoundsException ioe) {
|
||||||
// expected
|
// expected
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
FluentIterable.of(iterableEven).get(IterableUtils.size(iterableEven));
|
FluentIterable.of(iterableEven).get(IterableUtils.size(iterableEven));
|
||||||
fail("expecting IndexOutOfBoundsException");
|
fail("expecting IndexOutOfBoundsException");
|
||||||
} catch (IndexOutOfBoundsException ioe) {
|
} catch (final IndexOutOfBoundsException ioe) {
|
||||||
// expected
|
// expected
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -529,14 +529,14 @@ public class FluentIterableTest {
|
|||||||
@SuppressWarnings({ "rawtypes", "unchecked" })
|
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||||
@Test
|
@Test
|
||||||
public void toArray() {
|
public void toArray() {
|
||||||
Long[] arr = new Long[] {1L, 2L, 3L, 4L, 5L};
|
final Long[] arr = new Long[] {1L, 2L, 3L, 4L, 5L};
|
||||||
Long[] result = FluentIterable.of(arr).toArray(Long.class);
|
final Long[] result = FluentIterable.of(arr).toArray(Long.class);
|
||||||
assertNotNull(result);
|
assertNotNull(result);
|
||||||
assertArrayEquals(arr, result);
|
assertArrayEquals(arr, result);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
FluentIterable.of(arr).toArray((Class) String.class);
|
FluentIterable.of(arr).toArray((Class) String.class);
|
||||||
} catch (ArrayStoreException ase) {
|
} catch (final ArrayStoreException ase) {
|
||||||
// expected
|
// expected
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -62,7 +62,7 @@ public class IterableUtilsTest {
|
|||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
Collection<Integer> collectionA = new ArrayList<>();
|
final Collection<Integer> collectionA = new ArrayList<>();
|
||||||
collectionA.add(1);
|
collectionA.add(1);
|
||||||
collectionA.add(2);
|
collectionA.add(2);
|
||||||
collectionA.add(2);
|
collectionA.add(2);
|
||||||
@ -75,7 +75,7 @@ public class IterableUtilsTest {
|
|||||||
collectionA.add(4);
|
collectionA.add(4);
|
||||||
iterableA = collectionA;
|
iterableA = collectionA;
|
||||||
|
|
||||||
Collection<Long> collectionB = new LinkedList<>();
|
final Collection<Long> collectionB = new LinkedList<>();
|
||||||
collectionB.add(5L);
|
collectionB.add(5L);
|
||||||
collectionB.add(4L);
|
collectionB.add(4L);
|
||||||
collectionB.add(4L);
|
collectionB.add(4L);
|
||||||
@ -123,7 +123,7 @@ public class IterableUtilsTest {
|
|||||||
try {
|
try {
|
||||||
IterableUtils.forEach(col, null);
|
IterableUtils.forEach(col, null);
|
||||||
fail("expecting NullPointerException");
|
fail("expecting NullPointerException");
|
||||||
} catch (NullPointerException npe) {
|
} catch (final NullPointerException npe) {
|
||||||
// expected
|
// expected
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -161,7 +161,7 @@ public class IterableUtilsTest {
|
|||||||
try {
|
try {
|
||||||
IterableUtils.forEachButLast(col, null);
|
IterableUtils.forEachButLast(col, null);
|
||||||
fail("expecting NullPointerException");
|
fail("expecting NullPointerException");
|
||||||
} catch (NullPointerException npe) {
|
} catch (final NullPointerException npe) {
|
||||||
// expected
|
// expected
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -228,8 +228,8 @@ public class IterableUtilsTest {
|
|||||||
// Ensure that generic bounds accept valid parameters, but return
|
// Ensure that generic bounds accept valid parameters, but return
|
||||||
// expected results
|
// expected results
|
||||||
// e.g. no longs in the "int" Iterable<Number>, and vice versa.
|
// e.g. no longs in the "int" Iterable<Number>, and vice versa.
|
||||||
Iterable<Number> iterableIntAsNumber = Arrays.<Number>asList(1, 2, 3, 4, 5);
|
final Iterable<Number> iterableIntAsNumber = Arrays.<Number>asList(1, 2, 3, 4, 5);
|
||||||
Iterable<Number> iterableLongAsNumber = Arrays.<Number>asList(1L, 2L, 3L, 4L, 5L);
|
final Iterable<Number> iterableLongAsNumber = Arrays.<Number>asList(1L, 2L, 3L, 4L, 5L);
|
||||||
assertEquals(0, IterableUtils.frequency(iterableIntAsNumber, 2L));
|
assertEquals(0, IterableUtils.frequency(iterableIntAsNumber, 2L));
|
||||||
assertEquals(0, IterableUtils.frequency(iterableLongAsNumber, 2));
|
assertEquals(0, IterableUtils.frequency(iterableLongAsNumber, 2));
|
||||||
|
|
||||||
@ -316,14 +316,14 @@ public class IterableUtilsTest {
|
|||||||
try {
|
try {
|
||||||
assertEquals(0, IterableUtils.countMatches(iterableA, null));
|
assertEquals(0, IterableUtils.countMatches(iterableA, null));
|
||||||
fail("predicate must not be null");
|
fail("predicate must not be null");
|
||||||
} catch (NullPointerException ex) {
|
} catch (final NullPointerException ex) {
|
||||||
// expected
|
// expected
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
assertEquals(0, IterableUtils.countMatches(null, null));
|
assertEquals(0, IterableUtils.countMatches(null, null));
|
||||||
fail("predicate must not be null");
|
fail("predicate must not be null");
|
||||||
} catch (NullPointerException ex) {
|
} catch (final NullPointerException ex) {
|
||||||
// expected
|
// expected
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -335,14 +335,14 @@ public class IterableUtilsTest {
|
|||||||
try {
|
try {
|
||||||
assertFalse(IterableUtils.matchesAny(null, null));
|
assertFalse(IterableUtils.matchesAny(null, null));
|
||||||
fail("predicate must not be null");
|
fail("predicate must not be null");
|
||||||
} catch (NullPointerException ex) {
|
} catch (final NullPointerException ex) {
|
||||||
// expected
|
// expected
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
assertFalse(IterableUtils.matchesAny(list, null));
|
assertFalse(IterableUtils.matchesAny(list, null));
|
||||||
fail("predicate must not be null");
|
fail("predicate must not be null");
|
||||||
} catch (NullPointerException ex) {
|
} catch (final NullPointerException ex) {
|
||||||
// expected
|
// expected
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -362,18 +362,18 @@ public class IterableUtilsTest {
|
|||||||
try {
|
try {
|
||||||
assertFalse(IterableUtils.matchesAll(null, null));
|
assertFalse(IterableUtils.matchesAll(null, null));
|
||||||
fail("predicate must not be null");
|
fail("predicate must not be null");
|
||||||
} catch (NullPointerException ex) {
|
} catch (final NullPointerException ex) {
|
||||||
// expected
|
// expected
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
assertFalse(IterableUtils.matchesAll(iterableA, null));
|
assertFalse(IterableUtils.matchesAll(iterableA, null));
|
||||||
fail("predicate must not be null");
|
fail("predicate must not be null");
|
||||||
} catch (NullPointerException ex) {
|
} catch (final NullPointerException ex) {
|
||||||
// expected
|
// expected
|
||||||
}
|
}
|
||||||
|
|
||||||
Predicate<Integer> lessThanFive = new Predicate<Integer>() {
|
final Predicate<Integer> lessThanFive = new Predicate<Integer>() {
|
||||||
@Override
|
@Override
|
||||||
public boolean evaluate(final Integer object) {
|
public boolean evaluate(final Integer object) {
|
||||||
return object < 5;
|
return object < 5;
|
||||||
@ -381,7 +381,7 @@ public class IterableUtilsTest {
|
|||||||
};
|
};
|
||||||
assertTrue(IterableUtils.matchesAll(iterableA, lessThanFive));
|
assertTrue(IterableUtils.matchesAll(iterableA, lessThanFive));
|
||||||
|
|
||||||
Predicate<Integer> lessThanFour = new Predicate<Integer>() {
|
final Predicate<Integer> lessThanFour = new Predicate<Integer>() {
|
||||||
@Override
|
@Override
|
||||||
public boolean evaluate(final Integer object) {
|
public boolean evaluate(final Integer object) {
|
||||||
return object < 4;
|
return object < 4;
|
||||||
@ -407,7 +407,7 @@ public class IterableUtilsTest {
|
|||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
@Test
|
@Test
|
||||||
public void partition() {
|
public void partition() {
|
||||||
List<Integer> input = new ArrayList<>();
|
final List<Integer> input = new ArrayList<>();
|
||||||
input.add(1);
|
input.add(1);
|
||||||
input.add(2);
|
input.add(2);
|
||||||
input.add(3);
|
input.add(3);
|
||||||
@ -421,7 +421,7 @@ public class IterableUtilsTest {
|
|||||||
assertEquals(2, CollectionUtils.extractSingleton(partition).intValue());
|
assertEquals(2, CollectionUtils.extractSingleton(partition).intValue());
|
||||||
|
|
||||||
// second partition contains 1, 3, and 4
|
// second partition contains 1, 3, and 4
|
||||||
Integer[] expected = {1, 3, 4};
|
final Integer[] expected = {1, 3, 4};
|
||||||
partition = partitions.get(1);
|
partition = partitions.get(1);
|
||||||
Assert.assertArrayEquals(expected, partition.toArray());
|
Assert.assertArrayEquals(expected, partition.toArray());
|
||||||
|
|
||||||
@ -437,7 +437,7 @@ public class IterableUtilsTest {
|
|||||||
try {
|
try {
|
||||||
IterableUtils.partition(input, (Predicate<Integer>) null);
|
IterableUtils.partition(input, (Predicate<Integer>) null);
|
||||||
fail("expecting NullPointerException");
|
fail("expecting NullPointerException");
|
||||||
} catch (NullPointerException npe) {
|
} catch (final NullPointerException npe) {
|
||||||
// expected
|
// expected
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -445,12 +445,12 @@ public class IterableUtilsTest {
|
|||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
@Test
|
@Test
|
||||||
public void partitionMultiplePredicates() {
|
public void partitionMultiplePredicates() {
|
||||||
List<Integer> input = new ArrayList<>();
|
final List<Integer> input = new ArrayList<>();
|
||||||
input.add(1);
|
input.add(1);
|
||||||
input.add(2);
|
input.add(2);
|
||||||
input.add(3);
|
input.add(3);
|
||||||
input.add(4);
|
input.add(4);
|
||||||
List<List<Integer>> partitions = IterableUtils.partition(input, EQUALS_TWO, EVEN);
|
final List<List<Integer>> partitions = IterableUtils.partition(input, EQUALS_TWO, EVEN);
|
||||||
|
|
||||||
// first partition contains 2
|
// first partition contains 2
|
||||||
Collection<Integer> partition = partitions.get(0);
|
Collection<Integer> partition = partitions.get(0);
|
||||||
@ -463,13 +463,13 @@ public class IterableUtilsTest {
|
|||||||
assertEquals(4, partition.iterator().next().intValue());
|
assertEquals(4, partition.iterator().next().intValue());
|
||||||
|
|
||||||
// third partition contains 1 and 3
|
// third partition contains 1 and 3
|
||||||
Integer[] expected = {1, 3};
|
final Integer[] expected = {1, 3};
|
||||||
partition = partitions.get(2);
|
partition = partitions.get(2);
|
||||||
Assert.assertArrayEquals(expected, partition.toArray());
|
Assert.assertArrayEquals(expected, partition.toArray());
|
||||||
|
|
||||||
try {
|
try {
|
||||||
IterableUtils.partition(input, EQUALS_TWO, null);
|
IterableUtils.partition(input, EQUALS_TWO, null);
|
||||||
} catch (NullPointerException npe) {
|
} catch (final NullPointerException npe) {
|
||||||
// expected
|
// expected
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -515,7 +515,7 @@ public class IterableUtilsTest {
|
|||||||
@Test
|
@Test
|
||||||
public void testToStringDelimiter() {
|
public void testToStringDelimiter() {
|
||||||
|
|
||||||
Transformer<Integer, String> transformer = new Transformer<Integer, String>() {
|
final Transformer<Integer, String> transformer = new Transformer<Integer, String>() {
|
||||||
@Override
|
@Override
|
||||||
public String transform(final Integer input) {
|
public String transform(final Integer input) {
|
||||||
return new Integer(input * 2).toString();
|
return new Integer(input * 2).toString();
|
||||||
@ -552,7 +552,7 @@ public class IterableUtilsTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testToStringWithNullArguments() {
|
public void testToStringWithNullArguments() {
|
||||||
String result = IterableUtils.toString(null, new Transformer<Integer, String>() {
|
final String result = IterableUtils.toString(null, new Transformer<Integer, String>() {
|
||||||
@Override
|
@Override
|
||||||
public String transform(final Integer input) {
|
public String transform(final Integer input) {
|
||||||
fail("not supposed to reach here");
|
fail("not supposed to reach here");
|
||||||
|
@ -960,14 +960,14 @@ public class IteratorUtilsTest {
|
|||||||
try {
|
try {
|
||||||
IteratorUtils.collatedIterator(null, collectionOdd.iterator(), null);
|
IteratorUtils.collatedIterator(null, collectionOdd.iterator(), null);
|
||||||
fail("expecting NullPointerException");
|
fail("expecting NullPointerException");
|
||||||
} catch (NullPointerException npe) {
|
} catch (final NullPointerException npe) {
|
||||||
// expected
|
// expected
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
IteratorUtils.collatedIterator(null, null, collectionEven.iterator());
|
IteratorUtils.collatedIterator(null, null, collectionEven.iterator());
|
||||||
fail("expecting NullPointerException");
|
fail("expecting NullPointerException");
|
||||||
} catch (NullPointerException npe) {
|
} catch (final NullPointerException npe) {
|
||||||
// expected
|
// expected
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -978,7 +978,7 @@ public class IteratorUtilsTest {
|
|||||||
List<Integer> result = IteratorUtils.toList(it);
|
List<Integer> result = IteratorUtils.toList(it);
|
||||||
assertEquals(12, result.size());
|
assertEquals(12, result.size());
|
||||||
|
|
||||||
List<Integer> combinedList = new ArrayList<>();
|
final List<Integer> combinedList = new ArrayList<>();
|
||||||
combinedList.addAll(collectionOdd);
|
combinedList.addAll(collectionOdd);
|
||||||
combinedList.addAll(collectionEven);
|
combinedList.addAll(collectionEven);
|
||||||
Collections.sort(combinedList);
|
Collections.sort(combinedList);
|
||||||
@ -1021,7 +1021,7 @@ public class IteratorUtilsTest {
|
|||||||
try {
|
try {
|
||||||
IteratorUtils.forEach(col.iterator(), null);
|
IteratorUtils.forEach(col.iterator(), null);
|
||||||
fail("expecting NullPointerException");
|
fail("expecting NullPointerException");
|
||||||
} catch (NullPointerException npe) {
|
} catch (final NullPointerException npe) {
|
||||||
// expected
|
// expected
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1051,7 +1051,7 @@ public class IteratorUtilsTest {
|
|||||||
try {
|
try {
|
||||||
IteratorUtils.forEachButLast(col.iterator(), null);
|
IteratorUtils.forEachButLast(col.iterator(), null);
|
||||||
fail("expecting NullPointerException");
|
fail("expecting NullPointerException");
|
||||||
} catch (NullPointerException npe) {
|
} catch (final NullPointerException npe) {
|
||||||
// expected
|
// expected
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -128,7 +128,7 @@ public class ListUtilsTest {
|
|||||||
return o instanceof String;
|
return o instanceof String;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
List<Object> list = ListUtils.predicatedList(new ArrayList<>(), predicate);
|
final List<Object> list = ListUtils.predicatedList(new ArrayList<>(), predicate);
|
||||||
assertTrue("returned object should be a PredicatedList", list instanceof PredicatedList);
|
assertTrue("returned object should be a PredicatedList", list instanceof PredicatedList);
|
||||||
try {
|
try {
|
||||||
ListUtils.predicatedList(new ArrayList<>(), null);
|
ListUtils.predicatedList(new ArrayList<>(), null);
|
||||||
@ -339,20 +339,20 @@ public class ListUtilsTest {
|
|||||||
List<Character> lcs = ListUtils.longestCommonSubsequence(Collections.EMPTY_LIST, Collections.EMPTY_LIST);
|
List<Character> lcs = ListUtils.longestCommonSubsequence(Collections.EMPTY_LIST, Collections.EMPTY_LIST);
|
||||||
assertEquals(0, lcs.size());
|
assertEquals(0, lcs.size());
|
||||||
|
|
||||||
List<Character> list1 = Arrays.asList('B', 'A', 'N', 'A', 'N', 'A');
|
final List<Character> list1 = Arrays.asList('B', 'A', 'N', 'A', 'N', 'A');
|
||||||
List<Character> list2 = Arrays.asList('A', 'N', 'A', 'N', 'A', 'S');
|
final List<Character> list2 = Arrays.asList('A', 'N', 'A', 'N', 'A', 'S');
|
||||||
lcs = ListUtils.longestCommonSubsequence(list1, list2);
|
lcs = ListUtils.longestCommonSubsequence(list1, list2);
|
||||||
|
|
||||||
List<Character> expected = Arrays.asList('A', 'N', 'A', 'N', 'A');
|
List<Character> expected = Arrays.asList('A', 'N', 'A', 'N', 'A');
|
||||||
assertEquals(expected, lcs);
|
assertEquals(expected, lcs);
|
||||||
|
|
||||||
List<Character> list3 = Arrays.asList('A', 'T', 'A', 'N', 'A');
|
final List<Character> list3 = Arrays.asList('A', 'T', 'A', 'N', 'A');
|
||||||
lcs = ListUtils.longestCommonSubsequence(list1, list3);
|
lcs = ListUtils.longestCommonSubsequence(list1, list3);
|
||||||
|
|
||||||
expected = Arrays.asList('A', 'A', 'N', 'A');
|
expected = Arrays.asList('A', 'A', 'N', 'A');
|
||||||
assertEquals(expected, lcs);
|
assertEquals(expected, lcs);
|
||||||
|
|
||||||
List<Character> listZorro = Arrays.asList('Z', 'O', 'R', 'R', 'O');
|
final List<Character> listZorro = Arrays.asList('Z', 'O', 'R', 'R', 'O');
|
||||||
lcs = ListUtils.longestCommonSubsequence(list1, listZorro);
|
lcs = ListUtils.longestCommonSubsequence(list1, listZorro);
|
||||||
|
|
||||||
assertTrue(lcs.isEmpty());
|
assertTrue(lcs.isEmpty());
|
||||||
@ -379,18 +379,18 @@ public class ListUtilsTest {
|
|||||||
String lcs = ListUtils.longestCommonSubsequence("", "");
|
String lcs = ListUtils.longestCommonSubsequence("", "");
|
||||||
assertEquals(0, lcs.length());
|
assertEquals(0, lcs.length());
|
||||||
|
|
||||||
String banana = "BANANA";
|
final String banana = "BANANA";
|
||||||
String ananas = "ANANAS";
|
final String ananas = "ANANAS";
|
||||||
lcs = ListUtils.longestCommonSubsequence(banana, ananas);
|
lcs = ListUtils.longestCommonSubsequence(banana, ananas);
|
||||||
|
|
||||||
assertEquals("ANANA", lcs);
|
assertEquals("ANANA", lcs);
|
||||||
|
|
||||||
String atana = "ATANA";
|
final String atana = "ATANA";
|
||||||
lcs = ListUtils.longestCommonSubsequence(banana, atana);
|
lcs = ListUtils.longestCommonSubsequence(banana, atana);
|
||||||
|
|
||||||
assertEquals("AANA", lcs);
|
assertEquals("AANA", lcs);
|
||||||
|
|
||||||
String zorro = "ZORRO";
|
final String zorro = "ZORRO";
|
||||||
lcs = ListUtils.longestCommonSubsequence(banana, zorro);
|
lcs = ListUtils.longestCommonSubsequence(banana, zorro);
|
||||||
|
|
||||||
assertEquals(0, lcs.length());
|
assertEquals(0, lcs.length());
|
||||||
|
@ -65,7 +65,7 @@ public class MapUtilsTest {
|
|||||||
@Test
|
@Test
|
||||||
public void testPredicatedMap() {
|
public void testPredicatedMap() {
|
||||||
final Predicate<Object> p = getPredicate();
|
final Predicate<Object> p = getPredicate();
|
||||||
Map<Object, Object> map = MapUtils.predicatedMap(new HashMap<>(), p, p);
|
final Map<Object, Object> map = MapUtils.predicatedMap(new HashMap<>(), p, p);
|
||||||
assertTrue("returned object should be a PredicatedMap", map instanceof PredicatedMap);
|
assertTrue("returned object should be a PredicatedMap", map instanceof PredicatedMap);
|
||||||
try {
|
try {
|
||||||
MapUtils.predicatedMap(null, p, p);
|
MapUtils.predicatedMap(null, p, p);
|
||||||
@ -1142,7 +1142,7 @@ public class MapUtilsTest {
|
|||||||
final Map<String, String> inMap = new HashMap<String, String>();
|
final Map<String, String> inMap = new HashMap<String, String>();
|
||||||
inMap.put("key1", "value1");
|
inMap.put("key1", "value1");
|
||||||
inMap.put("key2", "value2");
|
inMap.put("key2", "value2");
|
||||||
Map<String, String> map = MapUtils.orderedMap(inMap);
|
final Map<String, String> map = MapUtils.orderedMap(inMap);
|
||||||
assertTrue("returned object should be a OrderedMap", map instanceof OrderedMap);
|
assertTrue("returned object should be a OrderedMap", map instanceof OrderedMap);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -44,7 +44,7 @@ public class MultiMapUtilsTest {
|
|||||||
try {
|
try {
|
||||||
map.put("key", "value");
|
map.put("key", "value");
|
||||||
fail("Should throw UnsupportedOperationException");
|
fail("Should throw UnsupportedOperationException");
|
||||||
} catch (UnsupportedOperationException e) {
|
} catch (final UnsupportedOperationException e) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -55,7 +55,7 @@ public class MultiMapUtilsTest {
|
|||||||
try {
|
try {
|
||||||
map.put("key", "value");
|
map.put("key", "value");
|
||||||
fail("Should throw UnsupportedOperationException");
|
fail("Should throw UnsupportedOperationException");
|
||||||
} catch (UnsupportedOperationException e) {
|
} catch (final UnsupportedOperationException e) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -91,14 +91,14 @@ public class MultiMapUtilsTest {
|
|||||||
public void testGetCollection() {
|
public void testGetCollection() {
|
||||||
assertNull(MultiMapUtils.getCollection(null, "key1"));
|
assertNull(MultiMapUtils.getCollection(null, "key1"));
|
||||||
|
|
||||||
String values[] = { "v1", "v2", "v3" };
|
final String values[] = { "v1", "v2", "v3" };
|
||||||
final MultiValuedMap<String, String> map = new ArrayListValuedHashMap<>();
|
final MultiValuedMap<String, String> map = new ArrayListValuedHashMap<>();
|
||||||
for (String val : values) {
|
for (final String val : values) {
|
||||||
map.put("key1", val);
|
map.put("key1", val);
|
||||||
}
|
}
|
||||||
|
|
||||||
Collection<String> col = MultiMapUtils.getCollection(map, "key1");
|
final Collection<String> col = MultiMapUtils.getCollection(map, "key1");
|
||||||
for (String val : values) {
|
for (final String val : values) {
|
||||||
assertTrue(col.contains(val));
|
assertTrue(col.contains(val));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -107,15 +107,15 @@ public class MultiMapUtilsTest {
|
|||||||
public void testGetValuesAsList() {
|
public void testGetValuesAsList() {
|
||||||
assertNull(MultiMapUtils.getValuesAsList(null, "key1"));
|
assertNull(MultiMapUtils.getValuesAsList(null, "key1"));
|
||||||
|
|
||||||
String values[] = { "v1", "v2", "v3" };
|
final String values[] = { "v1", "v2", "v3" };
|
||||||
final MultiValuedMap<String, String> map = new ArrayListValuedHashMap<>();
|
final MultiValuedMap<String, String> map = new ArrayListValuedHashMap<>();
|
||||||
for (String val : values) {
|
for (final String val : values) {
|
||||||
map.put("key1", val);
|
map.put("key1", val);
|
||||||
}
|
}
|
||||||
|
|
||||||
List<String> list = MultiMapUtils.getValuesAsList(map, "key1");
|
final List<String> list = MultiMapUtils.getValuesAsList(map, "key1");
|
||||||
int i = 0;
|
int i = 0;
|
||||||
for (String val : list) {
|
for (final String val : list) {
|
||||||
assertTrue(val.equals(values[i++]));
|
assertTrue(val.equals(values[i++]));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -124,16 +124,16 @@ public class MultiMapUtilsTest {
|
|||||||
public void testGetValuesAsSet() {
|
public void testGetValuesAsSet() {
|
||||||
assertNull(MultiMapUtils.getValuesAsList(null, "key1"));
|
assertNull(MultiMapUtils.getValuesAsList(null, "key1"));
|
||||||
|
|
||||||
String values[] = { "v1", "v2", "v3" };
|
final String values[] = { "v1", "v2", "v3" };
|
||||||
final MultiValuedMap<String, String> map = new ArrayListValuedHashMap<>();
|
final MultiValuedMap<String, String> map = new ArrayListValuedHashMap<>();
|
||||||
for (String val : values) {
|
for (final String val : values) {
|
||||||
map.put("key1", val);
|
map.put("key1", val);
|
||||||
map.put("key1", val);
|
map.put("key1", val);
|
||||||
}
|
}
|
||||||
|
|
||||||
Set<String> set = MultiMapUtils.getValuesAsSet(map, "key1");
|
final Set<String> set = MultiMapUtils.getValuesAsSet(map, "key1");
|
||||||
assertEquals(3, set.size());
|
assertEquals(3, set.size());
|
||||||
for (String val : values) {
|
for (final String val : values) {
|
||||||
assertTrue(set.contains(val));
|
assertTrue(set.contains(val));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -142,16 +142,16 @@ public class MultiMapUtilsTest {
|
|||||||
public void testGetValuesAsBag() {
|
public void testGetValuesAsBag() {
|
||||||
assertNull(MultiMapUtils.getValuesAsBag(null, "key1"));
|
assertNull(MultiMapUtils.getValuesAsBag(null, "key1"));
|
||||||
|
|
||||||
String values[] = { "v1", "v2", "v3" };
|
final String values[] = { "v1", "v2", "v3" };
|
||||||
final MultiValuedMap<String, String> map = new ArrayListValuedHashMap<>();
|
final MultiValuedMap<String, String> map = new ArrayListValuedHashMap<>();
|
||||||
for (String val : values) {
|
for (final String val : values) {
|
||||||
map.put("key1", val);
|
map.put("key1", val);
|
||||||
map.put("key1", val);
|
map.put("key1", val);
|
||||||
}
|
}
|
||||||
|
|
||||||
Bag<String> bag = MultiMapUtils.getValuesAsBag(map, "key1");
|
final Bag<String> bag = MultiMapUtils.getValuesAsBag(map, "key1");
|
||||||
assertEquals(6, bag.size());
|
assertEquals(6, bag.size());
|
||||||
for (String val : values) {
|
for (final String val : values) {
|
||||||
assertTrue(bag.contains(val));
|
assertTrue(bag.contains(val));
|
||||||
assertEquals(2, bag.getCount(val));
|
assertEquals(2, bag.getCount(val));
|
||||||
}
|
}
|
||||||
|
@ -40,7 +40,7 @@ public class QueueUtilsTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testUnmodifiableQueue() {
|
public void testUnmodifiableQueue() {
|
||||||
Queue<Object> queue = QueueUtils.unmodifiableQueue(new LinkedList<>());
|
final Queue<Object> queue = QueueUtils.unmodifiableQueue(new LinkedList<>());
|
||||||
assertTrue("Returned object should be an UnmodifiableQueue.", queue instanceof UnmodifiableQueue);
|
assertTrue("Returned object should be an UnmodifiableQueue.", queue instanceof UnmodifiableQueue);
|
||||||
try {
|
try {
|
||||||
QueueUtils.unmodifiableQueue(null);
|
QueueUtils.unmodifiableQueue(null);
|
||||||
@ -54,7 +54,7 @@ public class QueueUtilsTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPredicatedQueue() {
|
public void testPredicatedQueue() {
|
||||||
Queue<Object> queue = QueueUtils.predicatedQueue(new LinkedList<>(), truePredicate);
|
final Queue<Object> queue = QueueUtils.predicatedQueue(new LinkedList<>(), truePredicate);
|
||||||
assertTrue("Returned object should be a PredicatedQueue.", queue instanceof PredicatedQueue);
|
assertTrue("Returned object should be a PredicatedQueue.", queue instanceof PredicatedQueue);
|
||||||
try {
|
try {
|
||||||
QueueUtils.predicatedQueue(null, truePredicate);
|
QueueUtils.predicatedQueue(null, truePredicate);
|
||||||
@ -72,7 +72,7 @@ public class QueueUtilsTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testTransformedQueue() {
|
public void testTransformedQueue() {
|
||||||
Queue<Object> queue = QueueUtils.transformingQueue(new LinkedList<>(), nopTransformer);
|
final Queue<Object> queue = QueueUtils.transformingQueue(new LinkedList<>(), nopTransformer);
|
||||||
assertTrue("Returned object should be an TransformedQueue.", queue instanceof TransformedQueue);
|
assertTrue("Returned object should be an TransformedQueue.", queue instanceof TransformedQueue);
|
||||||
try {
|
try {
|
||||||
QueueUtils.transformingQueue(null, nopTransformer);
|
QueueUtils.transformingQueue(null, nopTransformer);
|
||||||
@ -90,7 +90,7 @@ public class QueueUtilsTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testEmptyQueue() {
|
public void testEmptyQueue() {
|
||||||
Queue<Object> queue = QueueUtils.emptyQueue();
|
final Queue<Object> queue = QueueUtils.emptyQueue();
|
||||||
assertTrue("Returned object should be an UnmodifiableQueue.", queue instanceof UnmodifiableQueue);
|
assertTrue("Returned object should be an UnmodifiableQueue.", queue instanceof UnmodifiableQueue);
|
||||||
assertTrue("Returned queue is not empty.", queue.isEmpty());
|
assertTrue("Returned queue is not empty.", queue.isEmpty());
|
||||||
|
|
||||||
|
@ -68,7 +68,7 @@ public class SetUtilsTest {
|
|||||||
return o instanceof String;
|
return o instanceof String;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
Set<Object> set = SetUtils.predicatedSet(new HashSet<>(), predicate);
|
final Set<Object> set = SetUtils.predicatedSet(new HashSet<>(), predicate);
|
||||||
assertTrue("returned object should be a PredicatedSet", set instanceof PredicatedSet);
|
assertTrue("returned object should be a PredicatedSet", set instanceof PredicatedSet);
|
||||||
try {
|
try {
|
||||||
SetUtils.predicatedSet(new HashSet<>(), null);
|
SetUtils.predicatedSet(new HashSet<>(), null);
|
||||||
@ -126,8 +126,8 @@ public class SetUtilsTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testNewIdentityHashSet() {
|
public void testNewIdentityHashSet() {
|
||||||
Set<String> set = SetUtils.newIdentityHashSet();
|
final Set<String> set = SetUtils.newIdentityHashSet();
|
||||||
String a = new String("a");
|
final String a = new String("a");
|
||||||
set.add(a);
|
set.add(a);
|
||||||
set.add(new String("b"));
|
set.add(new String("b"));
|
||||||
set.add(a);
|
set.add(a);
|
||||||
@ -154,14 +154,14 @@ public class SetUtilsTest {
|
|||||||
try {
|
try {
|
||||||
SetUtils.union(setA, null);
|
SetUtils.union(setA, null);
|
||||||
fail("Expecting NullPointerException");
|
fail("Expecting NullPointerException");
|
||||||
} catch (NullPointerException npe) {
|
} catch (final NullPointerException npe) {
|
||||||
// expected
|
// expected
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
SetUtils.union(null, setA);
|
SetUtils.union(null, setA);
|
||||||
fail("Expecting NullPointerException");
|
fail("Expecting NullPointerException");
|
||||||
} catch (NullPointerException npe) {
|
} catch (final NullPointerException npe) {
|
||||||
// expected
|
// expected
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -172,7 +172,7 @@ public class SetUtilsTest {
|
|||||||
assertEquals(2, set.size());
|
assertEquals(2, set.size());
|
||||||
assertTrue(set.contains(1));
|
assertTrue(set.contains(1));
|
||||||
assertTrue(set.contains(2));
|
assertTrue(set.contains(2));
|
||||||
for (Integer i : setB) {
|
for (final Integer i : setB) {
|
||||||
assertFalse(set.contains(i));
|
assertFalse(set.contains(i));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -182,14 +182,14 @@ public class SetUtilsTest {
|
|||||||
try {
|
try {
|
||||||
SetUtils.difference(setA, null);
|
SetUtils.difference(setA, null);
|
||||||
fail("Expecting NullPointerException");
|
fail("Expecting NullPointerException");
|
||||||
} catch (NullPointerException npe) {
|
} catch (final NullPointerException npe) {
|
||||||
// expected
|
// expected
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
SetUtils.difference(null, setA);
|
SetUtils.difference(null, setA);
|
||||||
fail("Expecting NullPointerException");
|
fail("Expecting NullPointerException");
|
||||||
} catch (NullPointerException npe) {
|
} catch (final NullPointerException npe) {
|
||||||
// expected
|
// expected
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -212,14 +212,14 @@ public class SetUtilsTest {
|
|||||||
try {
|
try {
|
||||||
SetUtils.intersection(setA, null);
|
SetUtils.intersection(setA, null);
|
||||||
fail("Expecting NullPointerException");
|
fail("Expecting NullPointerException");
|
||||||
} catch (NullPointerException npe) {
|
} catch (final NullPointerException npe) {
|
||||||
// expected
|
// expected
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
SetUtils.intersection(null, setA);
|
SetUtils.intersection(null, setA);
|
||||||
fail("Expecting NullPointerException");
|
fail("Expecting NullPointerException");
|
||||||
} catch (NullPointerException npe) {
|
} catch (final NullPointerException npe) {
|
||||||
// expected
|
// expected
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -242,14 +242,14 @@ public class SetUtilsTest {
|
|||||||
try {
|
try {
|
||||||
SetUtils.disjunction(setA, null);
|
SetUtils.disjunction(setA, null);
|
||||||
fail("Expecting NullPointerException");
|
fail("Expecting NullPointerException");
|
||||||
} catch (NullPointerException npe) {
|
} catch (final NullPointerException npe) {
|
||||||
// expected
|
// expected
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
SetUtils.disjunction(null, setA);
|
SetUtils.disjunction(null, setA);
|
||||||
fail("Expecting NullPointerException");
|
fail("Expecting NullPointerException");
|
||||||
} catch (NullPointerException npe) {
|
} catch (final NullPointerException npe) {
|
||||||
// expected
|
// expected
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -247,7 +247,7 @@ public class TransformerUtilsTest {
|
|||||||
assertEquals("A", TransformerUtils.ifTransformer(TruePredicate.truePredicate(), a, b).transform(null));
|
assertEquals("A", TransformerUtils.ifTransformer(TruePredicate.truePredicate(), a, b).transform(null));
|
||||||
assertEquals("B", TransformerUtils.ifTransformer(FalsePredicate.falsePredicate(), a, b).transform(null));
|
assertEquals("B", TransformerUtils.ifTransformer(FalsePredicate.falsePredicate(), a, b).transform(null));
|
||||||
|
|
||||||
Predicate<Integer> lessThanFivePredicate = new Predicate<Integer>() {
|
final Predicate<Integer> lessThanFivePredicate = new Predicate<Integer>() {
|
||||||
@Override
|
@Override
|
||||||
public boolean evaluate(final Integer value) {
|
public boolean evaluate(final Integer value) {
|
||||||
return value < 5;
|
return value < 5;
|
||||||
@ -258,7 +258,7 @@ public class TransformerUtilsTest {
|
|||||||
assertEquals("B", TransformerUtils.<Integer, String>ifTransformer(lessThanFivePredicate, a, b).transform(5));
|
assertEquals("B", TransformerUtils.<Integer, String>ifTransformer(lessThanFivePredicate, a, b).transform(5));
|
||||||
|
|
||||||
// if tests
|
// if tests
|
||||||
Predicate<String> equalsAPredicate = EqualPredicate.equalPredicate("A");
|
final Predicate<String> equalsAPredicate = EqualPredicate.equalPredicate("A");
|
||||||
assertEquals("C", TransformerUtils.<String>ifTransformer(equalsAPredicate, c).transform("A"));
|
assertEquals("C", TransformerUtils.<String>ifTransformer(equalsAPredicate, c).transform("A"));
|
||||||
assertEquals("B", TransformerUtils.<String>ifTransformer(equalsAPredicate, c).transform("B"));
|
assertEquals("B", TransformerUtils.<String>ifTransformer(equalsAPredicate, c).transform("B"));
|
||||||
|
|
||||||
|
@ -32,7 +32,7 @@ public class TrieUtilsTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testUnmodifiableTrie() {
|
public void testUnmodifiableTrie() {
|
||||||
Trie<String, Object> trie = TrieUtils.unmodifiableTrie(new PatriciaTrie<>());
|
final Trie<String, Object> trie = TrieUtils.unmodifiableTrie(new PatriciaTrie<>());
|
||||||
assertTrue("Returned object should be an UnmodifiableTrie.",
|
assertTrue("Returned object should be an UnmodifiableTrie.",
|
||||||
trie instanceof UnmodifiableTrie);
|
trie instanceof UnmodifiableTrie);
|
||||||
try {
|
try {
|
||||||
|
@ -153,7 +153,7 @@ public class DualTreeBidiMap2Test<K extends Comparable<K>, V extends Comparable<
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public String[] ignoredTests() {
|
public String[] ignoredTests() {
|
||||||
String recursiveTest = "DualTreeBidiMap2Test.bulkTestInverseMap.bulkTestInverseMap";
|
final String recursiveTest = "DualTreeBidiMap2Test.bulkTestInverseMap.bulkTestInverseMap";
|
||||||
|
|
||||||
if (IBMJDK16) {
|
if (IBMJDK16) {
|
||||||
final String preSub = "DualTreeBidiMap2Test.bulkTestSubMap.";
|
final String preSub = "DualTreeBidiMap2Test.bulkTestSubMap.";
|
||||||
|
@ -671,7 +671,7 @@ public abstract class AbstractCollectionTest<E> extends AbstractObjectTest {
|
|||||||
|
|
||||||
resetFull();
|
resetFull();
|
||||||
elements = getOtherElements();
|
elements = getOtherElements();
|
||||||
for (Object element : elements) {
|
for (final Object element : elements) {
|
||||||
assertTrue("Full collection shouldn't contain element",
|
assertTrue("Full collection shouldn't contain element",
|
||||||
!getCollection().contains(element));
|
!getCollection().contains(element));
|
||||||
}
|
}
|
||||||
@ -861,7 +861,7 @@ public abstract class AbstractCollectionTest<E> extends AbstractObjectTest {
|
|||||||
|
|
||||||
resetEmpty();
|
resetEmpty();
|
||||||
final E[] elements = getFullElements();
|
final E[] elements = getFullElements();
|
||||||
for (E element : elements) {
|
for (final E element : elements) {
|
||||||
assertTrue("Shouldn't remove nonexistent element", !getCollection().remove(element));
|
assertTrue("Shouldn't remove nonexistent element", !getCollection().remove(element));
|
||||||
verify();
|
verify();
|
||||||
}
|
}
|
||||||
@ -869,7 +869,7 @@ public abstract class AbstractCollectionTest<E> extends AbstractObjectTest {
|
|||||||
final E[] other = getOtherElements();
|
final E[] other = getOtherElements();
|
||||||
|
|
||||||
resetFull();
|
resetFull();
|
||||||
for (E element : other) {
|
for (final E element : other) {
|
||||||
assertTrue("Shouldn't remove nonexistent other element", !getCollection().remove(element));
|
assertTrue("Shouldn't remove nonexistent other element", !getCollection().remove(element));
|
||||||
verify();
|
verify();
|
||||||
}
|
}
|
||||||
@ -939,7 +939,7 @@ public abstract class AbstractCollectionTest<E> extends AbstractObjectTest {
|
|||||||
verify();
|
verify();
|
||||||
|
|
||||||
assertTrue("Collection should shrink after removeAll", getCollection().size() < size);
|
assertTrue("Collection should shrink after removeAll", getCollection().size() < size);
|
||||||
for (E element : all) {
|
for (final E element : all) {
|
||||||
assertTrue("Collection shouldn't contain removed element", !getCollection().contains(element));
|
assertTrue("Collection shouldn't contain removed element", !getCollection().contains(element));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -991,7 +991,7 @@ public abstract class AbstractCollectionTest<E> extends AbstractObjectTest {
|
|||||||
getConfirmed().retainAll(elements.subList(min, max));
|
getConfirmed().retainAll(elements.subList(min, max));
|
||||||
verify();
|
verify();
|
||||||
|
|
||||||
for (E element : getCollection()) {
|
for (final E element : getCollection()) {
|
||||||
assertTrue("Collection only contains retained element", elements.subList(min, max).contains(element));
|
assertTrue("Collection only contains retained element", elements.subList(min, max).contains(element));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -39,7 +39,7 @@ public class PredicatedCollectionBuilderTest {
|
|||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void addPass() {
|
public void addPass() {
|
||||||
PredicatedCollection.Builder<String> builder = PredicatedCollection.notNullBuilder();
|
final PredicatedCollection.Builder<String> builder = PredicatedCollection.notNullBuilder();
|
||||||
builder.add("test");
|
builder.add("test");
|
||||||
Assert.assertEquals(builder.createPredicatedList().size(), 1);
|
Assert.assertEquals(builder.createPredicatedList().size(), 1);
|
||||||
}
|
}
|
||||||
@ -49,7 +49,7 @@ public class PredicatedCollectionBuilderTest {
|
|||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void addFail() {
|
public void addFail() {
|
||||||
PredicatedCollection.Builder<String> builder = PredicatedCollection.notNullBuilder();
|
final PredicatedCollection.Builder<String> builder = PredicatedCollection.notNullBuilder();
|
||||||
builder.add((String) null);
|
builder.add((String) null);
|
||||||
Assert.assertTrue(builder.createPredicatedList().isEmpty());
|
Assert.assertTrue(builder.createPredicatedList().isEmpty());
|
||||||
|
|
||||||
@ -61,27 +61,27 @@ public class PredicatedCollectionBuilderTest {
|
|||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void addAllPass() {
|
public void addAllPass() {
|
||||||
PredicatedCollection.Builder<String> builder = PredicatedCollection.notNullBuilder();
|
final PredicatedCollection.Builder<String> builder = PredicatedCollection.notNullBuilder();
|
||||||
builder.addAll(Arrays.asList("test1", null, "test2"));
|
builder.addAll(Arrays.asList("test1", null, "test2"));
|
||||||
Assert.assertEquals(builder.createPredicatedList().size(), 2);
|
Assert.assertEquals(builder.createPredicatedList().size(), 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void createPredicatedCollectionWithNotNullPredicate() {
|
public void createPredicatedCollectionWithNotNullPredicate() {
|
||||||
PredicatedCollection.Builder<String> builder = PredicatedCollection.notNullBuilder();
|
final PredicatedCollection.Builder<String> builder = PredicatedCollection.notNullBuilder();
|
||||||
builder.add("test1");
|
builder.add("test1");
|
||||||
builder.add((String) null);
|
builder.add((String) null);
|
||||||
|
|
||||||
List<String> predicatedList = builder.createPredicatedList();
|
final List<String> predicatedList = builder.createPredicatedList();
|
||||||
checkPredicatedCollection1(predicatedList);
|
checkPredicatedCollection1(predicatedList);
|
||||||
|
|
||||||
Set<String> predicatedSet = builder.createPredicatedSet();
|
final Set<String> predicatedSet = builder.createPredicatedSet();
|
||||||
checkPredicatedCollection1(predicatedSet);
|
checkPredicatedCollection1(predicatedSet);
|
||||||
|
|
||||||
Bag<String> predicatedBag = builder.createPredicatedBag();
|
final Bag<String> predicatedBag = builder.createPredicatedBag();
|
||||||
checkPredicatedCollection1(predicatedBag);
|
checkPredicatedCollection1(predicatedBag);
|
||||||
|
|
||||||
Queue<String> predicatedQueue = builder.createPredicatedQueue();
|
final Queue<String> predicatedQueue = builder.createPredicatedQueue();
|
||||||
checkPredicatedCollection1(predicatedQueue);
|
checkPredicatedCollection1(predicatedQueue);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -94,30 +94,30 @@ public class PredicatedCollectionBuilderTest {
|
|||||||
try {
|
try {
|
||||||
collection.add(null);
|
collection.add(null);
|
||||||
Assert.fail("Expecting IllegalArgumentException for failing predicate!");
|
Assert.fail("Expecting IllegalArgumentException for failing predicate!");
|
||||||
} catch (IllegalArgumentException iae) {
|
} catch (final IllegalArgumentException iae) {
|
||||||
// expected
|
// expected
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void createPredicatedCollectionWithPredicate() {
|
public void createPredicatedCollectionWithPredicate() {
|
||||||
OddPredicate p = new OddPredicate();
|
final OddPredicate p = new OddPredicate();
|
||||||
PredicatedCollection.Builder<Integer> builder = PredicatedCollection.builder(p);
|
final PredicatedCollection.Builder<Integer> builder = PredicatedCollection.builder(p);
|
||||||
|
|
||||||
builder.add(1);
|
builder.add(1);
|
||||||
builder.add(2);
|
builder.add(2);
|
||||||
builder.add(3);
|
builder.add(3);
|
||||||
|
|
||||||
List<Integer> predicatedList = builder.createPredicatedList();
|
final List<Integer> predicatedList = builder.createPredicatedList();
|
||||||
checkPredicatedCollection2(predicatedList);
|
checkPredicatedCollection2(predicatedList);
|
||||||
|
|
||||||
Set<Integer> predicatedSet = builder.createPredicatedSet();
|
final Set<Integer> predicatedSet = builder.createPredicatedSet();
|
||||||
checkPredicatedCollection2(predicatedSet);
|
checkPredicatedCollection2(predicatedSet);
|
||||||
|
|
||||||
Bag<Integer> predicatedBag = builder.createPredicatedBag();
|
final Bag<Integer> predicatedBag = builder.createPredicatedBag();
|
||||||
checkPredicatedCollection2(predicatedBag);
|
checkPredicatedCollection2(predicatedBag);
|
||||||
|
|
||||||
Queue<Integer> predicatedQueue = builder.createPredicatedQueue();
|
final Queue<Integer> predicatedQueue = builder.createPredicatedQueue();
|
||||||
checkPredicatedCollection2(predicatedQueue);
|
checkPredicatedCollection2(predicatedQueue);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -127,7 +127,7 @@ public class PredicatedCollectionBuilderTest {
|
|||||||
try {
|
try {
|
||||||
collection.add(4);
|
collection.add(4);
|
||||||
Assert.fail("Expecting IllegalArgumentException for failing predicate!");
|
Assert.fail("Expecting IllegalArgumentException for failing predicate!");
|
||||||
} catch (IllegalArgumentException iae) {
|
} catch (final IllegalArgumentException iae) {
|
||||||
}
|
}
|
||||||
Assert.assertEquals(2, collection.size());
|
Assert.assertEquals(2, collection.size());
|
||||||
|
|
||||||
|
@ -61,9 +61,9 @@ public class TransformingComparatorTest extends AbstractComparatorTest<Integer>
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void testEquals() {
|
public void testEquals() {
|
||||||
Transformer<String, String> t1 = TransformerUtils.nopTransformer();
|
final Transformer<String, String> t1 = TransformerUtils.nopTransformer();
|
||||||
TransformingComparator<String, String> comp1 = new TransformingComparator<>(t1);
|
final TransformingComparator<String, String> comp1 = new TransformingComparator<>(t1);
|
||||||
TransformingComparator<String, String> comp2 = new TransformingComparator<>(t1, comp1);
|
final TransformingComparator<String, String> comp2 = new TransformingComparator<>(t1, comp1);
|
||||||
|
|
||||||
// Checks the contract: equals-hashcode on comp1 and comp2
|
// Checks the contract: equals-hashcode on comp1 and comp2
|
||||||
assertTrue("Contract failed: equals-hashcode",
|
assertTrue("Contract failed: equals-hashcode",
|
||||||
|
@ -66,7 +66,7 @@ public class BoundedIteratorTest<E> extends AbstractIteratorTest<E> {
|
|||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testBounded() {
|
public void testBounded() {
|
||||||
Iterator<E> iter = new BoundedIterator<>(testList.iterator(), 2, 4);
|
final Iterator<E> iter = new BoundedIterator<>(testList.iterator(), 2, 4);
|
||||||
|
|
||||||
assertTrue(iter.hasNext());
|
assertTrue(iter.hasNext());
|
||||||
assertEquals("c", iter.next());
|
assertEquals("c", iter.next());
|
||||||
@ -81,7 +81,7 @@ public class BoundedIteratorTest<E> extends AbstractIteratorTest<E> {
|
|||||||
try {
|
try {
|
||||||
iter.next();
|
iter.next();
|
||||||
fail("Expected NoSuchElementException.");
|
fail("Expected NoSuchElementException.");
|
||||||
} catch (NoSuchElementException nsee) { /* Success case */
|
} catch (final NoSuchElementException nsee) { /* Success case */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -92,7 +92,7 @@ public class BoundedIteratorTest<E> extends AbstractIteratorTest<E> {
|
|||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testSameAsDecorated() {
|
public void testSameAsDecorated() {
|
||||||
Iterator<E> iter = new BoundedIterator<>(testList.iterator(), 0,
|
final Iterator<E> iter = new BoundedIterator<>(testList.iterator(), 0,
|
||||||
testList.size());
|
testList.size());
|
||||||
|
|
||||||
assertTrue(iter.hasNext());
|
assertTrue(iter.hasNext());
|
||||||
@ -114,7 +114,7 @@ public class BoundedIteratorTest<E> extends AbstractIteratorTest<E> {
|
|||||||
try {
|
try {
|
||||||
iter.next();
|
iter.next();
|
||||||
fail("Expected NoSuchElementException.");
|
fail("Expected NoSuchElementException.");
|
||||||
} catch (NoSuchElementException nsee) { /* Success case */
|
} catch (final NoSuchElementException nsee) { /* Success case */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -125,12 +125,12 @@ public class BoundedIteratorTest<E> extends AbstractIteratorTest<E> {
|
|||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testEmptyBounded() {
|
public void testEmptyBounded() {
|
||||||
Iterator<E> iter = new BoundedIterator<>(testList.iterator(), 3, 0);
|
final Iterator<E> iter = new BoundedIterator<>(testList.iterator(), 3, 0);
|
||||||
assertFalse(iter.hasNext());
|
assertFalse(iter.hasNext());
|
||||||
try {
|
try {
|
||||||
iter.next();
|
iter.next();
|
||||||
fail("Expected NoSuchElementException.");
|
fail("Expected NoSuchElementException.");
|
||||||
} catch (NoSuchElementException nsee) { /* Success case */
|
} catch (final NoSuchElementException nsee) { /* Success case */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -143,7 +143,7 @@ public class BoundedIteratorTest<E> extends AbstractIteratorTest<E> {
|
|||||||
try {
|
try {
|
||||||
new BoundedIterator<>(testList.iterator(), -1, 4);
|
new BoundedIterator<>(testList.iterator(), -1, 4);
|
||||||
fail("Expected IllegalArgumentException.");
|
fail("Expected IllegalArgumentException.");
|
||||||
} catch (IllegalArgumentException iae) { /* Success case */
|
} catch (final IllegalArgumentException iae) { /* Success case */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -156,7 +156,7 @@ public class BoundedIteratorTest<E> extends AbstractIteratorTest<E> {
|
|||||||
try {
|
try {
|
||||||
new BoundedIterator<>(testList.iterator(), 3, -1);
|
new BoundedIterator<>(testList.iterator(), 3, -1);
|
||||||
fail("Expected IllegalArgumentException.");
|
fail("Expected IllegalArgumentException.");
|
||||||
} catch (IllegalArgumentException iae) { /* Success case */
|
} catch (final IllegalArgumentException iae) { /* Success case */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -167,12 +167,12 @@ public class BoundedIteratorTest<E> extends AbstractIteratorTest<E> {
|
|||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testOffsetGreaterThanSize() {
|
public void testOffsetGreaterThanSize() {
|
||||||
Iterator<E> iter = new BoundedIterator<>(testList.iterator(), 10, 4);
|
final Iterator<E> iter = new BoundedIterator<>(testList.iterator(), 10, 4);
|
||||||
assertFalse(iter.hasNext());
|
assertFalse(iter.hasNext());
|
||||||
try {
|
try {
|
||||||
iter.next();
|
iter.next();
|
||||||
fail("Expected NoSuchElementException.");
|
fail("Expected NoSuchElementException.");
|
||||||
} catch (NoSuchElementException nsee) { /* Success case */
|
} catch (final NoSuchElementException nsee) { /* Success case */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -184,7 +184,7 @@ public class BoundedIteratorTest<E> extends AbstractIteratorTest<E> {
|
|||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testMaxGreaterThanSize() {
|
public void testMaxGreaterThanSize() {
|
||||||
Iterator<E> iter = new BoundedIterator<>(testList.iterator(), 1, 10);
|
final Iterator<E> iter = new BoundedIterator<>(testList.iterator(), 1, 10);
|
||||||
|
|
||||||
assertTrue(iter.hasNext());
|
assertTrue(iter.hasNext());
|
||||||
assertEquals("b", iter.next());
|
assertEquals("b", iter.next());
|
||||||
@ -203,7 +203,7 @@ public class BoundedIteratorTest<E> extends AbstractIteratorTest<E> {
|
|||||||
try {
|
try {
|
||||||
iter.next();
|
iter.next();
|
||||||
fail("Expected NoSuchElementException.");
|
fail("Expected NoSuchElementException.");
|
||||||
} catch (NoSuchElementException nsee) { /* Success case */
|
} catch (final NoSuchElementException nsee) { /* Success case */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -213,13 +213,13 @@ public class BoundedIteratorTest<E> extends AbstractIteratorTest<E> {
|
|||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testRemoveWithoutCallingNext() {
|
public void testRemoveWithoutCallingNext() {
|
||||||
List<E> testListCopy = new ArrayList<>(testList);
|
final List<E> testListCopy = new ArrayList<>(testList);
|
||||||
Iterator<E> iter = new BoundedIterator<>(testListCopy.iterator(), 1, 5);
|
final Iterator<E> iter = new BoundedIterator<>(testListCopy.iterator(), 1, 5);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
iter.remove();
|
iter.remove();
|
||||||
fail("Expected IllegalStateException.");
|
fail("Expected IllegalStateException.");
|
||||||
} catch (IllegalStateException ise) { /* Success case */
|
} catch (final IllegalStateException ise) { /* Success case */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -229,8 +229,8 @@ public class BoundedIteratorTest<E> extends AbstractIteratorTest<E> {
|
|||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testRemoveCalledTwice() {
|
public void testRemoveCalledTwice() {
|
||||||
List<E> testListCopy = new ArrayList<>(testList);
|
final List<E> testListCopy = new ArrayList<>(testList);
|
||||||
Iterator<E> iter = new BoundedIterator<>(testListCopy.iterator(), 1, 5);
|
final Iterator<E> iter = new BoundedIterator<>(testListCopy.iterator(), 1, 5);
|
||||||
|
|
||||||
assertTrue(iter.hasNext());
|
assertTrue(iter.hasNext());
|
||||||
assertEquals("b", iter.next());
|
assertEquals("b", iter.next());
|
||||||
@ -239,7 +239,7 @@ public class BoundedIteratorTest<E> extends AbstractIteratorTest<E> {
|
|||||||
try {
|
try {
|
||||||
iter.remove();
|
iter.remove();
|
||||||
fail("Expected IllegalStateException.");
|
fail("Expected IllegalStateException.");
|
||||||
} catch (IllegalStateException ise) { /* Success case */
|
} catch (final IllegalStateException ise) { /* Success case */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -249,8 +249,8 @@ public class BoundedIteratorTest<E> extends AbstractIteratorTest<E> {
|
|||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testRemoveFirst() {
|
public void testRemoveFirst() {
|
||||||
List<E> testListCopy = new ArrayList<>(testList);
|
final List<E> testListCopy = new ArrayList<>(testList);
|
||||||
Iterator<E> iter = new BoundedIterator<>(testListCopy.iterator(), 1, 5);
|
final Iterator<E> iter = new BoundedIterator<>(testListCopy.iterator(), 1, 5);
|
||||||
|
|
||||||
assertTrue(iter.hasNext());
|
assertTrue(iter.hasNext());
|
||||||
assertEquals("b", iter.next());
|
assertEquals("b", iter.next());
|
||||||
@ -271,7 +271,7 @@ public class BoundedIteratorTest<E> extends AbstractIteratorTest<E> {
|
|||||||
try {
|
try {
|
||||||
iter.next();
|
iter.next();
|
||||||
fail("Expected NoSuchElementException.");
|
fail("Expected NoSuchElementException.");
|
||||||
} catch (NoSuchElementException nsee) { /* Success case */
|
} catch (final NoSuchElementException nsee) { /* Success case */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -281,8 +281,8 @@ public class BoundedIteratorTest<E> extends AbstractIteratorTest<E> {
|
|||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testRemoveMiddle() {
|
public void testRemoveMiddle() {
|
||||||
List<E> testListCopy = new ArrayList<>(testList);
|
final List<E> testListCopy = new ArrayList<>(testList);
|
||||||
Iterator<E> iter = new BoundedIterator<>(testListCopy.iterator(), 1, 5);
|
final Iterator<E> iter = new BoundedIterator<>(testListCopy.iterator(), 1, 5);
|
||||||
|
|
||||||
assertTrue(iter.hasNext());
|
assertTrue(iter.hasNext());
|
||||||
assertEquals("b", iter.next());
|
assertEquals("b", iter.next());
|
||||||
@ -303,7 +303,7 @@ public class BoundedIteratorTest<E> extends AbstractIteratorTest<E> {
|
|||||||
try {
|
try {
|
||||||
iter.next();
|
iter.next();
|
||||||
fail("Expected NoSuchElementException.");
|
fail("Expected NoSuchElementException.");
|
||||||
} catch (NoSuchElementException nsee) { /* Success case */
|
} catch (final NoSuchElementException nsee) { /* Success case */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -313,8 +313,8 @@ public class BoundedIteratorTest<E> extends AbstractIteratorTest<E> {
|
|||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testRemoveLast() {
|
public void testRemoveLast() {
|
||||||
List<E> testListCopy = new ArrayList<>(testList);
|
final List<E> testListCopy = new ArrayList<>(testList);
|
||||||
Iterator<E> iter = new BoundedIterator<>(testListCopy.iterator(), 1, 5);
|
final Iterator<E> iter = new BoundedIterator<>(testListCopy.iterator(), 1, 5);
|
||||||
|
|
||||||
assertTrue(iter.hasNext());
|
assertTrue(iter.hasNext());
|
||||||
assertEquals("b", iter.next());
|
assertEquals("b", iter.next());
|
||||||
@ -331,7 +331,7 @@ public class BoundedIteratorTest<E> extends AbstractIteratorTest<E> {
|
|||||||
try {
|
try {
|
||||||
iter.next();
|
iter.next();
|
||||||
fail("Expected NoSuchElementException.");
|
fail("Expected NoSuchElementException.");
|
||||||
} catch (NoSuchElementException nsee) { /* Success case */
|
} catch (final NoSuchElementException nsee) { /* Success case */
|
||||||
}
|
}
|
||||||
|
|
||||||
iter.remove();
|
iter.remove();
|
||||||
@ -341,7 +341,7 @@ public class BoundedIteratorTest<E> extends AbstractIteratorTest<E> {
|
|||||||
try {
|
try {
|
||||||
iter.next();
|
iter.next();
|
||||||
fail("Expected NoSuchElementException.");
|
fail("Expected NoSuchElementException.");
|
||||||
} catch (NoSuchElementException nsee) { /* Success case */
|
} catch (final NoSuchElementException nsee) { /* Success case */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -351,20 +351,20 @@ public class BoundedIteratorTest<E> extends AbstractIteratorTest<E> {
|
|||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testRemoveUnsupported() {
|
public void testRemoveUnsupported() {
|
||||||
Iterator<E> mockIterator = new AbstractIteratorDecorator<E>(testList.iterator()) {
|
final Iterator<E> mockIterator = new AbstractIteratorDecorator<E>(testList.iterator()) {
|
||||||
@Override
|
@Override
|
||||||
public void remove() {
|
public void remove() {
|
||||||
throw new UnsupportedOperationException();
|
throw new UnsupportedOperationException();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
Iterator<E> iter = new BoundedIterator<>(mockIterator, 1, 5);
|
final Iterator<E> iter = new BoundedIterator<>(mockIterator, 1, 5);
|
||||||
assertTrue(iter.hasNext());
|
assertTrue(iter.hasNext());
|
||||||
assertEquals("b", iter.next());
|
assertEquals("b", iter.next());
|
||||||
try {
|
try {
|
||||||
iter.remove();
|
iter.remove();
|
||||||
fail("Expected UnsupportedOperationException.");
|
fail("Expected UnsupportedOperationException.");
|
||||||
} catch (UnsupportedOperationException usoe) { /* Success case */
|
} catch (final UnsupportedOperationException usoe) { /* Success case */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -30,8 +30,8 @@ import junit.framework.TestCase;
|
|||||||
public class IteratorEnumerationTest extends TestCase {
|
public class IteratorEnumerationTest extends TestCase {
|
||||||
|
|
||||||
public void testEnumeration() {
|
public void testEnumeration() {
|
||||||
Iterator<String> iterator = Arrays.asList("a", "b", "c").iterator();
|
final Iterator<String> iterator = Arrays.asList("a", "b", "c").iterator();
|
||||||
IteratorEnumeration<String> enumeration = new IteratorEnumeration<>(iterator);
|
final IteratorEnumeration<String> enumeration = new IteratorEnumeration<>(iterator);
|
||||||
|
|
||||||
assertEquals(iterator, enumeration.getIterator());
|
assertEquals(iterator, enumeration.getIterator());
|
||||||
|
|
||||||
@ -44,7 +44,7 @@ public class IteratorEnumerationTest extends TestCase {
|
|||||||
try {
|
try {
|
||||||
enumeration.nextElement();
|
enumeration.nextElement();
|
||||||
fail("NoSuchElementException expected");
|
fail("NoSuchElementException expected");
|
||||||
} catch (NoSuchElementException e) {
|
} catch (final NoSuchElementException e) {
|
||||||
// expected
|
// expected
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -70,14 +70,14 @@ public class PeekingIteratorTest<E> extends AbstractIteratorTest<E> {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testEmpty() {
|
public void testEmpty() {
|
||||||
Iterator<E> it = makeEmptyIterator();
|
final Iterator<E> it = makeEmptyIterator();
|
||||||
assertFalse(it.hasNext());
|
assertFalse(it.hasNext());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public void testSinglePeek() {
|
public void testSinglePeek() {
|
||||||
PeekingIterator<E> it = makeObject();
|
final PeekingIterator<E> it = makeObject();
|
||||||
assertEquals("a", it.peek());
|
assertEquals("a", it.peek());
|
||||||
assertEquals("a", it.element());
|
assertEquals("a", it.element());
|
||||||
validate(it, (E[]) testArray);
|
validate(it, (E[]) testArray);
|
||||||
@ -85,7 +85,7 @@ public class PeekingIteratorTest<E> extends AbstractIteratorTest<E> {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testMultiplePeek() {
|
public void testMultiplePeek() {
|
||||||
PeekingIterator<E> it = makeObject();
|
final PeekingIterator<E> it = makeObject();
|
||||||
assertEquals("a", it.peek());
|
assertEquals("a", it.peek());
|
||||||
assertEquals("a", it.peek());
|
assertEquals("a", it.peek());
|
||||||
assertEquals("a", it.next());
|
assertEquals("a", it.next());
|
||||||
@ -102,7 +102,7 @@ public class PeekingIteratorTest<E> extends AbstractIteratorTest<E> {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testIteratorExhausted() {
|
public void testIteratorExhausted() {
|
||||||
PeekingIterator<E> it = makeObject();
|
final PeekingIterator<E> it = makeObject();
|
||||||
it.next();
|
it.next();
|
||||||
it.next();
|
it.next();
|
||||||
it.next();
|
it.next();
|
||||||
@ -112,14 +112,14 @@ public class PeekingIteratorTest<E> extends AbstractIteratorTest<E> {
|
|||||||
try {
|
try {
|
||||||
it.element();
|
it.element();
|
||||||
fail();
|
fail();
|
||||||
} catch (NoSuchElementException e) {
|
} catch (final NoSuchElementException e) {
|
||||||
// expected
|
// expected
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testIllegalRemove() {
|
public void testIllegalRemove() {
|
||||||
PeekingIterator<E> it = makeObject();
|
final PeekingIterator<E> it = makeObject();
|
||||||
it.next();
|
it.next();
|
||||||
it.remove(); // supported
|
it.remove(); // supported
|
||||||
|
|
||||||
@ -129,13 +129,13 @@ public class PeekingIteratorTest<E> extends AbstractIteratorTest<E> {
|
|||||||
try {
|
try {
|
||||||
it.remove();
|
it.remove();
|
||||||
fail();
|
fail();
|
||||||
} catch (IllegalStateException e) {
|
} catch (final IllegalStateException e) {
|
||||||
// expected
|
// expected
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void validate(final Iterator<E> iter, final E... items) {
|
private void validate(final Iterator<E> iter, final E... items) {
|
||||||
for (E x : items) {
|
for (final E x : items) {
|
||||||
assertTrue(iter.hasNext());
|
assertTrue(iter.hasNext());
|
||||||
assertEquals(x, iter.next());
|
assertEquals(x, iter.next());
|
||||||
}
|
}
|
||||||
|
@ -73,11 +73,11 @@ public class PermutationIteratorTest extends AbstractIteratorTest<List<Character
|
|||||||
public void testPermutationResultSize() {
|
public void testPermutationResultSize() {
|
||||||
int factorial = 1;
|
int factorial = 1;
|
||||||
for (int i = 0; i < 8; i++, factorial*=i) {
|
for (int i = 0; i < 8; i++, factorial*=i) {
|
||||||
List<Integer> list = new ArrayList<>();
|
final List<Integer> list = new ArrayList<>();
|
||||||
for (int j = 0; j < i; j++) {
|
for (int j = 0; j < i; j++) {
|
||||||
list.add(j);
|
list.add(j);
|
||||||
}
|
}
|
||||||
Iterator<List<Integer>> it = new PermutationIterator<>(list);
|
final Iterator<List<Integer>> it = new PermutationIterator<>(list);
|
||||||
int count = 0;
|
int count = 0;
|
||||||
while (it.hasNext()) {
|
while (it.hasNext()) {
|
||||||
it.next();
|
it.next();
|
||||||
@ -92,12 +92,12 @@ public class PermutationIteratorTest extends AbstractIteratorTest<List<Character
|
|||||||
*/
|
*/
|
||||||
@SuppressWarnings("boxing") // OK in test code
|
@SuppressWarnings("boxing") // OK in test code
|
||||||
public void testPermutationExhaustivity() {
|
public void testPermutationExhaustivity() {
|
||||||
List<Character> perm1 = new ArrayList<>();
|
final List<Character> perm1 = new ArrayList<>();
|
||||||
List<Character> perm2 = new ArrayList<>();
|
final List<Character> perm2 = new ArrayList<>();
|
||||||
List<Character> perm3 = new ArrayList<>();
|
final List<Character> perm3 = new ArrayList<>();
|
||||||
List<Character> perm4 = new ArrayList<>();
|
final List<Character> perm4 = new ArrayList<>();
|
||||||
List<Character> perm5 = new ArrayList<>();
|
final List<Character> perm5 = new ArrayList<>();
|
||||||
List<Character> perm6 = new ArrayList<>();
|
final List<Character> perm6 = new ArrayList<>();
|
||||||
|
|
||||||
perm1.add('A');
|
perm1.add('A');
|
||||||
perm2.add('A');
|
perm2.add('A');
|
||||||
@ -120,11 +120,11 @@ public class PermutationIteratorTest extends AbstractIteratorTest<List<Character
|
|||||||
perm5.add('B');
|
perm5.add('B');
|
||||||
perm6.add('A');
|
perm6.add('A');
|
||||||
|
|
||||||
List<List<Character>> results = new ArrayList<>();
|
final List<List<Character>> results = new ArrayList<>();
|
||||||
|
|
||||||
PermutationIterator<Character> it = makeObject();
|
final PermutationIterator<Character> it = makeObject();
|
||||||
while (it.hasNext()) {
|
while (it.hasNext()) {
|
||||||
List<Character> next = it.next();
|
final List<Character> next = it.next();
|
||||||
results.add(next);
|
results.add(next);
|
||||||
}
|
}
|
||||||
//3! permutation for 3 elements
|
//3! permutation for 3 elements
|
||||||
@ -141,12 +141,12 @@ public class PermutationIteratorTest extends AbstractIteratorTest<List<Character
|
|||||||
* test checking that all the permutations are returned only once.
|
* test checking that all the permutations are returned only once.
|
||||||
*/
|
*/
|
||||||
public void testPermutationUnicity() {
|
public void testPermutationUnicity() {
|
||||||
List<List<Character>> resultsList = new ArrayList<>();
|
final List<List<Character>> resultsList = new ArrayList<>();
|
||||||
Set<List<Character>> resultsSet = new HashSet<>();
|
final Set<List<Character>> resultsSet = new HashSet<>();
|
||||||
|
|
||||||
PermutationIterator<Character> it = makeObject();
|
final PermutationIterator<Character> it = makeObject();
|
||||||
while (it.hasNext()) {
|
while (it.hasNext()) {
|
||||||
List<Character> permutation = it.next();
|
final List<Character> permutation = it.next();
|
||||||
resultsList.add(permutation);
|
resultsList.add(permutation);
|
||||||
resultsSet.add(permutation);
|
resultsSet.add(permutation);
|
||||||
}
|
}
|
||||||
@ -156,24 +156,24 @@ public class PermutationIteratorTest extends AbstractIteratorTest<List<Character
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void testPermutationException() {
|
public void testPermutationException() {
|
||||||
List<List<Character>> resultsList = new ArrayList<>();
|
final List<List<Character>> resultsList = new ArrayList<>();
|
||||||
|
|
||||||
PermutationIterator<Character> it = makeObject();
|
final PermutationIterator<Character> it = makeObject();
|
||||||
while (it.hasNext()) {
|
while (it.hasNext()) {
|
||||||
List<Character> permutation = it.next();
|
final List<Character> permutation = it.next();
|
||||||
resultsList.add(permutation);
|
resultsList.add(permutation);
|
||||||
}
|
}
|
||||||
//asking for another permutation should throw an exception
|
//asking for another permutation should throw an exception
|
||||||
try {
|
try {
|
||||||
it.next();
|
it.next();
|
||||||
fail();
|
fail();
|
||||||
} catch (NoSuchElementException e) {
|
} catch (final NoSuchElementException e) {
|
||||||
// expected
|
// expected
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testPermutatorHasMore() {
|
public void testPermutatorHasMore() {
|
||||||
PermutationIterator<Character> it = makeObject();
|
final PermutationIterator<Character> it = makeObject();
|
||||||
for (int i = 0; i < 6; i++) {
|
for (int i = 0; i < 6; i++) {
|
||||||
assertTrue(it.hasNext());
|
assertTrue(it.hasNext());
|
||||||
it.next();
|
it.next();
|
||||||
@ -182,11 +182,11 @@ public class PermutationIteratorTest extends AbstractIteratorTest<List<Character
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void testEmptyCollection() {
|
public void testEmptyCollection() {
|
||||||
PermutationIterator<Character> it = makeEmptyIterator();
|
final PermutationIterator<Character> it = makeEmptyIterator();
|
||||||
// there is one permutation for an empty set: 0! = 1
|
// there is one permutation for an empty set: 0! = 1
|
||||||
assertTrue(it.hasNext());
|
assertTrue(it.hasNext());
|
||||||
|
|
||||||
List<Character> nextPermutation = it.next();
|
final List<Character> nextPermutation = it.next();
|
||||||
assertEquals(0, nextPermutation.size());
|
assertEquals(0, nextPermutation.size());
|
||||||
|
|
||||||
assertFalse(it.hasNext());
|
assertFalse(it.hasNext());
|
||||||
|
@ -68,7 +68,7 @@ public class PushbackIteratorTest<E> extends AbstractIteratorTest<E> {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testNormalIteration() {
|
public void testNormalIteration() {
|
||||||
PushbackIterator<E> iter = makeObject();
|
final PushbackIterator<E> iter = makeObject();
|
||||||
assertEquals("a", iter.next());
|
assertEquals("a", iter.next());
|
||||||
assertEquals("b", iter.next());
|
assertEquals("b", iter.next());
|
||||||
assertEquals("c", iter.next());
|
assertEquals("c", iter.next());
|
||||||
@ -78,7 +78,7 @@ public class PushbackIteratorTest<E> extends AbstractIteratorTest<E> {
|
|||||||
@Test
|
@Test
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public void testImmediatePushback() {
|
public void testImmediatePushback() {
|
||||||
PushbackIterator<E> iter = makeObject();
|
final PushbackIterator<E> iter = makeObject();
|
||||||
iter.pushback((E) "x");
|
iter.pushback((E) "x");
|
||||||
assertEquals("x", iter.next());
|
assertEquals("x", iter.next());
|
||||||
assertEquals("a", iter.next());
|
assertEquals("a", iter.next());
|
||||||
@ -88,7 +88,7 @@ public class PushbackIteratorTest<E> extends AbstractIteratorTest<E> {
|
|||||||
@Test
|
@Test
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public void testDelayedPushback() {
|
public void testDelayedPushback() {
|
||||||
PushbackIterator<E> iter = makeObject();
|
final PushbackIterator<E> iter = makeObject();
|
||||||
assertEquals("a", iter.next());
|
assertEquals("a", iter.next());
|
||||||
iter.pushback((E) "x");
|
iter.pushback((E) "x");
|
||||||
assertEquals("x", iter.next());
|
assertEquals("x", iter.next());
|
||||||
@ -99,7 +99,7 @@ public class PushbackIteratorTest<E> extends AbstractIteratorTest<E> {
|
|||||||
@Test
|
@Test
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public void testMultiplePushback() {
|
public void testMultiplePushback() {
|
||||||
PushbackIterator<E> iter = makeObject();
|
final PushbackIterator<E> iter = makeObject();
|
||||||
assertEquals("a", iter.next());
|
assertEquals("a", iter.next());
|
||||||
iter.pushback((E) "x");
|
iter.pushback((E) "x");
|
||||||
iter.pushback((E) "y");
|
iter.pushback((E) "y");
|
||||||
|
@ -66,7 +66,7 @@ public class SkippingIteratorTest<E> extends AbstractIteratorTest<E> {
|
|||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testSkipping() {
|
public void testSkipping() {
|
||||||
Iterator<E> iter = new SkippingIterator<>(testList.iterator(), 2);
|
final Iterator<E> iter = new SkippingIterator<>(testList.iterator(), 2);
|
||||||
|
|
||||||
assertTrue(iter.hasNext());
|
assertTrue(iter.hasNext());
|
||||||
assertEquals("c", iter.next());
|
assertEquals("c", iter.next());
|
||||||
@ -83,7 +83,7 @@ public class SkippingIteratorTest<E> extends AbstractIteratorTest<E> {
|
|||||||
try {
|
try {
|
||||||
iter.next();
|
iter.next();
|
||||||
fail("Expected NoSuchElementException.");
|
fail("Expected NoSuchElementException.");
|
||||||
} catch (NoSuchElementException nsee) { /* Success case */
|
} catch (final NoSuchElementException nsee) { /* Success case */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -94,7 +94,7 @@ public class SkippingIteratorTest<E> extends AbstractIteratorTest<E> {
|
|||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testSameAsDecorated() {
|
public void testSameAsDecorated() {
|
||||||
Iterator<E> iter = new SkippingIterator<>(testList.iterator(), 0);
|
final Iterator<E> iter = new SkippingIterator<>(testList.iterator(), 0);
|
||||||
|
|
||||||
assertTrue(iter.hasNext());
|
assertTrue(iter.hasNext());
|
||||||
assertEquals("a", iter.next());
|
assertEquals("a", iter.next());
|
||||||
@ -115,7 +115,7 @@ public class SkippingIteratorTest<E> extends AbstractIteratorTest<E> {
|
|||||||
try {
|
try {
|
||||||
iter.next();
|
iter.next();
|
||||||
fail("Expected NoSuchElementException.");
|
fail("Expected NoSuchElementException.");
|
||||||
} catch (NoSuchElementException nsee) { /* Success case */
|
} catch (final NoSuchElementException nsee) { /* Success case */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -126,12 +126,12 @@ public class SkippingIteratorTest<E> extends AbstractIteratorTest<E> {
|
|||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testOffsetGreaterThanSize() {
|
public void testOffsetGreaterThanSize() {
|
||||||
Iterator<E> iter = new SkippingIterator<>(testList.iterator(), 10);
|
final Iterator<E> iter = new SkippingIterator<>(testList.iterator(), 10);
|
||||||
assertFalse(iter.hasNext());
|
assertFalse(iter.hasNext());
|
||||||
try {
|
try {
|
||||||
iter.next();
|
iter.next();
|
||||||
fail("Expected NoSuchElementException.");
|
fail("Expected NoSuchElementException.");
|
||||||
} catch (NoSuchElementException nsee) { /* Success case */
|
} catch (final NoSuchElementException nsee) { /* Success case */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -144,7 +144,7 @@ public class SkippingIteratorTest<E> extends AbstractIteratorTest<E> {
|
|||||||
try {
|
try {
|
||||||
new SkippingIterator<>(testList.iterator(), -1);
|
new SkippingIterator<>(testList.iterator(), -1);
|
||||||
fail("Expected IllegalArgumentException.");
|
fail("Expected IllegalArgumentException.");
|
||||||
} catch (IllegalArgumentException iae) { /* Success case */
|
} catch (final IllegalArgumentException iae) { /* Success case */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -154,13 +154,13 @@ public class SkippingIteratorTest<E> extends AbstractIteratorTest<E> {
|
|||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testRemoveWithoutCallingNext() {
|
public void testRemoveWithoutCallingNext() {
|
||||||
List<E> testListCopy = new ArrayList<>(testList);
|
final List<E> testListCopy = new ArrayList<>(testList);
|
||||||
Iterator<E> iter = new SkippingIterator<>(testListCopy.iterator(), 1);
|
final Iterator<E> iter = new SkippingIterator<>(testListCopy.iterator(), 1);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
iter.remove();
|
iter.remove();
|
||||||
fail("Expected IllegalStateException.");
|
fail("Expected IllegalStateException.");
|
||||||
} catch (IllegalStateException ise) { /* Success case */
|
} catch (final IllegalStateException ise) { /* Success case */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -170,8 +170,8 @@ public class SkippingIteratorTest<E> extends AbstractIteratorTest<E> {
|
|||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testRemoveCalledTwice() {
|
public void testRemoveCalledTwice() {
|
||||||
List<E> testListCopy = new ArrayList<>(testList);
|
final List<E> testListCopy = new ArrayList<>(testList);
|
||||||
Iterator<E> iter = new SkippingIterator<>(testListCopy.iterator(), 1);
|
final Iterator<E> iter = new SkippingIterator<>(testListCopy.iterator(), 1);
|
||||||
|
|
||||||
assertTrue(iter.hasNext());
|
assertTrue(iter.hasNext());
|
||||||
assertEquals("b", iter.next());
|
assertEquals("b", iter.next());
|
||||||
@ -180,7 +180,7 @@ public class SkippingIteratorTest<E> extends AbstractIteratorTest<E> {
|
|||||||
try {
|
try {
|
||||||
iter.remove();
|
iter.remove();
|
||||||
fail("Expected IllegalStateException.");
|
fail("Expected IllegalStateException.");
|
||||||
} catch (IllegalStateException ise) { /* Success case */
|
} catch (final IllegalStateException ise) { /* Success case */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -190,8 +190,8 @@ public class SkippingIteratorTest<E> extends AbstractIteratorTest<E> {
|
|||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testRemoveFirst() {
|
public void testRemoveFirst() {
|
||||||
List<E> testListCopy = new ArrayList<>(testList);
|
final List<E> testListCopy = new ArrayList<>(testList);
|
||||||
Iterator<E> iter = new SkippingIterator<>(testListCopy.iterator(), 4);
|
final Iterator<E> iter = new SkippingIterator<>(testListCopy.iterator(), 4);
|
||||||
|
|
||||||
assertTrue(iter.hasNext());
|
assertTrue(iter.hasNext());
|
||||||
assertEquals("e", iter.next());
|
assertEquals("e", iter.next());
|
||||||
@ -208,7 +208,7 @@ public class SkippingIteratorTest<E> extends AbstractIteratorTest<E> {
|
|||||||
try {
|
try {
|
||||||
iter.next();
|
iter.next();
|
||||||
fail("Expected NoSuchElementException.");
|
fail("Expected NoSuchElementException.");
|
||||||
} catch (NoSuchElementException nsee) { /* Success case */
|
} catch (final NoSuchElementException nsee) { /* Success case */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -218,8 +218,8 @@ public class SkippingIteratorTest<E> extends AbstractIteratorTest<E> {
|
|||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testRemoveMiddle() {
|
public void testRemoveMiddle() {
|
||||||
List<E> testListCopy = new ArrayList<>(testList);
|
final List<E> testListCopy = new ArrayList<>(testList);
|
||||||
Iterator<E> iter = new SkippingIterator<>(testListCopy.iterator(), 3);
|
final Iterator<E> iter = new SkippingIterator<>(testListCopy.iterator(), 3);
|
||||||
|
|
||||||
assertTrue(iter.hasNext());
|
assertTrue(iter.hasNext());
|
||||||
assertEquals("d", iter.next());
|
assertEquals("d", iter.next());
|
||||||
@ -238,7 +238,7 @@ public class SkippingIteratorTest<E> extends AbstractIteratorTest<E> {
|
|||||||
try {
|
try {
|
||||||
iter.next();
|
iter.next();
|
||||||
fail("Expected NoSuchElementException.");
|
fail("Expected NoSuchElementException.");
|
||||||
} catch (NoSuchElementException nsee) { /* Success case */
|
} catch (final NoSuchElementException nsee) { /* Success case */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -248,8 +248,8 @@ public class SkippingIteratorTest<E> extends AbstractIteratorTest<E> {
|
|||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testRemoveLast() {
|
public void testRemoveLast() {
|
||||||
List<E> testListCopy = new ArrayList<>(testList);
|
final List<E> testListCopy = new ArrayList<>(testList);
|
||||||
Iterator<E> iter = new SkippingIterator<>(testListCopy.iterator(), 5);
|
final Iterator<E> iter = new SkippingIterator<>(testListCopy.iterator(), 5);
|
||||||
|
|
||||||
assertTrue(iter.hasNext());
|
assertTrue(iter.hasNext());
|
||||||
assertEquals("f", iter.next());
|
assertEquals("f", iter.next());
|
||||||
@ -260,7 +260,7 @@ public class SkippingIteratorTest<E> extends AbstractIteratorTest<E> {
|
|||||||
try {
|
try {
|
||||||
iter.next();
|
iter.next();
|
||||||
fail("Expected NoSuchElementException.");
|
fail("Expected NoSuchElementException.");
|
||||||
} catch (NoSuchElementException nsee) { /* Success case */
|
} catch (final NoSuchElementException nsee) { /* Success case */
|
||||||
}
|
}
|
||||||
|
|
||||||
iter.remove();
|
iter.remove();
|
||||||
@ -270,7 +270,7 @@ public class SkippingIteratorTest<E> extends AbstractIteratorTest<E> {
|
|||||||
try {
|
try {
|
||||||
iter.next();
|
iter.next();
|
||||||
fail("Expected NoSuchElementException.");
|
fail("Expected NoSuchElementException.");
|
||||||
} catch (NoSuchElementException nsee) { /* Success case */
|
} catch (final NoSuchElementException nsee) { /* Success case */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -280,20 +280,20 @@ public class SkippingIteratorTest<E> extends AbstractIteratorTest<E> {
|
|||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testRemoveUnsupported() {
|
public void testRemoveUnsupported() {
|
||||||
Iterator<E> mockIterator = new AbstractIteratorDecorator<E>(testList.iterator()) {
|
final Iterator<E> mockIterator = new AbstractIteratorDecorator<E>(testList.iterator()) {
|
||||||
@Override
|
@Override
|
||||||
public void remove() {
|
public void remove() {
|
||||||
throw new UnsupportedOperationException();
|
throw new UnsupportedOperationException();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
Iterator<E> iter = new SkippingIterator<>(mockIterator, 1);
|
final Iterator<E> iter = new SkippingIterator<>(mockIterator, 1);
|
||||||
assertTrue(iter.hasNext());
|
assertTrue(iter.hasNext());
|
||||||
assertEquals("b", iter.next());
|
assertEquals("b", iter.next());
|
||||||
try {
|
try {
|
||||||
iter.remove();
|
iter.remove();
|
||||||
fail("Expected UnsupportedOperationException.");
|
fail("Expected UnsupportedOperationException.");
|
||||||
} catch (UnsupportedOperationException usoe) { /* Success case */
|
} catch (final UnsupportedOperationException usoe) { /* Success case */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -100,7 +100,7 @@ public class ZippingIteratorTest extends AbstractIteratorTest<Integer> {
|
|||||||
final ZippingIterator<Integer> iter = new ZippingIterator<>(odds.iterator(), evens.iterator());
|
final ZippingIterator<Integer> iter = new ZippingIterator<>(odds.iterator(), evens.iterator());
|
||||||
for (int i = 0, j = 0; i < 20; i++) {
|
for (int i = 0, j = 0; i < 20; i++) {
|
||||||
assertTrue(iter.hasNext());
|
assertTrue(iter.hasNext());
|
||||||
int val = iter.next();
|
final int val = iter.next();
|
||||||
if (i % 2 == 0) {
|
if (i % 2 == 0) {
|
||||||
assertEquals(odds.get(j).intValue(), val);
|
assertEquals(odds.get(j).intValue(), val);
|
||||||
} else {
|
} else {
|
||||||
|
@ -472,7 +472,7 @@ public abstract class AbstractListTest<E> extends AbstractCollectionTest<E> {
|
|||||||
final List<E> list1 = getCollection();
|
final List<E> list1 = getCollection();
|
||||||
final List<E> list2 = getConfirmed();
|
final List<E> list2 = getConfirmed();
|
||||||
|
|
||||||
for (E element : list2) {
|
for (final E element : list2) {
|
||||||
assertEquals("indexOf should return correct result",
|
assertEquals("indexOf should return correct result",
|
||||||
list1.indexOf(element), list2.indexOf(element));
|
list1.indexOf(element), list2.indexOf(element));
|
||||||
verify();
|
verify();
|
||||||
|
@ -463,11 +463,11 @@ public class SetUniqueListTest<E> extends AbstractListTest<E> {
|
|||||||
|
|
||||||
public void testSubListIsUnmodifiable() {
|
public void testSubListIsUnmodifiable() {
|
||||||
resetFull();
|
resetFull();
|
||||||
List<E> subList = getCollection().subList(1, 3);
|
final List<E> subList = getCollection().subList(1, 3);
|
||||||
try {
|
try {
|
||||||
subList.remove(0);
|
subList.remove(0);
|
||||||
fail("subList should be unmodifiable");
|
fail("subList should be unmodifiable");
|
||||||
} catch (UnsupportedOperationException e) {
|
} catch (final UnsupportedOperationException e) {
|
||||||
// expected
|
// expected
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -273,20 +273,20 @@ public class TreeListTest<E> extends AbstractListTest<E> {
|
|||||||
// when initializing the TreeList with another collection
|
// when initializing the TreeList with another collection
|
||||||
|
|
||||||
for (int size = 1; size < 1000; size++) {
|
for (int size = 1; size < 1000; size++) {
|
||||||
List<Integer> other = new ArrayList<>(size);
|
final List<Integer> other = new ArrayList<>(size);
|
||||||
for (int i = 0; i < size; i++) {
|
for (int i = 0; i < size; i++) {
|
||||||
other.add(i);
|
other.add(i);
|
||||||
}
|
}
|
||||||
TreeList<Integer> l = new TreeList<>(other);
|
final TreeList<Integer> l = new TreeList<>(other);
|
||||||
ListIterator<Integer> it = l.listIterator();
|
final ListIterator<Integer> it = l.listIterator();
|
||||||
int i = 0;
|
int i = 0;
|
||||||
while (it.hasNext()) {
|
while (it.hasNext()) {
|
||||||
Integer val = it.next();
|
final Integer val = it.next();
|
||||||
assertEquals(i++, val.intValue());
|
assertEquals(i++, val.intValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
while (it.hasPrevious()) {
|
while (it.hasPrevious()) {
|
||||||
Integer val = it.previous();
|
final Integer val = it.previous();
|
||||||
assertEquals(--i, val.intValue());
|
assertEquals(--i, val.intValue());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -301,28 +301,28 @@ public class TreeListTest<E> extends AbstractListTest<E> {
|
|||||||
// to simulate different cases in addAll, do different runs where
|
// to simulate different cases in addAll, do different runs where
|
||||||
// the number of elements already in the list and being added by addAll differ
|
// the number of elements already in the list and being added by addAll differ
|
||||||
|
|
||||||
int size = 1000;
|
final int size = 1000;
|
||||||
for (int i = 0; i < 100; i++) {
|
for (int i = 0; i < 100; i++) {
|
||||||
List<Integer> other = new ArrayList<>(size);
|
final List<Integer> other = new ArrayList<>(size);
|
||||||
for (int j = i; j < size; j++) {
|
for (int j = i; j < size; j++) {
|
||||||
other.add(j);
|
other.add(j);
|
||||||
}
|
}
|
||||||
TreeList<Integer> l = new TreeList<>();
|
final TreeList<Integer> l = new TreeList<>();
|
||||||
for (int j = 0; j < i; j++) {
|
for (int j = 0; j < i; j++) {
|
||||||
l.add(j);
|
l.add(j);
|
||||||
}
|
}
|
||||||
|
|
||||||
l.addAll(other);
|
l.addAll(other);
|
||||||
|
|
||||||
ListIterator<Integer> it = l.listIterator();
|
final ListIterator<Integer> it = l.listIterator();
|
||||||
int cnt = 0;
|
int cnt = 0;
|
||||||
while (it.hasNext()) {
|
while (it.hasNext()) {
|
||||||
Integer val = it.next();
|
final Integer val = it.next();
|
||||||
assertEquals(cnt++, val.intValue());
|
assertEquals(cnt++, val.intValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
while (it.hasPrevious()) {
|
while (it.hasPrevious()) {
|
||||||
Integer val = it.previous();
|
final Integer val = it.previous();
|
||||||
assertEquals(--cnt, val.intValue());
|
assertEquals(--cnt, val.intValue());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -624,14 +624,14 @@ public abstract class AbstractMapTest<K, V> extends AbstractObjectTest {
|
|||||||
final Object[] keys = getSampleKeys();
|
final Object[] keys = getSampleKeys();
|
||||||
|
|
||||||
resetEmpty();
|
resetEmpty();
|
||||||
for (Object key : keys) {
|
for (final Object key : keys) {
|
||||||
assertTrue("Map must not contain key when map is empty",
|
assertTrue("Map must not contain key when map is empty",
|
||||||
!getMap().containsKey(key));
|
!getMap().containsKey(key));
|
||||||
}
|
}
|
||||||
verify();
|
verify();
|
||||||
|
|
||||||
resetFull();
|
resetFull();
|
||||||
for (Object key : keys) {
|
for (final Object key : keys) {
|
||||||
assertTrue("Map must contain key for a mapping in the map. " +
|
assertTrue("Map must contain key for a mapping in the map. " +
|
||||||
"Missing: " + key, getMap().containsKey(key));
|
"Missing: " + key, getMap().containsKey(key));
|
||||||
}
|
}
|
||||||
|
@ -90,7 +90,7 @@ public abstract class AbstractSortedMapTest<K, V> extends AbstractMapTest<K, V>
|
|||||||
public void testLastKey() {
|
public void testLastKey() {
|
||||||
final SortedMap<K, V> sm = makeFullMap();
|
final SortedMap<K, V> sm = makeFullMap();
|
||||||
K obj = null;
|
K obj = null;
|
||||||
for (K k : sm.keySet()) {
|
for (final K k : sm.keySet()) {
|
||||||
obj = k;
|
obj = k;
|
||||||
}
|
}
|
||||||
assertSame(obj, sm.lastKey());
|
assertSame(obj, sm.lastKey());
|
||||||
|
@ -74,42 +74,42 @@ public class LRUMapTest<K, V> extends AbstractOrderedMapTest<K, V> {
|
|||||||
try {
|
try {
|
||||||
new LRUMap<K, V>(0);
|
new LRUMap<K, V>(0);
|
||||||
fail("maxSize must be positive");
|
fail("maxSize must be positive");
|
||||||
} catch(IllegalArgumentException ex) {
|
} catch(final IllegalArgumentException ex) {
|
||||||
// expected
|
// expected
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
new LRUMap<K, V>(-1, 12, 0.75f, false);
|
new LRUMap<K, V>(-1, 12, 0.75f, false);
|
||||||
fail("maxSize must be positive");
|
fail("maxSize must be positive");
|
||||||
} catch(IllegalArgumentException ex) {
|
} catch(final IllegalArgumentException ex) {
|
||||||
// expected
|
// expected
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
new LRUMap<K, V>(10, -1);
|
new LRUMap<K, V>(10, -1);
|
||||||
fail("initialSize must not be negative");
|
fail("initialSize must not be negative");
|
||||||
} catch(IllegalArgumentException ex) {
|
} catch(final IllegalArgumentException ex) {
|
||||||
// expected
|
// expected
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
new LRUMap<K, V>(10, 12);
|
new LRUMap<K, V>(10, 12);
|
||||||
fail("initialSize must not be larger than maxSize");
|
fail("initialSize must not be larger than maxSize");
|
||||||
} catch(IllegalArgumentException ex) {
|
} catch(final IllegalArgumentException ex) {
|
||||||
// expected
|
// expected
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
new LRUMap<K, V>(10, -1, 0.75f, false);
|
new LRUMap<K, V>(10, -1, 0.75f, false);
|
||||||
fail("initialSize must not be negative");
|
fail("initialSize must not be negative");
|
||||||
} catch(IllegalArgumentException ex) {
|
} catch(final IllegalArgumentException ex) {
|
||||||
// expected
|
// expected
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
new LRUMap<K, V>(10, 12, 0.75f, false);
|
new LRUMap<K, V>(10, 12, 0.75f, false);
|
||||||
fail("initialSize must not be larger than maxSize");
|
fail("initialSize must not be larger than maxSize");
|
||||||
} catch(IllegalArgumentException ex) {
|
} catch(final IllegalArgumentException ex) {
|
||||||
// expected
|
// expected
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -280,7 +280,7 @@ public class LRUMapTest<K, V> extends AbstractOrderedMapTest<K, V> {
|
|||||||
Iterator<V> vit = null;
|
Iterator<V> vit = null;
|
||||||
|
|
||||||
resetEmpty();
|
resetEmpty();
|
||||||
LRUMap<K, V> lruMap = (LRUMap<K, V>) map;
|
final LRUMap<K, V> lruMap = (LRUMap<K, V>) map;
|
||||||
|
|
||||||
lruMap.put(keys[0], values[0]);
|
lruMap.put(keys[0], values[0]);
|
||||||
lruMap.put(keys[1], values[1]);
|
lruMap.put(keys[1], values[1]);
|
||||||
|
@ -386,13 +386,13 @@ public class ListOrderedMapTest<K, V> extends AbstractOrderedMapTest<K, V> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void testCOLLECTIONS_474_nullValues () {
|
public void testCOLLECTIONS_474_nullValues () {
|
||||||
Object key1 = new Object();
|
final Object key1 = new Object();
|
||||||
Object key2 = new Object();
|
final Object key2 = new Object();
|
||||||
HashMap<Object, Object> hmap = new HashMap<>();
|
final HashMap<Object, Object> hmap = new HashMap<>();
|
||||||
hmap.put(key1, null);
|
hmap.put(key1, null);
|
||||||
hmap.put(key2, null);
|
hmap.put(key2, null);
|
||||||
assertEquals("Should have two elements", 2, hmap.size());
|
assertEquals("Should have two elements", 2, hmap.size());
|
||||||
ListOrderedMap<Object, Object> listMap = new ListOrderedMap<>();
|
final ListOrderedMap<Object, Object> listMap = new ListOrderedMap<>();
|
||||||
listMap.put(key1, null);
|
listMap.put(key1, null);
|
||||||
listMap.put(key2, null);
|
listMap.put(key2, null);
|
||||||
assertEquals("Should have two elements", 2, listMap.size());
|
assertEquals("Should have two elements", 2, listMap.size());
|
||||||
@ -400,13 +400,13 @@ public class ListOrderedMapTest<K, V> extends AbstractOrderedMapTest<K, V> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void testCOLLECTIONS_474_nonNullValues () {
|
public void testCOLLECTIONS_474_nonNullValues () {
|
||||||
Object key1 = new Object();
|
final Object key1 = new Object();
|
||||||
Object key2 = new Object();
|
final Object key2 = new Object();
|
||||||
HashMap<Object, Object> hmap = new HashMap<>();
|
final HashMap<Object, Object> hmap = new HashMap<>();
|
||||||
hmap.put(key1, "1");
|
hmap.put(key1, "1");
|
||||||
hmap.put(key2, "2");
|
hmap.put(key2, "2");
|
||||||
assertEquals("Should have two elements", 2, hmap.size());
|
assertEquals("Should have two elements", 2, hmap.size());
|
||||||
ListOrderedMap<Object, Object> listMap = new ListOrderedMap<>();
|
final ListOrderedMap<Object, Object> listMap = new ListOrderedMap<>();
|
||||||
listMap.put(key1, "3");
|
listMap.put(key1, "3");
|
||||||
listMap.put(key2, "4");
|
listMap.put(key2, "4");
|
||||||
assertEquals("Should have two elements", 2, listMap.size());
|
assertEquals("Should have two elements", 2, listMap.size());
|
||||||
|
@ -152,10 +152,11 @@ public class MultiValueMapTest<K, V> extends AbstractObjectTest {
|
|||||||
public void testIterator() {
|
public void testIterator() {
|
||||||
final MultiValueMap<K, V> map = createTestMap();
|
final MultiValueMap<K, V> map = createTestMap();
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
|
final
|
||||||
Collection<V> values = new ArrayList<>((Collection<V>) map.values());
|
Collection<V> values = new ArrayList<>((Collection<V>) map.values());
|
||||||
Iterator<Map.Entry<K, V>> iterator = map.iterator();
|
final Iterator<Map.Entry<K, V>> iterator = map.iterator();
|
||||||
while (iterator.hasNext()) {
|
while (iterator.hasNext()) {
|
||||||
Map.Entry<K, V> entry = iterator.next();
|
final Map.Entry<K, V> entry = iterator.next();
|
||||||
assertTrue(map.containsValue(entry.getKey(), entry.getValue()));
|
assertTrue(map.containsValue(entry.getKey(), entry.getValue()));
|
||||||
assertTrue(values.contains(entry.getValue()));
|
assertTrue(values.contains(entry.getValue()));
|
||||||
assertTrue(values.remove(entry.getValue()));
|
assertTrue(values.remove(entry.getValue()));
|
||||||
@ -392,24 +393,24 @@ public class MultiValueMapTest<K, V> extends AbstractObjectTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void testUnsafeDeSerialization() throws Exception {
|
public void testUnsafeDeSerialization() throws Exception {
|
||||||
MultiValueMap map1 = MultiValueMap.multiValueMap(new HashMap(), ArrayList.class);
|
final MultiValueMap map1 = MultiValueMap.multiValueMap(new HashMap(), ArrayList.class);
|
||||||
byte[] bytes = serialize(map1);
|
byte[] bytes = serialize(map1);
|
||||||
Object result = deserialize(bytes);
|
Object result = deserialize(bytes);
|
||||||
assertEquals(map1, result);
|
assertEquals(map1, result);
|
||||||
|
|
||||||
MultiValueMap map2 = MultiValueMap.multiValueMap(new HashMap(), (Class) String.class);
|
final MultiValueMap map2 = MultiValueMap.multiValueMap(new HashMap(), (Class) String.class);
|
||||||
bytes = serialize(map2);
|
bytes = serialize(map2);
|
||||||
try {
|
try {
|
||||||
result = deserialize(bytes);
|
result = deserialize(bytes);
|
||||||
fail("unsafe clazz accepted when de-serializing MultiValueMap");
|
fail("unsafe clazz accepted when de-serializing MultiValueMap");
|
||||||
} catch (UnsupportedOperationException ex) {
|
} catch (final UnsupportedOperationException ex) {
|
||||||
// expected
|
// expected
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private byte[] serialize(final Object object) throws IOException {
|
private byte[] serialize(final Object object) throws IOException {
|
||||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||||
ObjectOutputStream oos = new ObjectOutputStream(baos);
|
final ObjectOutputStream oos = new ObjectOutputStream(baos);
|
||||||
|
|
||||||
oos.writeObject(object);
|
oos.writeObject(object);
|
||||||
oos.close();
|
oos.close();
|
||||||
@ -418,8 +419,8 @@ public class MultiValueMapTest<K, V> extends AbstractObjectTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private Object deserialize(final byte[] data) throws IOException, ClassNotFoundException {
|
private Object deserialize(final byte[] data) throws IOException, ClassNotFoundException {
|
||||||
ByteArrayInputStream bais = new ByteArrayInputStream(data);
|
final ByteArrayInputStream bais = new ByteArrayInputStream(data);
|
||||||
ObjectInputStream iis = new ObjectInputStream(bais);
|
final ObjectInputStream iis = new ObjectInputStream(bais);
|
||||||
|
|
||||||
return iis.readObject();
|
return iis.readObject();
|
||||||
}
|
}
|
||||||
|
@ -241,7 +241,7 @@ public class PassiveExpiringMapTest<K, V> extends AbstractMapTest<K, V> {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
Thread.sleep(2 * timeout);
|
Thread.sleep(2 * timeout);
|
||||||
} catch (InterruptedException e) {
|
} catch (final InterruptedException e) {
|
||||||
fail();
|
fail();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -206,6 +206,7 @@ public abstract class AbstractMultiValuedMapTest<K, V> extends AbstractObjectTes
|
|||||||
public void testMultipleValues() {
|
public void testMultipleValues() {
|
||||||
final MultiValuedMap<K, V> map = makeFullMap();
|
final MultiValuedMap<K, V> map = makeFullMap();
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
|
final
|
||||||
Collection<V> col = map.get((K) "one");
|
Collection<V> col = map.get((K) "one");
|
||||||
assertTrue(col.contains("uno"));
|
assertTrue(col.contains("uno"));
|
||||||
assertTrue(col.contains("un"));
|
assertTrue(col.contains("un"));
|
||||||
@ -229,8 +230,8 @@ public abstract class AbstractMultiValuedMapTest<K, V> extends AbstractObjectTes
|
|||||||
}
|
}
|
||||||
resetEmpty();
|
resetEmpty();
|
||||||
final MultiValuedMap<K, V> map = getMap();
|
final MultiValuedMap<K, V> map = getMap();
|
||||||
Collection<V> col1 = map.get((K) "one");
|
final Collection<V> col1 = map.get((K) "one");
|
||||||
Collection<V> col2 = map.get((K) "one");
|
final Collection<V> col2 = map.get((K) "one");
|
||||||
assertTrue(col1.isEmpty());
|
assertTrue(col1.isEmpty());
|
||||||
assertTrue(col2.isEmpty());
|
assertTrue(col2.isEmpty());
|
||||||
assertEquals(0, map.size());
|
assertEquals(0, map.size());
|
||||||
@ -275,6 +276,7 @@ public abstract class AbstractMultiValuedMapTest<K, V> extends AbstractObjectTes
|
|||||||
resetFull();
|
resetFull();
|
||||||
final MultiValuedMap<K, V> map = getMap();
|
final MultiValuedMap<K, V> map = getMap();
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
|
final
|
||||||
Iterator<V> it = map.get((K) "one").iterator();
|
Iterator<V> it = map.get((K) "one").iterator();
|
||||||
while (it.hasNext()) {
|
while (it.hasNext()) {
|
||||||
it.next();
|
it.next();
|
||||||
@ -286,7 +288,7 @@ public abstract class AbstractMultiValuedMapTest<K, V> extends AbstractObjectTes
|
|||||||
assertFalse(map.containsValue("uno"));
|
assertFalse(map.containsValue("uno"));
|
||||||
assertFalse(map.containsValue("un"));
|
assertFalse(map.containsValue("un"));
|
||||||
assertEquals(4, map.size());
|
assertEquals(4, map.size());
|
||||||
Collection<V> coll = map.remove("one");
|
final Collection<V> coll = map.remove("one");
|
||||||
assertNotNull(coll);
|
assertNotNull(coll);
|
||||||
assertEquals(0, coll.size());
|
assertEquals(0, coll.size());
|
||||||
}
|
}
|
||||||
@ -354,7 +356,7 @@ public abstract class AbstractMultiValuedMapTest<K, V> extends AbstractObjectTes
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
final MultiValuedMap<K, V> map = makeFullMap();
|
final MultiValuedMap<K, V> map = makeFullMap();
|
||||||
Collection<V> values = map.values();
|
final Collection<V> values = map.values();
|
||||||
values.remove("uno");
|
values.remove("uno");
|
||||||
values.remove("un");
|
values.remove("un");
|
||||||
assertFalse(map.containsKey("one"));
|
assertFalse(map.containsKey("one"));
|
||||||
@ -388,10 +390,10 @@ public abstract class AbstractMultiValuedMapTest<K, V> extends AbstractObjectTes
|
|||||||
|
|
||||||
public void testEntriesCollectionIterator() {
|
public void testEntriesCollectionIterator() {
|
||||||
final MultiValuedMap<K, V> map = makeFullMap();
|
final MultiValuedMap<K, V> map = makeFullMap();
|
||||||
Collection<V> values = new ArrayList<>(map.values());
|
final Collection<V> values = new ArrayList<>(map.values());
|
||||||
Iterator<Map.Entry<K, V>> iterator = map.entries().iterator();
|
final Iterator<Map.Entry<K, V>> iterator = map.entries().iterator();
|
||||||
while (iterator.hasNext()) {
|
while (iterator.hasNext()) {
|
||||||
Map.Entry<K, V> entry = iterator.next();
|
final Map.Entry<K, V> entry = iterator.next();
|
||||||
assertTrue(map.containsMapping(entry.getKey(), entry.getValue()));
|
assertTrue(map.containsMapping(entry.getKey(), entry.getValue()));
|
||||||
assertTrue(values.contains(entry.getValue()));
|
assertTrue(values.contains(entry.getValue()));
|
||||||
if (isRemoveSupported()) {
|
if (isRemoveSupported()) {
|
||||||
@ -596,7 +598,7 @@ public abstract class AbstractMultiValuedMapTest<K, V> extends AbstractObjectTes
|
|||||||
try {
|
try {
|
||||||
map.putAll((K) "A", null);
|
map.putAll((K) "A", null);
|
||||||
fail("expecting NullPointerException");
|
fail("expecting NullPointerException");
|
||||||
} catch (NullPointerException npe) {
|
} catch (final NullPointerException npe) {
|
||||||
// expected
|
// expected
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -638,8 +640,8 @@ public abstract class AbstractMultiValuedMapTest<K, V> extends AbstractObjectTes
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void testKeysMultiSet() {
|
public void testKeysMultiSet() {
|
||||||
MultiValuedMap<K, V> map = makeFullMap();
|
final MultiValuedMap<K, V> map = makeFullMap();
|
||||||
MultiSet<K> keyMultiSet = map.keys();
|
final MultiSet<K> keyMultiSet = map.keys();
|
||||||
assertEquals(2, keyMultiSet.getCount("one"));
|
assertEquals(2, keyMultiSet.getCount("one"));
|
||||||
assertEquals(2, keyMultiSet.getCount("two"));
|
assertEquals(2, keyMultiSet.getCount("two"));
|
||||||
assertEquals(2, keyMultiSet.getCount("three"));
|
assertEquals(2, keyMultiSet.getCount("three"));
|
||||||
@ -647,13 +649,13 @@ public abstract class AbstractMultiValuedMapTest<K, V> extends AbstractObjectTes
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void testKeysBagIterator() {
|
public void testKeysBagIterator() {
|
||||||
MultiValuedMap<K, V> map = makeFullMap();
|
final MultiValuedMap<K, V> map = makeFullMap();
|
||||||
Collection<K> col = new ArrayList<>();
|
final Collection<K> col = new ArrayList<>();
|
||||||
Iterator<K> it = map.keys().iterator();
|
final Iterator<K> it = map.keys().iterator();
|
||||||
while (it.hasNext()) {
|
while (it.hasNext()) {
|
||||||
col.add(it.next());
|
col.add(it.next());
|
||||||
}
|
}
|
||||||
Bag<K> bag = new HashBag<>(col);
|
final Bag<K> bag = new HashBag<>(col);
|
||||||
assertEquals(2, bag.getCount("one"));
|
assertEquals(2, bag.getCount("one"));
|
||||||
assertEquals(2, bag.getCount("two"));
|
assertEquals(2, bag.getCount("two"));
|
||||||
assertEquals(2, bag.getCount("three"));
|
assertEquals(2, bag.getCount("three"));
|
||||||
@ -662,9 +664,9 @@ public abstract class AbstractMultiValuedMapTest<K, V> extends AbstractObjectTes
|
|||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public void testKeysBagContainsAll() {
|
public void testKeysBagContainsAll() {
|
||||||
MultiValuedMap<K, V> map = makeFullMap();
|
final MultiValuedMap<K, V> map = makeFullMap();
|
||||||
MultiSet<K> keyMultiSet = map.keys();
|
final MultiSet<K> keyMultiSet = map.keys();
|
||||||
Collection<K> col = (Collection<K>) Arrays.asList("one", "two", "three", "one", "two", "three");
|
final Collection<K> col = (Collection<K>) Arrays.asList("one", "two", "three", "one", "two", "three");
|
||||||
assertTrue(keyMultiSet.containsAll(col));
|
assertTrue(keyMultiSet.containsAll(col));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -676,7 +678,7 @@ public abstract class AbstractMultiValuedMapTest<K, V> extends AbstractObjectTes
|
|||||||
|
|
||||||
resetFull();
|
resetFull();
|
||||||
mapCol = getMap().asMap();
|
mapCol = getMap().asMap();
|
||||||
Collection<V> col = mapCol.get("one");
|
final Collection<V> col = mapCol.get("one");
|
||||||
assertNotNull(col);
|
assertNotNull(col);
|
||||||
assertTrue(col.contains("un"));
|
assertTrue(col.contains("un"));
|
||||||
assertTrue(col.contains("uno"));
|
assertTrue(col.contains("uno"));
|
||||||
@ -687,7 +689,7 @@ public abstract class AbstractMultiValuedMapTest<K, V> extends AbstractObjectTes
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
resetFull();
|
resetFull();
|
||||||
Map<K, Collection<V>> mapCol = getMap().asMap();
|
final Map<K, Collection<V>> mapCol = getMap().asMap();
|
||||||
mapCol.remove("one");
|
mapCol.remove("one");
|
||||||
assertFalse(getMap().containsKey("one"));
|
assertFalse(getMap().containsKey("one"));
|
||||||
assertEquals(4, getMap().size());
|
assertEquals(4, getMap().size());
|
||||||
@ -701,8 +703,8 @@ public abstract class AbstractMultiValuedMapTest<K, V> extends AbstractObjectTes
|
|||||||
resetFull();
|
resetFull();
|
||||||
mapIt = getMap().mapIterator();
|
mapIt = getMap().mapIterator();
|
||||||
while (mapIt.hasNext()) {
|
while (mapIt.hasNext()) {
|
||||||
K key = mapIt.next();
|
final K key = mapIt.next();
|
||||||
V value = mapIt.getValue();
|
final V value = mapIt.getValue();
|
||||||
assertTrue(getMap().containsMapping(key, value));
|
assertTrue(getMap().containsMapping(key, value));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -712,7 +714,7 @@ public abstract class AbstractMultiValuedMapTest<K, V> extends AbstractObjectTes
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
resetFull();
|
resetFull();
|
||||||
MapIterator<K, V> mapIt = getMap().mapIterator();
|
final MapIterator<K, V> mapIt = getMap().mapIterator();
|
||||||
while (mapIt.hasNext()) {
|
while (mapIt.hasNext()) {
|
||||||
mapIt.next();
|
mapIt.next();
|
||||||
mapIt.remove();
|
mapIt.remove();
|
||||||
@ -723,12 +725,12 @@ public abstract class AbstractMultiValuedMapTest<K, V> extends AbstractObjectTes
|
|||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public void testMapIteratorUnsupportedSet() {
|
public void testMapIteratorUnsupportedSet() {
|
||||||
resetFull();
|
resetFull();
|
||||||
MapIterator<K, V> mapIt = getMap().mapIterator();
|
final MapIterator<K, V> mapIt = getMap().mapIterator();
|
||||||
mapIt.next();
|
mapIt.next();
|
||||||
try {
|
try {
|
||||||
mapIt.setValue((V) "some value");
|
mapIt.setValue((V) "some value");
|
||||||
fail();
|
fail();
|
||||||
} catch (UnsupportedOperationException e) {
|
} catch (final UnsupportedOperationException e) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1075,8 +1077,8 @@ public abstract class AbstractMultiValuedMapTest<K, V> extends AbstractObjectTes
|
|||||||
@Override
|
@Override
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public K[] getSampleKeys() {
|
public K[] getSampleKeys() {
|
||||||
K[] samplekeys = AbstractMultiValuedMapTest.this.getSampleKeys();
|
final K[] samplekeys = AbstractMultiValuedMapTest.this.getSampleKeys();
|
||||||
Object[] finalKeys = new Object[3];
|
final Object[] finalKeys = new Object[3];
|
||||||
for (int i = 0; i < 3; i++) {
|
for (int i = 0; i < 3; i++) {
|
||||||
finalKeys[i] = samplekeys[i * 2];
|
finalKeys[i] = samplekeys[i * 2];
|
||||||
}
|
}
|
||||||
@ -1086,11 +1088,11 @@ public abstract class AbstractMultiValuedMapTest<K, V> extends AbstractObjectTes
|
|||||||
@Override
|
@Override
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public Collection<V>[] getSampleValues() {
|
public Collection<V>[] getSampleValues() {
|
||||||
boolean isSetValuedMap = AbstractMultiValuedMapTest.this.getMap() instanceof SetValuedMap;
|
final boolean isSetValuedMap = AbstractMultiValuedMapTest.this.getMap() instanceof SetValuedMap;
|
||||||
V[] sampleValues = AbstractMultiValuedMapTest.this.getSampleValues();
|
final V[] sampleValues = AbstractMultiValuedMapTest.this.getSampleValues();
|
||||||
Collection<V>[] colArr = new Collection[3];
|
final Collection<V>[] colArr = new Collection[3];
|
||||||
for(int i = 0; i < 3; i++) {
|
for(int i = 0; i < 3; i++) {
|
||||||
Collection<V> coll = Arrays.asList(sampleValues[i*2], sampleValues[i*2 + 1]);
|
final Collection<V> coll = Arrays.asList(sampleValues[i*2], sampleValues[i*2 + 1]);
|
||||||
colArr[i] = isSetValuedMap ? new HashSet<>(coll) : coll;
|
colArr[i] = isSetValuedMap ? new HashSet<>(coll) : coll;
|
||||||
}
|
}
|
||||||
return colArr;
|
return colArr;
|
||||||
@ -1099,11 +1101,11 @@ public abstract class AbstractMultiValuedMapTest<K, V> extends AbstractObjectTes
|
|||||||
@Override
|
@Override
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public Collection<V>[] getNewSampleValues() {
|
public Collection<V>[] getNewSampleValues() {
|
||||||
boolean isSetValuedMap = AbstractMultiValuedMapTest.this.getMap() instanceof SetValuedMap;
|
final boolean isSetValuedMap = AbstractMultiValuedMapTest.this.getMap() instanceof SetValuedMap;
|
||||||
Object[] sampleValues = { "ein", "ek", "zwei", "duey", "drei", "teen" };
|
final Object[] sampleValues = { "ein", "ek", "zwei", "duey", "drei", "teen" };
|
||||||
Collection<V>[] colArr = new Collection[3];
|
final Collection<V>[] colArr = new Collection[3];
|
||||||
for (int i = 0; i < 3; i++) {
|
for (int i = 0; i < 3; i++) {
|
||||||
Collection<V> coll = Arrays.asList((V) sampleValues[i * 2], (V) sampleValues[i * 2 + 1]);
|
final Collection<V> coll = Arrays.asList((V) sampleValues[i * 2], (V) sampleValues[i * 2 + 1]);
|
||||||
colArr[i] = isSetValuedMap ? new HashSet<>(coll) : coll;
|
colArr[i] = isSetValuedMap ? new HashSet<>(coll) : coll;
|
||||||
}
|
}
|
||||||
return colArr;
|
return colArr;
|
||||||
|
@ -51,7 +51,7 @@ public class ArrayListValuedHashMapTest<K, V> extends AbstractMultiValuedMapTest
|
|||||||
public void testListValuedMapAdd() {
|
public void testListValuedMapAdd() {
|
||||||
final ListValuedMap<K, V> listMap = makeObject();
|
final ListValuedMap<K, V> listMap = makeObject();
|
||||||
assertTrue(listMap.get((K) "whatever") instanceof List);
|
assertTrue(listMap.get((K) "whatever") instanceof List);
|
||||||
List<V> list = listMap.get((K) "A");
|
final List<V> list = listMap.get((K) "A");
|
||||||
list.add((V) "a1");
|
list.add((V) "a1");
|
||||||
assertEquals(1, listMap.size());
|
assertEquals(1, listMap.size());
|
||||||
assertTrue(listMap.containsKey("A"));
|
assertTrue(listMap.containsKey("A"));
|
||||||
@ -60,7 +60,7 @@ public class ArrayListValuedHashMapTest<K, V> extends AbstractMultiValuedMapTest
|
|||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public void testListValuedMapAddViaListIterator() {
|
public void testListValuedMapAddViaListIterator() {
|
||||||
final ListValuedMap<K, V> listMap = makeObject();
|
final ListValuedMap<K, V> listMap = makeObject();
|
||||||
ListIterator<V> listIt = listMap.get((K) "B").listIterator();
|
final ListIterator<V> listIt = listMap.get((K) "B").listIterator();
|
||||||
assertFalse(listIt.hasNext());
|
assertFalse(listIt.hasNext());
|
||||||
listIt.add((V) "b1");
|
listIt.add((V) "b1");
|
||||||
listIt.add((V) "b2");
|
listIt.add((V) "b2");
|
||||||
@ -74,7 +74,7 @@ public class ArrayListValuedHashMapTest<K, V> extends AbstractMultiValuedMapTest
|
|||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public void testListValuedMapRemove() {
|
public void testListValuedMapRemove() {
|
||||||
final ListValuedMap<K, V> listMap = makeObject();
|
final ListValuedMap<K, V> listMap = makeObject();
|
||||||
List<V> list = listMap.get((K) "A");
|
final List<V> list = listMap.get((K) "A");
|
||||||
list.add((V) "a1");
|
list.add((V) "a1");
|
||||||
list.add((V) "a2");
|
list.add((V) "a2");
|
||||||
list.add((V) "a3");
|
list.add((V) "a3");
|
||||||
@ -110,8 +110,8 @@ public class ArrayListValuedHashMapTest<K, V> extends AbstractMultiValuedMapTest
|
|||||||
|
|
||||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||||
public void testEqualsHashCodeContract() {
|
public void testEqualsHashCodeContract() {
|
||||||
MultiValuedMap map1 = makeObject();
|
final MultiValuedMap map1 = makeObject();
|
||||||
MultiValuedMap map2 = makeObject();
|
final MultiValuedMap map2 = makeObject();
|
||||||
|
|
||||||
map1.put("a", "a1");
|
map1.put("a", "a1");
|
||||||
map1.put("a", "a2");
|
map1.put("a", "a2");
|
||||||
@ -127,8 +127,8 @@ public class ArrayListValuedHashMapTest<K, V> extends AbstractMultiValuedMapTest
|
|||||||
|
|
||||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||||
public void testListValuedMapEqualsHashCodeContract() {
|
public void testListValuedMapEqualsHashCodeContract() {
|
||||||
ListValuedMap map1 = makeObject();
|
final ListValuedMap map1 = makeObject();
|
||||||
ListValuedMap map2 = makeObject();
|
final ListValuedMap map2 = makeObject();
|
||||||
|
|
||||||
map1.put("a", "a1");
|
map1.put("a", "a1");
|
||||||
map1.put("a", "a2");
|
map1.put("a", "a2");
|
||||||
|
@ -57,7 +57,7 @@ public class HashSetValuedHashMapTest<K, V> extends AbstractMultiValuedMapTest<K
|
|||||||
final SetValuedMap<K, V> setMap = makeObject();
|
final SetValuedMap<K, V> setMap = makeObject();
|
||||||
assertTrue(setMap.get((K) "whatever") instanceof Set);
|
assertTrue(setMap.get((K) "whatever") instanceof Set);
|
||||||
|
|
||||||
Set<V> set = setMap.get((K) "A");
|
final Set<V> set = setMap.get((K) "A");
|
||||||
assertTrue(set.add((V) "a1"));
|
assertTrue(set.add((V) "a1"));
|
||||||
assertTrue(set.add((V) "a2"));
|
assertTrue(set.add((V) "a2"));
|
||||||
assertFalse(set.add((V) "a1"));
|
assertFalse(set.add((V) "a1"));
|
||||||
@ -70,7 +70,7 @@ public class HashSetValuedHashMapTest<K, V> extends AbstractMultiValuedMapTest<K
|
|||||||
final SetValuedMap<K, V> setMap = makeObject();
|
final SetValuedMap<K, V> setMap = makeObject();
|
||||||
assertTrue(setMap.get((K) "whatever") instanceof Set);
|
assertTrue(setMap.get((K) "whatever") instanceof Set);
|
||||||
|
|
||||||
Set<V> set = setMap.get((K) "A");
|
final Set<V> set = setMap.get((K) "A");
|
||||||
assertTrue(set.add((V) "a1"));
|
assertTrue(set.add((V) "a1"));
|
||||||
assertTrue(set.add((V) "a2"));
|
assertTrue(set.add((V) "a2"));
|
||||||
assertFalse(set.add((V) "a1"));
|
assertFalse(set.add((V) "a1"));
|
||||||
@ -90,12 +90,12 @@ public class HashSetValuedHashMapTest<K, V> extends AbstractMultiValuedMapTest<K
|
|||||||
final SetValuedMap<K, V> setMap = makeObject();
|
final SetValuedMap<K, V> setMap = makeObject();
|
||||||
assertTrue(setMap.get((K) "whatever") instanceof Set);
|
assertTrue(setMap.get((K) "whatever") instanceof Set);
|
||||||
|
|
||||||
Set<V> set = setMap.get((K) "A");
|
final Set<V> set = setMap.get((K) "A");
|
||||||
set.add((V) "a1");
|
set.add((V) "a1");
|
||||||
set.add((V) "a2");
|
set.add((V) "a2");
|
||||||
set.add((V) "a1");
|
set.add((V) "a1");
|
||||||
|
|
||||||
Iterator<V> it = set.iterator();
|
final Iterator<V> it = set.iterator();
|
||||||
while (it.hasNext()) {
|
while (it.hasNext()) {
|
||||||
it.next();
|
it.next();
|
||||||
it.remove();
|
it.remove();
|
||||||
@ -106,8 +106,8 @@ public class HashSetValuedHashMapTest<K, V> extends AbstractMultiValuedMapTest<K
|
|||||||
|
|
||||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||||
public void testSetValuedMapEqualsHashCodeContract() {
|
public void testSetValuedMapEqualsHashCodeContract() {
|
||||||
SetValuedMap map1 = makeObject();
|
final SetValuedMap map1 = makeObject();
|
||||||
SetValuedMap map2 = makeObject();
|
final SetValuedMap map2 = makeObject();
|
||||||
|
|
||||||
map1.put("a", "a1");
|
map1.put("a", "a1");
|
||||||
map1.put("a", "a2");
|
map1.put("a", "a2");
|
||||||
|
@ -53,7 +53,7 @@ public class TransformedMultiValuedMapTest<K, V> extends AbstractMultiValuedMapT
|
|||||||
public void testKeyTransformedMap() {
|
public void testKeyTransformedMap() {
|
||||||
final Object[] els = new Object[] { "1", "3", "5", "7", "2", "4", "6" };
|
final Object[] els = new Object[] { "1", "3", "5", "7", "2", "4", "6" };
|
||||||
|
|
||||||
MultiValuedMap<K, V> map = TransformedMultiValuedMap.transformingMap(
|
final MultiValuedMap<K, V> map = TransformedMultiValuedMap.transformingMap(
|
||||||
new ArrayListValuedHashMap<K, V>(),
|
new ArrayListValuedHashMap<K, V>(),
|
||||||
(Transformer<? super K, ? extends K>) TransformedCollectionTest.STRING_TO_INTEGER_TRANSFORMER,
|
(Transformer<? super K, ? extends K>) TransformedCollectionTest.STRING_TO_INTEGER_TRANSFORMER,
|
||||||
null);
|
null);
|
||||||
@ -67,7 +67,7 @@ public class TransformedMultiValuedMapTest<K, V> extends AbstractMultiValuedMapT
|
|||||||
assertEquals(true, map.get((K) Integer.valueOf((String) els[i])).contains(els[i]));
|
assertEquals(true, map.get((K) Integer.valueOf((String) els[i])).contains(els[i]));
|
||||||
}
|
}
|
||||||
|
|
||||||
Collection<V> coll = map.remove(els[0]);
|
final Collection<V> coll = map.remove(els[0]);
|
||||||
assertNotNull(coll);
|
assertNotNull(coll);
|
||||||
assertEquals(0, coll.size());
|
assertEquals(0, coll.size());
|
||||||
assertEquals(true, map.remove(Integer.valueOf((String) els[0])).contains(els[0]));
|
assertEquals(true, map.remove(Integer.valueOf((String) els[0])).contains(els[0]));
|
||||||
@ -77,7 +77,7 @@ public class TransformedMultiValuedMapTest<K, V> extends AbstractMultiValuedMapT
|
|||||||
public void testValueTransformedMap() {
|
public void testValueTransformedMap() {
|
||||||
final Object[] els = new Object[] { "1", "3", "5", "7", "2", "4", "6" };
|
final Object[] els = new Object[] { "1", "3", "5", "7", "2", "4", "6" };
|
||||||
|
|
||||||
MultiValuedMap<K, V> map = TransformedMultiValuedMap.transformingMap(
|
final MultiValuedMap<K, V> map = TransformedMultiValuedMap.transformingMap(
|
||||||
new ArrayListValuedHashMap<K, V>(), null,
|
new ArrayListValuedHashMap<K, V>(), null,
|
||||||
(Transformer<? super V, ? extends V>) TransformedCollectionTest.STRING_TO_INTEGER_TRANSFORMER);
|
(Transformer<? super V, ? extends V>) TransformedCollectionTest.STRING_TO_INTEGER_TRANSFORMER);
|
||||||
assertEquals(0, map.size());
|
assertEquals(0, map.size());
|
||||||
|
@ -85,179 +85,179 @@ public class UnmodifiableMultiValuedMapTest<K, V> extends AbstractMultiValuedMap
|
|||||||
try {
|
try {
|
||||||
UnmodifiableMultiValuedMap.unmodifiableMultiValuedMap(null);
|
UnmodifiableMultiValuedMap.unmodifiableMultiValuedMap(null);
|
||||||
fail("map must not be null");
|
fail("map must not be null");
|
||||||
} catch (NullPointerException e) {
|
} catch (final NullPointerException e) {
|
||||||
// expected
|
// expected
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public void testAddException() {
|
public void testAddException() {
|
||||||
MultiValuedMap<K, V> map = makeObject();
|
final MultiValuedMap<K, V> map = makeObject();
|
||||||
try {
|
try {
|
||||||
map.put((K) "one", (V) "uno");
|
map.put((K) "one", (V) "uno");
|
||||||
fail();
|
fail();
|
||||||
} catch (UnsupportedOperationException e) {
|
} catch (final UnsupportedOperationException e) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public void testUnmodifiableEntries() {
|
public void testUnmodifiableEntries() {
|
||||||
resetFull();
|
resetFull();
|
||||||
Collection<Entry<K, V>> entries = getMap().entries();
|
final Collection<Entry<K, V>> entries = getMap().entries();
|
||||||
try {
|
try {
|
||||||
entries.clear();
|
entries.clear();
|
||||||
fail();
|
fail();
|
||||||
} catch (UnsupportedOperationException e) {
|
} catch (final UnsupportedOperationException e) {
|
||||||
}
|
}
|
||||||
|
|
||||||
Iterator<Entry<K, V>> it = entries.iterator();
|
final Iterator<Entry<K, V>> it = entries.iterator();
|
||||||
Entry<K, V> entry = it.next();
|
final Entry<K, V> entry = it.next();
|
||||||
try {
|
try {
|
||||||
it.remove();
|
it.remove();
|
||||||
fail();
|
fail();
|
||||||
} catch (UnsupportedOperationException e) {
|
} catch (final UnsupportedOperationException e) {
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
entry.setValue((V) "three");
|
entry.setValue((V) "three");
|
||||||
fail();
|
fail();
|
||||||
} catch (UnsupportedOperationException e) {
|
} catch (final UnsupportedOperationException e) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public void testUnmodifiableMapIterator() {
|
public void testUnmodifiableMapIterator() {
|
||||||
resetFull();
|
resetFull();
|
||||||
MapIterator<K, V> mapIt = getMap().mapIterator();
|
final MapIterator<K, V> mapIt = getMap().mapIterator();
|
||||||
try {
|
try {
|
||||||
mapIt.remove();
|
mapIt.remove();
|
||||||
fail();
|
fail();
|
||||||
} catch (UnsupportedOperationException e) {
|
} catch (final UnsupportedOperationException e) {
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
mapIt.setValue((V) "three");
|
mapIt.setValue((V) "three");
|
||||||
fail();
|
fail();
|
||||||
} catch (UnsupportedOperationException e) {
|
} catch (final UnsupportedOperationException e) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public void testUnmodifiableKeySet() {
|
public void testUnmodifiableKeySet() {
|
||||||
resetFull();
|
resetFull();
|
||||||
Set<K> keySet = getMap().keySet();
|
final Set<K> keySet = getMap().keySet();
|
||||||
try {
|
try {
|
||||||
keySet.add((K) "four");
|
keySet.add((K) "four");
|
||||||
fail();
|
fail();
|
||||||
} catch (UnsupportedOperationException e) {
|
} catch (final UnsupportedOperationException e) {
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
keySet.remove("four");
|
keySet.remove("four");
|
||||||
fail();
|
fail();
|
||||||
} catch (UnsupportedOperationException e) {
|
} catch (final UnsupportedOperationException e) {
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
keySet.clear();
|
keySet.clear();
|
||||||
fail();
|
fail();
|
||||||
} catch (UnsupportedOperationException e) {
|
} catch (final UnsupportedOperationException e) {
|
||||||
}
|
}
|
||||||
|
|
||||||
Iterator<K> it = keySet.iterator();
|
final Iterator<K> it = keySet.iterator();
|
||||||
try {
|
try {
|
||||||
it.remove();
|
it.remove();
|
||||||
fail();
|
fail();
|
||||||
} catch (UnsupportedOperationException e) {
|
} catch (final UnsupportedOperationException e) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public void testUnmodifiableValues() {
|
public void testUnmodifiableValues() {
|
||||||
resetFull();
|
resetFull();
|
||||||
Collection<V> values = getMap().values();
|
final Collection<V> values = getMap().values();
|
||||||
try {
|
try {
|
||||||
values.add((V) "four");
|
values.add((V) "four");
|
||||||
fail();
|
fail();
|
||||||
} catch (UnsupportedOperationException e) {
|
} catch (final UnsupportedOperationException e) {
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
values.remove("four");
|
values.remove("four");
|
||||||
fail();
|
fail();
|
||||||
} catch (UnsupportedOperationException e) {
|
} catch (final UnsupportedOperationException e) {
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
values.clear();
|
values.clear();
|
||||||
fail();
|
fail();
|
||||||
} catch (UnsupportedOperationException e) {
|
} catch (final UnsupportedOperationException e) {
|
||||||
}
|
}
|
||||||
|
|
||||||
Iterator<V> it = values.iterator();
|
final Iterator<V> it = values.iterator();
|
||||||
try {
|
try {
|
||||||
it.remove();
|
it.remove();
|
||||||
fail();
|
fail();
|
||||||
} catch (UnsupportedOperationException e) {
|
} catch (final UnsupportedOperationException e) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public void testUnmodifiableAsMap() {
|
public void testUnmodifiableAsMap() {
|
||||||
resetFull();
|
resetFull();
|
||||||
Map<K, Collection<V>> mapCol = getMap().asMap();
|
final Map<K, Collection<V>> mapCol = getMap().asMap();
|
||||||
try {
|
try {
|
||||||
mapCol.put((K) "four", (Collection<V>) Arrays.asList("four"));
|
mapCol.put((K) "four", (Collection<V>) Arrays.asList("four"));
|
||||||
fail();
|
fail();
|
||||||
} catch (UnsupportedOperationException e) {
|
} catch (final UnsupportedOperationException e) {
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
mapCol.remove("four");
|
mapCol.remove("four");
|
||||||
fail();
|
fail();
|
||||||
} catch (UnsupportedOperationException e) {
|
} catch (final UnsupportedOperationException e) {
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
mapCol.clear();
|
mapCol.clear();
|
||||||
fail();
|
fail();
|
||||||
} catch (UnsupportedOperationException e) {
|
} catch (final UnsupportedOperationException e) {
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
mapCol.clear();
|
mapCol.clear();
|
||||||
fail();
|
fail();
|
||||||
} catch (UnsupportedOperationException e) {
|
} catch (final UnsupportedOperationException e) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public void testUnmodifiableKeys() {
|
public void testUnmodifiableKeys() {
|
||||||
resetFull();
|
resetFull();
|
||||||
MultiSet<K> keys = getMap().keys();
|
final MultiSet<K> keys = getMap().keys();
|
||||||
try {
|
try {
|
||||||
keys.add((K) "four");
|
keys.add((K) "four");
|
||||||
fail();
|
fail();
|
||||||
} catch (UnsupportedOperationException e) {
|
} catch (final UnsupportedOperationException e) {
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
keys.remove("four");
|
keys.remove("four");
|
||||||
fail();
|
fail();
|
||||||
} catch (UnsupportedOperationException e) {
|
} catch (final UnsupportedOperationException e) {
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
keys.clear();
|
keys.clear();
|
||||||
fail();
|
fail();
|
||||||
} catch (UnsupportedOperationException e) {
|
} catch (final UnsupportedOperationException e) {
|
||||||
}
|
}
|
||||||
|
|
||||||
Iterator<K> it = keys.iterator();
|
final Iterator<K> it = keys.iterator();
|
||||||
try {
|
try {
|
||||||
it.remove();
|
it.remove();
|
||||||
fail();
|
fail();
|
||||||
} catch (UnsupportedOperationException e) {
|
} catch (final UnsupportedOperationException e) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -72,7 +72,7 @@ public abstract class AbstractQueueTest<E> extends AbstractCollectionTest<E> {
|
|||||||
public void verify() {
|
public void verify() {
|
||||||
super.verify();
|
super.verify();
|
||||||
final Iterator<E> iterator1 = getCollection().iterator();
|
final Iterator<E> iterator1 = getCollection().iterator();
|
||||||
for (E e : getConfirmed()) {
|
for (final E e : getConfirmed()) {
|
||||||
assertTrue(iterator1.hasNext());
|
assertTrue(iterator1.hasNext());
|
||||||
final Object o1 = iterator1.next();
|
final Object o1 = iterator1.next();
|
||||||
final Object o2 = e;
|
final Object o2 = e;
|
||||||
|
@ -48,7 +48,7 @@ public class CircularFifoQueueTest<E> extends AbstractQueueTest<E> {
|
|||||||
public void verify() {
|
public void verify() {
|
||||||
super.verify();
|
super.verify();
|
||||||
final Iterator<E> iterator1 = getCollection().iterator();
|
final Iterator<E> iterator1 = getCollection().iterator();
|
||||||
for (E e : getConfirmed()) {
|
for (final E e : getConfirmed()) {
|
||||||
assertTrue(iterator1.hasNext());
|
assertTrue(iterator1.hasNext());
|
||||||
final Object o1 = iterator1.next();
|
final Object o1 = iterator1.next();
|
||||||
final Object o2 = e;
|
final Object o2 = e;
|
||||||
|
@ -130,7 +130,7 @@ public class SequencesComparatorTest {
|
|||||||
final ExecutionVisitor<String> ev = new ExecutionVisitor<>();
|
final ExecutionVisitor<String> ev = new ExecutionVisitor<>();
|
||||||
|
|
||||||
for (int i = 0; i < shadokSentences.size(); ++i) {
|
for (int i = 0; i < shadokSentences.size(); ++i) {
|
||||||
for (List<String> shadokSentence : shadokSentences) {
|
for (final List<String> shadokSentence : shadokSentences) {
|
||||||
ev.setList(shadokSentences.get(i));
|
ev.setList(shadokSentences.get(i));
|
||||||
new SequencesComparator<>(shadokSentences.get(i),
|
new SequencesComparator<>(shadokSentences.get(i),
|
||||||
shadokSentence).getScript().visit(ev);
|
shadokSentence).getScript().visit(ev);
|
||||||
|
@ -62,7 +62,7 @@ public abstract class AbstractSetTest<E> extends AbstractCollectionTest<E> {
|
|||||||
assertEquals("Sets should have equal hashCodes",
|
assertEquals("Sets should have equal hashCodes",
|
||||||
getConfirmed().hashCode(), getCollection().hashCode());
|
getConfirmed().hashCode(), getCollection().hashCode());
|
||||||
final Collection<E> set = makeConfirmedCollection();
|
final Collection<E> set = makeConfirmedCollection();
|
||||||
for (E element : getCollection()) {
|
for (final E element : getCollection()) {
|
||||||
assertTrue("Set.iterator should only return unique elements", set.add(element));
|
assertTrue("Set.iterator should only return unique elements", set.add(element));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -331,7 +331,7 @@ public class PatriciaTrieTest<V> extends AbstractSortedMapTest<String, V> {
|
|||||||
|
|
||||||
public void testPrefixMapSizes() {
|
public void testPrefixMapSizes() {
|
||||||
// COLLECTIONS-525
|
// COLLECTIONS-525
|
||||||
PatriciaTrie<String> aTree = new PatriciaTrie<>();
|
final PatriciaTrie<String> aTree = new PatriciaTrie<>();
|
||||||
aTree.put("点评", "测试");
|
aTree.put("点评", "测试");
|
||||||
aTree.put("书评", "测试");
|
aTree.put("书评", "测试");
|
||||||
assertTrue(aTree.prefixMap("点").containsKey("点评"));
|
assertTrue(aTree.prefixMap("点").containsKey("点评"));
|
||||||
@ -370,7 +370,7 @@ public class PatriciaTrieTest<V> extends AbstractSortedMapTest<String, V> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void testPrefixMapClear() {
|
public void testPrefixMapClear() {
|
||||||
Trie<String, Integer> trie = new PatriciaTrie<>();
|
final Trie<String, Integer> trie = new PatriciaTrie<>();
|
||||||
trie.put("Anna", 1);
|
trie.put("Anna", 1);
|
||||||
trie.put("Anael", 2);
|
trie.put("Anael", 2);
|
||||||
trie.put("Analu", 3);
|
trie.put("Analu", 3);
|
||||||
@ -378,7 +378,7 @@ public class PatriciaTrieTest<V> extends AbstractSortedMapTest<String, V> {
|
|||||||
trie.put("Andrea", 5);
|
trie.put("Andrea", 5);
|
||||||
trie.put("Andres", 6);
|
trie.put("Andres", 6);
|
||||||
trie.put("Anatole", 7);
|
trie.put("Anatole", 7);
|
||||||
SortedMap<String, Integer> prefixMap = trie.prefixMap("And");
|
final SortedMap<String, Integer> prefixMap = trie.prefixMap("And");
|
||||||
assertEquals(new HashSet<>(Arrays.asList("Andrea", "Andreas", "Andres")), prefixMap.keySet());
|
assertEquals(new HashSet<>(Arrays.asList("Andrea", "Andreas", "Andres")), prefixMap.keySet());
|
||||||
assertEquals(Arrays.asList(5, 4, 6), new ArrayList<>(prefixMap.values()));
|
assertEquals(Arrays.asList(5, 4, 6), new ArrayList<>(prefixMap.values()));
|
||||||
|
|
||||||
@ -391,8 +391,8 @@ public class PatriciaTrieTest<V> extends AbstractSortedMapTest<String, V> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void testPrefixMapClearNothing() {
|
public void testPrefixMapClearNothing() {
|
||||||
Trie<String, Integer> trie = new PatriciaTrie<>();
|
final Trie<String, Integer> trie = new PatriciaTrie<>();
|
||||||
SortedMap<String, Integer> prefixMap = trie.prefixMap("And");
|
final SortedMap<String, Integer> prefixMap = trie.prefixMap("And");
|
||||||
assertEquals(new HashSet<String>(), prefixMap.keySet());
|
assertEquals(new HashSet<String>(), prefixMap.keySet());
|
||||||
assertEquals(new ArrayList<Integer>(0), new ArrayList<>(prefixMap.values()));
|
assertEquals(new ArrayList<Integer>(0), new ArrayList<>(prefixMap.values()));
|
||||||
|
|
||||||
@ -405,7 +405,7 @@ public class PatriciaTrieTest<V> extends AbstractSortedMapTest<String, V> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void testPrefixMapClearUsingRemove() {
|
public void testPrefixMapClearUsingRemove() {
|
||||||
Trie<String, Integer> trie = new PatriciaTrie<>();
|
final Trie<String, Integer> trie = new PatriciaTrie<>();
|
||||||
trie.put("Anna", 1);
|
trie.put("Anna", 1);
|
||||||
trie.put("Anael", 2);
|
trie.put("Anael", 2);
|
||||||
trie.put("Analu", 3);
|
trie.put("Analu", 3);
|
||||||
@ -413,11 +413,11 @@ public class PatriciaTrieTest<V> extends AbstractSortedMapTest<String, V> {
|
|||||||
trie.put("Andrea", 5);
|
trie.put("Andrea", 5);
|
||||||
trie.put("Andres", 6);
|
trie.put("Andres", 6);
|
||||||
trie.put("Anatole", 7);
|
trie.put("Anatole", 7);
|
||||||
SortedMap<String, Integer> prefixMap = trie.prefixMap("And");
|
final SortedMap<String, Integer> prefixMap = trie.prefixMap("And");
|
||||||
assertEquals(new HashSet<>(Arrays.asList("Andrea", "Andreas", "Andres")), prefixMap.keySet());
|
assertEquals(new HashSet<>(Arrays.asList("Andrea", "Andreas", "Andres")), prefixMap.keySet());
|
||||||
assertEquals(Arrays.asList(5, 4, 6), new ArrayList<>(prefixMap.values()));
|
assertEquals(Arrays.asList(5, 4, 6), new ArrayList<>(prefixMap.values()));
|
||||||
|
|
||||||
Set<String> keys = new HashSet<>(prefixMap.keySet());
|
final Set<String> keys = new HashSet<>(prefixMap.keySet());
|
||||||
for (final String key : keys) {
|
for (final String key : keys) {
|
||||||
prefixMap.remove(key);
|
prefixMap.remove(key);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user