public class KdbDict extends Object
Provides the ability to represent (and generate) kdb dictionaries in a more Java friendly way. Objects are not thread-safe.
(c) 2014 - 2017 Sport Trades LtdModifier and Type | Field and Description |
---|---|
private Map<Object,Object> |
data
The dictionary as stored within Java
|
private static org.slf4j.Logger |
log |
Modifier and Type | Method and Description |
---|---|
KdbDict |
add(Object key,
Object value)
Adds a new key / value pair to the dictionary
|
KdbDict |
add(Object key,
Object value,
Class<?> elementType)
Adds a new key / value pair to the dictionary with
null detection |
c.Dict |
convertToDict()
Generates a
c.Dict for use before sending the object down the wire to a kdb process |
boolean |
equals(Object obj)
Delegates equality check to the underlying data store object (
data ) |
static KdbDict |
fromObject(Object object)
Generates a new
KdbDict object from an object. |
Object |
get(Object key) |
<T> T |
getAs(Object key,
Class<T> returnType)
Gets the specified key and also casts it to the specified type
|
Map<Object,Object> |
getDataStore() |
Map<String,Object> |
getDataStoreWithStringKeys()
Useful when the dictionary is from a table row as the keys will always be strings in this case.
|
List<Object> |
getKeys() |
List<String> |
getKeysAsString() |
Boolean |
has(Object key) |
int |
hashCode()
Delegates hash code calculation to underlying data store object (
data ) |
Boolean |
isEmpty() |
void |
setInitialDataSet(c.Dict kdbDict)
Takes the provided kdb dictionary and maps it into
data for use in this object |
String |
toString() |
KdbDict |
union(KdbDict that)
Allows the joining of 2 dictionaries of distinct elements together
|
public KdbDict()
public KdbDict(c.Dict kdbDict)
kdbDict
- The dictionary as received from kdb to generate this object frompublic void setInitialDataSet(c.Dict kdbDict) throws DataOverwriteNotPermittedException, UnsupportedOperationException
data
for use in this objectkdbDict
- The dictionary as received from kdb to generates this object fromDataOverwriteNotPermittedException
- If the dictionary already has data in itUnsupportedOperationException
- If the dictionary is does not contain object arrays, or if the x
and y
array lengths do not line uppublic KdbDict add(Object key, Object value) throws IllegalArgumentException, DataOverwriteNotPermittedException
Adds a new key / value pair to the dictionary
If the value object is a List
, it will be automatically converted to an array for proper serialisation to kdb.
NOTE: Java's null
cannot be provided as either the key or value parameter. If there is a possibility that the value
to be added might be null
, you should use add(Object, Object, Class)
.
IllegalArgumentException
- If either the key or value to be added to the dictionary are null
DataOverwriteNotPermittedException
- If there is already a key in the dictionary that matches the specified keypublic KdbDict add(Object key, Object value, Class<?> elementType) throws DataOverwriteNotPermittedException
Adds a new key / value pair to the dictionary with null
detection
If the specified value is null
, the appropriate kdb value is selected to represent null in the specified type.
elementType
- The expected type of the value. Used to derive the correct kdb value to represent null.DataOverwriteNotPermittedException
add(Object, Object)
,
Types.getKdbNullFor(Class)
public Object get(Object key)
HashMap.get(Object)
public <T> T getAs(Object key, Class<T> returnType) throws ClassCastException
key
- returnType
- The type that the object should be cast to before returningClassCastException
- If the cast fails for any reasonpublic List<String> getKeysAsString()
public Map<String,Object> getDataStoreWithStringKeys()
Objects.toString(Object)
)public KdbDict union(KdbDict that) throws DictUnionNotPermittedException
that
- The other dictionary to join togetherDictUnionNotPermittedException
- If there is one or more matching elements in both dictionariespublic c.Dict convertToDict()
c.Dict
for use before sending the object down the wire to a kdb processPrintableDict
public Boolean isEmpty()
public Boolean has(Object key)
true
if the dictionary contains the specified key, false
otherwiseHashMap.containsKey(Object)
public boolean equals(Object obj)
data
)public int hashCode()
data
)public static KdbDict fromObject(Object object) throws ClassCastException
Generates a new KdbDict
object from an object. This method will only succeed if the object provided can be cast into a c.Dict
.
Use this method along with KdbQuery
to convert a query result into a dictionary when one is expected.
object
- The object to generate a new KdbDict
fromnull
if the provided object is nullClassCastException
- If the specified object cannot be cast into a c.Dict
Copyright © 2017. All rights reserved.