nl.knowledgeplaza.util
Class LinearMap<K,V>

java.lang.Object
  extended by nl.knowledgeplaza.util.LinearMap<K,V>
All Implemented Interfaces:
Serializable, Cloneable, Map<K,V>
Direct Known Subclasses:
JdbcUtil.JdbcMap, ParameterSet

public class LinearMap<K,V>
extends Object
implements Map<K,V>, Cloneable, Serializable

LinearMap is a simplistic light-weight Map designed for use when the number of entries is small. It is backed by a ArrayList. TreeMap is not a 100% replacement, since TreeMap does not allow for NULL as a key.

Version:
$Revision: 1.4 $
Author:
$Author: toeukpap $
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from interface java.util.Map
Map.Entry<K,V>
 
Constructor Summary
LinearMap()
          Creates a LinearMap.
LinearMap(int capacity)
          Creates a LinearMap with specified capacity.
LinearMap(Map map)
           
 
Method Summary
 void clear()
           
 boolean containsKey(Object key)
           
 boolean containsValue(Object value)
           
 Set entrySet()
          must return the same collection everytime as defined in the Map interface
 int find(Object key)
          find the index of a key
 int findValue(V value)
          find the index of a key
 V get(Object key)
           
 K getKeyAt(int idx)
           
 V getValueAt(int idx)
           
 boolean isEmpty()
           
 Set<K> keySet()
          Return a set with all keys must return the same collection everytime as defined in the Map interface
 V put(K key, V value)
           
 void putAll(Map<? extends K,? extends V> t)
           
 V putAt(int idx, K key, V value)
          Put key in certain place in index
 V putBefore(K refKey, K key, V value)
          Append to end
 V remove(Object key)
           
 V removeAt(int lIdx)
           
 int size()
           
 String toString()
           
 Collection<V> values()
          must return the same collection everytime as defined in the Map interface
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.Map
equals, hashCode
 

Constructor Detail

LinearMap

public LinearMap()
Creates a LinearMap.


LinearMap

public LinearMap(int capacity)
Creates a LinearMap with specified capacity.


LinearMap

public LinearMap(Map map)
Method Detail

entrySet

public Set entrySet()
must return the same collection everytime as defined in the Map interface

Specified by:
entrySet in interface Map<K,V>

put

public V put(K key,
             V value)
Specified by:
put in interface Map<K,V>

putBefore

public V putBefore(K refKey,
                   K key,
                   V value)
Append to end

Parameters:
refKey -
key -
value - Throws IllegalArgumentException when the refKey does not exist
Returns:
old value

putAt

public V putAt(int idx,
               K key,
               V value)
Put key in certain place in index

Parameters:
idx -
key -
value -
Returns:

removeAt

public V removeAt(int lIdx)

remove

public V remove(Object key)
Specified by:
remove in interface Map<K,V>

keySet

public Set<K> keySet()
Return a set with all keys must return the same collection everytime as defined in the Map interface

Specified by:
keySet in interface Map<K,V>

find

public int find(Object key)
find the index of a key

Returns:
idx (> 0) or -1 when not found

findValue

public int findValue(V value)
find the index of a key

Returns:
idx (> 0) or -1 when not found

clear

public void clear()
Specified by:
clear in interface Map<K,V>

containsKey

public boolean containsKey(Object key)
Specified by:
containsKey in interface Map<K,V>

containsValue

public boolean containsValue(Object value)
Specified by:
containsValue in interface Map<K,V>

getKeyAt

public K getKeyAt(int idx)
Parameters:
idx -
Returns:

getValueAt

public V getValueAt(int idx)
Parameters:
idx -
Returns:

get

public V get(Object key)
Specified by:
get in interface Map<K,V>
Parameters:
key -

isEmpty

public boolean isEmpty()
Specified by:
isEmpty in interface Map<K,V>

putAll

public void putAll(Map<? extends K,? extends V> t)
Specified by:
putAll in interface Map<K,V>

size

public int size()
Specified by:
size in interface Map<K,V>

values

public Collection<V> values()
must return the same collection everytime as defined in the Map interface

Specified by:
values in interface Map<K,V>

toString

public String toString()
Overrides:
toString in class Object


Copyright © 2012 KnowledgePlaza. All Rights Reserved.