This commit is contained in:
Gary Gregory 2024-08-25 17:54:17 -04:00
parent a06dee1b39
commit 2ae865abc2
10 changed files with 173 additions and 23 deletions

View File

@ -322,10 +322,20 @@ public class DualTreeBidiMap<K, V> extends AbstractDualBidiMap<K, V>
return (SortedBidiMap<V, K>) super.inverseBidiMap(); return (SortedBidiMap<V, K>) super.inverseBidiMap();
} }
/**
* Defaults to {@link #inverseBidiMap()}.
*
* @return Defaults to {@link #inverseBidiMap()}.
*/
public OrderedBidiMap<V, K> inverseOrderedBidiMap() { public OrderedBidiMap<V, K> inverseOrderedBidiMap() {
return inverseBidiMap(); return inverseBidiMap();
} }
/**
* Defaults to {@link #inverseBidiMap()}.
*
* @return Defaults to {@link #inverseBidiMap()}.
*/
public SortedBidiMap<V, K> inverseSortedBidiMap() { public SortedBidiMap<V, K> inverseSortedBidiMap() {
return inverseBidiMap(); return inverseBidiMap();
} }
@ -340,6 +350,7 @@ public class DualTreeBidiMap<K, V> extends AbstractDualBidiMap<K, V>
* <p> * <p>
* This implementation copies the elements to an ArrayList in order to * This implementation copies the elements to an ArrayList in order to
* provide the forward/backward behavior. * provide the forward/backward behavior.
* </p>
* *
* @return a new ordered map iterator * @return a new ordered map iterator
*/ */

View File

@ -53,11 +53,26 @@ import java.util.Objects;
public class FixedOrderComparator<T> implements Comparator<T>, Serializable { public class FixedOrderComparator<T> implements Comparator<T>, Serializable {
/** /**
* Unknown object behavior enum. * Enumerates the unknown object behaviors.
*
* @since 4.0 * @since 4.0
*/ */
public enum UnknownObjectBehavior { public enum UnknownObjectBehavior {
BEFORE, AFTER, EXCEPTION
/**
* Before unknown object behaviors.
*/
BEFORE,
/**
* After unknown object behaviors.
*/
AFTER,
/**
* Exception unknown object behaviors.
*/
EXCEPTION
} }
/** Serialization version from Collections 4.0. */ /** Serialization version from Collections 4.0. */

View File

@ -79,14 +79,39 @@ import org.apache.commons.collections4.Predicate;
*/ */
public class ComparatorPredicate<T> extends AbstractPredicate<T> implements Serializable { public class ComparatorPredicate<T> extends AbstractPredicate<T> implements Serializable {
/**
* Enumerates the comparator criteria.
*/
public enum Criterion { public enum Criterion {
EQUAL, GREATER, LESS, GREATER_OR_EQUAL, LESS_OR_EQUAL,
/**
* Equal criterion.
*/
EQUAL,
/**
* Greater criterion.
*/
GREATER,
/**
* Less criterion.
*/
LESS,
/**
* Greater or equal criterion.
*/
GREATER_OR_EQUAL,
/**
* Less or equal Criterion.
*/
LESS_OR_EQUAL,
} }
private static final long serialVersionUID = -1863209236504077399L; private static final long serialVersionUID = -1863209236504077399L;
// Instance variables:
/** /**
* Factory to create the comparator predicate * Factory to create the comparator predicate
* *

View File

@ -101,9 +101,9 @@ public abstract class AbstractLinkedList<E> implements List<E> {
/** /**
* Create a ListIterator for a list. * Create a ListIterator for a list.
* *
* @param parent the parent list * @param parent the parent list.
* @param fromIndex the index to start at * @param fromIndex The starting index.
* @throws IndexOutOfBoundsException if fromIndex is less than 0 or greater than the size of the list * @throws IndexOutOfBoundsException if fromIndex is less than 0 or greater than the size of the list.
*/ */
protected LinkedListIterator(final AbstractLinkedList<E> parent, final int fromIndex) protected LinkedListIterator(final AbstractLinkedList<E> parent, final int fromIndex)
throws IndexOutOfBoundsException { throws IndexOutOfBoundsException {
@ -226,15 +226,26 @@ public abstract class AbstractLinkedList<E> implements List<E> {
* @param <E> the type of elements in this list. * @param <E> the type of elements in this list.
*/ */
protected static class LinkedSubList<E> extends AbstractList<E> { protected static class LinkedSubList<E> extends AbstractList<E> {
/** The main list */ /** The main list */
AbstractLinkedList<E> parent; AbstractLinkedList<E> parent;
/** Offset from the main list */ /** Offset from the main list */
int offset; int offset;
/** Sublist size */ /** Sublist size */
int size; int size;
/** Sublist modCount */ /** Sublist modCount */
int expectedModCount; int expectedModCount;
/**
* Constructs a new instance.
*
* @param parent The parent AbstractLinkedList.
* @param fromIndex An index greater or equal to 0 and less than {@code toIndex}.
* @param toIndex An index greater than {@code fromIndex}.
*/
protected LinkedSubList(final AbstractLinkedList<E> parent, final int fromIndex, final int toIndex) { protected LinkedSubList(final AbstractLinkedList<E> parent, final int fromIndex, final int toIndex) {
if (fromIndex < 0) { if (fromIndex < 0) {
throw new IndexOutOfBoundsException("fromIndex = " + fromIndex); throw new IndexOutOfBoundsException("fromIndex = " + fromIndex);
@ -361,9 +372,15 @@ public abstract class AbstractLinkedList<E> implements List<E> {
*/ */
protected static class LinkedSubListIterator<E> extends LinkedListIterator<E> { protected static class LinkedSubListIterator<E> extends LinkedListIterator<E> {
/** The sub list */ /** The sub list. */
protected final LinkedSubList<E> sub; protected final LinkedSubList<E> sub;
/**
* Constructs a new instance.
*
* @param sub The sub-list.
* @param startIndex The starting index.
*/
protected LinkedSubListIterator(final LinkedSubList<E> sub, final int startIndex) { protected LinkedSubListIterator(final LinkedSubList<E> sub, final int startIndex) {
super(sub.parent, startIndex + sub.offset); super(sub.parent, startIndex + sub.offset);
this.sub = sub; this.sub = sub;

View File

@ -168,6 +168,14 @@ public class AbstractHashedMap<K, V> extends AbstractMap<K, V> implements Iterab
/** The value */ /** The value */
protected Object value; protected Object value;
/**
* Constructs a new instance.
*
* @param next next.
* @param hashCode hash code.
* @param key key.
* @param value value.
*/
protected HashEntry(final HashEntry<K, V> next, final int hashCode, final Object key, final V value) { protected HashEntry(final HashEntry<K, V> next, final int hashCode, final Object key, final V value) {
this.next = next; this.next = next;
this.hashCode = hashCode; this.hashCode = hashCode;
@ -246,6 +254,11 @@ public class AbstractHashedMap<K, V> extends AbstractMap<K, V> implements Iterab
/** The modification count expected */ /** The modification count expected */
private int expectedModCount; private int expectedModCount;
/**
* Constructs a new instance.
*
* @param parent The parent AbstractHashedMap.
*/
protected HashIterator(final AbstractHashedMap<K, V> parent) { protected HashIterator(final AbstractHashedMap<K, V> parent) {
this.parent = parent; this.parent = parent;
final HashEntry<K, V>[] data = parent.data; final HashEntry<K, V>[] data = parent.data;
@ -316,6 +329,11 @@ public class AbstractHashedMap<K, V> extends AbstractMap<K, V> implements Iterab
*/ */
protected static class HashMapIterator<K, V> extends HashIterator<K, V> implements MapIterator<K, V> { protected static class HashMapIterator<K, V> extends HashIterator<K, V> implements MapIterator<K, V> {
/**
* Constructs a new instance.
*
* @param parent The parent AbstractHashedMap.
*/
protected HashMapIterator(final AbstractHashedMap<K, V> parent) { protected HashMapIterator(final AbstractHashedMap<K, V> parent) {
super(parent); super(parent);
} }
@ -359,9 +377,15 @@ public class AbstractHashedMap<K, V> extends AbstractMap<K, V> implements Iterab
* @param <K> the type of elements maintained by this set * @param <K> the type of elements maintained by this set
*/ */
protected static class KeySet<K> extends AbstractSet<K> { protected static class KeySet<K> extends AbstractSet<K> {
/** The parent map */ /** The parent map */
private final AbstractHashedMap<K, ?> parent; private final AbstractHashedMap<K, ?> parent;
/**
* Constructs a new instance.
*
* @param parent The parent AbstractHashedMap.
*/
protected KeySet(final AbstractHashedMap<K, ?> parent) { protected KeySet(final AbstractHashedMap<K, ?> parent) {
this.parent = parent; this.parent = parent;
} }
@ -401,6 +425,11 @@ public class AbstractHashedMap<K, V> extends AbstractMap<K, V> implements Iterab
*/ */
protected static class KeySetIterator<K> extends HashIterator<K, Object> implements Iterator<K> { protected static class KeySetIterator<K> extends HashIterator<K, Object> implements Iterator<K> {
/**
* Constructs a new instance.
*
* @param parent The parent AbstractHashedMap.
*/
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
protected KeySetIterator(final AbstractHashedMap<K, ?> parent) { protected KeySetIterator(final AbstractHashedMap<K, ?> parent) {
super((AbstractHashedMap<K, Object>) parent); super((AbstractHashedMap<K, Object>) parent);
@ -418,9 +447,15 @@ public class AbstractHashedMap<K, V> extends AbstractMap<K, V> implements Iterab
* @param <V> the type of elements maintained by this collection * @param <V> the type of elements maintained by this collection
*/ */
protected static class Values<V> extends AbstractCollection<V> { protected static class Values<V> extends AbstractCollection<V> {
/** The parent map */ /** The parent map */
private final AbstractHashedMap<?, V> parent; private final AbstractHashedMap<?, V> parent;
/**
* Constructs a new instance.
*
* @param parent The parent AbstractHashedMap.
*/
protected Values(final AbstractHashedMap<?, V> parent) { protected Values(final AbstractHashedMap<?, V> parent) {
this.parent = parent; this.parent = parent;
} }
@ -453,6 +488,11 @@ public class AbstractHashedMap<K, V> extends AbstractMap<K, V> implements Iterab
*/ */
protected static class ValuesIterator<V> extends HashIterator<Object, V> implements Iterator<V> { protected static class ValuesIterator<V> extends HashIterator<Object, V> implements Iterator<V> {
/**
* Constructs a new instance.
*
* @param parent The parent AbstractHashedMap.
*/
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
protected ValuesIterator(final AbstractHashedMap<?, V> parent) { protected ValuesIterator(final AbstractHashedMap<?, V> parent) {
super((AbstractHashedMap<Object, V>) parent); super((AbstractHashedMap<Object, V>) parent);

View File

@ -495,10 +495,24 @@ public abstract class AbstractReferenceMap<K, V> extends AbstractHashedMap<K, V>
} }
/** /**
* Reference type enum. * Enumerates reference types.
*/ */
public enum ReferenceStrength { public enum ReferenceStrength {
HARD(0), SOFT(1), WEAK(2);
/**
* Hard reference type.
*/
HARD(0),
/**
* Soft reference type.
*/
SOFT(1),
/**
* Weak reference type.
*/
WEAK(2);
/** /**
* Resolve enum from int. * Resolve enum from int.

View File

@ -41,8 +41,14 @@ public abstract class AbstractBitwiseTrie<K, V> extends AbstractMap<K, V>
private static final long serialVersionUID = -944364551314110330L; private static final long serialVersionUID = -944364551314110330L;
/**
* The entry's key.
*/
protected K key; protected K key;
/**
* The entry's value.
*/
protected V value; protected V value;
BasicEntry(final K key) { BasicEntry(final K key) {
@ -89,6 +95,10 @@ public abstract class AbstractBitwiseTrie<K, V> extends AbstractMap<K, V>
/** /**
* Replaces the current key and value with the provided key &amp; value. * Replaces the current key and value with the provided key &amp; value.
*
* @param key The new key.
* @param value The new value.
* @return The previous value.
*/ */
public V setKeyValue(final K key, final V value) { public V setKeyValue(final K key, final V value) {
this.key = key; this.key = key;

View File

@ -996,11 +996,16 @@ public abstract class AbstractPatriciaTrie<K, V> extends AbstractBitwiseTrie<K,
/** The entry who uplinks to this entry. */ /** The entry who uplinks to this entry. */
protected TrieEntry<K, V> predecessor; protected TrieEntry<K, V> predecessor;
/**
* Constructs a new instance.
*
* @param key The entry's key.
* @param value The entry's value.
* @param bitIndex The entry's bitIndex.
*/
public TrieEntry(final K key, final V value, final int bitIndex) { public TrieEntry(final K key, final V value, final int bitIndex) {
super(key, value); super(key, value);
this.bitIndex = bitIndex; this.bitIndex = bitIndex;
this.parent = null; this.parent = null;
this.left = this; this.left = this;
this.right = null; this.right = null;
@ -1008,23 +1013,29 @@ public abstract class AbstractPatriciaTrie<K, V> extends AbstractBitwiseTrie<K,
} }
/** /**
* Whether or not the entry is storing a key. * Whether the entry is storing a key.
* Only the root can potentially be empty, all other * Only the root can potentially be empty, all other
* nodes must have a key. * nodes must have a key.
*
* @return Whether the entry is storing a key
*/ */
public boolean isEmpty() { public boolean isEmpty() {
return key == null; return key == null;
} }
/** /**
* Either the left or right child is a loopback. * Whether the left or right child is a loopback.
*
* @return Whether the left or right child is a loopback.
*/ */
public boolean isExternalNode() { public boolean isExternalNode() {
return !isInternalNode(); return !isInternalNode();
} }
/** /**
* Neither the left nor right child is a loopback. * Tests that neither the left nor right child is a loopback.
*
* @return That neither the left nor right child is a loopback.
*/ */
public boolean isInternalNode() { public boolean isInternalNode() {
return left != this && right != this; return left != this && right != this;
@ -1245,19 +1256,20 @@ public abstract class AbstractPatriciaTrie<K, V> extends AbstractBitwiseTrie<K,
/** /**
* Constructs a new {@link Trie} using the given {@link KeyAnalyzer}. * Constructs a new {@link Trie} using the given {@link KeyAnalyzer}.
* *
* @param keyAnalyzer the {@link KeyAnalyzer} to use * @param keyAnalyzer the {@link KeyAnalyzer}.
*/ */
protected AbstractPatriciaTrie(final KeyAnalyzer<? super K> keyAnalyzer) { protected AbstractPatriciaTrie(final KeyAnalyzer<? super K> keyAnalyzer) {
super(keyAnalyzer); super(keyAnalyzer);
} }
/** /**
* Constructs a new {@link org.apache.commons.collections4.Trie} * Constructs a new {@link org.apache.commons.collections4.Trie} using the given {@link KeyAnalyzer} and initializes the
* using the given {@link KeyAnalyzer} and initializes the {@link org.apache.commons.collections4.Trie} * {@link org.apache.commons.collections4.Trie} with the values from the provided {@link Map}.
* with the values from the provided {@link Map}. *
* @param keyAnalyzer the {@link KeyAnalyzer}.
* @param map The source map.
*/ */
protected AbstractPatriciaTrie(final KeyAnalyzer<? super K> keyAnalyzer, protected AbstractPatriciaTrie(final KeyAnalyzer<? super K> keyAnalyzer, final Map<? extends K, ? extends V> map) {
final Map<? extends K, ? extends V> map) {
super(keyAnalyzer); super(keyAnalyzer);
putAll(map); putAll(map);
} }

View File

@ -46,10 +46,13 @@ public abstract class KeyAnalyzer<K> implements Comparator<K>, Serializable {
/** /**
* Returned by {@link #bitIndex(Object, int, int, Object, int, int)} if key and found key are equal. * Returned by {@link #bitIndex(Object, int, int, Object, int, int)} if key and found key are equal.
* This is a very, very specific case and shouldn't happen on a regular basis. * This is a very specific case and shouldn't happen on a regular basis.
*/ */
public static final int EQUAL_BIT_KEY = -2; public static final int EQUAL_BIT_KEY = -2;
/**
* Used to test a {@code bitIndex} in {@link #isOutOfBoundsIndex(int)}.
*/
public static final int OUT_OF_BOUNDS_BIT_KEY = -3; public static final int OUT_OF_BOUNDS_BIT_KEY = -3;
/** /**

View File

@ -60,6 +60,9 @@ public class UnmodifiableTrie<K, V> implements Trie<K, V>, Serializable, Unmodif
return new UnmodifiableTrie<>(trie); return new UnmodifiableTrie<>(trie);
} }
/**
* The delegate Trie.
*/
private final Trie<K, V> delegate; private final Trie<K, V> delegate;
/** /**