@Immutable public interface Value extends MapAccessor, MapAccessorWithDefaultValue
isType
methods along with
typeValue
methods. The first set of these correlate with types from
the Neo4j Type System and are used to determine which Neo4j type is represented.
The second set of methods perform coercions to Java types (wherever possible).
For example, a common String value should be tested for using isString
and extracted using stringValue
.
Value
lets you navigate arbitrary tree
structures without having to resort to type casting.
Given a tree structure like:
{
users : [
{ name : "Anders" },
{ name : "John" }
]
}
You can retrieve the name of the second user, John, like so:
String username = value.get("users").get(1).get("name").asString();
You can also easily iterate over the users:
List<String> names = new LinkedList<>();
for(Value user : value.get("users").values() )
{
names.add(user.get("name").asString());
}
Modifier and Type | Method and Description |
---|---|
boolean |
asBoolean() |
boolean |
asBoolean(boolean defaultValue) |
byte[] |
asByteArray() |
byte[] |
asByteArray(byte[] defaultValue) |
double |
asDouble()
Returns a Java double if no precision is lost in the conversion.
|
double |
asDouble(double defaultValue)
Returns a Java double if no precision is lost in the conversion.
|
Entity |
asEntity() |
float |
asFloat()
Returns a Java float if no precision is lost in the conversion.
|
float |
asFloat(float defaultValue)
Returns a Java float if no precision is lost in the conversion.
|
int |
asInt()
Returns a Java int if no precision is lost in the conversion.
|
int |
asInt(int defaultValue)
Returns a Java int if no precision is lost in the conversion.
|
IsoDuration |
asIsoDuration() |
IsoDuration |
asIsoDuration(IsoDuration defaultValue) |
List<Object> |
asList()
If the underlying type can be viewed as a list, returns a java list of
values, where each value has been converted using
asObject() . |
<T> List<T> |
asList(Function<Value,T> mapFunction) |
<T> List<T> |
asList(Function<Value,T> mapFunction,
List<T> defaultValue) |
List<Object> |
asList(List<Object> defaultValue)
If the underlying type can be viewed as a list, returns a java list of
values, where each value has been converted using
asObject() . |
LocalDate |
asLocalDate() |
LocalDate |
asLocalDate(LocalDate defaultValue) |
LocalDateTime |
asLocalDateTime() |
LocalDateTime |
asLocalDateTime(LocalDateTime defaultValue) |
LocalTime |
asLocalTime() |
LocalTime |
asLocalTime(LocalTime defaultValue) |
long |
asLong()
Returns a Java long if no precision is lost in the conversion.
|
long |
asLong(long defaultValue)
Returns a Java long if no precision is lost in the conversion.
|
<T> Map<String,T> |
asMap(Function<Value,T> mapFunction,
Map<String,T> defaultValue) |
Map<String,Object> |
asMap(Map<String,Object> defaultValue)
Return as a map of string keys and values converted using
asObject() . |
Node |
asNode() |
Number |
asNumber() |
Object |
asObject()
This returns a java standard library representation of the underlying value,
using a java type that is "sensible" given the underlying type.
|
OffsetDateTime |
asOffsetDateTime() |
OffsetDateTime |
asOffsetDateTime(OffsetDateTime defaultValue) |
OffsetTime |
asOffsetTime() |
OffsetTime |
asOffsetTime(OffsetTime defaultValue) |
Path |
asPath() |
Point |
asPoint() |
Point |
asPoint(Point defaultValue) |
Relationship |
asRelationship() |
String |
asString() |
String |
asString(String defaultValue) |
ZonedDateTime |
asZonedDateTime() |
ZonedDateTime |
asZonedDateTime(ZonedDateTime defaultValue) |
<T> T |
computeOrDefault(Function<Value,T> mapper,
T defaultValue)
|
boolean |
equals(Object other) |
Value |
get(int index)
Retrieve the value at the given index
|
int |
hashCode() |
boolean |
hasType(Type type)
Test if this value is a value of the given type
|
boolean |
isEmpty()
If this value represents a list or map, test if the collection is empty.
|
boolean |
isFalse() |
boolean |
isNull() |
boolean |
isTrue() |
Iterable<String> |
keys()
If the underlying value supports
key-based indexing , return an iterable of the keys in the
map, this applies to map , node and TypeSystem.RELATIONSHIP() relationship} values. |
int |
size()
If the underlying value is a collection type, return the number of values in the collection.
|
String |
toString() |
Type |
type() |
asMap, asMap, containsKey, get, values, values
int size()
For TypeSystem.LIST()
list} values, this will return the size of the list.
For map
values, this will return the number of entries in the map.
For node
and TypeSystem.RELATIONSHIP()
relationship} values,
this will return the number of properties.
For path
values, this returns the length (number of relationships) in the path.
size
in interface MapAccessor
boolean isEmpty()
true
if size() is 0, otherwise false
Iterable<String> keys()
key-based indexing
, return an iterable of the keys in the
map, this applies to map
, node
and TypeSystem.RELATIONSHIP()
relationship} values.keys
in interface MapAccessor
Value get(int index)
index
- the index of the valueNullValue
if the index is out of boundsClientException
- if record has not been initialized@Experimental Type type()
@Experimental boolean hasType(Type type)
type
- the given typeboolean isTrue()
true
if the value is a Boolean value and has the value True.boolean isFalse()
true
if the value is a Boolean value and has the value False.boolean isNull()
true
if the value is a Null, otherwise false
Object asObject()
TypeSystem.NULL()
- null
TypeSystem.LIST()
- List
TypeSystem.MAP()
- Map
TypeSystem.BOOLEAN()
- Boolean
TypeSystem.INTEGER()
- Long
TypeSystem.FLOAT()
- Double
TypeSystem.STRING()
- String
TypeSystem.BYTES()
- byte[]TypeSystem.DATE()
- LocalDate
TypeSystem.TIME()
- OffsetTime
TypeSystem.LOCAL_TIME()
- LocalTime
TypeSystem.DATE_TIME()
- ZonedDateTime
TypeSystem.LOCAL_DATE_TIME()
- LocalDateTime
TypeSystem.DURATION()
- IsoDuration
TypeSystem.POINT()
- Point
TypeSystem.NODE()
- Node
TypeSystem.RELATIONSHIP()
- Relationship
TypeSystem.PATH()
- Path
TypeSystem
refers to the Neo4j type system
where TypeSystem.INTEGER()
and TypeSystem.FLOAT()
are both
64-bit precision. This is why these types return java Long
and
Double
, respectively.boolean asBoolean()
Uncoercible
- if value types are incompatible.boolean asBoolean(boolean defaultValue)
defaultValue
- return this value if the value is a NullValue
.Uncoercible
- if value types are incompatible.byte[] asByteArray()
Uncoercible
- if value types are incompatible.byte[] asByteArray(byte[] defaultValue)
defaultValue
- default to this value if the original value is a NullValue
Uncoercible
- if value types are incompatible.String asString()
Uncoercible
- if value types are incompatible.String asString(String defaultValue)
defaultValue
- return this value if the value is null.Uncoercible
- if value types are incompatible.Number asNumber()
Uncoercible
- if value types are incompatible.long asLong()
LossyCoercion
- if it is not possible to convert the value without loosing precision.Uncoercible
- if value types are incompatible.long asLong(long defaultValue)
defaultValue
- return this default value if the value is a NullValue
.LossyCoercion
- if it is not possible to convert the value without loosing precision.Uncoercible
- if value types are incompatible.int asInt()
LossyCoercion
- if it is not possible to convert the value without loosing precision.Uncoercible
- if value types are incompatible.int asInt(int defaultValue)
defaultValue
- return this default value if the value is a NullValue
.LossyCoercion
- if it is not possible to convert the value without loosing precision.Uncoercible
- if value types are incompatible.double asDouble()
LossyCoercion
- if it is not possible to convert the value without loosing precision.Uncoercible
- if value types are incompatible.double asDouble(double defaultValue)
defaultValue
- default to this value if the value is a NullValue
.LossyCoercion
- if it is not possible to convert the value without loosing precision.Uncoercible
- if value types are incompatible.float asFloat()
LossyCoercion
- if it is not possible to convert the value without loosing precision.Uncoercible
- if value types are incompatible.float asFloat(float defaultValue)
defaultValue
- default to this value if the value is a NullValue
LossyCoercion
- if it is not possible to convert the value without loosing precision.Uncoercible
- if value types are incompatible.List<Object> asList()
asObject()
.asObject()
List<Object> asList(List<Object> defaultValue)
asObject()
.defaultValue
- default to this value if the value is a NullValue
asObject()
<T> List<T> asList(Function<Value,T> mapFunction)
T
- the type of target list elementsmapFunction
- a function to map from Value to T. See Values
for some predefined functions, such
as Values.ofBoolean()
, Values.ofList(Function)
.for a long list of built-in conversion functions
<T> List<T> asList(Function<Value,T> mapFunction, List<T> defaultValue)
T
- the type of target list elementsmapFunction
- a function to map from Value to T. See Values
for some predefined functions, such
as Values.ofBoolean()
, Values.ofList(Function)
.defaultValue
- default to this value if the value is a NullValue
for a long list of built-in conversion functions
Entity asEntity()
Entity
, if possible.Uncoercible
- if value types are incompatible.Node asNode()
Node
, if possible.Uncoercible
- if value types are incompatible.Relationship asRelationship()
Relationship
, if possible.Uncoercible
- if value types are incompatible.Path asPath()
Path
, if possible.Uncoercible
- if value types are incompatible.LocalDate asLocalDate()
LocalDate
, if possible.Uncoercible
- if value types are incompatible.OffsetTime asOffsetTime()
OffsetTime
, if possible.Uncoercible
- if value types are incompatible.LocalTime asLocalTime()
LocalTime
, if possible.Uncoercible
- if value types are incompatible.LocalDateTime asLocalDateTime()
LocalDateTime
, if possible.Uncoercible
- if value types are incompatible.OffsetDateTime asOffsetDateTime()
OffsetDateTime
, if possible.Uncoercible
- if value types are incompatible.ZonedDateTime asZonedDateTime()
ZonedDateTime
, if possible.Uncoercible
- if value types are incompatible.IsoDuration asIsoDuration()
IsoDuration
, if possible.Uncoercible
- if value types are incompatible.Point asPoint()
Point
, if possible.Uncoercible
- if value types are incompatible.LocalDate asLocalDate(LocalDate defaultValue)
defaultValue
- default to this value if the value is a NullValue
LocalDate
, if possible.Uncoercible
- if value types are incompatible.OffsetTime asOffsetTime(OffsetTime defaultValue)
defaultValue
- default to this value if the value is a NullValue
OffsetTime
, if possible.Uncoercible
- if value types are incompatible.LocalTime asLocalTime(LocalTime defaultValue)
defaultValue
- default to this value if the value is a NullValue
LocalTime
, if possible.Uncoercible
- if value types are incompatible.LocalDateTime asLocalDateTime(LocalDateTime defaultValue)
defaultValue
- default to this value if the value is a NullValue
LocalDateTime
, if possible.Uncoercible
- if value types are incompatible.OffsetDateTime asOffsetDateTime(OffsetDateTime defaultValue)
defaultValue
- default to this value if the value is a NullValue
OffsetDateTime
, if possible.Uncoercible
- if value types are incompatible.ZonedDateTime asZonedDateTime(ZonedDateTime defaultValue)
defaultValue
- default to this value if the value is a NullValue
ZonedDateTime
, if possible.Uncoercible
- if value types are incompatible.IsoDuration asIsoDuration(IsoDuration defaultValue)
defaultValue
- default to this value if the value is a NullValue
IsoDuration
, if possible.Uncoercible
- if value types are incompatible.Point asPoint(Point defaultValue)
defaultValue
- default to this value if the value is a NullValue
Point
, if possible.Uncoercible
- if value types are incompatible.Map<String,Object> asMap(Map<String,Object> defaultValue)
asObject()
.
This is equivalent to calling asMap(Function, Map)
with Values.ofObject()
.defaultValue
- default to this value if the value is a NullValue
<T> Map<String,T> asMap(Function<Value,T> mapFunction, Map<String,T> defaultValue)
T
- the type of map valuesmapFunction
- a function to map from Value to T. See Values
for some predefined functions, such
as Values.ofBoolean()
, Values.ofList(Function)
.defaultValue
- default to this value if the value is a NullValue
for a long list of built-in conversion functions