Package com.microstrategy.utils
Class HashList<K,V>
- java.lang.Object
-
- com.microstrategy.utils.HashList<K,V>
-
- All Implemented Interfaces:
java.io.Serializable
,java.lang.Cloneable
public class HashList<K,V> extends java.lang.Object implements java.lang.Cloneable, java.io.Serializable
The HashList class allows the user to add, remove and examine the s in a given collection. The s can be access either by the index or by the key in the collection. This collection can also be used as read only.- Since:
- MicroStrategy Web 7.3.1 or earlier
- See Also:
- Serialized Form
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description void
add(K key, V newItem)
Adds the , with the specified key, into the collection.void
clear()
Clears all items from the collection.java.lang.Object
clone()
boolean
containsKey(K key)
Returns true if the key is already in the collection, false otherwise.boolean
containsValue(V value)
Returns true if this collection maps one or more keys to the specified value.java.util.Enumeration<V>
elements()
Return the enumeration of the items inside this list.V
get(int index)
Gets the contained in the specified index of the collection.V
get(K key)
Returns the contained with the specified key in the collection.java.util.HashMap<K,V>
getItemSet()
Deprecated.replaced byitems()
K
getKey(int index)
Gets the key of the item contained in the specified index of the collection.static <K,V>
KgetKey(java.util.LinkedHashMap<K,V> map, int index)
Get the key of aLinkedHashMap
by index.java.util.ArrayList<K>
getKeyList()
Deprecated.replaced bykeys()
int
indexOf(K key)
Returns the index of the given key.boolean
isEmpty()
Returns true if the collection is empyt, false otherwise.java.util.Map<K,V>
items()
Returns an unmodifiableMap
of the items.java.util.List<K>
keys()
Returns an unmodifiableList
of the keys.void
put(K key, V newItem)
Adds or replaces the , with the specified key, into the collection.void
putAll(HashList<K,V> list)
Adds all the s in the HashList in the same order defined in it.void
putAll(java.util.Map<K,V> m)
Adds all the s in the map to the collectionV
remove(int index)
Removes the contained in the specified index of the collection.V
remove(K key)
Removes the contained with the specified key in the collection.V
replace(K key, V newItem)
Replace the current item associated with the given key.void
setItemSet(java.util.HashMap<K,V> newValue)
Deprecated.dangerous method pending removalvoid
setKeyList(java.util.ArrayList<K> newValue)
Deprecated.dangerous method pending removalint
size()
Returns the current size of the collection.void
sort(java.util.Comparator<K> comp)
Sorts the existing list according to the order induced by the specified comparator.java.lang.String
toString()
Returns a string representation of the .java.util.Collection<V>
values()
-
-
-
Method Detail
-
size
public int size()
Returns the current size of the collection.- Returns:
- The number of items in the collection.
-
get
public V get(int index) throws java.lang.IndexOutOfBoundsException
Gets the contained in the specified index of the collection. Throws IndexOutOfBoundsException in case the index is greater than the collection size or < 0.- Parameters:
index
- The index of the item in the collection to get.- Returns:
- the value contained in the specified index of the collection.
- Throws:
java.lang.IndexOutOfBoundsException
- Thrown if no item in the collection has the given index.
-
get
public V get(K key) throws java.lang.IllegalArgumentException
Returns the contained with the specified key in the collection. Throws IllegalArgumentException in case the key does not exist in the collection.- Parameters:
key
- The key of the item in the collection to get.- Returns:
- the value to which collection maps the specified key.
- Throws:
java.lang.IllegalArgumentException
- Thrown if no item in the collection has the given key.- Since:
- MicroStrategy Web 9.0.0
-
getKey
public K getKey(int index) throws java.lang.IndexOutOfBoundsException
Gets the key of the item contained in the specified index of the collection. Throws IndexOutOfBoundsException in case the index is greater than the collection size or < 0.- Parameters:
index
- The index of the item in the collection.- Returns:
- the key of the item contained in the specified index of the collection.
- Throws:
java.lang.IndexOutOfBoundsException
- thrown if no item in the collection has the given index.
-
remove
public V remove(int index) throws java.lang.IndexOutOfBoundsException
Removes the contained in the specified index of the collection. Throws IndexOutOfBoundsException in case the index is greater than the collection size or < 0; and UnsupportedOperationException in case the collection is a read-only .- Parameters:
index
- The index of the item in the collection to remove.- Returns:
- previous value in the specified index of the collection.
- Throws:
java.lang.IndexOutOfBoundsException
- Thrown if no item in the collection has the given index.
-
remove
public V remove(K key) throws java.lang.IllegalArgumentException
Removes the contained with the specified key in the collection. Throws IllegalArgumentException if the key is not contained in the collection; and UnsupportedOperationException in case the collection is a read-only .- Parameters:
key
- The key of the item in the collection to remove.- Returns:
- previous value associated with specified key.
- Throws:
java.lang.IllegalArgumentException
- Thrown if no item in the collection has the given key.- Since:
- MicroStrategy Web 9.0.0
-
add
public void add(K key, V newItem) throws java.lang.IllegalArgumentException
Adds the , with the specified key, into the collection. Throws UnsupportedOperationException in case the collection is a read-only ; and IllegalArgumentException in case the key is null, or it already exists in the collection.- Parameters:
key
- The key used to identify the in the collection.newItem
- The to add to the collection.- Throws:
java.lang.IllegalArgumentException
- Thrown if the given key is already contained in the collection.- Since:
- MicroStrategy Web 9.0.0
-
put
public void put(K key, V newItem) throws java.lang.IllegalArgumentException
Adds or replaces the , with the specified key, into the collection. Throws UnsupportedOperationException in case the collection is a read-only- Parameters:
key
- The key used to identify the in the collection.newItem
- The to add to the collection.- Throws:
java.lang.IllegalArgumentException
- Thrown if the given key is already contained in the collection.- Since:
- MicroStrategy Web 9.0.0
-
putAll
public void putAll(java.util.Map<K,V> m) throws java.lang.IllegalArgumentException
Adds all the s in the map to the collection- Parameters:
m
- A Map with a list of key/value entries.- Throws:
java.lang.IllegalArgumentException
- Thrown if any of the given keys is already contained in the collection.- Since:
- MicroStrategy Web 8.0.1
-
putAll
public void putAll(HashList<K,V> list) throws java.lang.IllegalArgumentException
Adds all the s in the HashList in the same order defined in it.- Parameters:
list
- A HashList with a list of key/value entries.- Throws:
java.lang.IllegalArgumentException
- Thrown if any of the given keys is already contained in the collection.- Since:
- MicroStrategy Web 9.0.0
-
replace
public V replace(K key, V newItem)
Replace the current item associated with the given key. Returns the item that was previously associated. Throws an exception If there is no element with the given value or with a null key.- Parameters:
key
- the key of the element to replacenewItem
- the new item to be inserted.- Returns:
- the previously associated with that key.
- Since:
- MicroStrategy Web 9.0.0
-
clear
public void clear()
Clears all items from the collection.
-
isEmpty
public boolean isEmpty()
Returns true if the collection is empyt, false otherwise.- Returns:
- Whether the collection is empty.
-
containsKey
public boolean containsKey(K key)
Returns true if the key is already in the collection, false otherwise.- Parameters:
key
- The key that we want to look for in the collection.- Returns:
- Wheter the collection contains the key.
- Since:
- MicroStrategy Web 9.0.0
-
containsValue
public boolean containsValue(V value)
Returns true if this collection maps one or more keys to the specified value.- Parameters:
value
- value whose presence in this collection is to be tested.- Returns:
- true if this collection maps one or more keys to the specified value.
- Since:
- MicroStrategy Web 9.0.0
-
indexOf
public int indexOf(K key)
Returns the index of the given key.- Parameters:
key
- that represents the key.- Returns:
- the index of the key in the collection, -1 if the is not found.
- Since:
- MicroStrategy Web 9.0.0
-
elements
public java.util.Enumeration<V> elements()
Return the enumeration of the items inside this list.- Returns:
- An enumeration of the items inside this list.
-
values
public java.util.Collection<V> values()
- Since:
- MicroStrategy Web 8.1.0
-
getKeyList
@Deprecated public java.util.ArrayList<K> getKeyList()
Deprecated.replaced bykeys()
Do NOT use! Altering the contents of theMap
can corrupt the underlyingHashList
.
-
keys
public java.util.List<K> keys()
Returns an unmodifiableList
of the keys.- Since:
- MicroStrategy Web 9.0.0
-
getItemSet
@Deprecated public java.util.HashMap<K,V> getItemSet()
Deprecated.replaced byitems()
Do NOT use! Altering the contents of theMap
can corrupt the underlyingHashList
.
-
items
public java.util.Map<K,V> items()
Returns an unmodifiableMap
of the items.- Since:
- MicroStrategy Web 9.0.0
-
setKeyList
@Deprecated public void setKeyList(java.util.ArrayList<K> newValue)
Deprecated.dangerous method pending removalDo NOT use! Altering the contents of theMap
can corrupt the underlyingHashList
.
-
setItemSet
@Deprecated public void setItemSet(java.util.HashMap<K,V> newValue)
Deprecated.dangerous method pending removalDo NOT use! Altering the contents of theMap
can corrupt the underlyingHashList
.
-
clone
public java.lang.Object clone() throws java.lang.CloneNotSupportedException
- Overrides:
clone
in classjava.lang.Object
- Throws:
java.lang.CloneNotSupportedException
-
sort
public void sort(java.util.Comparator<K> comp)
Sorts the existing list according to the order induced by the specified comparator.- Since:
- MicroStrategy Web 8.0.2
-
toString
public java.lang.String toString()
Returns a string representation of the .- Overrides:
toString
in classjava.lang.Object
- Returns:
- a string representation of the .
- Since:
- MicroStrategy Web 8.0.0
-
getKey
public static <K,V> K getKey(java.util.LinkedHashMap<K,V> map, int index)
Get the key of aLinkedHashMap
by index.- Parameters:
map
- theLinkedHashMap
index
- the index of the key- Returns:
- the key of a
LinkedHashMap
by index.
-
-