Use final for read-only local variables.

git-svn-id: https://svn.apache.org/repos/asf/commons/proper/collections/trunk@1457876 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Gary D. Gregory 2013-03-18 17:16:42 +00:00
parent 5dd750e745
commit cce4634e79
9 changed files with 33 additions and 29 deletions

View File

@ -584,6 +584,7 @@ public class CollectionUtils {
return false;
}
@SuppressWarnings("unchecked")
final
EquatorWrapper<O> otherObj = (EquatorWrapper<O>) obj;
return equator.equate(object, otherObj.getObject());
}

View File

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

View File

@ -176,6 +176,7 @@ public class IndexedCollection<K, C> extends AbstractCollectionDecorator<C> {
*/
public C get(final K key) {
@SuppressWarnings("unchecked") // index is a MultiMap which returns a Collection
final
Collection<C> coll = (Collection<C>) index.get(key);
return coll == null ? null : coll.iterator().next();
}

View File

@ -429,7 +429,7 @@ public class TreeList<E> extends AbstractList<E> {
if (relativePosition >= 0) {
relativePosition++;
}
AVLNode<E> ret = balance();
final AVLNode<E> ret = balance();
recalcHeight();
return ret;
}
@ -443,7 +443,7 @@ public class TreeList<E> extends AbstractList<E> {
if (relativePosition < 0) {
relativePosition--;
}
AVLNode<E> ret = balance();
final AVLNode<E> ret = balance();
recalcHeight();
return ret;
}

View File

@ -823,7 +823,7 @@ public class MultiKeyMap<K, V> extends AbstractMapDecorator<MultiKey<? extends K
public MultiKeyMap<K, V> clone() {
try {
return (MultiKeyMap<K, V>) super.clone();
} catch (CloneNotSupportedException e) {
} catch (final CloneNotSupportedException e) {
throw new InternalError();
}
}

View File

@ -510,7 +510,7 @@ public class CollectionUtilsTest extends MockTestCase {
@Test
public void testIsEqualCollectionEquator() {
Collection<Integer> collB = CollectionUtils.collect(collectionB, TRANSFORM_TO_INTEGER);
final Collection<Integer> collB = CollectionUtils.collect(collectionB, TRANSFORM_TO_INTEGER);
// odd / even equator
final Equator<Integer> e = new Equator<Integer>() {
@ -993,12 +993,12 @@ public class CollectionUtilsTest extends MockTestCase {
@Test
public void filterInverse() {
List<Integer> ints = new ArrayList<Integer>();
final List<Integer> ints = new ArrayList<Integer>();
ints.add(1);
ints.add(2);
ints.add(3);
ints.add(3);
Iterable<Integer> iterable = ints;
final Iterable<Integer> iterable = ints;
assertTrue(CollectionUtils.filterInverse(iterable, EQUALS_TWO));
assertEquals(3, ints.size());
assertEquals(1, (int) ints.get(0));
@ -1008,7 +1008,7 @@ public class CollectionUtilsTest extends MockTestCase {
@Test
public void filterInverseNullParameters() throws Exception {
List<Long> longs = Collections.nCopies(4, 10L);
final List<Long> longs = Collections.nCopies(4, 10L);
assertFalse(CollectionUtils.filterInverse(longs, null));
assertEquals(4, longs.size());
assertFalse(CollectionUtils.filterInverse(null, EQUALS_TWO));

View File

@ -795,8 +795,8 @@ public class IteratorUtilsTest extends BulkTest {
* Tests method nodeListIterator(NodeList)
*/
public void testNodeListIterator() {
Node[] nodes = createNodes();
NodeList nodeList = createNodeList(nodes);
final Node[] nodes = createNodes();
final NodeList nodeList = createNodeList(nodes);
final Iterator<Node> iterator = IteratorUtils.nodeListIterator(nodeList);
int expectedNodeIndex = 0;
@ -817,9 +817,9 @@ public class IteratorUtilsTest extends BulkTest {
* Tests method nodeListIterator(Node)
*/
public void testNodeIterator() {
Node[] nodes = createNodes();
NodeList nodeList = createNodeList(nodes);
Node parentNode = createMock(Node.class);
final Node[] nodes = createNodes();
final NodeList nodeList = createNodeList(nodes);
final Node parentNode = createMock(Node.class);
expect(parentNode.getChildNodes()).andStubReturn(nodeList);
replay(parentNode);
@ -844,10 +844,10 @@ public class IteratorUtilsTest extends BulkTest {
* @return
*/
private Node[] createNodes() {
Node node1 = createMock(Node.class);
Node node2 = createMock(Node.class);
Node node3 = createMock(Node.class);
Node node4 = createMock(Node.class);
final Node node1 = createMock(Node.class);
final Node node2 = createMock(Node.class);
final Node node3 = createMock(Node.class);
final Node node4 = createMock(Node.class);
replay(node1);
replay(node2);
replay(node3);

View File

@ -133,14 +133,14 @@ public class IndexedCollectionTest extends AbstractCollectionTest<String> {
try {
coll.add("1");
fail();
} catch (IllegalArgumentException e) {
} catch (final IllegalArgumentException e) {
// expected
}
}
public void testDecoratedCollectionIsIndexedOnCreation() throws Exception {
Collection<String> original = makeFullCollection();
IndexedCollection<Integer, String> indexed = decorateUniqueCollection(original);
final Collection<String> original = makeFullCollection();
final IndexedCollection<Integer, String> indexed = decorateUniqueCollection(original);
assertEquals("1", indexed.get(1));
assertEquals("2", indexed.get(2));
@ -148,8 +148,8 @@ public class IndexedCollectionTest extends AbstractCollectionTest<String> {
}
public void testReindexUpdatesIndexWhenDecoratedCollectionIsModifiedSeparately() throws Exception {
Collection<String> original = new ArrayList<String>();
IndexedCollection<Integer, String> indexed = decorateUniqueCollection(original);
final Collection<String> original = new ArrayList<String>();
final IndexedCollection<Integer, String> indexed = decorateUniqueCollection(original);
original.add("1");
original.add("2");

View File

@ -54,10 +54,10 @@ public class NodeListIteratorTest extends AbstractIteratorTest<Node> {
// create mocked Node Instances and fill Node[] to be used by test cases
Node node1 = createMock(Element.class);
Node node2 = createMock(Element.class);
Node node3 = createMock(Text.class);
Node node4 = createMock(Element.class);
final Node node1 = createMock(Element.class);
final Node node2 = createMock(Element.class);
final Node node3 = createMock(Text.class);
final Node node4 = createMock(Element.class);
nodes = new Node[] {node1, node2, node3, node4};
replay(node1);
@ -68,7 +68,7 @@ public class NodeListIteratorTest extends AbstractIteratorTest<Node> {
@Override
public Iterator<Node> makeEmptyIterator() {
NodeList emptyNodeList = new NodeList() {
final NodeList emptyNodeList = new NodeList() {
public Node item(final int index) {
throw new IndexOutOfBoundsException();
}
@ -80,7 +80,7 @@ public class NodeListIteratorTest extends AbstractIteratorTest<Node> {
if (createIteratorWithStandardConstr) {
return new NodeListIterator(emptyNodeList);
} else {
Node parentNode = createMock(Node.class);
final Node parentNode = createMock(Node.class);
expect(parentNode.getChildNodes()).andStubReturn(emptyNodeList);
replay(parentNode);
@ -90,7 +90,7 @@ public class NodeListIteratorTest extends AbstractIteratorTest<Node> {
@Override
public Iterator<Node> makeObject() {
NodeList nodeList = new NodeList() {
final NodeList nodeList = new NodeList() {
public Node item(final int index) {
return nodes[index];
}
@ -111,9 +111,10 @@ public class NodeListIteratorTest extends AbstractIteratorTest<Node> {
public void testNullConstructor(){
try{
@SuppressWarnings("unused")
final
NodeListIterator iter = new NodeListIterator((Node) null);
fail("IllegalArgumentException expected!");
}catch(IllegalArgumentException e){
}catch(final IllegalArgumentException e){
// expected.
}
}