Package com.ericsson.otp.erlang
Class OtpErlangList
- java.lang.Object
-
- com.ericsson.otp.erlang.OtpErlangObject
-
- 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
Nested Classes Modifier and Type Class Description static classOtpErlangList.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
Constructors Constructor Description 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
All Methods Instance Methods Concrete Methods Modifier and Type Method Description intarity()Get the arity of the list.<T> OtpErlangObjectbind(T binds)Make new Erlang term replacing variables with the respective values from bindings argument(s).java.lang.Objectclone()protected intdoHashCode()OtpErlangObjectelementAt(int i)Get the specified element from the list.OtpErlangObject[]elements()Get all the elements from the list as an array.voidencode(OtpOutputStream buf)Convert this list to the equivalent Erlang external representation.protected voidencode(OtpOutputStream buf, int start)booleanequals(java.lang.Object o)Determine if two lists are equal.OtpErlangObjectgetHead()OtpErlangObjectgetLastTail()OtpErlangObjectgetNthTail(int n)OtpErlangObjectgetTail()booleanisProper()java.util.Iterator<OtpErlangObject>iterator()<T> booleanmatch(OtpErlangObject term, T bindings)Perform match operation against given term.java.lang.StringstringValue()Convert a list of integers into a Unicode string, interpreting each integer as a Unicode code point value.java.lang.StringtoString()Get the string representation of the list.protected java.lang.StringtoString(int start)-
Methods inherited from class com.ericsson.otp.erlang.OtpErlangObject
decode, hashCode
-
-
-
-
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 listlastTail-- 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:
toStringin classOtpErlangObject- 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:
encodein classOtpErlangObject- 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:
equalsin classOtpErlangObject- 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:OtpErlangObjectPerform match operation against given term.- Overrides:
matchin classOtpErlangObject- Parameters:
term- the object to matchbindings- variable bindings- Returns:
- true if match succeeded
-
bind
public <T> OtpErlangObject bind(T binds) throws OtpErlangException
Description copied from class:OtpErlangObjectMake new Erlang term replacing variables with the respective values from bindings argument(s).- Overrides:
bindin classOtpErlangObject- Parameters:
binds- variable bindings- Returns:
- new term
- Throws:
OtpErlangException
-
getLastTail
public OtpErlangObject getLastTail()
-
doHashCode
protected int doHashCode()
- Overrides:
doHashCodein classOtpErlangObject
-
clone
public java.lang.Object clone()
- Overrides:
clonein classOtpErlangObject
-
iterator
public java.util.Iterator<OtpErlangObject> iterator()
- Specified by:
iteratorin interfacejava.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 OtpErlangExceptionConvert 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(int[], int, int)
-
-