edu.umd.cloud9.io.map
Class HMapIIW

java.lang.Object
  extended by edu.umd.cloud9.util.map.HMapII
      extended by edu.umd.cloud9.io.map.HMapIIW
All Implemented Interfaces:
MapII, Serializable, Cloneable, Writable

public class HMapIIW
extends HMapII
implements Writable

Writable representing a map where both keys and values are ints.

One notable feature of this class is the ability to support lazy decoding, controlled by the setLazyDecodeFlag(boolean) method. In lazy decoding mode, when an object of this type is deserialized, key-value pairs are not inserted into the map, but rather held in arrays. The reduces memory used in cases where random access to values is not required. In lazy decoding mode, the raw keys and values may be fetched by the getKeys() and getValues() methods, respectively. The map can be subsequently populated with the decode() method.

Author:
Jimmy Lin
See Also:
Serialized Form

Field Summary
 
Fields inherited from interface edu.umd.cloud9.util.map.MapII
DEFAULT_VALUE
 
Constructor Summary
HMapIIW()
          Creates a HMapIIW object.
 
Method Summary
static HMapIIW create(byte[] bytes)
          Creates a HMapIIW object from a byte array.
static HMapIIW create(DataInput in)
          Creates a HMapIIW object from a DataInput.
 void decode()
          In lazy decoding mode, populates the map with deserialized data.
 int[] getKeys()
          In lazy decoding mode, returns an array of all the keys if the map hasn't been decoded yet.
static boolean getLazyDecodeFlag()
          Returns the value of the lazy decoding flag
 int[] getValues()
          In lazy decoding mode, returns an array of all the values if the map hasn't been decoded yet.
 boolean isDecoded()
          Returns whether or not this map has been decoded.
 void lazyplus(HMapIIW m)
          In lazy decoding mode, adds values from keys of another map to this map.
 void readFields(DataInput in)
          Deserializes the map.
 byte[] serialize()
          Returns the serialized representation of this object as a byte array.
static void setLazyDecodeFlag(boolean b)
          Sets the lazy decoding flag.
 int size()
          Returns the number of key-value mappings in this map.
 void write(DataOutput out)
          Serializes the map.
 
Methods inherited from class edu.umd.cloud9.util.map.HMapII
clear, clone, containsKey, containsValue, dot, entrySet, get, getEntriesSortedByValue, getEntriesSortedByValue, increment, increment, isEmpty, keySet, plus, put, putAll, remove, toString, values
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface edu.umd.cloud9.util.map.MapII
equals, hashCode
 

Constructor Detail

HMapIIW

public HMapIIW()
Creates a HMapIIW object.

Method Detail

readFields

public void readFields(DataInput in)
                throws IOException
Deserializes the map.

Specified by:
readFields in interface Writable
Parameters:
in - source for raw byte representation
Throws:
IOException

decode

public void decode()
            throws IOException
In lazy decoding mode, populates the map with deserialized data. Otherwise, does nothing.

Throws:
IOException

isDecoded

public boolean isDecoded()
Returns whether or not this map has been decoded. If not in lazy decoding mode, this method always return true.


write

public void write(DataOutput out)
           throws IOException
Serializes the map.

Specified by:
write in interface Writable
Parameters:
out - where to write the raw byte representation
Throws:
IOException

serialize

public byte[] serialize()
                 throws IOException
Returns the serialized representation of this object as a byte array.

Returns:
byte array representing the serialized representation of this object
Throws:
IOException

create

public static HMapIIW create(DataInput in)
                      throws IOException
Creates a HMapIIW object from a DataInput.

Parameters:
in - source for reading the serialized representation
Returns:
a newly-created HMapIIW object
Throws:
IOException

create

public static HMapIIW create(byte[] bytes)
                      throws IOException
Creates a HMapIIW object from a byte array.

Parameters:
bytes - raw serialized representation
Returns:
a newly-created HMapIIW object
Throws:
IOException

setLazyDecodeFlag

public static void setLazyDecodeFlag(boolean b)
Sets the lazy decoding flag.


getLazyDecodeFlag

public static boolean getLazyDecodeFlag()
Returns the value of the lazy decoding flag


getKeys

public int[] getKeys()
In lazy decoding mode, returns an array of all the keys if the map hasn't been decoded yet. Otherwise, returns null.

Returns:
an array of all the keys

getValues

public int[] getValues()
In lazy decoding mode, returns an array of all the values if the map hasn't been decoded yet. Otherwise, returns null.

Returns:
an array of all the values

lazyplus

public void lazyplus(HMapIIW m)
In lazy decoding mode, adds values from keys of another map to this map. This map must have already been decoded, but the other map must not have been already decoded.

Parameters:
m - the other map

size

public int size()
Description copied from interface: MapII
Returns the number of key-value mappings in this map.

Specified by:
size in interface MapII
Overrides:
size in class HMapII
Returns:
the number of key-value mappings in this map