Make eclipse compiler happy.

git-svn-id: https://svn.apache.org/repos/asf/commons/proper/collections/trunk@1715973 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Thomas Neidhart 2015-11-23 21:42:01 +00:00
parent 64e8b87291
commit a0eff4bffd
3 changed files with 47 additions and 25 deletions

View File

@ -573,7 +573,8 @@ public class IteratorUtils {
final Iterator<? extends E> iterator1, final Iterator<? extends E> iterator1,
final Iterator<? extends E> iterator2) { final Iterator<? extends E> iterator2) {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
final Comparator<E> comp = comparator == null ? ComparatorUtils.NATURAL_COMPARATOR : comparator; final Comparator<E> comp =
comparator == null ? ComparatorUtils.NATURAL_COMPARATOR : (Comparator<E>) comparator;
return new CollatingIterator<E>(comp, iterator1, iterator2); return new CollatingIterator<E>(comp, iterator1, iterator2);
} }
@ -596,7 +597,8 @@ public class IteratorUtils {
public static <E> Iterator<E> collatedIterator(final Comparator<? super E> comparator, public static <E> Iterator<E> collatedIterator(final Comparator<? super E> comparator,
final Iterator<? extends E>... iterators) { final Iterator<? extends E>... iterators) {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
final Comparator<E> comp = comparator == null ? ComparatorUtils.NATURAL_COMPARATOR : comparator; final Comparator<E> comp =
comparator == null ? ComparatorUtils.NATURAL_COMPARATOR : (Comparator<E>) comparator;
return new CollatingIterator<E>(comp, iterators); return new CollatingIterator<E>(comp, iterators);
} }
@ -620,7 +622,8 @@ public class IteratorUtils {
public static <E> Iterator<E> collatedIterator(final Comparator<? super E> comparator, public static <E> Iterator<E> collatedIterator(final Comparator<? super E> comparator,
final Collection<Iterator<? extends E>> iterators) { final Collection<Iterator<? extends E>> iterators) {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
final Comparator<E> comp = comparator == null ? ComparatorUtils.NATURAL_COMPARATOR : comparator; final Comparator<E> comp =
comparator == null ? ComparatorUtils.NATURAL_COMPARATOR : (Comparator<E>) comparator;
return new CollatingIterator<E>(comp, iterators); return new CollatingIterator<E>(comp, iterators);
} }

View File

@ -16,8 +16,13 @@
*/ */
package org.apache.commons.collections4; package org.apache.commons.collections4;
import static org.apache.commons.collections4.functors.EqualPredicate.*; import static org.apache.commons.collections4.functors.EqualPredicate.equalPredicate;
import static org.junit.Assert.*; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
@ -109,7 +114,7 @@ public class CollectionUtilsTest extends MockTestCase {
private Iterable<Number> iterableB2 = null; private Iterable<Number> iterableB2 = null;
private Collection<Integer> emptyCollection = new ArrayList<Integer>(1); private final Collection<Integer> emptyCollection = new ArrayList<Integer>(1);
@Before @Before
public void setUp() { public void setUp() {
@ -439,6 +444,7 @@ public class CollectionUtilsTest extends MockTestCase {
public void testSubtractWithPredicate() { public void testSubtractWithPredicate() {
// greater than 3 // greater than 3
final Predicate<Number> predicate = new Predicate<Number>() { final Predicate<Number> predicate = new Predicate<Number>() {
@Override
public boolean evaluate(final Number n) { public boolean evaluate(final Number n) {
return n.longValue() > 3L; return n.longValue() > 3L;
} }
@ -559,6 +565,7 @@ public class CollectionUtilsTest extends MockTestCase {
// odd / even equator // odd / even equator
final Equator<Integer> e = new Equator<Integer>() { final Equator<Integer> e = new Equator<Integer>() {
@Override
public boolean equate(final Integer o1, final Integer o2) { public boolean equate(final Integer o1, final Integer o2) {
if (o1.intValue() % 2 == 0 ^ o2.intValue() % 2 == 0) { if (o1.intValue() % 2 == 0 ^ o2.intValue() % 2 == 0) {
return false; return false;
@ -567,6 +574,7 @@ public class CollectionUtilsTest extends MockTestCase {
} }
} }
@Override
public int hash(final Integer o) { public int hash(final Integer o) {
return o.intValue() % 2 == 0 ? Integer.valueOf(0).hashCode() : Integer.valueOf(1).hashCode(); return o.intValue() % 2 == 0 ? Integer.valueOf(0).hashCode() : Integer.valueOf(1).hashCode();
} }
@ -621,43 +629,41 @@ public class CollectionUtilsTest extends MockTestCase {
assertNull(CollectionUtils.find(collectionA, null)); assertNull(CollectionUtils.find(collectionA, null));
} }
@SuppressWarnings({ "unchecked", "rawtypes" })
@Test @Test
@Deprecated @Deprecated
public void forAllDoCollection() { public void forAllDoCollection() {
final Closure<List<? extends Number>> testClosure = ClosureUtils.invokerClosure("clear"); final Closure<Collection<Integer>> testClosure = ClosureUtils.invokerClosure("clear");
final Collection<List<? extends Number>> col = new ArrayList<List<? extends Number>>(); final Collection<Collection<Integer>> col = new ArrayList<Collection<Integer>>();
col.add(collectionA); col.add(collectionA);
col.add(collectionB); col.add(collectionC);
Closure<List<? extends Number>> resultClosure = CollectionUtils.forAllDo(col, testClosure); Closure<Collection<Integer>> resultClosure = CollectionUtils.forAllDo(col, testClosure);
assertSame(testClosure, resultClosure); assertSame(testClosure, resultClosure);
assertTrue(collectionA.isEmpty() && collectionB.isEmpty()); assertTrue(collectionA.isEmpty() && collectionC.isEmpty());
// fix for various java 1.6 versions: keep the cast // fix for various java 1.6 versions: keep the cast
resultClosure = CollectionUtils.forAllDo(col, (Closure<List<? extends Number>>) null); resultClosure = CollectionUtils.forAllDo(col, (Closure<Collection<Integer>>) null);
assertNull(resultClosure); assertNull(resultClosure);
assertTrue(collectionA.isEmpty() && collectionB.isEmpty()); assertTrue(collectionA.isEmpty() && collectionC.isEmpty());
resultClosure = CollectionUtils.forAllDo((Collection) null, testClosure); resultClosure = CollectionUtils.forAllDo((Collection<Collection<Integer>>) null, testClosure);
col.add(null); col.add(null);
// null should be OK // null should be OK
CollectionUtils.forAllDo(col, testClosure); CollectionUtils.forAllDo(col, testClosure);
} }
@SuppressWarnings({ "unchecked", "rawtypes" })
@Test @Test
@Deprecated @Deprecated
public void forAllDoIterator() { public void forAllDoIterator() {
final Closure<List<? extends Number>> testClosure = ClosureUtils.invokerClosure("clear"); final Closure<Collection<Integer>> testClosure = ClosureUtils.invokerClosure("clear");
final Collection<List<? extends Number>> col = new ArrayList<List<? extends Number>>(); final Collection<Collection<Integer>> col = new ArrayList<Collection<Integer>>();
col.add(collectionA); col.add(collectionA);
col.add(collectionB); col.add(collectionC);
Closure<List<? extends Number>> resultClosure = CollectionUtils.forAllDo(col.iterator(), testClosure); Closure<Collection<Integer>> resultClosure = CollectionUtils.forAllDo(col.iterator(), testClosure);
assertSame(testClosure, resultClosure); assertSame(testClosure, resultClosure);
assertTrue(collectionA.isEmpty() && collectionB.isEmpty()); assertTrue(collectionA.isEmpty() && collectionC.isEmpty());
// fix for various java 1.6 versions: keep the cast // fix for various java 1.6 versions: keep the cast
resultClosure = CollectionUtils.forAllDo(col.iterator(), (Closure<List<? extends Number>>) null); resultClosure = CollectionUtils.forAllDo(col.iterator(), (Closure<Collection<Integer>>) null);
assertNull(resultClosure); assertNull(resultClosure);
assertTrue(collectionA.isEmpty() && collectionB.isEmpty()); assertTrue(collectionA.isEmpty() && collectionC.isEmpty());
resultClosure = CollectionUtils.forAllDo((Iterator) null, testClosure); resultClosure = CollectionUtils.forAllDo((Iterator<Collection<Integer>>) null, testClosure);
col.add(null); col.add(null);
// null should be OK // null should be OK
CollectionUtils.forAllDo(col.iterator(), testClosure); CollectionUtils.forAllDo(col.iterator(), testClosure);
@ -696,6 +702,7 @@ public class CollectionUtilsTest extends MockTestCase {
Collection<String> strings = Arrays.asList("a", "b", "c"); 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
public void execute(String input) { public void execute(String input) {
result.append(input+";"); result.append(input+";");
} }
@ -705,6 +712,7 @@ public class CollectionUtilsTest extends MockTestCase {
Collection<String> oneString = Arrays.asList("a"); 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
public void execute(String input) { public void execute(String input) {
resultOne.append(input+";"); resultOne.append(input+";");
} }
@ -1069,6 +1077,7 @@ public class CollectionUtilsTest extends MockTestCase {
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
private static Predicate<Number> EQUALS_TWO = new Predicate<Number>() { private static Predicate<Number> EQUALS_TWO = new Predicate<Number>() {
@Override
public boolean evaluate(final Number input) { public boolean evaluate(final Number input) {
return input.intValue() == 2; return input.intValue() == 2;
} }
@ -1256,6 +1265,7 @@ public class CollectionUtilsTest extends MockTestCase {
} }
Transformer<Object, Integer> TRANSFORM_TO_INTEGER = new Transformer<Object, Integer>() { Transformer<Object, Integer> TRANSFORM_TO_INTEGER = new Transformer<Object, Integer>() {
@Override
public Integer transform(final Object input) { public Integer transform(final Object input) {
return Integer.valueOf(((Long)input).intValue()); return Integer.valueOf(((Long)input).intValue());
} }
@ -1292,6 +1302,7 @@ public class CollectionUtilsTest extends MockTestCase {
set.add(2L); set.add(2L);
set.add(3L); set.add(3L);
CollectionUtils.transform(set, new Transformer<Object, Integer>() { CollectionUtils.transform(set, new Transformer<Object, Integer>() {
@Override
public Integer transform(final Object input) { public Integer transform(final Object input) {
return 4; return 4;
} }
@ -1789,6 +1800,7 @@ public class CollectionUtilsTest extends MockTestCase {
assertFalse(CollectionUtils.matchesAll(collectionA, null)); assertFalse(CollectionUtils.matchesAll(collectionA, null));
Predicate<Integer> lessThanFive = new Predicate<Integer>() { Predicate<Integer> lessThanFive = new Predicate<Integer>() {
@Override
public boolean evaluate(Integer object) { public boolean evaluate(Integer object) {
return object < 5; return object < 5;
} }
@ -1796,6 +1808,7 @@ public class CollectionUtilsTest extends MockTestCase {
assertTrue(CollectionUtils.matchesAll(collectionA, lessThanFive)); assertTrue(CollectionUtils.matchesAll(collectionA, lessThanFive));
Predicate<Integer> lessThanFour = new Predicate<Integer>() { Predicate<Integer> lessThanFour = new Predicate<Integer>() {
@Override
public boolean evaluate(Integer object) { public boolean evaluate(Integer object) {
return object < 4; return object < 4;
} }
@ -1821,10 +1834,12 @@ public class CollectionUtilsTest extends MockTestCase {
// use an equator which compares the second letter only // use an equator which compares the second letter only
final Collection<String> result = CollectionUtils.removeAll(base, remove, new Equator<String>() { final Collection<String> result = CollectionUtils.removeAll(base, remove, new Equator<String>() {
@Override
public boolean equate(String o1, String o2) { public boolean equate(String o1, String o2) {
return o1.charAt(1) == o2.charAt(1); return o1.charAt(1) == o2.charAt(1);
} }
@Override
public int hash(String o) { public int hash(String o) {
return o.charAt(1); return o.charAt(1);
} }
@ -1871,10 +1886,12 @@ public class CollectionUtilsTest extends MockTestCase {
// use an equator which compares the second letter only // use an equator which compares the second letter only
final Collection<String> result = CollectionUtils.retainAll(base, retain, new Equator<String>() { final Collection<String> result = CollectionUtils.retainAll(base, retain, new Equator<String>() {
@Override
public boolean equate(String o1, String o2) { public boolean equate(String o1, String o2) {
return o1.charAt(1) == o2.charAt(1); return o1.charAt(1) == o2.charAt(1);
} }
@Override
public int hash(String o) { public int hash(String o) {
return o.charAt(1); return o.charAt(1);
} }

View File

@ -68,7 +68,9 @@ public class TransformedMapTest<K, V> extends AbstractIterableMapTest<K, V> {
assertEquals(null, map.remove(els[0])); assertEquals(null, map.remove(els[0]));
assertEquals(els[0], map.remove(Integer.valueOf((String) els[0]))); assertEquals(els[0], map.remove(Integer.valueOf((String) els[0])));
map = TransformedMap.transformingMap(new HashMap(), null, TransformedCollectionTest.STRING_TO_INTEGER_TRANSFORMER); map = TransformedMap.transformingMap(new HashMap(), null,
// cast needed for eclipse compiler
(Transformer) TransformedCollectionTest.STRING_TO_INTEGER_TRANSFORMER);
assertEquals(0, map.size()); assertEquals(0, map.size());
for (int i = 0; i < els.length; i++) { for (int i = 0; i < els.length; i++) {
map.put((K) els[i], (V) els[i]); map.put((K) els[i], (V) els[i]);