@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() |
double |
asDouble()
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.
|
int |
asInt()
Returns a Java int if no precision is lost in the conversion.
|
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) |
long |
asLong()
Returns a Java long if no precision is lost in the conversion.
|
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.
|
Path |
asPath() |
Relationship |
asRelationship() |
String |
asString() |
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, valuesint 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 MapAccessorboolean isEmpty()
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 MapAccessorValue 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()
boolean isFalse()
boolean isNull()
Object asObject()
TypeSystem.INTEGER() - LongTypeSystem.FLOAT() - DoubleTypeSystem.NUMBER() - NumberTypeSystem.STRING() - StringTypeSystem.BOOLEAN() - BooleanTypeSystem.NULL() - nullTypeSystem.NODE() - NodeTypeSystem.RELATIONSHIP() - RelationshipTypeSystem.PATH() - PathTypeSystem.MAP() - MapTypeSystem.LIST() - ListTypeSystem 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.String asString()
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.int asInt()
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.float asFloat()
LossyCoercion - if it is not possible to convert the value without loosing precision.Uncoercible - if value types are incompatible.List<Object> asList()
asObject().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 functionsEntity 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.Copyright © 2017. All rights reserved.