From fcf4320023d468df672d9773c3a2755b7857b296 Mon Sep 17 00:00:00 2001 From: Sebastian Bazley Date: Mon, 29 Apr 2013 22:58:50 +0000 Subject: [PATCH] Make fields private (and final) if possible git-svn-id: https://svn.apache.org/repos/asf/commons/proper/collections/trunk@1477400 13f79535-47bb-0310-9956-ffa450edef68 --- .../commons/collections4/bag/SynchronizedBag.java | 2 +- .../collections4/bag/SynchronizedSortedBag.java | 2 +- .../commons/collections4/bidimap/DualTreeBidiMap.java | 4 ++-- .../commons/collections4/bidimap/TreeBidiMap.java | 8 ++++---- .../collections4/collection/CompositeCollection.java | 4 ++-- .../collection/SynchronizedCollection.java | 2 +- .../collection/UnmodifiableBoundedCollection.java | 2 +- .../collections4/comparators/ComparatorChain.java | 6 +++--- .../comparators/TransformingComparator.java | 4 ++-- .../iterators/AbstractListIteratorDecorator.java | 2 +- .../iterators/AbstractMapIteratorDecorator.java | 2 +- .../iterators/AbstractOrderedMapIteratorDecorator.java | 2 +- .../iterators/AbstractUntypedIteratorDecorator.java | 2 +- .../commons/collections4/iterators/IteratorChain.java | 10 +++++----- .../collections4/iterators/NodeListIterator.java | 2 +- .../iterators/ObjectArrayListIterator.java | 2 +- .../keyvalue/AbstractMapEntryDecorator.java | 2 +- .../commons/collections4/list/PredicatedList.java | 4 ++-- .../commons/collections4/list/TransformedList.java | 4 ++-- .../map/AbstractInputCheckedMapDecorator.java | 4 ++-- .../commons/collections4/map/UnmodifiableEntrySet.java | 2 +- .../commons/collections4/set/ListOrderedSet.java | 8 ++++---- 22 files changed, 40 insertions(+), 40 deletions(-) diff --git a/src/main/java/org/apache/commons/collections4/bag/SynchronizedBag.java b/src/main/java/org/apache/commons/collections4/bag/SynchronizedBag.java index eec71e1f0..26c6a2561 100644 --- a/src/main/java/org/apache/commons/collections4/bag/SynchronizedBag.java +++ b/src/main/java/org/apache/commons/collections4/bag/SynchronizedBag.java @@ -78,7 +78,7 @@ public class SynchronizedBag extends SynchronizedCollection implements Bag * @return the decorated bag */ protected Bag getBag() { - return (Bag) collection; + return (Bag) decorated(); } //----------------------------------------------------------------------- diff --git a/src/main/java/org/apache/commons/collections4/bag/SynchronizedSortedBag.java b/src/main/java/org/apache/commons/collections4/bag/SynchronizedSortedBag.java index ec98cd8cf..324272f25 100644 --- a/src/main/java/org/apache/commons/collections4/bag/SynchronizedSortedBag.java +++ b/src/main/java/org/apache/commons/collections4/bag/SynchronizedSortedBag.java @@ -78,7 +78,7 @@ public class SynchronizedSortedBag extends SynchronizedBag implements Sort * @return the decorated bag */ protected SortedBag getSortedBag() { - return (SortedBag) collection; + return (SortedBag) decorated(); } //----------------------------------------------------------------------- diff --git a/src/main/java/org/apache/commons/collections4/bidimap/DualTreeBidiMap.java b/src/main/java/org/apache/commons/collections4/bidimap/DualTreeBidiMap.java index b3c0edbed..45c78a40d 100644 --- a/src/main/java/org/apache/commons/collections4/bidimap/DualTreeBidiMap.java +++ b/src/main/java/org/apache/commons/collections4/bidimap/DualTreeBidiMap.java @@ -59,10 +59,10 @@ public class DualTreeBidiMap extends AbstractDualBidiMap private static final long serialVersionUID = 721969328361809L; /** The key comparator to use */ - protected final Comparator comparator; + private final Comparator comparator; /** The value comparator to use */ - protected final Comparator valueComparator; + private final Comparator valueComparator; /** * Creates an empty DualTreeBidiMap diff --git a/src/main/java/org/apache/commons/collections4/bidimap/TreeBidiMap.java b/src/main/java/org/apache/commons/collections4/bidimap/TreeBidiMap.java index 7ef4782bc..c7c1a04aa 100644 --- a/src/main/java/org/apache/commons/collections4/bidimap/TreeBidiMap.java +++ b/src/main/java/org/apache/commons/collections4/bidimap/TreeBidiMap.java @@ -1610,13 +1610,13 @@ public class TreeBidiMap, V extends Comparable> abstract class ViewIterator { /** Whether to return KEY or VALUE order. */ - protected final DataElement orderType; + private final DataElement orderType; /** The last node returned by the iterator. */ - protected Node lastReturnedNode; + Node lastReturnedNode; /** The next node to be returned by the iterator. */ - protected Node nextNode; + private Node nextNode; /** The previous node in the sequence returned by the iterator. */ - protected Node previousNode; + private Node previousNode; /** The modification count. */ private int expectedModifications; diff --git a/src/main/java/org/apache/commons/collections4/collection/CompositeCollection.java b/src/main/java/org/apache/commons/collections4/collection/CompositeCollection.java index 8230b7c05..2c338faac 100644 --- a/src/main/java/org/apache/commons/collections4/collection/CompositeCollection.java +++ b/src/main/java/org/apache/commons/collections4/collection/CompositeCollection.java @@ -45,10 +45,10 @@ public class CompositeCollection implements Collection, Serializable { private static final long serialVersionUID = 8417515734108306801L; /** CollectionMutator to handle changes to the collection */ - protected CollectionMutator mutator; + private CollectionMutator mutator; /** Collections in the composite */ - protected List> all = new ArrayList>(); + private final List> all = new ArrayList>(); /** * Create an empty CompositeCollection. diff --git a/src/main/java/org/apache/commons/collections4/collection/SynchronizedCollection.java b/src/main/java/org/apache/commons/collections4/collection/SynchronizedCollection.java index b696a6a0a..c619a5084 100644 --- a/src/main/java/org/apache/commons/collections4/collection/SynchronizedCollection.java +++ b/src/main/java/org/apache/commons/collections4/collection/SynchronizedCollection.java @@ -44,7 +44,7 @@ public class SynchronizedCollection implements Collection, Serializable { private static final long serialVersionUID = 2412805092710877986L; /** The collection to decorate */ - protected final Collection collection; + private final Collection collection; /** The object to lock on, needed for List/SortedSet views */ protected final Object lock; diff --git a/src/main/java/org/apache/commons/collections4/collection/UnmodifiableBoundedCollection.java b/src/main/java/org/apache/commons/collections4/collection/UnmodifiableBoundedCollection.java index e3b426c3d..11a716595 100644 --- a/src/main/java/org/apache/commons/collections4/collection/UnmodifiableBoundedCollection.java +++ b/src/main/java/org/apache/commons/collections4/collection/UnmodifiableBoundedCollection.java @@ -82,7 +82,7 @@ public final class UnmodifiableBoundedCollection extends AbstractCollectionDe if (coll instanceof AbstractCollectionDecorator) { coll = ((AbstractCollectionDecorator) coll).collection; } else if (coll instanceof SynchronizedCollection) { - coll = ((SynchronizedCollection) coll).collection; + coll = ((SynchronizedCollection) coll).decorated(); } } diff --git a/src/main/java/org/apache/commons/collections4/comparators/ComparatorChain.java b/src/main/java/org/apache/commons/collections4/comparators/ComparatorChain.java index 7920434c3..18d57b159 100644 --- a/src/main/java/org/apache/commons/collections4/comparators/ComparatorChain.java +++ b/src/main/java/org/apache/commons/collections4/comparators/ComparatorChain.java @@ -53,11 +53,11 @@ public class ComparatorChain implements Comparator, Serializable { private static final long serialVersionUID = -721644942746081630L; /** The list of comparators in the chain. */ - protected List> comparatorChain = null; + private final List> comparatorChain; /** Order - false (clear) = ascend; true (set) = descend. */ - protected BitSet orderingBits = null; + private BitSet orderingBits = null; /** Whether the chain has been "locked". */ - protected boolean isLocked = false; + private boolean isLocked = false; //----------------------------------------------------------------------- /** diff --git a/src/main/java/org/apache/commons/collections4/comparators/TransformingComparator.java b/src/main/java/org/apache/commons/collections4/comparators/TransformingComparator.java index 7a2f9b8b7..704961d96 100644 --- a/src/main/java/org/apache/commons/collections4/comparators/TransformingComparator.java +++ b/src/main/java/org/apache/commons/collections4/comparators/TransformingComparator.java @@ -41,9 +41,9 @@ public class TransformingComparator implements Comparator, Serializable private static final long serialVersionUID = 3456940356043606220L; /** The decorated comparator. */ - protected final Comparator decorated; + private final Comparator decorated; /** The transformer being used. */ - protected final Transformer transformer; + private final Transformer transformer; //----------------------------------------------------------------------- /** diff --git a/src/main/java/org/apache/commons/collections4/iterators/AbstractListIteratorDecorator.java b/src/main/java/org/apache/commons/collections4/iterators/AbstractListIteratorDecorator.java index bdb120e44..216492328 100644 --- a/src/main/java/org/apache/commons/collections4/iterators/AbstractListIteratorDecorator.java +++ b/src/main/java/org/apache/commons/collections4/iterators/AbstractListIteratorDecorator.java @@ -29,7 +29,7 @@ import java.util.ListIterator; public class AbstractListIteratorDecorator implements ListIterator { /** The iterator being decorated */ - protected final ListIterator iterator; + private final ListIterator iterator; //----------------------------------------------------------------------- /** diff --git a/src/main/java/org/apache/commons/collections4/iterators/AbstractMapIteratorDecorator.java b/src/main/java/org/apache/commons/collections4/iterators/AbstractMapIteratorDecorator.java index d65c7772f..ba83e4ec9 100644 --- a/src/main/java/org/apache/commons/collections4/iterators/AbstractMapIteratorDecorator.java +++ b/src/main/java/org/apache/commons/collections4/iterators/AbstractMapIteratorDecorator.java @@ -29,7 +29,7 @@ import org.apache.commons.collections4.MapIterator; public class AbstractMapIteratorDecorator implements MapIterator { /** The iterator being decorated */ - protected final MapIterator iterator; + private final MapIterator iterator; //----------------------------------------------------------------------- /** diff --git a/src/main/java/org/apache/commons/collections4/iterators/AbstractOrderedMapIteratorDecorator.java b/src/main/java/org/apache/commons/collections4/iterators/AbstractOrderedMapIteratorDecorator.java index f215036f6..681ecef88 100644 --- a/src/main/java/org/apache/commons/collections4/iterators/AbstractOrderedMapIteratorDecorator.java +++ b/src/main/java/org/apache/commons/collections4/iterators/AbstractOrderedMapIteratorDecorator.java @@ -29,7 +29,7 @@ import org.apache.commons.collections4.OrderedMapIterator; public class AbstractOrderedMapIteratorDecorator implements OrderedMapIterator { /** The iterator being decorated */ - protected final OrderedMapIterator iterator; + private final OrderedMapIterator iterator; //----------------------------------------------------------------------- /** diff --git a/src/main/java/org/apache/commons/collections4/iterators/AbstractUntypedIteratorDecorator.java b/src/main/java/org/apache/commons/collections4/iterators/AbstractUntypedIteratorDecorator.java index 29762e17b..017cd20e5 100644 --- a/src/main/java/org/apache/commons/collections4/iterators/AbstractUntypedIteratorDecorator.java +++ b/src/main/java/org/apache/commons/collections4/iterators/AbstractUntypedIteratorDecorator.java @@ -30,7 +30,7 @@ import java.util.Iterator; public abstract class AbstractUntypedIteratorDecorator implements Iterator { /** The iterator being decorated */ - protected final Iterator iterator; + private final Iterator iterator; /** * Create a new AbstractUntypedIteratorDecorator. diff --git a/src/main/java/org/apache/commons/collections4/iterators/IteratorChain.java b/src/main/java/org/apache/commons/collections4/iterators/IteratorChain.java index d65a79b65..e9976b056 100644 --- a/src/main/java/org/apache/commons/collections4/iterators/IteratorChain.java +++ b/src/main/java/org/apache/commons/collections4/iterators/IteratorChain.java @@ -48,25 +48,25 @@ import org.apache.commons.collections4.list.UnmodifiableList; public class IteratorChain implements Iterator { /** The chain of iterators */ - protected final List> iteratorChain = new ArrayList>(); + private final List> iteratorChain = new ArrayList>(); /** The index of the current iterator */ - protected int currentIteratorIndex = 0; + private int currentIteratorIndex = 0; /** The current iterator */ - protected Iterator currentIterator = null; + private Iterator currentIterator = null; /** * The "last used" Iterator is the Iterator upon which next() or hasNext() * was most recently called used for the remove() operation only */ - protected Iterator lastUsedIterator = null; + private Iterator lastUsedIterator = null; /** * ComparatorChain is "locked" after the first time compare(Object,Object) * is called */ - protected boolean isLocked = false; + private boolean isLocked = false; //----------------------------------------------------------------------- /** diff --git a/src/main/java/org/apache/commons/collections4/iterators/NodeListIterator.java b/src/main/java/org/apache/commons/collections4/iterators/NodeListIterator.java index b33377c7a..b90811b2f 100644 --- a/src/main/java/org/apache/commons/collections4/iterators/NodeListIterator.java +++ b/src/main/java/org/apache/commons/collections4/iterators/NodeListIterator.java @@ -35,7 +35,7 @@ public class NodeListIterator implements Iterator { /** the original NodeList instance */ private final NodeList nodeList; /** The current iterator index */ - protected int index = 0; + private int index = 0; /** * Convenience constructor, which creates a new NodeListIterator from diff --git a/src/main/java/org/apache/commons/collections4/iterators/ObjectArrayListIterator.java b/src/main/java/org/apache/commons/collections4/iterators/ObjectArrayListIterator.java index 873631712..41747e32e 100644 --- a/src/main/java/org/apache/commons/collections4/iterators/ObjectArrayListIterator.java +++ b/src/main/java/org/apache/commons/collections4/iterators/ObjectArrayListIterator.java @@ -46,7 +46,7 @@ public class ObjectArrayListIterator extends ObjectArrayIterator * has yet been invoked. lastItemIndex is used to to implement the * {@link #set} method. */ - protected int lastItemIndex = -1; + private int lastItemIndex = -1; /** * Constructor for use with setArray. diff --git a/src/main/java/org/apache/commons/collections4/keyvalue/AbstractMapEntryDecorator.java b/src/main/java/org/apache/commons/collections4/keyvalue/AbstractMapEntryDecorator.java index 57013e1bf..6e5fc5c3e 100644 --- a/src/main/java/org/apache/commons/collections4/keyvalue/AbstractMapEntryDecorator.java +++ b/src/main/java/org/apache/commons/collections4/keyvalue/AbstractMapEntryDecorator.java @@ -30,7 +30,7 @@ import org.apache.commons.collections4.KeyValue; public abstract class AbstractMapEntryDecorator implements Map.Entry, KeyValue { /** The Map.Entry to decorate */ - protected final Map.Entry entry; + private final Map.Entry entry; /** * Constructor that wraps (not copies). diff --git a/src/main/java/org/apache/commons/collections4/list/PredicatedList.java b/src/main/java/org/apache/commons/collections4/list/PredicatedList.java index 31062b040..e0222070e 100644 --- a/src/main/java/org/apache/commons/collections4/list/PredicatedList.java +++ b/src/main/java/org/apache/commons/collections4/list/PredicatedList.java @@ -155,13 +155,13 @@ public class PredicatedList extends PredicatedCollection implements List extends TransformedCollection implements List @Override public void add(E object) { object = transform(object); - iterator.add(object); + getListIterator().add(object); } @Override public void set(E object) { object = transform(object); - iterator.set(object); + getListIterator().set(object); } } diff --git a/src/main/java/org/apache/commons/collections4/map/AbstractInputCheckedMapDecorator.java b/src/main/java/org/apache/commons/collections4/map/AbstractInputCheckedMapDecorator.java index 8e7dbbf81..8886db016 100644 --- a/src/main/java/org/apache/commons/collections4/map/AbstractInputCheckedMapDecorator.java +++ b/src/main/java/org/apache/commons/collections4/map/AbstractInputCheckedMapDecorator.java @@ -178,7 +178,7 @@ abstract class AbstractInputCheckedMapDecorator @Override public Map.Entry next() { - final Map.Entry entry = iterator.next(); + final Map.Entry entry = getIterator().next(); return new MapEntry(entry, parent); } } @@ -199,7 +199,7 @@ abstract class AbstractInputCheckedMapDecorator @Override public V setValue(V value) { value = parent.checkSetValue(value); - return entry.setValue(value); + return getMapEntry().setValue(value); } } diff --git a/src/main/java/org/apache/commons/collections4/map/UnmodifiableEntrySet.java b/src/main/java/org/apache/commons/collections4/map/UnmodifiableEntrySet.java index 9355f4077..93d0f6672 100644 --- a/src/main/java/org/apache/commons/collections4/map/UnmodifiableEntrySet.java +++ b/src/main/java/org/apache/commons/collections4/map/UnmodifiableEntrySet.java @@ -154,7 +154,7 @@ public final class UnmodifiableEntrySet @Override public Map.Entry next() { - return new UnmodifiableEntry(iterator.next()); + return new UnmodifiableEntry(getIterator().next()); } @Override diff --git a/src/main/java/org/apache/commons/collections4/set/ListOrderedSet.java b/src/main/java/org/apache/commons/collections4/set/ListOrderedSet.java index 0d00c4fde..fdeb8b4d4 100644 --- a/src/main/java/org/apache/commons/collections4/set/ListOrderedSet.java +++ b/src/main/java/org/apache/commons/collections4/set/ListOrderedSet.java @@ -380,23 +380,23 @@ public class ListOrderedSet @Override public E next() { - last = iterator.next(); + last = getIterator().next(); return last; } @Override public void remove() { set.remove(last); - iterator.remove(); + getIterator().remove(); last = null; } public boolean hasPrevious() { - return ((ListIterator) iterator).hasPrevious(); + return ((ListIterator) getIterator()).hasPrevious(); } public E previous() { - last = ((ListIterator) iterator).previous(); + last = ((ListIterator) getIterator()).previous(); return last; } }