Minor Improvements: (#208)

* Add final
* Remove Redundant initializer
* fix javadoc
* Array initializer empty
This commit is contained in:
Arturo Bernal 2021-01-16 18:24:36 +01:00 committed by GitHub
parent 563d2fce7d
commit 27bd0dfd13
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
37 changed files with 84 additions and 84 deletions

View File

@ -98,7 +98,7 @@ public class ComparatorUtils {
@SuppressWarnings("unchecked")
public static <E> Comparator<E> chainedComparator(final Collection<Comparator<E>> comparators) {
return chainedComparator(
(Comparator<E>[]) comparators.toArray(new Comparator[comparators.size()])
(Comparator<E>[]) comparators.toArray(new Comparator[0])
);
}

View File

@ -59,22 +59,22 @@ public abstract class AbstractDualBidiMap<K, V> implements BidiMap<K, V> {
/**
* Inverse view of this map.
*/
transient BidiMap<V, K> inverseBidiMap = null;
transient BidiMap<V, K> inverseBidiMap;
/**
* View of the keys.
*/
transient Set<K> keySet = null;
transient Set<K> keySet;
/**
* View of the values.
*/
transient Set<V> values = null;
transient Set<V> values;
/**
* View of the entries.
*/
transient Set<Map.Entry<K, V>> entrySet = null;
transient Set<Map.Entry<K, V>> entrySet;
/**
* Creates an empty map, initialized by {@code createMap}.
@ -485,10 +485,10 @@ public abstract class AbstractDualBidiMap<K, V> implements BidiMap<K, V> {
protected final AbstractDualBidiMap<K, ?> parent;
/** The last returned key */
protected K lastKey = null;
protected K lastKey;
/** Whether remove is allowed at present */
protected boolean canRemove = false;
protected boolean canRemove;
/**
* Constructor.
@ -569,10 +569,10 @@ public abstract class AbstractDualBidiMap<K, V> implements BidiMap<K, V> {
protected final AbstractDualBidiMap<Object, V> parent;
/** The last returned value */
protected V lastValue = null;
protected V lastValue;
/** Whether remove is allowed at present */
protected boolean canRemove = false;
protected boolean canRemove;
/**
* Constructor.
@ -655,10 +655,10 @@ public abstract class AbstractDualBidiMap<K, V> implements BidiMap<K, V> {
protected final AbstractDualBidiMap<K, V> parent;
/** The last returned entry */
protected Map.Entry<K, V> last = null;
protected Map.Entry<K, V> last;
/** Whether remove is allowed at present */
protected boolean canRemove = false;
protected boolean canRemove;
/**
* Constructor.
@ -734,10 +734,10 @@ public abstract class AbstractDualBidiMap<K, V> implements BidiMap<K, V> {
protected Iterator<Map.Entry<K, V>> iterator;
/** The last returned entry */
protected Map.Entry<K, V> last = null;
protected Map.Entry<K, V> last;
/** Whether remove is allowed at present */
protected boolean canRemove = false;
protected boolean canRemove;
/**
* Constructor.

View File

@ -308,7 +308,7 @@ public class DualTreeBidiMap<K, V> extends AbstractDualBidiMap<K, V>
private ListIterator<Map.Entry<K, V>> iterator;
/** The last returned entry */
private Map.Entry<K, V> last = null;
private Map.Entry<K, V> last;
/**
* Constructor.

View File

@ -109,12 +109,12 @@ public class TreeBidiMap<K extends Comparable<K>, V extends Comparable<V>>
private static final long serialVersionUID = 721969328361807L;
private transient Node<K, V>[] rootNode;
private transient int nodeCount = 0;
private transient int modifications = 0;
private transient int nodeCount;
private transient int modifications;
private transient Set<K> keySet;
private transient Set<V> valuesSet;
private transient Set<Map.Entry<K, V>> entrySet;
private transient Inverse inverse = null;
private transient Inverse inverse;
//-----------------------------------------------------------------------
/**

View File

@ -41,7 +41,7 @@ public final class Murmur128x64Cyclic implements HashFunction {
/**
* The result of the hash 0 call.
*/
private long[] parts = null;
private long[] parts;
/**
* The signature for this hash function.

View File

@ -46,7 +46,7 @@ public final class ObjectsHashIterative implements HashFunction {
/**
* The value of the last hash.
*/
private long last = 0;
private long last;
/**
* Constructs a hash that uses the Objects.hash method to has values.

View File

@ -41,7 +41,7 @@ public final class BooleanComparator implements Comparator<Boolean>, Serializabl
private static final BooleanComparator FALSE_FIRST = new BooleanComparator(false);
/** {@code true} iff {@code true} values sort before {@code false} values. */
private boolean trueFirst = false;
private final boolean trueFirst;
//-----------------------------------------------------------------------
/**

View File

@ -30,10 +30,10 @@ import java.util.Comparator;
* <p>
* Note: In the 2.0 and 2.1 releases of Commons Collections, this class would
* throw a {@link ClassCastException} if either of the arguments to
* {@link #compare(Object, Object) compare} were {@code null}, not
* {@link #compare(Comparable, Comparable)} compare} were {@code null}, not
* {@link Comparable Comparable}, or for which
* {@link Comparable#compareTo(Object) compareTo} gave inconsistent results.
* This is no longer the case. See {@link #compare(Object, Object) compare} for
* This is no longer the case. See {@link #compare(Comparable, Comparable)} compare} for
* details.
* </p>
*

View File

@ -58,9 +58,9 @@ public class ComparatorChain<E> implements Comparator<E>, Serializable {
/** The list of comparators in the chain. */
private final List<Comparator<E>> comparatorChain;
/** Order - false (clear) = ascend; true (set) = descend. */
private BitSet orderingBits = null;
private final BitSet orderingBits;
/** Whether the chain has been "locked". */
private boolean isLocked = false;
private boolean isLocked;
//-----------------------------------------------------------------------
/**

View File

@ -67,10 +67,10 @@ public class FixedOrderComparator<T> implements Comparator<T>, Serializable {
private final Map<T, Integer> map = new HashMap<>();
/** Counter used in determining the position in the map */
private int counter = 0;
private int counter;
/** Is the comparator locked against further change */
private boolean isLocked = false;
private boolean isLocked;
/** The behavior in the case of an unknown object */
private UnknownObjectBehavior unknownObjectBehavior = UnknownObjectBehavior.EXCEPTION;

View File

@ -74,7 +74,7 @@ public class ChainedTransformer<T> implements Transformer<T, T>, Serializable {
return NOPTransformer.<T>nopTransformer();
}
// convert to array like this to guarantee iterator() ordering
final Transformer<T, T>[] cmds = transformers.toArray(new Transformer[transformers.size()]);
final Transformer<T, T>[] cmds = transformers.toArray(new Transformer[0]);
FunctorUtils.validate(cmds);
return new ChainedTransformer<>(false, cmds);
}

View File

@ -43,7 +43,7 @@ public class InstantiateFactory<T> implements Factory<T> {
/** The constructor arguments */
private final Object[] iArgs;
/** The constructor */
private transient Constructor<T> iConstructor = null;
private transient Constructor<T> iConstructor;
/**
* Factory method that performs validation.

View File

@ -44,7 +44,7 @@ public class ArrayIterator<E> implements ResettableIterator<E> {
/** The end index to loop to */
final int endIndex;
/** The current iterator index */
int index = 0;
int index;
// Constructors
// ----------------------------------------------------------------------

View File

@ -42,16 +42,16 @@ import org.apache.commons.collections4.list.UnmodifiableList;
public class CollatingIterator<E> implements Iterator<E> {
/** The {@link Comparator} used to evaluate order. */
private Comparator<? super E> comparator = null;
private Comparator<? super E> comparator;
/** The list of {@link Iterator}s to evaluate. */
private List<Iterator<? extends E>> iterators = null;
private final List<Iterator<? extends E>> iterators;
/** {@link Iterator#next Next} objects peeked from each iterator. */
private List<E> values = null;
private List<E> values;
/** Whether or not each {@link #values} element has been set. */
private BitSet valueSet = null;
private BitSet valueSet;
/**
* Index of the {@link #iterators iterator} from whom the last returned

View File

@ -43,7 +43,7 @@ public class EntrySetMapIterator<K, V> implements MapIterator<K, V>, ResettableI
private final Map<K, V> map;
private Iterator<Map.Entry<K, V>> iterator;
private Map.Entry<K, V> last;
private boolean canRemove = false;
private boolean canRemove;
/**
* Constructor.

View File

@ -39,7 +39,7 @@ public class FilterIterator<E> implements Iterator<E> {
/** The next object in the iteration */
private E nextObject;
/** Whether the next object has been calculated yet */
private boolean nextObjectSet = false;
private boolean nextObjectSet;
//-----------------------------------------------------------------------
/**

View File

@ -48,7 +48,7 @@ public class FilterListIterator<E> implements ListIterator<E> {
* Whether or not the {@link #nextObject} has been set
* (possibly to {@code null}).
*/
private boolean nextObjectSet = false;
private boolean nextObjectSet;
/**
* The value of the previous (matching) object, when
@ -60,12 +60,12 @@ public class FilterListIterator<E> implements ListIterator<E> {
* Whether or not the {@link #previousObject} has been set
* (possibly to {@code null}).
*/
private boolean previousObjectSet = false;
private boolean previousObjectSet;
/**
* The index of the element that would be returned by {@link #next}.
*/
private int nextIndex = 0;
private int nextIndex;
//-----------------------------------------------------------------------
/**

View File

@ -54,19 +54,19 @@ public class IteratorChain<E> implements Iterator<E> {
private final Queue<Iterator<? extends E>> iteratorChain = new LinkedList<>();
/** The current iterator */
private Iterator<? extends E> currentIterator = null;
private Iterator<? extends E> currentIterator;
/**
* The "last used" Iterator is the Iterator upon which next() or hasNext()
* was most recently called used for the remove() operation only
*/
private Iterator<? extends E> lastUsedIterator = null;
private Iterator<? extends E> lastUsedIterator;
/**
* ComparatorChain is "locked" after the first time compare(Object,Object)
* is called
*/
private boolean isLocked = false;
private boolean isLocked;
//-----------------------------------------------------------------------
/**

View File

@ -48,19 +48,19 @@ import java.util.Iterator;
public abstract class LazyIteratorChain<E> implements Iterator<E> {
/** The number of times {@link #next()} was already called. */
private int callCounter = 0;
private int callCounter;
/** Indicates that the Iterator chain has been exhausted. */
private boolean chainExhausted = false;
private boolean chainExhausted;
/** The current iterator. */
private Iterator<? extends E> currentIterator = null;
private Iterator<? extends E> currentIterator;
/**
* The "last used" Iterator is the Iterator upon which next() or hasNext()
* was most recently called used for the remove() operation only.
*/
private Iterator<? extends E> lastUsedIterator = null;
private Iterator<? extends E> lastUsedIterator;
//-----------------------------------------------------------------------

View File

@ -60,9 +60,9 @@ public class ListIteratorWrapper<E> implements ResettableListIterator<E> {
private final List<E> list = new ArrayList<>();
/** The current index of this iterator. */
private int currentIndex = 0;
private int currentIndex;
/** The current index of the wrapped iterator. */
private int wrappedIteratorIndex = 0;
private int wrappedIteratorIndex;
/** recall whether the wrapped iterator's "cursor" is in such a state as to allow remove() to be called */
private boolean removeState;

View File

@ -37,7 +37,7 @@ public class NodeListIterator implements Iterator<Node> {
/** the original NodeList instance */
private final NodeList nodeList;
/** The current iterator index */
private int index = 0;
private int index;
/**
* Convenience constructor, which creates a new NodeListIterator from

View File

@ -41,7 +41,7 @@ public class ObjectArrayIterator<E> implements ResettableIterator<E> {
/** The end index to loop to */
final int endIndex;
/** The current iterator index */
int index = 0;
int index;
//-------------------------------------------------------------------------
/**

View File

@ -84,7 +84,7 @@ public class ObjectGraphIterator<E> implements Iterator<E> {
private final Transformer<? super E, ? extends E> transformer;
/** Whether there is another element in the iteration */
private boolean hasNext = false;
private boolean hasNext;
/** The current iterator */
private Iterator<? extends E> currentIterator;
/** The current value */

View File

@ -36,10 +36,10 @@ public class PeekingIterator<E> implements Iterator<E> {
private final Iterator<? extends E> iterator;
/** Indicates that the decorated iterator is exhausted. */
private boolean exhausted = false;
private boolean exhausted;
/** Indicates if the lookahead slot is filled. */
private boolean slotFilled = false;
private boolean slotFilled;
/** The current slot for lookahead. */
private E slot;

View File

@ -35,7 +35,7 @@ public class SingletonIterator<E>
/** Is the cursor before the first element */
private boolean beforeFirst = true;
/** Has the element been removed */
private boolean removed = false;
private boolean removed;
/** The object */
private E object;

View File

@ -30,8 +30,8 @@ import org.apache.commons.collections4.ResettableListIterator;
public class SingletonListIterator<E> implements ResettableListIterator<E> {
private boolean beforeFirst = true;
private boolean nextCalled = false;
private boolean removed = false;
private boolean nextCalled;
private boolean removed;
private E object;
/**

View File

@ -42,10 +42,10 @@ public class ZippingIterator<E> implements Iterator<E> {
private final Iterator<Iterator<? extends E>> iterators;
/** The next iterator to use for next(). */
private Iterator<? extends E> nextIterator = null;
private Iterator<? extends E> nextIterator;
/** The last iterator which was used for next(). */
private Iterator<? extends E> lastReturned = null;
private Iterator<? extends E> lastReturned;
// Constructors
// ----------------------------------------------------------------------

View File

@ -407,7 +407,7 @@ public class CursorableLinkedList<E> extends AbstractLinkedList<E> implements Se
/** Is the next index valid */
boolean nextIndexValid = true;
/** Flag to indicate if the current element was removed by another object. */
boolean currentRemovedByAnother = false;
boolean currentRemovedByAnother;
/**
* Constructs a new cursor.

View File

@ -362,7 +362,7 @@ public class SetUniqueList<E> extends AbstractSerializableListDecorator<E> {
static class SetListIterator<E> extends AbstractIteratorDecorator<E> {
private final Set<E> set;
private E last = null;
private E last;
protected SetListIterator(final Iterator<E> it, final Set<E> set) {
super(it);
@ -390,7 +390,7 @@ public class SetUniqueList<E> extends AbstractSerializableListDecorator<E> {
AbstractListIteratorDecorator<E> {
private final Set<E> set;
private E last = null;
private E last;
protected SetListListIterator(final ListIterator<E> it, final Set<E> set) {
super(it);

View File

@ -34,7 +34,7 @@ import org.apache.commons.collections4.ResettableIterator;
public class EntrySetToMapIteratorAdapter<K, V> implements MapIterator<K, V>, ResettableIterator<K> {
/** The adapted Map entry Set. */
Set<Map.Entry<K, V>> entrySet;
final Set<Map.Entry<K, V>> entrySet;
/** The resettable iterator in use. */
transient Iterator<Map.Entry<K, V>> iterator;

View File

@ -637,8 +637,8 @@ public class Flat3Map<K, V> implements IterableMap<K, V>, Serializable, Cloneabl
*/
static class FlatMapIterator<K, V> implements MapIterator<K, V>, ResettableIterator<K> {
private final Flat3Map<K, V> parent;
private int nextIndex = 0;
private boolean canRemove = false;
private int nextIndex;
private boolean canRemove;
FlatMapIterator(final Flat3Map<K, V> parent) {
this.parent = parent;
@ -916,8 +916,8 @@ public class Flat3Map<K, V> implements IterableMap<K, V>, Serializable, Cloneabl
abstract static class EntryIterator<K, V> {
private final Flat3Map<K, V> parent;
private int nextIndex = 0;
private FlatMapEntry<K, V> currentEntry = null;
private int nextIndex;
private FlatMapEntry<K, V> currentEntry;
/**
* Create a new Flat3Map.EntryIterator.

View File

@ -675,7 +675,7 @@ public class ListOrderedMap<K, V>
//-----------------------------------------------------------------------
static class ListOrderedIterator<K, V> extends AbstractUntypedIteratorDecorator<K, Map.Entry<K, V>> {
private final ListOrderedMap<K, V> parent;
private K last = null;
private K last;
ListOrderedIterator(final ListOrderedMap<K, V> parent, final List<K> insertOrder) {
super(insertOrder.iterator());
@ -719,8 +719,8 @@ public class ListOrderedMap<K, V>
static class ListOrderedMapIterator<K, V> implements OrderedMapIterator<K, V>, ResettableIterator<K> {
private final ListOrderedMap<K, V> parent;
private ListIterator<K> iterator;
private K last = null;
private boolean readable = false;
private K last;
private boolean readable;
ListOrderedMapIterator(final ListOrderedMap<K, V> parent) {
this.parent = parent;

View File

@ -423,7 +423,7 @@ public class SingletonMap<K, V>
static class SingletonMapIterator<K, V> implements OrderedMapIterator<K, V>, ResettableIterator<K> {
private final SingletonMap<K, V> parent;
private boolean hasNext = true;
private boolean canGetSet = false;
private boolean canGetSet;
SingletonMapIterator(final SingletonMap<K, V> parent) {
this.parent = parent;

View File

@ -653,7 +653,7 @@ public abstract class AbstractMultiValuedMap<K, V> implements MultiValuedMap<K,
private final Iterator<Entry<K, V>> it;
private Entry<K, V> current = null;
private Entry<K, V> current;
MultiValuedMapIterator() {
this.it = AbstractMultiValuedMap.this.entries().iterator();

View File

@ -326,10 +326,10 @@ public abstract class AbstractMapMultiSet<E> extends AbstractMultiSet<E> {
protected final AbstractMapMultiSet<E> parent;
/** The last returned element */
protected E lastElement = null;
protected E lastElement;
/** Whether remove is allowed at present */
protected boolean canRemove = false;
protected boolean canRemove;
/**
* Constructor.
@ -372,10 +372,10 @@ public abstract class AbstractMapMultiSet<E> extends AbstractMultiSet<E> {
protected final Iterator<Map.Entry<E, MutableInteger>> decorated;
/** The last returned entry */
protected Entry<E> last = null;
protected Entry<E> last;
/** Whether remove is allowed at present */
protected boolean canRemove = false;
protected boolean canRemove;
/**
* Constructor.

View File

@ -60,7 +60,7 @@ public class CircularFifoQueue<E> extends AbstractCollection<E>
private transient E[] elements;
/** Array index of first (oldest) queue element. */
private transient int start = 0;
private transient int start;
/**
* Index mod maxElements of the array position following the last queue
@ -69,10 +69,10 @@ public class CircularFifoQueue<E> extends AbstractCollection<E>
* For example, elements = {c,a,b}, start=1, end=1 corresponds to
* the queue [a,b,c].
*/
private transient int end = 0;
private transient int end;
/** Flag to indicate if the queue is currently full. */
private transient boolean full = false;
private transient boolean full;
/** Capacity of the queue. */
private final int maxElements;

View File

@ -58,13 +58,13 @@ abstract class AbstractPatriciaTrie<K, V> extends AbstractBitwiseTrie<K, V> {
private transient volatile Set<Map.Entry<K, V>> entrySet;
/** The current size of the {@link org.apache.commons.collections4.Trie}. */
private transient int size = 0;
private transient int size;
/**
* The number of times this {@link org.apache.commons.collections4.Trie} has been modified.
* It's used to detect concurrent modifications and fail-fast the {@link Iterator}s.
*/
protected transient int modCount = 0;
protected transient int modCount;
protected AbstractPatriciaTrie(final KeyAnalyzer<? super K> keyAnalyzer) {
super(keyAnalyzer);
@ -2083,11 +2083,11 @@ abstract class AbstractPatriciaTrie<K, V> extends AbstractBitwiseTrie<K, V> {
private final int lengthInBits;
private K fromKey = null;
private K fromKey;
private K toKey = null;
private K toKey;
private transient int expectedModCount = 0;
private transient int expectedModCount;
private int size = -1;
@ -2266,7 +2266,7 @@ abstract class AbstractPatriciaTrie<K, V> extends AbstractBitwiseTrie<K, V> {
private TrieEntry<K, V> prefixStart;
private int expectedModCount = 0;
private int expectedModCount;
/**
* Creates a {@link PrefixRangeEntrySet}.
@ -2305,7 +2305,7 @@ abstract class AbstractPatriciaTrie<K, V> extends AbstractBitwiseTrie<K, V> {
private final TrieEntry<K, V> entry;
private int hit = 0;
private int hit;
SingletonIterator(final TrieEntry<K, V> entry) {
this.entry = entry;