com.neeve.util
Class UtlLinkedLongMap<V>

java.lang.Object
  extended by com.neeve.util.UtlLinkedLongMap<V>

public class UtlLinkedLongMap<V>
extends Object

A map implementation based on UtlLinkedHashMap but foregoes conformance to Map api to allow primitive long keys so that garbage needn't be created converting primitive long keys to their Long variants.

This class doesn't support Cloning or Serialization

This class IS NOT intended to be used by end users.

Threading:
This class is not safe for concurrent access by multiple threads.

Nested Class Summary
static class UtlLinkedLongMap.Entry<V>
          This class represents a UtlLinkedLongMap entry.
 class UtlLinkedLongMap.FastIterator
          This inner class represents a reusable list iterator over UtlLinkedLongMap entries.
 
Constructor Summary
UtlLinkedLongMap()
          Creates a UtlLinkedLongMap with a capacity of 16 entries.
UtlLinkedLongMap(int capacity)
          Creates a UtlLinkedLongMap with the specified capacity.
 
Method Summary
 int capacity()
          Returns the capacity of this UtlLinkedLongMap.
 void clear()
          Removes all mappings from this UtlLinkedLongMap.
 boolean containsKey(long key)
          Indicates if this UtlLinkedLongMap contains a mapping for the specified key.
 boolean containsValue(Object value)
          Indicates if this UtlLinkedLongMap maps one or more keys to the specified value.
 Set<UtlLinkedLongMap.Entry<V>> entrySet()
          Returns a collection view of the mappings contained in this UtlLinkedLongMap.
 UtlLinkedLongMap.FastIterator fastIterator()
          Returns a reusable UtlLinkedLongMap.FastIterator over this UtlLinkedLongMap entries (unique instance per map).
 V get(long key)
          Returns the value to which this UtlLinkedLongMap maps the specified key.
 UtlLinkedLongMap.Entry<V> getEntry(long key)
          Returns the entry with the specified key.
 int hashCode()
          Returns the hash code value for this UtlLinkedLongMap.
 boolean isEmpty()
          Indicates if this UtlLinkedLongMap contains no key-value mappings.
 V put(long key, V value)
          Associates the specified value with the specified key in this UtlLinkedLongMap.
 V remove(long key)
          Removes the mapping for this key from this UtlLinkedLongMap if present.
 void setCapacity(int newCapacity)
          Changes the current capacity of this UtlLinkedLongMap.
 int size()
          Returns the number of key-value mappings in this UtlLinkedLongMap.
 String toString()
          Returns a String representation of this UtlLinkedLongMap.
 Collection<V> values()
          Returns a collection view of the values contained in this UtlLinkedLongMap.
 
Methods inherited from class java.lang.Object
equals, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

UtlLinkedLongMap

public UtlLinkedLongMap()
Creates a UtlLinkedLongMap with a capacity of 16 entries.


UtlLinkedLongMap

public UtlLinkedLongMap(int capacity)
Creates a UtlLinkedLongMap with the specified capacity. Unless the capacity is exceeded, operations on this map do not allocate entries. For optimum performance, the capacity should be of the same order of magnitude or larger than the expected map's size.

Parameters:
capacity - the number of buckets in the hash table; it also defines the number of pre-allocated entries.
Method Detail

size

public int size()
Returns the number of key-value mappings in this UtlLinkedLongMap.

Returns:
this map's size.

capacity

public int capacity()
Returns the capacity of this UtlLinkedLongMap. The capacity defines the number of buckets in the hash table, as well as the maximum number of entries the map may contain without allocating memory.

Returns:
this map's capacity.

isEmpty

public boolean isEmpty()
Indicates if this UtlLinkedLongMap contains no key-value mappings.

Returns:
true if this map contains no key-value mappings; false otherwise.

containsKey

public boolean containsKey(long key)
Indicates if this UtlLinkedLongMap contains a mapping for the specified key.

Parameters:
key - the key whose presence in this map is to be tested.
Returns:
true if this map contains a mapping for the specified key; false otherwise.
Throws:
NullPointerException - if the key is null.

containsValue

public boolean containsValue(Object value)
Indicates if this UtlLinkedLongMap maps one or more keys to the specified value.

Parameters:
value - the value whose presence in this map is to be tested.
Returns:
true if this map maps one or more keys to the specified value.
Throws:
NullPointerException - if the key is null.

get

public V get(long key)
Returns the value to which this UtlLinkedLongMap maps the specified key.

Parameters:
key - the key whose associated value is to be returned.
Returns:
the value to which this map maps the specified key, or null if there is no mapping for the key.
Throws:
NullPointerException - if key is null.

getEntry

public UtlLinkedLongMap.Entry<V> getEntry(long key)
Returns the entry with the specified key.

Parameters:
key - the key whose associated entry is to be returned.
Returns:
the entry for the specified key or null if none.

put

public V put(long key,
             V value)
Associates the specified value with the specified key in this UtlLinkedLongMap. If the UtlLinkedLongMap previously contained a mapping for this key, the old value is replaced.

Parameters:
key - the key with which the specified value is to be associated.
value - the value to be associated with the specified key.
Returns:
the previous value associated with specified key, or null if there was no mapping for key. A null return can also indicate that the map previously associated null with the specified key.
Throws:
NullPointerException - if the key is null.

fastIterator

public UtlLinkedLongMap.FastIterator fastIterator()
Returns a reusable UtlLinkedLongMap.FastIterator over this UtlLinkedLongMap entries (unique instance per map). For example:
 
     // Iteration without memory allocation!
     for (FastIterator i=map.fastIterator().toFirst(); i.hasNext();) {
         Entry entry = i.nextEntry();
         ...
     }

Returns:
an iterator which can be reset for reuse over and over.
See Also:
UtlLinkedLongMap.FastIterator

remove

public V remove(long key)
Removes the mapping for this key from this UtlLinkedLongMap if present.

Parameters:
key - the key whose mapping is to be removed from the map.
Returns:
previous value associated with specified key, or null if there was no mapping for key. A null return can also indicate that the map previously associated null with the specified key.
Throws:
NullPointerException - if the key is null.

clear

public void clear()
Removes all mappings from this UtlLinkedLongMap.


setCapacity

public void setCapacity(int newCapacity)
Changes the current capacity of this UtlLinkedLongMap. If the capacity is increased, new entries are allocated and added to the pool. If the capacity is decreased, entries from the pool are deallocated (and are garbage collected eventually). The capacity also determined the number of buckets for the hash table.

Parameters:
newCapacity - the new capacity of this map.

hashCode

public int hashCode()
Returns the hash code value for this UtlLinkedLongMap.

Overrides:
hashCode in class Object
Returns:
the hash code value for this map.

toString

public String toString()
Returns a String representation of this UtlLinkedLongMap.

Overrides:
toString in class Object
Returns:
this.entrySet().toString();

values

public Collection<V> values()
Returns a collection view of the values contained in this UtlLinkedLongMap. The collection is backed by the map, so changes to the map are reflected in the collection, and vice-versa. The collection supports element removal, which removes the corresponding mapping from this map, via the Iterator.remove, Collection.remove, removeAll, retainAll, and clear operations. It does not support the add or addAll operations.

Returns:
a collection view of the values contained in this map.

entrySet

public Set<UtlLinkedLongMap.Entry<V>> entrySet()
Returns a collection view of the mappings contained in this UtlLinkedLongMap. Each element in the returned collection is a Map.Entry. The collection is backed by the map, so changes to the map are reflected in the collection, and vice-versa. The collection supports element removal, which removes the corresponding mapping from this map, via the Iterator.remove, Collection.remove, removeAll, retainAll, and clear operations. It does not support the add or addAll operations.

Returns:
a collection view of the mappings contained in this map.


Copyright © 2016 Neeve Research, LLC. All Rights Reserved.