Interface ValuesModel<T>

Type Parameters:
T - type

public interface ValuesModel<T>
Low-level model of a type whose instances are created from the values of their components, e.g. a record or an immutable collection. Knows how to read the values and to create an instance from them; what and how to copy is decided by the caller.
  • Method Summary

    Modifier and Type
    Method
    Description
    create(Object[] values)
    Creates an instance from the values of the components.
    default Field
    fieldOf(int index)
    Returns the field which holds the value of the component, so the field actions and values of the cloner apply to the component: e.g.
    Returns the type.
    default boolean
    Tells whether the values are hashed by the created instance (elements of a set, keys of a map).
    default boolean
    Tells whether the values are keys and values of a map in pairs.
    nameOf(int index)
    Returns the name of the component for messages.
    read(T object)
    Reads the values of the components.
  • Method Details

    • getType

      Class<T> getType()
      Returns the type.
      Returns:
      type
    • nameOf

      String nameOf(int index)
      Returns the name of the component for messages.
      Parameters:
      index - index of the value
      Returns:
      name of the component
    • fieldOf

      default Field fieldOf(int index)
      Returns the field which holds the value of the component, so the field actions and values of the cloner apply to the component: e.g. the field of a record component.
      Parameters:
      index - index of the value
      Returns:
      field or null if the component has no field, e.g. an element of a collection
    • hashesKeys

      default boolean hashesKeys()
      Tells whether the values are hashed by the created instance (elements of a set, keys of a map). Hash codes of copied values may be final only when the whole object graph is copied.
      Returns:
      true if values (or keys, see isMap()) are hashed
    • isMap

      default boolean isMap()
      Tells whether the values are keys and values of a map in pairs.
      Returns:
      true for a map
    • read

      Object[] read(T object)
      Reads the values of the components.
      Parameters:
      object - object
      Returns:
      values of the components
    • create

      T create(Object[] values)
      Creates an instance from the values of the components. If the constructor fails, throws ClonerException with the exception of the constructor as the cause.
      Parameters:
      values - values of the components
      Returns:
      new instance