Top Description Inners Constructors Methods
org.apache.commons.collections4.multimap

public abstract Class AbstractListValuedMap<K, V>

extends AbstractMultiValuedMap<K, V>
implements ListValuedMap<K, V>
Class Inheritance
All Implemented Interfaces
org.apache.commons.collections4.ListValuedMap, org.apache.commons.collections4.MultiValuedMap
Known Direct Subclasses
org.apache.commons.collections4.multimap.ArrayListValuedHashMap
Type Parameters
<K>
the type of the keys in this map
<V>
the type of the values in this map
Imports
java.util.Collection, .Collections, .List, .ListIterator, .Map, org.apache.commons.collections4.ListUtils, .ListValuedMap

Abstract implementation of the ListValuedMap interface to simplify the creation of subclass implementations.

Subclasses specify a Map implementation to use as the internal storage and the List implementation to use as values.

Since
4.1

Nested and Inner Type Summary

Modifier and TypeClass and Description
private class
private class
AbstractListValuedMap.WrappedList

Wrapped list to handle add and remove on the list returned by get(object)

Constructor Summary

AccessConstructor and Description
protected
AbstractListValuedMap()

Constructor needed for subclass serialisation.

protected
AbstractListValuedMap(final Map<K, ? extends List<V>>
the map to wrap, must not be null
map
)

A constructor that wraps, not copies

Method Summary

Modifier and TypeMethod and Description
protected abstract List<V>

Returns:

a new list
createCollection
()

Implements abstract org.apache.commons.collections4.multimap.AbstractMultiValuedMap.createCollection.

Creates a new value collection using the provided factory.
public List<V>

Returns:

the List of values, will return an empty List for no mapping
get
(final K
the key to retrieve
key
)

Overrides org.apache.commons.collections4.multimap.AbstractMultiValuedMap.get.

Implements org.apache.commons.collections4.ListValuedMap.get, org.apache.commons.collections4.MultiValuedMap.get.

Gets the list of values associated with the specified key.
protected Map<K, List<V>>
public List<V>

Returns:

the List of values removed, will return an empty, unmodifiable list for no mapping found.
remove
(final Object
the key to remove values from
key
)

Overrides org.apache.commons.collections4.multimap.AbstractMultiValuedMap.remove.

Implements org.apache.commons.collections4.ListValuedMap.remove, org.apache.commons.collections4.MultiValuedMap.remove.

Removes all values associated with the specified key.
pack-priv List<V>
Inherited from org.apache.commons.collections4.multimap.AbstractMultiValuedMap:
asMapclearcontainsKeycontainsMappingcontainsValuedoReadObjectdoWriteObjectentriesequalshashCodeisEmptykeyskeySetmapIteratorputputAllputAllputAllremoveMappingsetMapsizetoStringvalues

Constructor Detail

AbstractListValuedMapback to summary
protected AbstractListValuedMap()

Constructor needed for subclass serialisation.

AbstractListValuedMapback to summary
protected AbstractListValuedMap(final Map<K, ? extends List<V>> map)

A constructor that wraps, not copies

Parameters
map:Map<K, ? extends List<V>>

the map to wrap, must not be null

Exceptions
NullPointerException:
if the map is null

Method Detail

createCollectionback to summary
protected abstract List<V> createCollection()

Implements abstract org.apache.commons.collections4.multimap.AbstractMultiValuedMap.createCollection.

Creates a new value collection using the provided factory.

Returns:List<V>

a new list

Annotations
@Override
getback to summary
public List<V> get(final K key)

Overrides org.apache.commons.collections4.multimap.AbstractMultiValuedMap.get.

Implements org.apache.commons.collections4.ListValuedMap.get, org.apache.commons.collections4.MultiValuedMap.get.

Gets the list of values associated with the specified key. This would return an empty list in case the mapping is not present

Parameters
key:K

the key to retrieve

Returns:List<V>

the List of values, will return an empty List for no mapping

Annotations
@Override
getMapback to summary
protected Map<K, List<V>> getMap()

Overrides org.apache.commons.collections4.multimap.AbstractMultiValuedMap.getMap.

Doc from org.apache.commons.collections4.multimap.AbstractMultiValuedMap.getMap.

Gets the map being wrapped.

Returns:Map<K, List<V>>

the wrapped map

Annotations
@Override
@SuppressWarnings:unchecked
removeback to summary
public List<V> remove(final Object key)

Overrides org.apache.commons.collections4.multimap.AbstractMultiValuedMap.remove.

Implements org.apache.commons.collections4.ListValuedMap.remove, org.apache.commons.collections4.MultiValuedMap.remove.

Removes all values associated with the specified key.

A subsequent get(Object) would return an empty list.

Parameters
key:Object

the key to remove values from

Returns:List<V>

the List of values removed, will return an empty, unmodifiable list for no mapping found.

Annotations
@Override
wrappedCollectionback to summary
pack-priv List<V> wrappedCollection(final K key)

Overrides org.apache.commons.collections4.multimap.AbstractMultiValuedMap.wrappedCollection.

Annotations
@Override
org.apache.commons.collections4.multimap back to summary

private Class AbstractListValuedMap.ValuesListIterator

extends Object
implements ListIterator<V>
Class Inheritance
  • java.lang.Object
  • org.apache.commons.collections4.multimap.AbstractListValuedMap.ValuesListIterator
All Implemented Interfaces
java.util.ListIterator, java.util.Iterator

Values ListIterator

Field Summary

Modifier and TypeField and Description
private ListIterator<V>
private final K
private List<V>

Constructor Summary

AccessConstructor and Description
public
ValuesListIterator(final K key)

public
ValuesListIterator(final K key, final int index)

Method Summary

Modifier and TypeMethod and Description
public void
add(final V
the element to insert
value
)

Implements java.util.ListIterator.add.

Inserts the specified element into the list (optional operation).
public boolean
hasNext()

Implements java.util.ListIterator.hasNext.

Returns true if this list iterator has more elements when traversing the list in the forward direction.
public boolean
hasPrevious()

Implements java.util.ListIterator.hasPrevious.

Returns true if this list iterator has more elements when traversing the list in the reverse direction.
public V
next()

Implements java.util.ListIterator.next.

Returns the next element in the list and advances the cursor position.
public int
nextIndex()

Implements java.util.ListIterator.nextIndex.

Returns the index of the element that would be returned by a subsequent call to next.
public V
previous()

Implements java.util.ListIterator.previous.

Returns the previous element in the list and moves the cursor position backwards.
public int
previousIndex()

Implements java.util.ListIterator.previousIndex.

Returns the index of the element that would be returned by a subsequent call to previous.
public void
remove()

Implements java.util.ListIterator.remove.

Removes from the list the last element that was returned by next or previous (optional operation).
public void
set(final V
the element with which to replace the last element returned by next or previous
value
)

Implements java.util.ListIterator.set.

Replaces the last element returned by next or previous with the specified element (optional operation).
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

iteratorback to summary
private ListIterator<V> iterator
keyback to summary
private final K key
valuesback to summary
private List<V> values

Constructor Detail

ValuesListIteratorback to summary
public ValuesListIterator(final K key)
ValuesListIteratorback to summary
public ValuesListIterator(final K key, final int index)

Method Detail

addback to summary
public void add(final V value)

Implements java.util.ListIterator.add.

Doc from java.util.ListIterator.add.

Inserts the specified element into the list (optional operation). The element is inserted immediately before the element that would be returned by next, if any, and after the element that would be returned by previous, if any. (If the list contains no elements, the new element becomes the sole element on the list.) The new element is inserted before the implicit cursor: a subsequent call to next would be unaffected, and a subsequent call to previous would return the new element. (This call increases by one the value that would be returned by a call to nextIndex or previousIndex.)

Parameters
value:V

the element to insert

Annotations
@Override
hasNextback to summary
public boolean hasNext()

Implements java.util.ListIterator.hasNext.

Doc from java.util.ListIterator.hasNext.

Returns true if this list iterator has more elements when traversing the list in the forward direction. (In other words, returns true if next would return an element rather than throwing an exception.)

Returns:boolean

true if the list iterator has more elements when traversing the list in the forward direction

Annotations
@Override
hasPreviousback to summary
public boolean hasPrevious()

Implements java.util.ListIterator.hasPrevious.

Doc from java.util.ListIterator.hasPrevious.

Returns true if this list iterator has more elements when traversing the list in the reverse direction. (In other words, returns true if previous would return an element rather than throwing an exception.)

Returns:boolean

true if the list iterator has more elements when traversing the list in the reverse direction

Annotations
@Override
nextback to summary
public V next()

Implements java.util.ListIterator.next.

Doc from java.util.ListIterator.next.

Returns the next element in the list and advances the cursor position. This method may be called repeatedly to iterate through the list, or intermixed with calls to previous to go back and forth. (Note that alternating calls to next and previous will return the same element repeatedly.)

Returns:V

the next element in the list

Annotations
@Override
nextIndexback to summary
public int nextIndex()

Implements java.util.ListIterator.nextIndex.

Doc from java.util.ListIterator.nextIndex.

Returns the index of the element that would be returned by a subsequent call to next. (Returns list size if the list iterator is at the end of the list.)

Returns:int

the index of the element that would be returned by a subsequent call to next, or list size if the list iterator is at the end of the list

Annotations
@Override
previousback to summary
public V previous()

Implements java.util.ListIterator.previous.

Doc from java.util.ListIterator.previous.

Returns the previous element in the list and moves the cursor position backwards. This method may be called repeatedly to iterate through the list backwards, or intermixed with calls to next to go back and forth. (Note that alternating calls to next and previous will return the same element repeatedly.)

Returns:V

the previous element in the list

Annotations
@Override
previousIndexback to summary
public int previousIndex()

Implements java.util.ListIterator.previousIndex.

Doc from java.util.ListIterator.previousIndex.

Returns the index of the element that would be returned by a subsequent call to previous. (Returns -1 if the list iterator is at the beginning of the list.)

Returns:int

the index of the element that would be returned by a subsequent call to previous, or -1 if the list iterator is at the beginning of the list

Annotations
@Override
removeback to summary
public void remove()

Implements java.util.ListIterator.remove.

Doc from java.util.ListIterator.remove.

Removes from the list the last element that was returned by next or previous (optional operation). This call can only be made once per call to next or previous. It can be made only if add has not been called after the last call to next or previous.

Annotations
@Override
setback to summary
public void set(final V value)

Implements java.util.ListIterator.set.

Doc from java.util.ListIterator.set.

Replaces the last element returned by next or previous with the specified element (optional operation). This call can be made only if neither remove nor add have been called after the last call to next or previous.

Parameters
value:V

the element with which to replace the last element returned by next or previous

Annotations
@Override
org.apache.commons.collections4.multimap back to summary

private Class AbstractListValuedMap.WrappedList

extends AbstractMultiValuedMap<K, V>.WrappedCollection
implements List<V>
Class Inheritance
All Implemented Interfaces
java.util.List, java.util.SequencedCollection, java.util.Collection, java.lang.Iterable

Wrapped list to handle add and remove on the list returned by get(object)

Field Summary

Inherited from org.apache.commons.collections4.multimap.AbstractMultiValuedMap.WrappedCollection:
key

Constructor Summary

AccessConstructor and Description
public
WrappedList(final K key)

Method Summary

Modifier and TypeMethod and Description
public void
add(final int
index at which the specified element is to be inserted
index
,
final V
element to be inserted
value
)

Implements java.util.List.add.

Inserts the specified element at the specified position in this list (optional operation).
public boolean
addAll(final int
index at which to insert the first element from the specified collection
index
,
final Collection<? extends V>
collection containing elements to be added to this list
c
)

Implements java.util.List.addAll.

Inserts all of the elements in the specified collection into this list at the specified position (optional operation).
public boolean
equals(final Object
the object to be compared for equality with this list
other
)

Overrides java.lang.Object.equals.

Implements java.util.List.equals, java.util.Collection.equals.

Compares the specified object with this list for equality.
public V
get(final int
index of the element to return
index
)

Implements java.util.List.get.

Returns the element at the specified position in this list.
protected List<V>
public int
hashCode()

Overrides java.lang.Object.hashCode.

Implements java.util.List.hashCode, java.util.Collection.hashCode.

Returns the hash code value for this list.
public int
indexOf(final Object
element to search for
o
)

Implements java.util.List.indexOf.

Returns the index of the first occurrence of the specified element in this list, or -1 if this list does not contain the element.
public int
lastIndexOf(final Object
element to search for
o
)

Implements java.util.List.lastIndexOf.

Returns the index of the last occurrence of the specified element in this list, or -1 if this list does not contain the element.
public ListIterator<V>
listIterator()

Implements java.util.List.listIterator.

Returns a list iterator over the elements in this list (in proper sequence).
public ListIterator<V>
listIterator(final int
index of the first element to be returned from the list iterator (by a call to next)
index
)

Implements java.util.List.listIterator.

Returns a list iterator over the elements in this list (in proper sequence), starting at the specified position in the list.
public V
remove(final int
the index of the element to be removed
index
)

Implements java.util.List.remove.

Removes the element at the specified position in this list (optional operation).
public V
set(final int
index of the element to replace
index
,
final V
element to be stored at the specified position
value
)

Implements java.util.List.set.

Replaces the element at the specified position in this list with the specified element (optional operation).
public List<V>
subList(final int
low endpoint (inclusive) of the subList
fromIndex
,
final int
high endpoint (exclusive) of the subList
toIndex
)

Implements java.util.List.subList.

Returns a view of the portion of this list between the specified fromIndex, inclusive, and toIndex, exclusive.
Inherited from org.apache.commons.collections4.multimap.AbstractMultiValuedMap.WrappedCollection:
addaddAllclearcontainscontainsAllisEmptyiteratorremoveremoveAllretainAllsizetoArraytoArraytoString

Constructor Detail

WrappedListback to summary
public WrappedList(final K key)

Method Detail

addback to summary
public void add(final int index, final V value)

Implements java.util.List.add.

Doc from java.util.List.add.

Inserts the specified element at the specified position in this list (optional operation). Shifts the element currently at that position (if any) and any subsequent elements to the right (adds one to their indices).

Parameters
index:int

index at which the specified element is to be inserted

value:V

element to be inserted

Annotations
@Override
addAllback to summary
public boolean addAll(final int index, final Collection<? extends V> c)

Implements java.util.List.addAll.

Doc from java.util.List.addAll.

Inserts all of the elements in the specified collection into this list at the specified position (optional operation). Shifts the element currently at that position (if any) and any subsequent elements to the right (increases their indices). The new elements will appear in this list in the order that they are returned by the specified collection's iterator. The behavior of this operation is undefined if the specified collection is modified while the operation is in progress. (Note that this will occur if the specified collection is this list, and it's nonempty.)

Parameters
index:int

index at which to insert the first element from the specified collection

c:Collection<? extends V>

collection containing elements to be added to this list

Returns:boolean

true if this list changed as a result of the call

Annotations
@Override
equalsback to summary
public boolean equals(final Object other)

Overrides java.lang.Object.equals.

Implements java.util.List.equals, java.util.Collection.equals.

Doc from java.util.List.equals.

Compares the specified object with this list for equality. Returns true if and only if the specified object is also a list, both lists have the same size, and all corresponding pairs of elements in the two lists are equal. (Two elements e1 and e2 are equal if Objects.equals(e1, e2).) In other words, two lists are defined to be equal if they contain the same elements in the same order. This definition ensures that the equals method works properly across different implementations of the List interface.

Parameters
other:Object

the object to be compared for equality with this list

Returns:boolean

true if the specified object is equal to this list

Annotations
@Override
getback to summary
public V get(final int index)

Implements java.util.List.get.

Doc from java.util.List.get.

Returns the element at the specified position in this list.

Parameters
index:int

index of the element to return

Returns:V

the element at the specified position in this list

Annotations
@Override
getMappingback to summary
protected List<V> getMapping()

Overrides org.apache.commons.collections4.multimap.AbstractMultiValuedMap.WrappedCollection.getMapping.

Annotations
@Override
hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Implements java.util.List.hashCode, java.util.Collection.hashCode.

Doc from java.util.List.hashCode.

Returns the hash code value for this list. The hash code of a list is defined to be the result of the following calculation:

int hashCode = 1;
    for (E e : list)
        hashCode = 31*hashCode + (e==null ? 0 : e.hashCode());
This ensures that list1.equals(list2) implies that list1.hashCode()==list2.hashCode() for any two lists, list1 and list2, as required by the general contract of Object#hashCode.
Returns:int

the hash code value for this list

Annotations
@Override
indexOfback to summary
public int indexOf(final Object o)

Implements java.util.List.indexOf.

Doc from java.util.List.indexOf.

Returns the index of the first occurrence of the specified element in this list, or -1 if this list does not contain the element. More formally, returns the lowest index i such that Objects.equals(o, get(i)), or -1 if there is no such index.

Parameters
o:Object

element to search for

Returns:int

the index of the first occurrence of the specified element in this list, or -1 if this list does not contain the element

Annotations
@Override
lastIndexOfback to summary
public int lastIndexOf(final Object o)

Implements java.util.List.lastIndexOf.

Doc from java.util.List.lastIndexOf.

Returns the index of the last occurrence of the specified element in this list, or -1 if this list does not contain the element. More formally, returns the highest index i such that Objects.equals(o, get(i)), or -1 if there is no such index.

Parameters
o:Object

element to search for

Returns:int

the index of the last occurrence of the specified element in this list, or -1 if this list does not contain the element

Annotations
@Override
listIteratorback to summary
public ListIterator<V> listIterator()

Implements java.util.List.listIterator.

Doc from java.util.List.listIterator.

Returns a list iterator over the elements in this list (in proper sequence).

Returns:ListIterator<V>

a list iterator over the elements in this list (in proper sequence)

Annotations
@Override
listIteratorback to summary
public ListIterator<V> listIterator(final int index)

Implements java.util.List.listIterator.

Doc from java.util.List.listIterator.

Returns a list iterator over the elements in this list (in proper sequence), starting at the specified position in the list. The specified index indicates the first element that would be returned by an initial call to next. An initial call to previous would return the element with the specified index minus one.

Parameters
index:int

index of the first element to be returned from the list iterator (by a call to next)

Returns:ListIterator<V>

a list iterator over the elements in this list (in proper sequence), starting at the specified position in the list

Annotations
@Override
removeback to summary
public V remove(final int index)

Implements java.util.List.remove.

Doc from java.util.List.remove.

Removes the element at the specified position in this list (optional operation). Shifts any subsequent elements to the left (subtracts one from their indices). Returns the element that was removed from the list.

Parameters
index:int

the index of the element to be removed

Returns:V

the element previously at the specified position

Annotations
@Override
setback to summary
public V set(final int index, final V value)

Implements java.util.List.set.

Doc from java.util.List.set.

Replaces the element at the specified position in this list with the specified element (optional operation).

Parameters
index:int

index of the element to replace

value:V

element to be stored at the specified position

Returns:V

the element previously at the specified position

Annotations
@Override
subListback to summary
public List<V> subList(final int fromIndex, final int toIndex)

Implements java.util.List.subList.

Doc from java.util.List.subList.

Returns a view of the portion of this list between the specified fromIndex, inclusive, and toIndex, exclusive. (If fromIndex and toIndex are equal, the returned list is empty.) The returned list is backed by this list, so non-structural changes in the returned list are reflected in this list, and vice-versa. The returned list supports all of the optional list operations supported by this list.

This method eliminates the need for explicit range operations (of the sort that commonly exist for arrays). Any operation that expects a list can be used as a range operation by passing a subList view instead of a whole list. For example, the following idiom removes a range of elements from a list:

list.subList(from, to).clear();
Similar idioms may be constructed for indexOf and lastIndexOf, and all of the algorithms in the Collections class can be applied to a subList.

The semantics of the list returned by this method become undefined if the backing list (i.e., this list) is structurally modified in any way other than via the returned list. (Structural modifications are those that change the size of this list, or otherwise perturb it in such a fashion that iterations in progress may yield incorrect results.)

Parameters
fromIndex:int

low endpoint (inclusive) of the subList

toIndex:int

high endpoint (exclusive) of the subList

Returns:List<V>

a view of the specified range within this list

Annotations
@Override