com.ericsson.otp.erlang
Class OtpErlangMap

java.lang.Object
  extended by com.ericsson.otp.erlang.OtpErlangObject
      extended by com.ericsson.otp.erlang.OtpErlangMap
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable

public class OtpErlangMap
extends OtpErlangObject
implements java.io.Serializable, java.lang.Cloneable

Provides a Java representation of Erlang maps. Maps are created from one or more arbitrary Erlang terms.

The arity of the map is the number of elements it contains. The keys and values can be retrieved as arrays and the value for a key can be queried.

See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class com.ericsson.otp.erlang.OtpErlangObject
OtpErlangObject.Hash
 
Field Summary
 
Fields inherited from class com.ericsson.otp.erlang.OtpErlangObject
hashCodeValue
 
Constructor Summary
OtpErlangMap(OtpErlangObject[] keys, int kstart, int kcount, OtpErlangObject[] values, int vstart, int vcount)
          Create a map from an array of terms.
OtpErlangMap(OtpErlangObject[] keys, OtpErlangObject[] values)
          Create a map from an array of keys and an array of values.
OtpErlangMap(OtpInputStream buf)
          Create a map from a stream containing a map encoded in Erlang external format.
 
Method Summary
 int arity()
          Get the arity of the map.
 java.lang.Object clone()
           
protected  int doHashCode()
           
 void encode(OtpOutputStream buf)
          Convert this map to the equivalent Erlang external representation.
 boolean equals(java.lang.Object o)
          Determine if two maps are equal.
 OtpErlangObject get(OtpErlangObject key)
          Get the specified value from the map.
 OtpErlangObject[] keys()
          Get all the keys from the map as an array.
 java.lang.String toString()
          Get the string representation of the map.
 OtpErlangObject[] values()
          Get all the values from the map as an array.
 
Methods inherited from class com.ericsson.otp.erlang.OtpErlangObject
decode, hashCode
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

OtpErlangMap

public OtpErlangMap(OtpErlangObject[] keys,
                    OtpErlangObject[] values)
Create a map from an array of keys and an array of values.

Parameters:
keys - the array of terms to create the map keys from.
values - the array of terms to create the map values from.
Throws:
java.lang.IllegalArgumentException - if any array is empty (null) or contains null elements.

OtpErlangMap

public OtpErlangMap(OtpErlangObject[] keys,
                    int kstart,
                    int kcount,
                    OtpErlangObject[] values,
                    int vstart,
                    int vcount)
Create a map from an array of terms.

Parameters:
elems - the array of terms to create the map from.
start - the offset of the first term to insert.
vcount - the number of terms to insert.
Throws:
java.lang.IllegalArgumentException - if any array is empty (null) or contains null elements.

OtpErlangMap

public OtpErlangMap(OtpInputStream buf)
             throws OtpErlangDecodeException
Create a map from a stream containing a map encoded in Erlang external format.

Parameters:
buf - the stream containing the encoded map.
Throws:
OtpErlangDecodeException - if the buffer does not contain a valid external representation of an Erlang map.
Method Detail

arity

public int arity()
Get the arity of the map.

Returns:
the number of elements contained in the map.

get

public OtpErlangObject get(OtpErlangObject key)
Get the specified value from the map.

Parameters:
key - the key of the requested value.
Returns:
the requested value, of null if key is not a valid key.

keys

public OtpErlangObject[] keys()
Get all the keys from the map as an array.

Returns:
an array containing all of the map's keys.

values

public OtpErlangObject[] values()
Get all the values from the map as an array.

Returns:
an array containing all of the map's values.

toString

public java.lang.String toString()
Get the string representation of the map.

Specified by:
toString in class OtpErlangObject
Returns:
the string representation of the map.

encode

public void encode(OtpOutputStream buf)
Convert this map to the equivalent Erlang external representation.

Specified by:
encode in class OtpErlangObject
Parameters:
buf - an output stream to which the encoded map should be written.

equals

public boolean equals(java.lang.Object o)
Determine if two maps are equal. Maps are equal if they have the same arity and all of the elements are equal.

Specified by:
equals in class OtpErlangObject
Parameters:
o - the map to compare to.
Returns:
true if the maps have the same arity and all the elements are equal.

doHashCode

protected int doHashCode()
Overrides:
doHashCode in class OtpErlangObject

clone

public java.lang.Object clone()
Overrides:
clone in class OtpErlangObject