Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Util.Collections
Class LightMap  view LightMap download LightMap.java

java.lang.Object
  extended byUtil.Collections.LightMap
All Implemented Interfaces:
java.lang.Cloneable, java.util.Map, java.io.Serializable

public class LightMap
extends java.lang.Object
implements java.util.Map, java.lang.Cloneable, java.io.Serializable

LightMap is a very lightweight implementation of the java.util.Map interface.

Version:
$Id: LightMap.java,v 1.2 2003/05/12 10:05:21 joewhaley Exp $

Nested Class Summary
private static class LightMap.BinTreeNode
           
private static class LightMap.Entry
           
static class LightMap.Factory
           
 
Field Summary
private  int hash_code
           
private  LightMap.BinTreeNode root
           
private  int size
           
 
Constructor Summary
LightMap()
          Creates a LightMap.
 
Method Summary
private  void build_str(LightMap.BinTreeNode node, java.lang.StringBuffer buffer)
           
 void clear()
          Removes all mappings from this map.
 java.lang.Object clone()
          This method may be called to create a new copy of the Object.
private  int compute_hash_code(LightMap.BinTreeNode node)
           
 boolean containsKey(java.lang.Object key)
          Returns true if this map contains a mapping for the specified key.
 boolean containsValue(java.lang.Object value)
          Unsupported yet.
private  LightMap.BinTreeNode copy_tree(LightMap.BinTreeNode node)
           
 java.util.Set entrySet()
          Returns the set of entries of this map.
 boolean equals(java.lang.Object o)
          Compares the specified object with this map for equality.
private  LightMap.BinTreeNode extract_next(LightMap.BinTreeNode node)
           
private  LightMap.BinTreeNode extract_prev(LightMap.BinTreeNode node)
           
private  java.lang.Object finish_removal(LightMap.BinTreeNode node, LightMap.BinTreeNode prev, int son, LightMap.BinTreeNode m)
           
private static void get_entries(LightMap.BinTreeNode node, java.util.Set eset)
           
private static void get_keys(LightMap.BinTreeNode node, java.util.Set kset)
           
private static void get_values(LightMap.BinTreeNode node, java.util.Collection vals)
           
 java.lang.Object get(java.lang.Object key)
          Returns the value to which this map maps the specified key.
 int hashCode()
          Returns the hash code for this map.
 boolean isEmpty()
          Returns true if the map contains no mappings.
 java.util.Set keySet()
          Returns a set view of the keys contained in this map.
 java.lang.Object put(java.lang.Object key, java.lang.Object value)
          Associates the specified value with the specified key in this map.
 void putAll(java.util.Map map)
          Copies all of the mappings from the specified map to this map.
private  java.lang.Object remove_node(LightMap.BinTreeNode node, LightMap.BinTreeNode prev, int son)
           
private  java.lang.Object remove_semi_leaf(LightMap.BinTreeNode node, LightMap.BinTreeNode prev, int son, LightMap.BinTreeNode m)
           
 java.lang.Object remove(java.lang.Object key)
          Removes the mapping previously attached to key.
 int size()
          Returns the number of key-value mappings in the map.
 java.lang.String toString()
          Convert this Object to a human-readable String.
 java.util.Collection values()
          Returns a collection view of the values contained in this map.
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

size

private int size

root

private LightMap.BinTreeNode root

hash_code

private int hash_code
Constructor Detail

LightMap

public LightMap()
Creates a LightMap.

Method Detail

size

public final int size()
Description copied from interface: java.util.Map
Returns the number of key-value mappings in the map. If there are more than Integer.MAX_VALUE mappings, return Integer.MAX_VALUE.

Specified by:
size in interface java.util.Map

isEmpty

public final boolean isEmpty()
Description copied from interface: java.util.Map
Returns true if the map contains no mappings.

Specified by:
isEmpty in interface java.util.Map

containsKey

public final boolean containsKey(java.lang.Object key)
Returns true if this map contains a mapping for the specified key.

Specified by:
containsKey in interface java.util.Map

containsValue

public final boolean containsValue(java.lang.Object value)
Unsupported yet.

Specified by:
containsValue in interface java.util.Map

get

public final java.lang.Object get(java.lang.Object key)
Returns the value to which this map maps the specified key.

Specified by:
get in interface java.util.Map

put

public final java.lang.Object put(java.lang.Object key,
                                  java.lang.Object value)
Associates the specified value with the specified key in this map.

Specified by:
put in interface java.util.Map

remove

public final java.lang.Object remove(java.lang.Object key)
Removes the mapping previously attached to key. Returns the old mapping if any, or null otherwise.

Specified by:
remove in interface java.util.Map

remove_node

private final java.lang.Object remove_node(LightMap.BinTreeNode node,
                                           LightMap.BinTreeNode prev,
                                           int son)

remove_semi_leaf

private final java.lang.Object remove_semi_leaf(LightMap.BinTreeNode node,
                                                LightMap.BinTreeNode prev,
                                                int son,
                                                LightMap.BinTreeNode m)

finish_removal

private final java.lang.Object finish_removal(LightMap.BinTreeNode node,
                                              LightMap.BinTreeNode prev,
                                              int son,
                                              LightMap.BinTreeNode m)

extract_next

private final LightMap.BinTreeNode extract_next(LightMap.BinTreeNode node)

extract_prev

private final LightMap.BinTreeNode extract_prev(LightMap.BinTreeNode node)

putAll

public final void putAll(java.util.Map map)
                  throws java.lang.UnsupportedOperationException
Copies all of the mappings from the specified map to this map.

Specified by:
putAll in interface java.util.Map

clear

public final void clear()
                 throws java.lang.UnsupportedOperationException
Removes all mappings from this map.

Specified by:
clear in interface java.util.Map

values

public final java.util.Collection values()
Returns a collection view of the values contained in this map.

Specified by:
values in interface java.util.Map

get_values

private static final void get_values(LightMap.BinTreeNode node,
                                     java.util.Collection vals)

entrySet

public final java.util.Set entrySet()
                             throws java.lang.UnsupportedOperationException
Returns the set of entries of this map. The result is a Set of Map.Entry.

Specified by:
entrySet in interface java.util.Map

get_entries

private static final void get_entries(LightMap.BinTreeNode node,
                                      java.util.Set eset)

keySet

public final java.util.Set keySet()
Returns a set view of the keys contained in this map. Unlike the java.util maps, this set is NOT backed by the map (eg removing a key from the returned set has no effect on the map).

Specified by:
keySet in interface java.util.Map

get_keys

private static final void get_keys(LightMap.BinTreeNode node,
                                   java.util.Set kset)

copy_tree

private LightMap.BinTreeNode copy_tree(LightMap.BinTreeNode node)

clone

public java.lang.Object clone()
Description copied from class: java.lang.Object
This method may be called to create a new copy of the Object. The typical behavior is as follows:
  • o == o.clone() is false
  • o.getClass() == o.clone().getClass() is true
  • o.equals(o) is true

However, these are not strict requirements, and may be violated if necessary. Of the three requirements, the last is the most commonly violated, particularly if the subclass does not override Object.equals(Object)>Object.equals(Object) 55 .

If the Object you call clone() on does not implement java.lang.Cloneable (which is a placeholder interface), then a CloneNotSupportedException is thrown. Notice that Object does not implement Cloneable; this method exists as a convenience for subclasses that do.

Object's implementation of clone allocates space for the new Object using the correct class, without calling any constructors, and then fills in all of the new field values with the old field values. Thus, it is a shallow copy. However, subclasses are permitted to make a deep copy.

All array types implement Cloneable, and override this method as follows (it should never fail):

 public Object clone()
 {
   try
     {
       super.clone();
     }
   catch (CloneNotSupportedException e)
     {
       throw new InternalError(e.getMessage());
     }
 }
 


equals

public boolean equals(java.lang.Object o)
Description copied from interface: java.util.Map
Compares the specified object with this map for equality. Returns true if the other object is a Map with the same mappings, that is,
o instanceof Map && entrySet().equals(((Map) o).entrySet(); This allows comparison of maps, regardless of implementation.

Specified by:
equals in interface java.util.Map

hashCode

public int hashCode()
Description copied from interface: java.util.Map
Returns the hash code for this map. This is the sum of all hashcodes for each Map.Entry object in entrySet. This allows comparison of maps, regardless of implementation, and satisfies the contract of Object.hashCode.

Specified by:
hashCode in interface java.util.Map

compute_hash_code

private int compute_hash_code(LightMap.BinTreeNode node)

toString

public java.lang.String toString()
Description copied from class: java.lang.Object
Convert this Object to a human-readable String. There are no limits placed on how long this String should be or what it should contain. We suggest you make it as intuitive as possible to be able to place it into System.out.println() 55 and such.

It is typical, but not required, to ensure that this method never completes abruptly with a java.lang.RuntimeException.

This method will be called when performing string concatenation with this object. If the result is null, string concatenation will instead use "null".

The default implementation returns getClass().getName() + "@" + Integer.toHexString(hashCode()).


build_str

private void build_str(LightMap.BinTreeNode node,
                       java.lang.StringBuffer buffer)