Package com.datastax.astra.client.model
Class Document
java.lang.Object
com.datastax.astra.client.model.Document
- All Implemented Interfaces:
Serializable
,Map<String,
Object>
Represents a document without schema constraints as a Map<String, Object>.(key/value)
- See Also:
-
Nested Class Summary
-
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionPut the given key/value pair into this Document and return this.appendIfNotNull
(String key, Object value) Put the given key/value pair into this Document and return this only if the value is not nullvoid
clear()
boolean
containsKey
(Object key) boolean
containsValue
(Object value) static Document
create()
Create a document with no attributes.static Document
Create a document with an id.entrySet()
boolean
<T> T
Gets the value of the given key, casting it to the givenClass<T>
.<K> K[]
Return an Array of items.getBoolean
(String key) Gets the value of the given key as a Boolean.Access element from the mapAccess element from the mapAccess element from the mapGets the value of the given key as a Date.Access element from the mapGets the value of the given key as a Double.Access element from the map<T> T
Access the document identifiergetInstant
(String k) Access element from the mapgetInteger
(String key) Gets the value of the given key as an Integer.<T> List
<T> Gets the list value of the given key, casting the list elements to the givenClass<T>
.<T> List
<T> Gets the list value of the given key, casting the list elements toClass<T>
or returning the default list value if null.Gets the value of the given key as a Long.Access element from the mapAccess element from the mapGet value for similarity.Gets the value of the given key as a String.Access element from the mapOptional
<float[]> Get value for vector.Access attribute with vectorize name if any.int
hashCode()
<T> Document
id
(T id) Set value for the identifier.boolean
isEmpty()
keySet()
<T> T
Marshall as a document if needed.static Document
Parses a string in MongoDB Extended JSON format to aDocument
void
int
size()
toJson()
Serialization with Jackson.toString()
Serialization with Jackson.values()
vector
(float[] vector) Set the vector value.Add a vectorize attribute to the document.Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.util.Map
compute, computeIfAbsent, computeIfPresent, forEach, getOrDefault, merge, putIfAbsent, remove, replace, replace, replaceAll
-
Field Details
-
documentMap
Data to be used in the document.
-
-
Constructor Details
-
Document
public Document()Default Constructor. -
Document
Default Constructor.- Parameters:
id
- provide the unique identifier.
-
Document
Creates a Document instance initialized with the given map.- Parameters:
map
- initial map
-
-
Method Details
-
create
Create a document with an id.- Parameters:
id
- document identifier- Returns:
- instance of document
-
create
Create a document with no attributes.- Returns:
- instance of document
-
map
Marshall as a document if needed.- Type Parameters:
T
- current type- Parameters:
clazz
- target class- Returns:
- instance of pojo
-
parse
Parses a string in MongoDB Extended JSON format to aDocument
- Parameters:
json
- the JSON string- Returns:
- the document
-
append
Put the given key/value pair into this Document and return this. Useful for chaining puts in a single expression, e.g.doc.append("a", 1).append("b", 2)}
- Parameters:
key
- keyvalue
- value- Returns:
- this
-
appendIfNotNull
Put the given key/value pair into this Document and return this only if the value is not nulldoc.append("a", 1).append("b", 2)}
- Parameters:
key
- keyvalue
- value- Returns:
- this
-
get
Gets the value of the given key, casting it to the givenClass<T>
. This is useful to avoid having casts in client code, though the effect is the same. So to get the value of a key that is of type String, you would writeString name = doc.get("name", String.class)
instead ofString name = (String) doc.get("x")
.- Type Parameters:
T
- the type of the class- Parameters:
key
- the keyclazz
- the non-null class to cast the value to- Returns:
- the value of the given key, or null if the instance does not contain this key.
- Throws:
ClassCastException
- if the value of the given key is not of type T
-
getId
Access the document identifier- Type Parameters:
T
- type of id- Parameters:
clazz
- can be different type- Returns:
- value for object
-
id
Set value for the identifier.- Type Parameters:
T
- type of id- Parameters:
id
- id value- Returns:
- self reference
-
vectorize
Add a vectorize attribute to the document.- Parameters:
text
- value for the vectorize attribute- Returns:
- self reference
-
getVectorize
Access attribute with vectorize name if any.- Returns:
- value for vectorize
-
getVector
Get value for vector.- Returns:
- vector list
-
vector
Set the vector value.- Parameters:
vector
- vector value- Returns:
- self reference
-
getSimilarity
Get value for similarity.- Returns:
- vector list
-
getInteger
Gets the value of the given key as an Integer.- Parameters:
key
- the key- Returns:
- the value as an integer, which may be null
- Throws:
ClassCastException
- if the value is not an integer
-
getLong
Gets the value of the given key as a Long.- Parameters:
key
- the key- Returns:
- the value as a long, which may be null
- Throws:
ClassCastException
- if the value is not a long
-
getDouble
Gets the value of the given key as a Double.- Parameters:
key
- the key- Returns:
- the value as a double, which may be null
- Throws:
ClassCastException
- if the value is not a double
-
getString
Gets the value of the given key as a String.- Parameters:
key
- the key- Returns:
- the value as a String, which may be null
- Throws:
ClassCastException
- if the value is not a String
-
getBoolean
Gets the value of the given key as a Boolean.- Parameters:
key
- the key- Returns:
- the value as a Boolean, which may be null
- Throws:
ClassCastException
- if the value is not a boolean
-
getDate
Gets the value of the given key as a Date.- Parameters:
key
- the key- Returns:
- the value as a Date, which may be null
- Throws:
ClassCastException
- if the value is not a Date
-
getArray
Return an Array of items.- Type Parameters:
K
- type of item- Parameters:
k
- keyitemClass
- expected class- Returns:
- list of items
-
getObjectId
Access element from the map- Parameters:
k
- current configuration key- Returns:
- configuration value
-
getUUID
Access element from the map- Parameters:
k
- current configuration key- Returns:
- configuration value
-
getFloat
Access element from the map- Parameters:
k
- current configuration key- Returns:
- configuration value
-
getShort
Access element from the map- Parameters:
k
- current configuration key- Returns:
- configuration value
-
getByte
Access element from the map- Parameters:
k
- current configuration key- Returns:
- configuration value
-
getCharacter
Access element from the map- Parameters:
k
- current configuration key- Returns:
- configuration value
-
getDate
Access element from the map- Parameters:
k
- current configuration key- Returns:
- configuration value
-
getCalendar
Access element from the map- Parameters:
k
- current configuration key- Returns:
- configuration value
-
getInstant
Access element from the map- Parameters:
k
- current configuration key- Returns:
- configuration value
-
getList
Gets the list value of the given key, casting the list elements to the givenClass<T>
. This is useful to avoid having casts in client code, though the effect is the same.- Type Parameters:
T
- the type of the class- Parameters:
key
- the keyclazz
- the non-null class to cast the list value to- Returns:
- the list value of the given key, or null if the instance does not contain this key.
- Throws:
ClassCastException
- if the elements in the list value of the given key is not of type T or the value is not a list- Since:
- 3.10
-
getList
Gets the list value of the given key, casting the list elements toClass<T>
or returning the default list value if null. This is useful to avoid having casts in client code, though the effect is the same.- Type Parameters:
T
- the type of the class- Parameters:
key
- the keyclazz
- the non-null class to cast the list value todefaultValue
- what to return if the value is null- Returns:
- the list value of the given key, or the default list value if the instance does not contain this key.
- Throws:
ClassCastException
- if the value of the given key is not of type T- Since:
- 3.10
-
toString
Serialization with Jackson. -
toJson
Serialization with Jackson.- Returns:
- json string
-
size
public int size() -
isEmpty
public boolean isEmpty() -
containsValue
- Specified by:
containsValue
in interfaceMap<String,
Object>
-
containsKey
- Specified by:
containsKey
in interfaceMap<String,
Object>
-
get
-
put
-
remove
-
putAll
-
clear
public void clear() -
keySet
-
values
-
entrySet
-
equals
-
hashCode
public int hashCode()
-