public class ErlangValue extends Object implements Comparable<ErlangValue>
ErlangValue(Object)
for a list of compatible types.Modifier and Type | Class and Description |
---|---|
static interface |
ErlangValue.ListElementConverter<T>
Converts list elements to a desired type.
|
static class |
ErlangValue.StringListElementConverter
Converts list elements to
String s. |
Constructor and Description |
---|
ErlangValue(OtpErlangObject value)
Creates a new object wrapping the given erlang value.
|
ErlangValue(T value)
Creates a new object from a given set of Java types.
|
Modifier and Type | Method and Description |
---|---|
BigInteger |
bigIntValue()
Returns the Java BigInteger value of the wrapped erlang value.
|
List<byte[]> |
binaryListValue()
Returns a list of byte[] values of the wrapped erlang value.
|
byte[] |
binaryValue()
Returns the Java byte[] value of the wrapped erlang value.
|
boolean |
boolValue()
Returns the Java int value of the wrapped erlang value.
|
int |
compareTo(ErlangValue o)
Compares two erlang values by their string representation (expensive!).
|
static <T> OtpErlangObject |
convertToErlang(T value)
Converts a (supported) Java type to an
OtpErlangObject . |
List<Double> |
doubleListValue()
Returns a list of
Double values of the wrapped erlang value. |
double |
doubleValue()
Returns the Java double value of the wrapped erlang value.
|
boolean |
equals(Object obj) |
int |
hashCode() |
int |
intValue()
Returns the Java int value of the wrapped erlang value.
|
<T> List<T> |
jsonListValue(Class<T> c)
Returns a list of JSON objects (as an instance of the given class) of the
wrapped erlang value.
|
Map<String,Object> |
jsonValue()
Returns a JSON object (as
Map <String, Object>) of the
wrapped erlang value. |
<T> T |
jsonValue(Class<T> c)
Returns a JSON object (as an instance of the given class) of the wrapped
erlang value.
|
Collection<ErlangValue> |
listCollectionValue(Class<? extends Collection<ErlangValue>> clazz)
Returns a
Collection of mixed Java values (wrapped in
ErlangValue objects) of the wrapped erlang value (internally
represented as a list in Erlang). |
<T> Collection<T> |
listCollectionValue(Class<? extends Collection<T>> clazz,
ErlangValue.ListElementConverter<T> converter)
Returns a
Collection of mixed Java values of the wrapped erlang
value (internally represented as a list in Erlang). |
List<ErlangValue> |
listValue()
Returns a list of mixed Java values (wrapped in
ErlangValue
objects) of the wrapped erlang value. |
<T> List<T> |
listValue(ErlangValue.ListElementConverter<T> converter)
Returns a list of mixed Java values of the wrapped erlang value.
|
List<Long> |
longListValue()
Returns a list of
Long values of the wrapped erlang value. |
long |
longValue()
Returns the Java long value of the wrapped erlang value.
|
static OtpErlangList |
otpObjectToOtpList(OtpErlangObject value)
Converts an
OtpErlangObject to a OtpErlangList taking
special care if the OTP library converted a list to an
OtpErlangString . |
List<String> |
stringListValue()
Returns a list of
String values of the wrapped erlang value. |
String |
stringValue()
Returns the Java
String value of the wrapped erlang value. |
String |
toString() |
OtpErlangObject |
value()
Gets the original erlang value.
|
public ErlangValue(OtpErlangObject value)
value
- a value from erlangpublic ErlangValue(T value) throws ClassCastException
Boolean
- OtpErlangBoolean
Long
- OtpErlangLong
Integer
- OtpErlangLong
BigInteger
- OtpErlangLong
Double
- OtpErlangDouble
String
- OtpErlangString
OtpErlangBinary
List
<Object> with one of the native types except
byte[] or another (supported) list/map - OtpErlangList
Collection
<Object> same as List
<Object>
(internally represented as a list)Map
<String, Object> representing a JSON object -
OtpErlangTuple
OtpErlangObject
- an arbitrary erlang valueErlangValue
T
- the type of the valuevalue
- the value to convert to an erlang typeClassCastException
- if thrown if a conversion is not possible, i.e. the type is
not supportedpublic static <T> OtpErlangObject convertToErlang(T value) throws ClassCastException
OtpErlangObject
.T
- the type of the valuevalue
- the value to convert to an erlang typeClassCastException
- if thrown if a conversion is not possible, i.e. the type is
not supportedpublic boolean boolValue() throws ClassCastException
ClassCastException
- if thrown if a conversion is not possible, i.e. the type is
not supported or the value is too bigpublic int intValue() throws ClassCastException
ClassCastException
- if thrown if a conversion is not possible, i.e. the type is
not supported or the value is too bigpublic long longValue() throws ClassCastException
ClassCastException
- if thrown if a conversion is not possible, i.e. the type is
not supported or the value is too bigpublic BigInteger bigIntValue() throws ClassCastException
ClassCastException
- if thrown if a conversion is not possible, i.e. the type is
not supportedpublic double doubleValue() throws ClassCastException
ClassCastException
- if thrown if a conversion is not possible, i.e. the type is
not supportedpublic String stringValue() throws ClassCastException
String
value of the wrapped erlang value.ClassCastException
- if thrown if a conversion is not possible, i.e. the type is
not supportedpublic byte[] binaryValue() throws ClassCastException
ClassCastException
- if thrown if a conversion is not possible, i.e. the type is
not supportedpublic Map<String,Object> jsonValue() throws ClassCastException
Map
<String, Object>) of the
wrapped erlang value.ClassCastException
- if thrown if a conversion is not possible, i.e. the type is
not supportedpublic <T> T jsonValue(Class<T> c) throws ClassCastException
T
- the type of the object to createc
- the class of the created objectClassCastException
- if thrown if a conversion is not possible, i.e. the type is
not supportedpublic static OtpErlangList otpObjectToOtpList(OtpErlangObject value) throws ClassCastException
OtpErlangObject
to a OtpErlangList
taking
special care if the OTP library converted a list to an
OtpErlangString
.value
- the value to convertClassCastException
- if the conversion failspublic <T> List<T> listValue(ErlangValue.ListElementConverter<T> converter) throws ClassCastException
T
- type of the elements in the listconverter
- object that converts the list value to the desired typeClassCastException
- if thrown if a conversion is not possible, i.e. the type is
not supportedpublic <T> Collection<T> listCollectionValue(Class<? extends Collection<T>> clazz, ErlangValue.ListElementConverter<T> converter) throws ClassCastException
Collection
of mixed Java values of the wrapped erlang
value (internally represented as a list in Erlang).T
- type of the elements in the listclazz
- class of the result typeconverter
- object that converts the list value to the desired typeClassCastException
- if thrown if a conversion is not possible, i.e. the type is
not supportedpublic List<ErlangValue> listValue() throws ClassCastException
ErlangValue
objects) of the wrapped erlang value.ClassCastException
- if thrown if a conversion is not possible, i.e. the type is
not supportedpublic Collection<ErlangValue> listCollectionValue(Class<? extends Collection<ErlangValue>> clazz) throws ClassCastException
Collection
of mixed Java values (wrapped in
ErlangValue
objects) of the wrapped erlang value (internally
represented as a list in Erlang).clazz
- class of the result typeClassCastException
- if thrown if a conversion is not possible, i.e. the type is
not supportedpublic List<Long> longListValue() throws ClassCastException
Long
values of the wrapped erlang value.
Provided for convenience.ClassCastException
- if thrown if a conversion is not possible, i.e. the type is
not supportedlistValue(ListElementConverter)
public List<Double> doubleListValue() throws ClassCastException
Double
values of the wrapped erlang value.
Provided for convenience.ClassCastException
- if thrown if a conversion is not possible, i.e. the type is
not supportedlistValue(ListElementConverter)
public List<String> stringListValue() throws ClassCastException
String
values of the wrapped erlang value.
Provided for convenience.ClassCastException
- if thrown if a conversion is not possible, i.e. the type is
not supportedlistValue(ListElementConverter)
public List<byte[]> binaryListValue() throws ClassCastException
ClassCastException
- if thrown if a conversion is not possible, i.e. the type is
not supportedlistValue(ListElementConverter)
public <T> List<T> jsonListValue(Class<T> c) throws ClassCastException
T
- the type of the object to create as a list elementc
- the class of the created objectClassCastException
- if thrown if a conversion is not possible, i.e. the type is
not supportedlistValue(ListElementConverter)
public OtpErlangObject value()
public int compareTo(ErlangValue o)
compareTo
in interface Comparable<ErlangValue>
o
- another erlang value