Class ValueAdapter

All Implemented Interfaces:
org.neo4j.driver.internal.AsValue, InternalValue, MapAccessor, MapAccessorWithDefaultValue, Value
Direct Known Subclasses:
BooleanValue, BytesValue, ListValue, MapValue, NullValue, NumberValueAdapter, ObjectValueAdapter, StringValue, UnsupportedDateTimeValue

public abstract class ValueAdapter extends InternalMapAccessorWithDefaultValue implements InternalValue
  • Constructor Details

    • ValueAdapter

      public ValueAdapter()
  • Method Details

    • asValue

      public Value asValue()
      Description copied from interface: org.neo4j.driver.internal.AsValue
      Retrieve a value representation of this
      Specified by:
      asValue in interface org.neo4j.driver.internal.AsValue
      Returns:
      Value that represents this
      See Also:
    • hasType

      public boolean hasType(Type type)
      Description copied from interface: Value
      Test if this value is a value of the given type.
      Specified by:
      hasType in interface Value
      Parameters:
      type - the given type
      Returns:
      type.isTypeOf(this)
    • isTrue

      public boolean isTrue()
      Description copied from interface: Value
      Returns true if the value is a Boolean value and has the value True.
      Specified by:
      isTrue in interface Value
      Returns:
      true if the value is a Boolean value and has the value True
    • isFalse

      public boolean isFalse()
      Description copied from interface: Value
      Returns true if the value is a Boolean value and has the value False.
      Specified by:
      isFalse in interface Value
      Returns:
      true if the value is a Boolean value and has the value False
    • isNull

      public boolean isNull()
      Description copied from interface: Value
      Returns true if the value is a Null, otherwise false.
      Specified by:
      isNull in interface Value
      Returns:
      true if the value is a Null, otherwise false
    • containsKey

      public boolean containsKey(String key)
      Description copied from interface: MapAccessor
      Check if the list of keys contains the given key
      Specified by:
      containsKey in interface MapAccessor
      Parameters:
      key - the key
      Returns:
      true if this map keys contains the given key otherwise false
    • asString

      public String asString()
      Description copied from interface: Value
      Returns the value as a Java String, if possible.
      Specified by:
      asString in interface Value
      Returns:
      the value as a Java String, if possible
    • asBoolean

      public boolean asBoolean(boolean defaultValue)
      Description copied from interface: Value
      Returns the value as a Java boolean, if possible.
      Specified by:
      asBoolean in interface Value
      Parameters:
      defaultValue - return this value if the value is a NullValue
      Returns:
      the value as a Java boolean, if possible
    • asString

      public String asString(String defaultValue)
      Description copied from interface: Value
      Returns the value as a Java String, if possible.
      Specified by:
      asString in interface Value
      Parameters:
      defaultValue - return this value if the value is null
      Returns:
      the value as a Java String, if possible
    • asLong

      public long asLong(long defaultValue)
      Description copied from interface: Value
      Returns a Java long if no precision is lost in the conversion.
      Specified by:
      asLong in interface Value
      Parameters:
      defaultValue - return this default value if the value is a NullValue.
      Returns:
      the value as a Java long.
    • asInt

      public int asInt(int defaultValue)
      Description copied from interface: Value
      Returns a Java int if no precision is lost in the conversion.
      Specified by:
      asInt in interface Value
      Parameters:
      defaultValue - return this default value if the value is a NullValue.
      Returns:
      the value as a Java int.
    • asDouble

      public double asDouble(double defaultValue)
      Description copied from interface: Value
      Returns a Java double if no precision is lost in the conversion.
      Specified by:
      asDouble in interface Value
      Parameters:
      defaultValue - default to this value if the value is a NullValue.
      Returns:
      the value as a Java double.
    • asFloat

      public float asFloat(float defaultValue)
      Description copied from interface: Value
      Returns a Java float if no precision is lost in the conversion.
      Specified by:
      asFloat in interface Value
      Parameters:
      defaultValue - default to this value if the value is a NullValue
      Returns:
      the value as a Java float.
    • asLong

      public long asLong()
      Description copied from interface: Value
      Returns a Java long if no precision is lost in the conversion.
      Specified by:
      asLong in interface Value
      Returns:
      the value as a Java long.
    • asInt

      public int asInt()
      Description copied from interface: Value
      Returns a Java int if no precision is lost in the conversion.
      Specified by:
      asInt in interface Value
      Returns:
      the value as a Java int.
    • asFloat

      public float asFloat()
      Description copied from interface: Value
      Returns a Java float if no precision is lost in the conversion.
      Specified by:
      asFloat in interface Value
      Returns:
      the value as a Java float.
    • asDouble

      public double asDouble()
      Description copied from interface: Value
      Returns a Java double if no precision is lost in the conversion.
      Specified by:
      asDouble in interface Value
      Returns:
      the value as a Java double.
    • asBoolean

      public boolean asBoolean()
      Description copied from interface: Value
      Returns the value as a Java boolean, if possible.
      Specified by:
      asBoolean in interface Value
      Returns:
      the value as a Java boolean, if possible
    • asList

      public List<Object> asList()
      Description copied from interface: Value
      If the underlying type can be viewed as a list, returns a java list of values, where each value has been converted using Value.asObject().
      Specified by:
      asList in interface Value
      Returns:
      the value as a Java list of values, if possible
      See Also:
    • asList

      public <T> List<T> asList(Function<Value,T> mapFunction)
      Description copied from interface: Value
      Returns the value as a list of T obtained by mapping from the list elements, if possible.
      Specified by:
      asList in interface Value
      Type Parameters:
      T - the type of target list elements
      Parameters:
      mapFunction - a function to map from Value to T. See Values for some predefined functions, such as Values.ofBoolean(), Values.ofList(Function).
      Returns:
      the value as a list of T obtained by mapping from the list elements, if possible
      See Also:
    • asMap

      public Map<String,Object> asMap()
      Description copied from interface: MapAccessor
      Return the underlying map as a map of string keys and values converted using Value.asObject().

      This is equivalent to calling MapAccessor.asMap(Function) with Values.ofObject().

      Specified by:
      asMap in interface MapAccessor
      Returns:
      the value as a Java map
    • asMap

      public <T> Map<String,T> asMap(Function<Value,T> mapFunction)
      Description copied from interface: MapAccessor
      Return the underlying map as a map of string keys and values converted using the supplied function.
      Specified by:
      asMap in interface MapAccessor
      Type Parameters:
      T - the type of map values
      Parameters:
      mapFunction - a function to map from Value to T. See Values for some predefined functions, such as Values.ofBoolean(), Values.ofList(Function).
      Returns:
      the value as a map from string keys to values of type T obtained from mapping the original map values, if possible
      See Also:
    • asObject

      public Object asObject()
      Description copied from interface: Value
      This returns a java standard library representation of the underlying value, using a java type that is "sensible" given the underlying type. The mapping for common types is as follows:

      Note that the types in 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.

      Specified by:
      asObject in interface Value
      Returns:
      the value as a Java Object.
    • computeOrDefault

      public <T> T computeOrDefault(Function<Value,T> mapper, T defaultValue)
      Description copied from interface: Value
      Apply the mapping function on the value if the value is not a NullValue, or the default value if the value is a NullValue.
      Specified by:
      computeOrDefault in interface Value
      Type Parameters:
      T - The return type
      Parameters:
      mapper - The mapping function defines how to map a Value to T.
      defaultValue - the value to return if the value is a NullValue
      Returns:
      The value after applying the given mapping function or the default value if the value is NullValue.
    • asMap

      public Map<String,Object> asMap(Map<String,Object> defaultValue)
      Description copied from interface: Value
      Return as a map of string keys and values converted using Value.asObject().

      This is equivalent to calling Value.asMap(Function, Map) with Values.ofObject().

      Specified by:
      asMap in interface Value
      Parameters:
      defaultValue - default to this value if the value is a NullValue
      Returns:
      the value as a Java map
    • asMap

      public <T> Map<String,T> asMap(Function<Value,T> mapFunction, Map<String,T> defaultValue)
      Description copied from interface: Value
      Returns the value as a map from string keys to values of type T obtained from mapping he original map values, if possible.
      Specified by:
      asMap in interface Value
      Type Parameters:
      T - the type of map values
      Parameters:
      mapFunction - 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
      Returns:
      the value as a map from string keys to values of type T obtained from mapping he original map values, if possible
      See Also:
    • asByteArray

      public byte[] asByteArray(byte[] defaultValue)
      Description copied from interface: Value
      Returns the value as a Java byte array, if possible.
      Specified by:
      asByteArray in interface Value
      Parameters:
      defaultValue - default to this value if the original value is a NullValue
      Returns:
      the value as a Java byte array, if possible
    • asList

      public List<Object> asList(List<Object> defaultValue)
      Description copied from interface: Value
      If the underlying type can be viewed as a list, returns a java list of values, where each value has been converted using Value.asObject().
      Specified by:
      asList in interface Value
      Parameters:
      defaultValue - default to this value if the value is a NullValue
      Returns:
      the value as a Java list of values, if possible
      See Also:
    • asList

      public <T> List<T> asList(Function<Value,T> mapFunction, List<T> defaultValue)
      Description copied from interface: Value
      Returns the value as a list of T obtained by mapping from the list elements, if possible.
      Specified by:
      asList in interface Value
      Type Parameters:
      T - the type of target list elements
      Parameters:
      mapFunction - 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
      Returns:
      the value as a list of T obtained by mapping from the list elements, if possible
      See Also:
    • asLocalDate

      public LocalDate asLocalDate(LocalDate defaultValue)
      Description copied from interface: Value
      Returns the value as a LocalDate, if possible.
      Specified by:
      asLocalDate in interface Value
      Parameters:
      defaultValue - default to this value if the value is a NullValue
      Returns:
      the value as a LocalDate, if possible
    • asOffsetTime

      public OffsetTime asOffsetTime(OffsetTime defaultValue)
      Description copied from interface: Value
      Returns the value as a OffsetTime, if possible.
      Specified by:
      asOffsetTime in interface Value
      Parameters:
      defaultValue - default to this value if the value is a NullValue
      Returns:
      the value as a OffsetTime, if possible
    • asLocalTime

      public LocalTime asLocalTime(LocalTime defaultValue)
      Description copied from interface: Value
      Returns the value as a LocalTime, if possible.
      Specified by:
      asLocalTime in interface Value
      Parameters:
      defaultValue - default to this value if the value is a NullValue
      Returns:
      the value as a LocalTime, if possible
    • asLocalDateTime

      public LocalDateTime asLocalDateTime(LocalDateTime defaultValue)
      Description copied from interface: Value
      Returns the value as a LocalDateTime, if possible.
      Specified by:
      asLocalDateTime in interface Value
      Parameters:
      defaultValue - default to this value if the value is a NullValue
      Returns:
      the value as a LocalDateTime, if possible
    • asOffsetDateTime

      public OffsetDateTime asOffsetDateTime(OffsetDateTime defaultValue)
      Description copied from interface: Value
      Returns the value as a OffsetDateTime, if possible.
      Specified by:
      asOffsetDateTime in interface Value
      Parameters:
      defaultValue - default to this value if the value is a NullValue
      Returns:
      the value as a OffsetDateTime, if possible
    • asZonedDateTime

      public ZonedDateTime asZonedDateTime(ZonedDateTime defaultValue)
      Description copied from interface: Value
      Returns the value as a ZonedDateTime, if possible.
      Specified by:
      asZonedDateTime in interface Value
      Parameters:
      defaultValue - default to this value if the value is a NullValue
      Returns:
      the value as a ZonedDateTime, if possible
    • asIsoDuration

      public IsoDuration asIsoDuration(IsoDuration defaultValue)
      Description copied from interface: Value
      Returns the value as a IsoDuration, if possible.
      Specified by:
      asIsoDuration in interface Value
      Parameters:
      defaultValue - default to this value if the value is a NullValue
      Returns:
      the value as a IsoDuration, if possible
    • asPoint

      public Point asPoint(Point defaultValue)
      Description copied from interface: Value
      Returns the value as a Point, if possible.
      Specified by:
      asPoint in interface Value
      Parameters:
      defaultValue - default to this value if the value is a NullValue
      Returns:
      the value as a Point, if possible
    • asByteArray

      public byte[] asByteArray()
      Description copied from interface: Value
      Returns the value as a Java byte array, if possible.
      Specified by:
      asByteArray in interface Value
      Returns:
      the value as a Java byte array, if possible
    • asNumber

      public Number asNumber()
      Description copied from interface: Value
      Returns the value as a Java Number, if possible.
      Specified by:
      asNumber in interface Value
      Returns:
      the value as a Java Number, if possible
    • asEntity

      public Entity asEntity()
      Description copied from interface: Value
      Returns the value as a Entity, if possible.
      Specified by:
      asEntity in interface Value
      Returns:
      the value as a Entity, if possible
    • asNode

      public Node asNode()
      Description copied from interface: Value
      Returns the value as a Node, if possible.
      Specified by:
      asNode in interface Value
      Returns:
      the value as a Node, if possible
    • asPath

      public Path asPath()
      Description copied from interface: Value
      Returns the value as a Path, if possible.
      Specified by:
      asPath in interface Value
      Returns:
      the value as a Path, if possible
    • asRelationship

      public Relationship asRelationship()
      Description copied from interface: Value
      Returns the value as a Relationship, if possible.
      Specified by:
      asRelationship in interface Value
      Returns:
      the value as a Relationship, if possible
    • asLocalDate

      public LocalDate asLocalDate()
      Description copied from interface: Value
      Returns the value as a LocalDate, if possible.
      Specified by:
      asLocalDate in interface Value
      Returns:
      the value as a LocalDate, if possible
    • asOffsetTime

      public OffsetTime asOffsetTime()
      Description copied from interface: Value
      Returns the value as a OffsetTime, if possible.
      Specified by:
      asOffsetTime in interface Value
      Returns:
      the value as a OffsetTime, if possible
    • asLocalTime

      public LocalTime asLocalTime()
      Description copied from interface: Value
      Returns the value as a LocalTime, if possible.
      Specified by:
      asLocalTime in interface Value
      Returns:
      the value as a LocalTime, if possible
    • asLocalDateTime

      public LocalDateTime asLocalDateTime()
      Description copied from interface: Value
      Returns the value as a LocalDateTime, if possible.
      Specified by:
      asLocalDateTime in interface Value
      Returns:
      the value as a LocalDateTime, if possible
    • asOffsetDateTime

      public OffsetDateTime asOffsetDateTime()
      Description copied from interface: Value
      Returns the value as a OffsetDateTime, if possible.
      Specified by:
      asOffsetDateTime in interface Value
      Returns:
      the value as a OffsetDateTime, if possible
    • asZonedDateTime

      public ZonedDateTime asZonedDateTime()
      Description copied from interface: Value
      Returns the value as a ZonedDateTime, if possible.
      Specified by:
      asZonedDateTime in interface Value
      Returns:
      the value as a ZonedDateTime, if possible
    • asIsoDuration

      public IsoDuration asIsoDuration()
      Description copied from interface: Value
      Returns the value as a IsoDuration, if possible.
      Specified by:
      asIsoDuration in interface Value
      Returns:
      the value as a IsoDuration, if possible
    • asPoint

      public Point asPoint()
      Description copied from interface: Value
      Returns the value as a Point, if possible.
      Specified by:
      asPoint in interface Value
      Returns:
      the value as a Point, if possible
    • get

      public Value get(int index)
      Description copied from interface: Value
      Retrieve the value at the given index
      Specified by:
      get in interface Value
      Parameters:
      index - the index of the value
      Returns:
      the value or a NullValue if the index is out of bounds
    • get

      public Value get(String key)
      Description copied from interface: MapAccessor
      Retrieve the value of the property with the given key
      Specified by:
      get in interface MapAccessor
      Specified by:
      get in class InternalMapAccessorWithDefaultValue
      Parameters:
      key - the key of the property
      Returns:
      the property's value or a NullValue if no such key exists
    • size

      public int size()
      Description copied from interface: Value
      If the underlying value is a collection type, return the number of values in the collection.

      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.

      Specified by:
      size in interface MapAccessor
      Specified by:
      size in interface Value
      Returns:
      the number of values in an underlying collection
    • keys

      public Iterable<String> keys()
      Description copied from interface: Value
      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.
      Specified by:
      keys in interface MapAccessor
      Specified by:
      keys in interface Value
      Returns:
      the keys in the value
    • isEmpty

      public boolean isEmpty()
      Description copied from interface: Value
      If this value represents a list or map, test if the collection is empty.
      Specified by:
      isEmpty in interface Value
      Returns:
      true if size() is 0, otherwise false
    • values

      public Iterable<Value> values()
      Description copied from interface: MapAccessor
      Retrieve all values of the underlying collection
      Specified by:
      values in interface MapAccessor
      Returns:
      all values in unspecified order
    • values

      public <T> Iterable<T> values(Function<Value,T> mapFunction)
      Description copied from interface: MapAccessor
      Map and retrieve all values of the underlying collection
      Specified by:
      values in interface MapAccessor
      Type Parameters:
      T - the target type of mapping
      Parameters:
      mapFunction - a function to map from Value to T. See Values for some predefined functions, such as Values.ofBoolean(), Values.ofList(Function).
      Returns:
      the result of mapping all values in unspecified order
    • typeConstructor

      public final TypeConstructor typeConstructor()
      Specified by:
      typeConstructor in interface InternalValue
    • asMapped

      protected <T> T asMapped(Class<T> targetClass)
    • equals

      public abstract boolean equals(Object obj)
      Specified by:
      equals in interface Value
      Overrides:
      equals in class Object
    • hashCode

      public abstract int hashCode()
      Specified by:
      hashCode in interface Value
      Overrides:
      hashCode in class Object
    • toString

      public abstract String toString()
      Specified by:
      toString in interface Value
      Overrides:
      toString in class Object