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

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

public class LinearMap<K,V>
extends java.lang.Object
implements java.util.Map<K,V>, java.lang.Cloneable, java.io.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.3 $
Author:
$Author: toeukpap $
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from interface java.util.Map
java.util.Map.Entry<K,V>
 
Constructor Summary
LinearMap()
          Creates a LinearMap.
LinearMap(int capacity)
          Creates a LinearMap with specified capacity.
LinearMap(java.util.Map map)
           
 
Method Summary
 void clear()
           
 boolean containsKey(java.lang.Object key)
           
 boolean containsValue(java.lang.Object value)
           
 java.util.Set entrySet()
          must return the same collection everytime as defined in the Map interface
 int find(java.lang.Object key)
          find the index of a key
 int findValue(V value)
          find the index of a key
 V get(java.lang.Object key)
           
 boolean isEmpty()
           
 java.util.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(java.util.Map<? extends K,? extends V> t)
           
 V putBefore(K refKey, K key, V value)
           
 V remove(java.lang.Object key)
           
 int size()
           
 java.lang.String toString()
           
 java.util.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(java.util.Map map)
Method Detail

entrySet

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

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

put

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

putBefore

public V putBefore(K refKey,
                   K key,
                   V value)
Parameters:
refKey -
key -
value - Throws IllegalArgumentException when the refKey does not exist
Returns:
old value

remove

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

keySet

public java.util.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 java.util.Map<K,V>

find

public int find(java.lang.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 java.util.Map<K,V>

containsKey

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

containsValue

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

get

public V get(java.lang.Object key)
Specified by:
get in interface java.util.Map<K,V>

isEmpty

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

putAll

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

size

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

values

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

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

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object


Copyright © 2010 KnowledgePlaza. All Rights Reserved.