Class DataKeyBase<T>

java.lang.Object
com.vladsch.flexmark.util.data.DataKeyBase<T>
All Implemented Interfaces:
MutableDataValueSetter<T>
Direct Known Subclasses:
DataKey, NullableDataKey

public abstract class DataKeyBase<T> extends Object implements MutableDataValueSetter<T>
  • Field Details

    • name

      @NotNull private final @NotNull String name
    • factory

      @NotNull private final @NotNull DataValueFactory<T> factory
    • defaultValue

      private final T defaultValue
  • Constructor Details

    • DataKeyBase

      public DataKeyBase(@NotNull @NotNull String name, T defaultValue, @NotNull @NotNull DataValueFactory<T> factory)
      Creates a NullableDataKey with a computed default value and a provided default value when data holder is null.

      Use this constructor to ensure that factory is never called with null data holder value

      Parameters:
      name - See getName().
      defaultValue - default to use when data holder is null
      factory - data value factory for creating a new default value for the key for a non-null data holder
    • DataKeyBase

      public DataKeyBase(@NotNull @NotNull String name, @NotNull @NotNull DataKeyBase<T> defaultKey)
      Creates a NullableDataKey with a dynamic default value taken from a value of another key

      does not cache the returned default value but will always delegate to another key until this key gets its own value set.

      Parameters:
      name - See getName().
      defaultKey - The NullableDataKey to take the default value from at time of construction.
    • DataKeyBase

      public DataKeyBase(@NotNull @NotNull String name, T defaultValue)
  • Method Details

    • getName

      @NotNull public @NotNull String getName()
    • getFactory

      @NotNull public @NotNull DataValueFactory<T> getFactory()
    • getDefaultValue

      public T getDefaultValue()
    • getDefaultValue

      public T getDefaultValue(@NotNull @NotNull DataHolder holder)
    • get

      public T get(@Nullable @Nullable DataHolder holder)
    • getFrom

      @Deprecated public final T getFrom(@Nullable @Nullable DataHolder holder)
      Deprecated.
      use get
      Parameters:
      holder - data holder
      Returns:
      return default value if holder is null, current value in holder or compute a new value
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • equals

      public final boolean equals(Object o)
      Compare only by address. Every key instance is unique
      Overrides:
      equals in class Object
      Parameters:
      o - other
      Returns:
      true if equal
    • hashCode

      public final int hashCode()
      Overrides:
      hashCode in class Object