Package org.tensorics.core.tensor
Class ImmutableScalar<V>
- java.lang.Object
-
- org.tensorics.core.tensor.AbstractTensor<V>
-
- org.tensorics.core.tensor.AbstractScalar<V>
-
- org.tensorics.core.tensor.ImmutableScalar<V>
-
- Type Parameters:
V
- the type of the value of the scalar
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 theof(Object)
method. An immutable scalar with a non-empty context can be created by chaining theof(Object)
method with thewithContext(Position)
method.- See Also:
- Serialized Form
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description Position
context()
Retrieves the context of the tensor, which is nothing else than a position.static <V> ImmutableScalar<V>
of(V value)
Factory method for a scalar with an empty context.java.lang.String
toString()
V
value()
Has to retrieve the value of the scalar.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.ImmutableScalar<V>
withContext(Position newContext)
Returns a new scalar with the same value as this scalar, but the context overridden by the given one.-
Methods inherited from class org.tensorics.core.tensor.AbstractScalar
contains, get, get, shape
-
Methods inherited from class org.tensorics.core.tensor.AbstractTensor
equals, hashCode
-
-
-
-
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 isnull
-
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 isnull
-
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 isnull
-
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
.
-
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 callingTensoric.get(Object...)
with an empty array of coordinates and with callingTensoric.get(Position)
with an empty position.
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-