Class DataKeyBase<T>

    • Constructor Detail

      • DataKeyBase

        public DataKeyBase​(@NotNull
                           java.lang.String name,
                           T defaultValue,
                           @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
                           java.lang.String name,
                           @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
                           java.lang.String name,
                           T defaultValue)
    • Method Detail

      • getName

        @NotNull
        public java.lang.String getName()
      • getDefaultValue

        public T getDefaultValue()
      • getDefaultValue

        public T getDefaultValue​(@NotNull
                                 DataHolder holder)
      • getFrom

        @Deprecated
        public final T getFrom​(@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 java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • equals

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

        public final int hashCode()
        Overrides:
        hashCode in class java.lang.Object