public abstract class ComplexData extends Object
ComplexOutput
Commands typically result in simple types, however some of the commands could return complex nested structures. In these
cases, and with the help of a ComplexDataParser
, the data gathered by the ComplexOutput
could be parsed to a
domain object.
An complex data object could only be an aggregate data type as per the RESP2 and RESP3 protocol definitions. Its contents, however, could be both the simple and aggregate data types.
For RESP2 the only possible aggregation is an array. RESP2 commands could also return sets (obviously, by simply making sure the elements of the array are unique) or maps (by sending the keys as odd elements and their values as even elements in the right order one after another.
For RESP3 all the three aggregate types are supported (and indicated with special characters when the result is returned by the server).
Aggregate data types could also be nested by using the storeObject(Object)
call.
Implementations of this class override the getDynamicSet()
, getDynamicList()
and
getDynamicMap()
methods to return the data received in the server in a implementation of the Collections
framework. If a given implementation could not do the conversion in a meaningful way an UnsupportedOperationException
would be thrown.
ComplexOutput
,
ArrayComplexData
,
SetComplexData
,
MapComplexData
Constructor and Description |
---|
ComplexData() |
Modifier and Type | Method and Description |
---|---|
List<Object> |
getDynamicList()
Returns the aggregate data in a
List form. |
Map<Object,Object> |
getDynamicMap()
Returns the aggregate data in a
Map form. |
Set<Object> |
getDynamicSet()
Returns the aggregate data in a
Set form. |
void |
store(boolean value)
Store a
boolean value in the underlying data structure |
void |
store(double value)
Store a
double value in the underlying data structure |
void |
store(long value)
Store a
long value in the underlying data structure |
void |
store(String value) |
abstract void |
storeObject(Object value)
Store an
Object value in the underlying data structure. |
public void store(long value)
long
value in the underlying data structurevalue
- the value to storepublic void store(double value)
double
value in the underlying data structurevalue
- the value to storepublic void store(boolean value)
boolean
value in the underlying data structurevalue
- the value to storepublic abstract void storeObject(Object value)
Object
value in the underlying data structure. This method should be used when nesting one instance of
ComplexData
inside anothervalue
- the value to storepublic void store(String value)
public List<Object> getDynamicList()
List
form. If the underlying implementation could not convert the data structure
to a List
then an UnsupportedOperationException
would be thrown.public Set<Object> getDynamicSet()
Set
form. If the underlying implementation could not convert the data structure
to a Set
then an UnsupportedOperationException
would be thrown.Copyright © 2024 lettuce.io. All rights reserved.