com.ericsson.otp.erlang
Class OtpErlangList

java.lang.Object
  extended by com.ericsson.otp.erlang.OtpErlangObject
      extended by com.ericsson.otp.erlang.OtpErlangList
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, java.lang.Iterable<OtpErlangObject>
Direct Known Subclasses:
OtpErlangList.SubList

public class OtpErlangList
extends OtpErlangObject
implements java.lang.Iterable<OtpErlangObject>

Provides a Java representation of Erlang lists. Lists are created from zero or more arbitrary Erlang terms.

The arity of the list is the number of elements it contains.

See Also:
Serialized Form

Nested Class Summary
static class OtpErlangList.SubList
           
 
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
OtpErlangList()
          Create an empty list.
OtpErlangList(OtpErlangObject elem)
          Create a list containing one element.
OtpErlangList(OtpErlangObject[] elems)
          Create a list from an array of arbitrary Erlang terms.
OtpErlangList(OtpErlangObject[] elems, int start, int count)
          Create a list from an array of arbitrary Erlang terms.
OtpErlangList(OtpErlangObject[] elems, OtpErlangObject lastTail)
          Create a list from an array of arbitrary Erlang terms.
OtpErlangList(OtpInputStream buf)
          Create a list from a stream containing an list encoded in Erlang external format.
OtpErlangList(java.lang.String str)
          Create a list of Erlang integers representing Unicode codePoints.
 
Method Summary
 int arity()
          Get the arity of the list.
<T> OtpErlangObject
bind(T binds)
          Make new Erlang term replacing variables with the respective values from bindings argument(s).
 java.lang.Object clone()
           
protected  int doHashCode()
           
 OtpErlangObject elementAt(int i)
          Get the specified element from the list.
 OtpErlangObject[] elements()
          Get all the elements from the list as an array.
 void encode(OtpOutputStream buf)
          Convert this list to the equivalent Erlang external representation.
protected  void encode(OtpOutputStream buf, int start)
           
 boolean equals(java.lang.Object o)
          Determine if two lists are equal.
 OtpErlangObject getHead()
           
 OtpErlangObject getLastTail()
           
 OtpErlangObject getNthTail(int n)
           
 OtpErlangObject getTail()
           
 boolean isProper()
           
 java.util.Iterator<OtpErlangObject> iterator()
           
<T> boolean
match(OtpErlangObject term, T bindings)
          Perform match operation against given term.
 java.lang.String stringValue()
          Convert a list of integers into a Unicode string, interpreting each integer as a Unicode code point value.
 java.lang.String toString()
          Get the string representation of the list.
protected  java.lang.String toString(int start)
           
 
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

OtpErlangList

public OtpErlangList()
Create an empty list.


OtpErlangList

public OtpErlangList(java.lang.String str)
Create a list of Erlang integers representing Unicode codePoints. This method does not check if the string contains valid code points.

Parameters:
str - the characters from which to create the list.

OtpErlangList

public OtpErlangList(OtpErlangObject elem)
Create a list containing one element.

Parameters:
elem - the elememet to make the list from.

OtpErlangList

public OtpErlangList(OtpErlangObject[] elems)
Create a list from an array of arbitrary Erlang terms.

Parameters:
elems - the array of terms from which to create the list.

OtpErlangList

public OtpErlangList(OtpErlangObject[] elems,
                     OtpErlangObject lastTail)
              throws OtpErlangException
Create a list from an array of arbitrary Erlang terms. Tail can be specified, if not null, the list will not be proper.

Parameters:
elems - array of terms from which to create the list
lastTail -
Throws:
OtpErlangException

OtpErlangList

public OtpErlangList(OtpErlangObject[] elems,
                     int start,
                     int count)
Create a list from an array of arbitrary Erlang terms.

Parameters:
elems - the array of terms from which to create the list.
start - the offset of the first term to insert.
count - the number of terms to insert.

OtpErlangList

public OtpErlangList(OtpInputStream buf)
              throws OtpErlangDecodeException
Create a list from a stream containing an list encoded in Erlang external format.

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

arity

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

Returns:
the number of elements contained in the list.

elementAt

public OtpErlangObject elementAt(int i)
Get the specified element from the list.

Parameters:
i - the index of the requested element. List elements are numbered as array elements, starting at 0.
Returns:
the requested element, of null if i is not a valid element index.

elements

public OtpErlangObject[] elements()
Get all the elements from the list as an array.

Returns:
an array containing all of the list's elements.

toString

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

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

toString

protected java.lang.String toString(int start)

encode

public void encode(OtpOutputStream buf)
Convert this list to the equivalent Erlang external representation. Note that this method never encodes lists as strings, even when it is possible to do so.

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

encode

protected void encode(OtpOutputStream buf,
                      int start)

equals

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

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

match

public <T> boolean match(OtpErlangObject term,
                         T bindings)
Description copied from class: OtpErlangObject
Perform match operation against given term.

Overrides:
match in class OtpErlangObject
Parameters:
term - the object to match
bindings - variable bindings
Returns:
true if match succeeded

bind

public <T> OtpErlangObject bind(T binds)
                     throws OtpErlangException
Description copied from class: OtpErlangObject
Make new Erlang term replacing variables with the respective values from bindings argument(s).

Overrides:
bind in class OtpErlangObject
Parameters:
binds - variable bindings
Returns:
new term
Throws:
OtpErlangException

getLastTail

public OtpErlangObject getLastTail()

doHashCode

protected int doHashCode()
Overrides:
doHashCode in class OtpErlangObject

clone

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

iterator

public java.util.Iterator<OtpErlangObject> iterator()
Specified by:
iterator in interface java.lang.Iterable<OtpErlangObject>

isProper

public boolean isProper()
Returns:
true if the list is proper, i.e. the last tail is nil

getHead

public OtpErlangObject getHead()

getTail

public OtpErlangObject getTail()

getNthTail

public OtpErlangObject getNthTail(int n)

stringValue

public java.lang.String stringValue()
                             throws OtpErlangException
Convert a list of integers into a Unicode string, interpreting each integer as a Unicode code point value.

Returns:
A java.lang.String object created through its constructor String(int[], int, int).
Throws:
OtpErlangException - for non-proper and non-integer lists.
OtpErlangRangeException - if any integer does not fit into a Java int.
java.security.InvalidParameterException - if any integer is not within the Unicode range.
See Also:
String.String(int[], int, int)