JUtil

net.cscott.jutil
Class PersistentMap<K,V>

java.lang.Object
  extended by net.cscott.jutil.PersistentMap<K,V>
All Implemented Interfaces:
Serializable

public class PersistentMap<K,V>
extends Object
implements Serializable

PersistentMap implements a persistent map, based on a persistent randomized treap. Unlike the Maps returned by PersistentMapFactory, PersistentMap does not implement that standard Map API but instead exposes the underlying functional operations.

Version:
$Id: PersistentMap.java,v 1.7 2006-10-30 19:58:06 cananian Exp $
Author:
C. Scott Ananian
See Also:
Serialized Form

Constructor Summary
PersistentMap()
          Creates an empty PersistentMap whose key objects will all implement Comparable.
PersistentMap(Comparator<K> c)
          Creates an empty PersistentMap whose key objects are ordered by the given Comparator.
 
Method Summary
 Map<K,V> asMap()
          Collections view of the mapping.
 PersistentMap<K,V> clone()
          Cloning takes constant time, regardless of the size of the map.
 boolean containsKey(K key)
          Determines if there is a mapping for the given key.
 V get(K key)
          Gets the value which key maps to.
 int hashCode()
           
 boolean isEmpty()
          Determines if this PersistentMap has any mappings.
 PersistentMap<K,V> put(K key, V value)
          Creates and returns a new PersistentMap identical to this one, except it contains a mapping from key to value.
 PersistentMap<K,V> putAll(PersistentMap<K,V> map)
          Put all the mappings in the given map into this map, throwing out conflicting mappings from this set as necessary.
 PersistentMap<K,V> remove(K key)
          Make a new PersistentMap identical to this one, except that it does not contain a mapping for key.
 int size()
          Count the number of key->value mappings in this PersistentMap.
 String toString()
          Human-readable representation of the map.
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

PersistentMap

public PersistentMap()
Creates an empty PersistentMap whose key objects will all implement Comparable. Note that good hashcode implementations for the key objects are still required.


PersistentMap

public PersistentMap(Comparator<K> c)
Creates an empty PersistentMap whose key objects are ordered by the given Comparator. Note that good hashcode implementations for the key objects are still required.

Method Detail

isEmpty

public boolean isEmpty()
Determines if this PersistentMap has any mappings.


size

public int size()
Count the number of key->value mappings in this PersistentMap.


put

public PersistentMap<K,V> put(K key,
                              V value)
Creates and returns a new PersistentMap identical to this one, except it contains a mapping from key to value.


get

public V get(K key)
Gets the value which key maps to.


containsKey

public boolean containsKey(K key)
Determines if there is a mapping for the given key.


remove

public PersistentMap<K,V> remove(K key)
Make a new PersistentMap identical to this one, except that it does not contain a mapping for key.


putAll

public PersistentMap<K,V> putAll(PersistentMap<K,V> map)
Put all the mappings in the given map into this map, throwing out conflicting mappings from this set as necessary.


clone

public PersistentMap<K,V> clone()
Cloning takes constant time, regardless of the size of the map.

Overrides:
clone in class Object

toString

public String toString()
Human-readable representation of the map.

Overrides:
toString in class Object

hashCode

public int hashCode()
Overrides:
hashCode in class Object

asMap

public Map<K,V> asMap()
Collections view of the mapping.


JUtil

Copyright (c) 2006 C. Scott Ananian