Package com.groiss.ds
Class KeyedList<K,V>
java.lang.Object
com.groiss.ds.KeyedList<K,V>
- All Implemented Interfaces:
Iterable<V>
,Collection<V>
,List<V>
This class implements an ordered map. A list of keys is mapped to a list of values.
The values can be accessed by the key or the position in the list.
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
boolean
Caution: This method destroys the one-to-one relation between keys and content!boolean
addAll
(int i, Collection<? extends V> c) Caution: This method destroys the one-to-one relation between keys and content!boolean
boolean
addAll
(Collection<? extends V> c) Caution: This method destroys the one-to-one relation between keys and content!void
clear()
boolean
boolean
containsAll
(Collection<?> c) get
(int pos) Get the object mapped to the given key.getKey
(int i) Returns the key a postion iint
Return the position of the given key in the key list.Returns an iterator for the key listgetKeys()
int
boolean
isEmpty()
iterator()
int
listIterator
(int i) void
Put an element at position.void
Put an element to the end of the list.remove
(int pos) boolean
boolean
removeAll
(Collection<?> c) boolean
Removes the key (and associated object) from the listboolean
retainAll
(Collection<?> c) void
Replace the element mapped to key with the given element.int
size()
subList
(int fromIndex, int toIndex) Object[]
toArray()
<T> T[]
toArray
(T[] a) values()
Return the content list.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface java.util.Collection
parallelStream, removeIf, stream, toArray
Methods inherited from interface java.util.List
equals, hashCode, replaceAll, sort, spliterator
-
Constructor Details
-
KeyedList
public KeyedList() -
KeyedList
Create a new KeyedList.- Parameters:
keys
-content
-
-
-
Method Details
-
put
Put an element to the end of the list.- Parameters:
key
- a keyelem
- an element
-
put
Put an element at position.- Parameters:
pos
- insert after this positionkey
- a keyelem
- an element
-
get
Get the object mapped to the given key.- Parameters:
key
-- Returns:
- the object for this key, null if key not bound to an object
-
set
Replace the element mapped to key with the given element.- Parameters:
key
-elem
-
-
values
Return the content list.- Returns:
- the content.
-
getKey
Returns the key a postion i- Parameters:
i
- the position- Returns:
- the key a position i
-
getKeyIterator
Returns an iterator for the key list- Returns:
- an iterotor over key
-
getKeys
-
getKey
Return the position of the given key in the key list.- Parameters:
key
-- Returns:
- the position of the key, -1 if not in keys
-
removeKey
Removes the key (and associated object) from the list- Parameters:
key
-- Returns:
- true it the key was in the list
-
size
public int size() -
clear
public void clear() -
isEmpty
public boolean isEmpty() -
toArray
-
get
-
remove
-
add
-
indexOf
-
lastIndexOf
- Specified by:
lastIndexOf
in interfaceList<K>
-
add
Caution: This method destroys the one-to-one relation between keys and content! It manipulates only the content. -
contains
-
remove
-
addAll
Caution: This method destroys the one-to-one relation between keys and content! It manipulates only the content. -
addAll
Caution: This method destroys the one-to-one relation between keys and content! It manipulates only the content. -
addAll
-
containsAll
- Specified by:
containsAll
in interfaceCollection<K>
- Specified by:
containsAll
in interfaceList<K>
-
removeAll
-
retainAll
-
iterator
-
subList
-
listIterator
- Specified by:
listIterator
in interfaceList<K>
-
listIterator
- Specified by:
listIterator
in interfaceList<K>
-
set
-
toArray
public <T> T[] toArray(T[] a)
-