Class ImmutableScalar<V>

  • Type Parameters:
    V - the type of the value of the scalar
    All Implemented Interfaces:
    java.io.Serializable, Scalar<V>, Tensor<V>, Tensoric<V>

    public final class ImmutableScalar<V>
    extends AbstractScalar<V>
    implements java.io.Serializable
    An immutable implementation of a scalar (a tensor with zero dimensions and exactly one value). To construct a simple scalar (with an empty context), use the of(Object) method. An immutable scalar with a non-empty context can be created by chaining the of(Object) method with the withContext(Position) method.
    See Also:
    Serialized Form
    • Method Detail

      • of

        public static <V> ImmutableScalar<V> of​(V value)
        Factory method for a scalar with an empty context.
        Parameters:
        value - the value of the scalar
        Returns:
        a new scalar with the given value
        Throws:
        java.lang.NullPointerException - if the given value is null
      • withContext

        public final ImmutableScalar<V> withContext​(Position newContext)
        Returns a new scalar with the same value as this scalar, but the context overridden by the given one.
        Parameters:
        newContext - the context for the new scalar instance
        Returns:
        a new immutable scalar with the new context
        Throws:
        java.lang.NullPointerException - if the given context is null
      • withContext

        public final ImmutableScalar<V> withContext​(java.lang.Object... coordinates)
        Returns a new scalar with the same value as this scalar, but the context overridden by a position constructed from the given coordinates.
        Parameters:
        coordinates - the coordinates for the context of the new scalar instance
        Returns:
        a new immutable scalar with the new context
        Throws:
        java.lang.NullPointerException - if the given context is null
      • context

        public Position context()
        Description copied from interface: Tensor
        Retrieves the context of the tensor, which is nothing else than a position. As context of the tensor we understand coordinates within a higher dimensional space than than the tensor has itself. This coordinates can e.g. transport information when e.g. a higher-dimensional tensor is split into smaller ones, so that it can potentially be reconstructed afterwards.

        Implementations have to guarantee that the returned value here is never null.

        Specified by:
        context in interface Tensor<V>
        Returns:
        the context of the tensor.
      • value

        public V value()
        Description copied from interface: Scalar
        Has to retrieve the value of the scalar. In implementations, this has to be equivalent to calling Tensoric.get(Object...) with an empty array of coordinates and with calling Tensoric.get(Position) with an empty position.
        Specified by:
        value in interface Scalar<V>
        Returns:
        the internal value of the scalar
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object