APIdia Launch Partner
Top Description Inners Fields Constructors Methods
com.badlogic.gdx.utils

public Class ArrayMap<K, V>

extends Object
implements Iterable<ObjectMap.Entry<K, V>>
Class Inheritance
All Implemented Interfaces
java.lang.Iterable
Imports
java.util.Arrays, .Iterator, .NoSuchElementException, com.badlogic.gdx.math.MathUtils, com.badlogic.gdx.utils.ObjectMap.Entry, com.badlogic.gdx.utils.reflect.ArrayReflection

An ordered or unordered map of objects. This implementation uses arrays to store the keys and values, which means gets do a comparison for each key in the map. This is slower than a typical hash map implementation, but may be acceptable for small maps and has the benefits that keys and values can be accessed by index, which makes iteration fast. Like Array, if ordered is false, this class avoids a memory copy when removing elements (the last element is moved to the removed element's position).
Author
Nathan Sweet

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static class
public static class
public static class

Field Summary

Modifier and TypeField and Description
private transient ArrayMap.Entries<K, V>
private transient ArrayMap.Entries<K, V>
public K[]
private transient ArrayMap.Keys<K>
private transient ArrayMap.Keys<K>
public boolean
public int
public V[]
private transient ArrayMap.Values<V>
private transient ArrayMap.Values<V>

Constructor Summary

AccessConstructor and Description
public
ArrayMap()

Creates an ordered map with a capacity of 16.

public
ArrayMap(int capacity)

Creates an ordered map with the specified capacity.

public
ArrayMap(boolean
If false, methods that remove elements may change the order of other elements in the arrays, which avoids a memory copy.
ordered
,
int
Any elements added beyond this will cause the backing arrays to be grown.
capacity
)

public
ArrayMap(boolean
If false, methods that remove elements may change the order of other elements in the arrays, which avoids a memory copy.
ordered
,
int
Any elements added beyond this will cause the backing arrays to be grown.
capacity
,
ArraySupplier<K[]> keyArraySupplier, ArraySupplier<V[]> valueArraySupplier)

Creates a new map with keys and values with the specified supplier.

public
ArrayMap(ArraySupplier<K[]> keyArraySupplier, ArraySupplier<V[]> valueArraySupplier)

Creates an ordered map with keys and values with the specified supplier and a capacity of 16.

public
ArrayMap(boolean
If false, methods that remove elements may change the order of other elements in the arrays, which avoids a memory copy.
ordered
,
int
Any elements added beyond this will cause the backing arrays to be grown.
capacity
,
Class<T> keyArrayType, Class<T> valueArrayType)

Creates a new map with keys and values of the specified type.

public
ArrayMap(Class<T> keyArrayType, Class<T> valueArrayType)

Creates an ordered map with keys and values of the specified type and a capacity of 16.

public
ArrayMap(ArrayMap<K, V> array)

Creates a new map containing the elements in the specified map.

Method Summary

Modifier and TypeMethod and Description
public void
clear(int maximumCapacity)

Clears the map and reduces the size of the backing arrays to be the specified capacity if they are larger.

public void
public boolean
containsKey(K key)

public boolean
containsValue(V value, boolean
If true, == comparison will be used. If false, .equals() comparison will be used.
identity
)

public void
ensureCapacity(int additionalCapacity)

Increases the size of the backing arrays to accommodate the specified number of additional entries.

public ArrayMap.Entries<K, V>
entries()

Returns an iterator for the entries in the map.

public boolean
equals(Object obj)

Overrides java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

public boolean
equalsIdentity(Object obj)

Uses == for comparison of each value.

public K
public V
public V
get(K key)

Returns the value (which may be null) for the specified key, or null if the key is not in the map.

public V
get(K key, V defaultValue)

Returns the value (which may be null) for the specified key, or the default value if the key is not in the map.

public K
getKey(V value, boolean
If true, == comparison will be used. If false, .equals() comparison will be used.
identity
)

Returns the key for the specified value.

public K
getKeyAt(int index)

public V
getValueAt(int index)

public int
hashCode()

Overrides java.lang.Object.hashCode.

Returns a hash code value for this object.

public int
indexOfKey(K key)

public int
indexOfValue(V value, boolean identity)

public void
insert(int index, K key, V value)

public boolean
isEmpty()

Returns true if the map is empty.

public Iterator<ObjectMap.Entry<K, V>>
iterator()

Implements java.lang.Iterable.iterator.

Returns an iterator over elements of type T.

public ArrayMap.Keys<K>
keys()

Returns an iterator for the keys in the map.

public boolean
notEmpty()

Returns true if the map has one or more items.

public K
peekKey()

Returns the last key.

public V
peekValue()

Returns the last value.

public int
put(K key, V value)

public int
put(K key, V value, int index)

public void
putAll(ArrayMap<? extends K, ? extends V> map)

public void
putAll(ArrayMap<? extends K, ? extends V> map, int offset, int length)

public V
putMissing(K key, V value)

public void
removeIndex(int index)

Removes and returns the key/values pair at the specified index.

public V
removeKey(K key)

public boolean
removeValue(V value, boolean identity)

protected void
resize(int newSize)

public void
public void
setKey(int index, K key)

public void
setValue(int index, V value)

public void
shrink()

Reduces the size of the backing arrays to the size of the actual number of entries.

public void
public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

public void
truncate(int newSize)

Reduces the size of the arrays to the specified size.

public ArrayMap.Values<V>
values()

Returns an iterator for the values in the map.

Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAllwaitwaitwait

Field Detail

entries1back to summary
private transient ArrayMap.Entries<K, V> entries1
entries2back to summary
private transient ArrayMap.Entries<K, V> entries2
keysback to summary
public K[] keys
keys1back to summary
private transient ArrayMap.Keys<K> keys1
keys2back to summary
private transient ArrayMap.Keys<K> keys2
orderedback to summary
public boolean ordered
sizeback to summary
public int size
valuesback to summary
public V[] values
values1back to summary
private transient ArrayMap.Values<V> values1
values2back to summary
private transient ArrayMap.Values<V> values2

Constructor Detail

ArrayMapback to summary
public ArrayMap()

Creates an ordered map with a capacity of 16.

ArrayMapback to summary
public ArrayMap(int capacity)

Creates an ordered map with the specified capacity.

ArrayMapback to summary
public ArrayMap(boolean ordered, int capacity)
Parameters
ordered:boolean

If false, methods that remove elements may change the order of other elements in the arrays, which avoids a memory copy.

capacity:int

Any elements added beyond this will cause the backing arrays to be grown.

ArrayMapback to summary
public ArrayMap(boolean ordered, int capacity, ArraySupplier<K[]> keyArraySupplier, ArraySupplier<V[]> valueArraySupplier)

Creates a new map with keys and values with the specified supplier.

Parameters
ordered:boolean

If false, methods that remove elements may change the order of other elements in the arrays, which avoids a memory copy.

capacity:int

Any elements added beyond this will cause the backing arrays to be grown.

ArrayMapback to summary
public ArrayMap(ArraySupplier<K[]> keyArraySupplier, ArraySupplier<V[]> valueArraySupplier)

Creates an ordered map with keys and values with the specified supplier and a capacity of 16.

ArrayMapback to summary
public ArrayMap(boolean ordered, int capacity, Class<T> keyArrayType, Class<T> valueArrayType)

Creates a new map with keys and values of the specified type.

Parameters
ordered:boolean

If false, methods that remove elements may change the order of other elements in the arrays, which avoids a memory copy.

capacity:int

Any elements added beyond this will cause the backing arrays to be grown.

Annotations
@Deprecated
ArrayMapback to summary
public ArrayMap(Class<T> keyArrayType, Class<T> valueArrayType)

Creates an ordered map with keys and values of the specified type and a capacity of 16.

Annotations
@Deprecated
ArrayMapback to summary
public ArrayMap(ArrayMap<K, V> array)

Creates a new map containing the elements in the specified map. The new map will have the same type of backing arrays and will be ordered if the specified map is ordered. The capacity is set to the number of elements, so any subsequent elements added will cause the backing arrays to be grown.

Method Detail

clearback to summary
public void clear(int maximumCapacity)

Clears the map and reduces the size of the backing arrays to be the specified capacity if they are larger.

clearback to summary
public void clear()
containsKeyback to summary
public boolean containsKey(K key)
containsValueback to summary
public boolean containsValue(V value, boolean identity)
Parameters
identity:boolean

If true, == comparison will be used. If false, .equals() comparison will be used.

ensureCapacityback to summary
public void ensureCapacity(int additionalCapacity)

Increases the size of the backing arrays to accommodate the specified number of additional entries. Useful before adding many entries to avoid multiple backing array resizes.

entriesback to summary
public ArrayMap.Entries<K, V> entries()

Returns an iterator for the entries in the map. Remove is supported.

If Collections#allocateIterators is false, the same iterator instance is returned each time this method is called. Use the Entries constructor for nested or multithreaded iteration.

See Also
Collections#allocateIterators
equalsback to summary
public boolean equals(Object obj)

Overrides java.lang.Object.equals.

Doc from java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

The equals method implements an equivalence relation on non-null object references:

  • It is reflexive: for any non-null reference value x, x.equals(x) should return true.
  • It is symmetric: for any non-null reference values x and y, x.equals(y) should return true if and only if y.equals(x) returns true.
  • It is transitive: for any non-null reference values x, y, and z, if x.equals(y) returns true and y.equals(z) returns true, then x.equals(z) should return true.
  • It is consistent: for any non-null reference values x and y, multiple invocations of x.equals(y) consistently return true or consistently return false, provided no information used in equals comparisons on the objects is modified.
  • For any non-null reference value x, x.equals(null) should return false.

An equivalence relation partitions the elements it operates on into equivalence classes; all the members of an equivalence class are equal to each other. Members of an equivalence class are substitutable for each other, at least for some purposes.

equalsIdentityback to summary
public boolean equalsIdentity(Object obj)

Uses == for comparison of each value.

firstKeyback to summary
public K firstKey()
firstValueback to summary
public V firstValue()
getback to summary
public V get(K key)

Returns the value (which may be null) for the specified key, or null if the key is not in the map. Note this does a .equals() comparison of each key in reverse order until the specified key is found.

Annotations
@Null
getback to summary
public V get(K key, V defaultValue)

Returns the value (which may be null) for the specified key, or the default value if the key is not in the map. Note this does a .equals() comparison of each key in reverse order until the specified key is found.

Annotations
@Null
getKeyback to summary
public K getKey(V value, boolean identity)

Returns the key for the specified value. Note this does a comparison of each value in reverse order until the specified value is found.

Parameters
identity:boolean

If true, == comparison will be used. If false, .equals() comparison will be used.

Annotations
@Null
getKeyAtback to summary
public K getKeyAt(int index)
getValueAtback to summary
public V getValueAt(int index)
hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Doc from java.lang.Object.hashCode.

Returns a hash code value for this object. This method is supported for the benefit of hash tables such as those provided by java.util.HashMap.

The general contract of hashCode is:

  • Whenever it is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer, provided no information used in equals comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application.
  • If two objects are equal according to the equals method, then calling the hashCode method on each of the two objects must produce the same integer result.
  • It is not required that if two objects are unequal according to the equals method, then calling the hashCode method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hash tables.
indexOfKeyback to summary
public int indexOfKey(K key)
indexOfValueback to summary
public int indexOfValue(V value, boolean identity)
insertback to summary
public void insert(int index, K key, V value)
isEmptyback to summary
public boolean isEmpty()

Returns true if the map is empty.

iteratorback to summary
public Iterator<ObjectMap.Entry<K, V>> iterator()

Implements java.lang.Iterable.iterator.

Doc from java.lang.Iterable.iterator.

Returns an iterator over elements of type T.

keysback to summary
public ArrayMap.Keys<K> keys()

Returns an iterator for the keys in the map. Remove is supported.

If Collections#allocateIterators is false, the same iterator instance is returned each time this method is called. Use the Entries constructor for nested or multithreaded iteration.

See Also
Collections#allocateIterators
notEmptyback to summary
public boolean notEmpty()

Returns true if the map has one or more items.

peekKeyback to summary
public K peekKey()

Returns the last key.

peekValueback to summary
public V peekValue()

Returns the last value.

putback to summary
public int put(K key, V value)
putback to summary
public int put(K key, V value, int index)
putAllback to summary
public void putAll(ArrayMap<? extends K, ? extends V> map)
putAllback to summary
public void putAll(ArrayMap<? extends K, ? extends V> map, int offset, int length)
putMissingback to summary
public V putMissing(K key, V value)
Annotations
@Null
removeIndexback to summary
public void removeIndex(int index)

Removes and returns the key/values pair at the specified index.

removeKeyback to summary
public V removeKey(K key)
Annotations
@Null
removeValueback to summary
public boolean removeValue(V value, boolean identity)
resizeback to summary
protected void resize(int newSize)
reverseback to summary
public void reverse()
setKeyback to summary
public void setKey(int index, K key)
setValueback to summary
public void setValue(int index, V value)
shrinkback to summary
public void shrink()

Reduces the size of the backing arrays to the size of the actual number of entries. This is useful to release memory when many items have been removed, or if it is known that more entries will not be added.

shuffleback to summary
public void shuffle()
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

truncateback to summary
public void truncate(int newSize)

Reduces the size of the arrays to the specified size. If the arrays are already smaller than the specified size, no action is taken.

valuesback to summary
public ArrayMap.Values<V> values()

Returns an iterator for the values in the map. Remove is supported.

If Collections#allocateIterators is false, the same iterator instance is returned each time this method is called. Use the Entries constructor for nested or multithreaded iteration.

See Also
Collections#allocateIterators
com.badlogic.gdx.utils back to summary

public Class ArrayMap.Entries<K, V>

extends Object
implements Iterable<ObjectMap.Entry<K, V>>, Iterator<ObjectMap.Entry<K, V>>
Class Inheritance
All Implemented Interfaces
java.util.Iterator, java.lang.Iterable

Field Summary

Modifier and TypeField and Description
pack-priv ObjectMap.Entry<K, V>
pack-priv int
private final ArrayMap<K, V>
pack-priv boolean

Constructor Summary

AccessConstructor and Description
public
Entries(ArrayMap<K, V> map)

Method Summary

Modifier and TypeMethod and Description
public boolean
hasNext()

Implements java.util.Iterator.hasNext.

Returns true if the iteration has more elements.

public Iterator<ObjectMap.Entry<K, V>>
iterator()

Implements java.lang.Iterable.iterator.

Returns an iterator over elements of type T.

public ObjectMap.Entry<K, V>
next()

Implements java.util.Iterator.next.

Note the same entry instance is returned each time this method is called.

public void
remove()

Overrides default java.util.Iterator.remove.

Removes from the underlying collection the last element returned by this iterator (optional operation).

public void
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

entryback to summary
pack-priv ObjectMap.Entry<K, V> entry
indexback to summary
pack-priv int index
mapback to summary
private final ArrayMap<K, V> map
validback to summary
pack-priv boolean valid

Constructor Detail

Entriesback to summary
public Entries(ArrayMap<K, V> map)

Method Detail

hasNextback to summary
public boolean hasNext()

Implements java.util.Iterator.hasNext.

Doc from java.util.Iterator.hasNext.

Returns true if the iteration has more elements. (In other words, returns true if next would return an element rather than throwing an exception.)

iteratorback to summary
public Iterator<ObjectMap.Entry<K, V>> iterator()

Implements java.lang.Iterable.iterator.

Doc from java.lang.Iterable.iterator.

Returns an iterator over elements of type T.

nextback to summary
public ObjectMap.Entry<K, V> next()

Implements java.util.Iterator.next.

Note the same entry instance is returned each time this method is called.

removeback to summary
public void remove()

Overrides default java.util.Iterator.remove.

Doc from java.util.Iterator.remove.

Removes from the underlying collection the last element returned by this iterator (optional operation). This method can be called only once per call to next.

The behavior of an iterator is unspecified if the underlying collection is modified while the iteration is in progress in any way other than by calling this method, unless an overriding class has specified a concurrent modification policy.

The behavior of an iterator is unspecified if this method is called after a call to the forEachRemaining method.

resetback to summary
public void reset()
com.badlogic.gdx.utils back to summary

public Class ArrayMap.Keys<K>

extends Object
implements Iterable<K>, Iterator<K>
Class Inheritance
All Implemented Interfaces
java.util.Iterator, java.lang.Iterable

Field Summary

Modifier and TypeField and Description
pack-priv int
private final ArrayMap<K, Object>
pack-priv boolean

Constructor Summary

AccessConstructor and Description
public
Keys(ArrayMap<K, Object> map)

Method Summary

Modifier and TypeMethod and Description
public boolean
hasNext()

Implements java.util.Iterator.hasNext.

Returns true if the iteration has more elements.

public Iterator<K>
iterator()

Implements java.lang.Iterable.iterator.

Returns an iterator over elements of type T.

public K
next()

Implements java.util.Iterator.next.

Returns the next element in the iteration.

public void
remove()

Overrides default java.util.Iterator.remove.

Removes from the underlying collection the last element returned by this iterator (optional operation).

public void
public Array<K>
public Array<K>
toArray(Array<T> array)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

indexback to summary
pack-priv int index
mapback to summary
private final ArrayMap<K, Object> map
validback to summary
pack-priv boolean valid

Constructor Detail

Keysback to summary
public Keys(ArrayMap<K, Object> map)

Method Detail

hasNextback to summary
public boolean hasNext()

Implements java.util.Iterator.hasNext.

Doc from java.util.Iterator.hasNext.

Returns true if the iteration has more elements. (In other words, returns true if next would return an element rather than throwing an exception.)

iteratorback to summary
public Iterator<K> iterator()

Implements java.lang.Iterable.iterator.

Doc from java.lang.Iterable.iterator.

Returns an iterator over elements of type T.

nextback to summary
public K next()

Implements java.util.Iterator.next.

Doc from java.util.Iterator.next.

Returns the next element in the iteration.

removeback to summary
public void remove()

Overrides default java.util.Iterator.remove.

Doc from java.util.Iterator.remove.

Removes from the underlying collection the last element returned by this iterator (optional operation). This method can be called only once per call to next.

The behavior of an iterator is unspecified if the underlying collection is modified while the iteration is in progress in any way other than by calling this method, unless an overriding class has specified a concurrent modification policy.

The behavior of an iterator is unspecified if this method is called after a call to the forEachRemaining method.

resetback to summary
public void reset()
toArrayback to summary
public Array<K> toArray()
toArrayback to summary
public Array<K> toArray(Array<T> array)
com.badlogic.gdx.utils back to summary

public Class ArrayMap.Values<V>

extends Object
implements Iterable<V>, Iterator<V>
Class Inheritance
All Implemented Interfaces
java.util.Iterator, java.lang.Iterable

Field Summary

Modifier and TypeField and Description
pack-priv int
private final ArrayMap<Object, V>
pack-priv boolean

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public boolean
hasNext()

Implements java.util.Iterator.hasNext.

Returns true if the iteration has more elements.

public Iterator<V>
iterator()

Implements java.lang.Iterable.iterator.

Returns an iterator over elements of type T.

public V
next()

Implements java.util.Iterator.next.

Returns the next element in the iteration.

public void
remove()

Overrides default java.util.Iterator.remove.

Removes from the underlying collection the last element returned by this iterator (optional operation).

public void
public Array<V>
public Array<V>
toArray(Array<T> array)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

indexback to summary
pack-priv int index
mapback to summary
private final ArrayMap<Object, V> map
validback to summary
pack-priv boolean valid

Constructor Detail

Valuesback to summary
public Values(ArrayMap<Object, V> map)

Method Detail

hasNextback to summary
public boolean hasNext()

Implements java.util.Iterator.hasNext.

Doc from java.util.Iterator.hasNext.

Returns true if the iteration has more elements. (In other words, returns true if next would return an element rather than throwing an exception.)

iteratorback to summary
public Iterator<V> iterator()

Implements java.lang.Iterable.iterator.

Doc from java.lang.Iterable.iterator.

Returns an iterator over elements of type T.

nextback to summary
public V next()

Implements java.util.Iterator.next.

Doc from java.util.Iterator.next.

Returns the next element in the iteration.

removeback to summary
public void remove()

Overrides default java.util.Iterator.remove.

Doc from java.util.Iterator.remove.

Removes from the underlying collection the last element returned by this iterator (optional operation). This method can be called only once per call to next.

The behavior of an iterator is unspecified if the underlying collection is modified while the iteration is in progress in any way other than by calling this method, unless an overriding class has specified a concurrent modification policy.

The behavior of an iterator is unspecified if this method is called after a call to the forEachRemaining method.

resetback to summary
public void reset()
toArrayback to summary
public Array<V> toArray()
toArrayback to summary
public Array<V> toArray(Array<T> array)