## ucar.multiarray
Class ScalarMultiArray

    java.lang.Object
      ucar.multiarray.ScalarMultiArray

All Implemented Interfaces:
  Accessor, MultiArray, MultiArrayInfo

public class ScalarMultiArray
extends Object
implements MultiArray

MultiArray implementation which can only contain single values, aka scalars. If you have a single object and want to wrap it in a MultiArray interface, use this class. Rank of these is always zero. The index argument to the set, setXXX, get, and getXXX is ignored.

When the component type is primitive, this class is an adapter for the appropriate java.lang primitive wrapper (Double, Float, and so on). One of the purposes of this class is to substitute for the wrappers in the MultiArray context, providing continuity of access method signature between arrays and scalars. Contrast this with the the discontinuity between java.util.reflect.Array.getDouble() and java.lang.Number.doubleValue().

See Also:
  `MultiArray`, `ArrayMultiArray`

Constructor Summary
`ScalarMultiArray(Class theComponentType)` Construct a new ScalarMultiArray with the specified component type.
`ScalarMultiArray(Class theComponentType, Object value)` Construct a new ScalarMultiArray with the specified component type and initialize it to the value given.
`ScalarMultiArray(Object value)` Construct a new ScalarMultiArray with component type value.getClass() and initialize it to the value given.

Method Summary
`void` `copyin(int[] origin, MultiArray src)` Aggregate write access.
`MultiArray` `copyout(int[] origin, int[] shape)` Aggregate read access.
`Object` `get(int[] index)` Retrieve the object in this container.
`boolean` `getBoolean(int[] index)` As if `(((Boolean)this.get(index)).booleanValue();` were called.
`byte` `getByte(int[] index)` As if `(((Number)this.get(index)).byteValue();` were called.
`char` `getChar(int[] index)` As if `(((Character)this.get(index)).charValue();` were called.
`Class` `getComponentType()` Returns the Class object representing the component type of the array.
`double` `getDouble(int[] index)` As if `(((Number)this.get(index)).doubleValue();` were called.
`float` `getFloat(int[] index)` As if `(((Number)this.get(index)).floatValue();` were called.
`int` `getInt(int[] index)` As if `(((Number)this.get(index)).intValue();` were called.
`int[]` `getLengths()` Always returns empty array for members of this class.
`long` `getLong(int[] index)` As if `(((Number)this.get(index)).longValue();` were called.
`int` `getRank()` Always returns zero for members of this class.
`short` `getShort(int[] index)` As if `(((Number)this.get(index)).shortValue();` were called.
`Object` `getStorage()` TODO: fishy semantics.
`boolean` `isScalar()` Alway `true` for members of this class.
`boolean` `isUnlimited()` Always returns `false` for members of this class.
`void` `set(int[] index, Object value)` Set the object contained here to value.
`void` `setBoolean(int[] index, boolean value)` Set the object contained here to a boolean value.
`void` `setByte(int[] index, byte value)` Set the object contained here to a byte value.
`void` `setChar(int[] index, char value)` Set the object contained here to a char value.
`void` `setDouble(int[] index, double value)` Set the object contained here to a double value.
`void` `setFloat(int[] index, float value)` Set the object contained here to a float value.
`void` `setInt(int[] index, int value)` Set the object contained here to a int value.
`void` `setLong(int[] index, long value)` Set the object contained here to a long value.
`void` `setShort(int[] index, short value)` Set the object contained here to a short value.
`Object` `toArray()` TODO: fishy semantics.
`Object` `toArray(Object oo, int[] origin, int[] shape)` TODO: fishy semantics.

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Constructor Detail

### ScalarMultiArray

    public ScalarMultiArray(Class theComponentType)

  Construct a new ScalarMultiArray with the specified component type. This form of constructor would typically be used for primitive component types such as java.lang.Double.TYPE.

Parameters:
  `theComponentType` - the Class object representing the component type of the new MultiArray

### ScalarMultiArray

    public ScalarMultiArray(Class theComponentType,
                            Object value)

  Construct a new ScalarMultiArray with the specified component type and initialize it to the value given. This form of constructor would typically be used for primitive component types such as java.lang.Double.TYPE, value would be a wrapped primitive of compatible class.

Parameters:
  `theComponentType` - the Class object representing the component type of the new MultiArray
  `value` - the initial value

### ScalarMultiArray

    public ScalarMultiArray(Object value)

  Construct a new ScalarMultiArray with component type value.getClass() and initialize it to the value given.

Parameters:
  `value` - the initial value

Method Detail

### getComponentType

    public Class getComponentType()

  Description copied from interface: `MultiArrayInfo`
  Returns the Class object representing the component type of the array.

  Specified by:
    `getComponentType` in interface `MultiArrayInfo`
  Returns:
    Class the component type
  See Also:
    `MultiArrayInfo.getComponentType()`

### getRank

    public int getRank()

  Always returns zero for members of this class.

  Specified by:
    `getRank` in interface `MultiArrayInfo`
  Returns:
    int 0
  See Also:
    `MultiArrayInfo.getRank()`

### getLengths

    public int[] getLengths()

  Always returns empty array for members of this class.

  Specified by:
    `getLengths` in interface `MultiArrayInfo`
  Returns:
    int array of length zero.
  See Also:
    `MultiArrayInfo.getLengths()`

### isUnlimited

    public boolean isUnlimited()

  Always returns `false` for members of this class.

  Specified by:
    `isUnlimited` in interface `MultiArrayInfo`
  Returns:
    boolean `false`
  See Also:
    `MultiArrayInfo.isUnlimited()`

### isScalar

    public boolean isScalar()

  Alway `true` for members of this class.

  Specified by:
    `isScalar` in interface `MultiArrayInfo`
  Returns:
    boolean `true`
  See Also:
    `MultiArrayInfo.isUnlimited()`

### get

    public Object get(int[] index)

  Retrieve the object in this container.

  Specified by:
    `get` in interface `Accessor`
  Parameters:
    `index` - ignored
  Returns:
    the Object contained herein
  See Also:
    `Accessor.get(int[])`

### getChar

    public char getChar(int[] index)

  As if `(((Character)this.get(index)).charValue();` were called.

  Specified by:
    `getChar` in interface `Accessor`
  See Also:
    `Accessor.getChar(int[])`, `get(int[])`, `Character.charValue()`

### getBoolean

    public boolean getBoolean(int[] index)

  As if `(((Boolean)this.get(index)).booleanValue();` were called.

  Specified by:
    `getBoolean` in interface `Accessor`
  See Also:
    `Accessor.getBoolean(int[])`, `get(int[])`, `Boolean.booleanValue()`

### getByte

    public byte getByte(int[] index)

  As if `(((Number)this.get(index)).byteValue();` were called.

  Specified by:
    `getByte` in interface `Accessor`
  See Also:
    `Accessor.getByte(int[])`, `get(int[])`, `Number.byteValue()`

### getShort

    public short getShort(int[] index)

  As if `(((Number)this.get(index)).shortValue();` were called.

  Specified by:
    `getShort` in interface `Accessor`
  See Also:
    `Accessor.getShort(int[])`, `get(int[])`, `Number.shortValue()`

### getInt

    public int getInt(int[] index)

  As if `(((Number)this.get(index)).intValue();` were called.

  Specified by:
    `getInt` in interface `Accessor`
  See Also:
    `Accessor.getInt(int[])`, `get(int[])`, `Number.intValue()`

### getLong

    public long getLong(int[] index)

  As if `(((Number)this.get(index)).longValue();` were called.

  Specified by:
    `getLong` in interface `Accessor`
  See Also:
    `Accessor.getLong(int[])`, `get(int[])`, `Number.longValue()`

### getFloat

    public float getFloat(int[] index)

  As if `(((Number)this.get(index)).floatValue();` were called.

  Specified by:
    `getFloat` in interface `Accessor`
  See Also:
    `Accessor.getFloat(int[])`, `get(int[])`, `Number.floatValue()`

### getDouble

    public double getDouble(int[] index)

  As if `(((Number)this.get(index)).doubleValue();` were called.

  Specified by:
    `getDouble` in interface `Accessor`
  See Also:
    `Accessor.getDouble(int[])`, `get(int[])`, `Number.doubleValue()`

### set

    public void set(int[] index,
                    Object value)

  Set the object contained here to value. The index argument is ignored.

  Specified by:
    `set` in interface `Accessor`
  Parameters:
    `index` - ignored
    `value` - the replacement contents
  See Also:
    `Accessor.set(int[], java.lang.Object)`

### setBoolean

    public void setBoolean(int[] index,
                           boolean value)

  Set the object contained here to a boolean value. The index argument is ignored.

  Specified by:
    `setBoolean` in interface `Accessor`
  Parameters:
    `index` - ignored
    `value` - the new value
  See Also:
    `Accessor.setBoolean(int[], boolean)`

### setChar

    public void setChar(int[] index,
                        char value)

  Set the object contained here to a char value. The index argument is ignored.

  Specified by:
    `setChar` in interface `Accessor`
  Parameters:
    `index` - ignored
    `value` - the new value
  See Also:
    `Accessor.setChar(int[], char)`

### setByte

    public void setByte(int[] index,
                        byte value)

  Set the object contained here to a byte value. The index argument is ignored.

  Specified by:
    `setByte` in interface `Accessor`
  Parameters:
    `index` - ignored
    `value` - the new value
  See Also:
    `Accessor.setByte(int[], byte)`

### setShort

    public void setShort(int[] index,
                         short value)

  Set the object contained here to a short value. The index argument is ignored.

  Specified by:
    `setShort` in interface `Accessor`
  Parameters:
    `index` - ignored
    `value` - the new value
  See Also:
    `Accessor.setShort(int[], short)`

### setInt

    public void setInt(int[] index,
                       int value)

  Set the object contained here to a int value. The index argument is ignored.

  Specified by:
    `setInt` in interface `Accessor`
  Parameters:
    `index` - ignored
    `value` - the new value
  See Also:
    `Accessor.setInt(int[], int)`

### setLong

    public void setLong(int[] index,
                        long value)

  Set the object contained here to a long value. The index argument is ignored.

  Specified by:
    `setLong` in interface `Accessor`
  Parameters:
    `index` - ignored
    `value` - the new value
  See Also:
    `Accessor.setLong(int[], long)`

### setFloat

    public void setFloat(int[] index,
                         float value)

  Set the object contained here to a float value. The index argument is ignored.

  Specified by:
    `setFloat` in interface `Accessor`
  Parameters:
    `index` - ignored
    `value` - the new value
  See Also:
    `Accessor.setFloat(int[], float)`

### setDouble

    public void setDouble(int[] index,
                          double value)

  Set the object contained here to a double value. The index argument is ignored.

  Specified by:
    `setDouble` in interface `Accessor`
  Parameters:
    `index` - ignored
    `value` - the new value
  See Also:
    `Accessor.setDouble(int[], double)`

### copyout

    public MultiArray copyout(int[] origin,
                              int[] shape)

  Description copied from interface: `Accessor`
  Aggregate read access. Return a new MultiArray of the same componentType as this, and with shape as specified, which is initialized to the values of this, as clipped to (origin, origin + shape).

  It is easier to implement than to specify :-).

  The main reason to implement this instead of using the equivalent proxy is for remote or file access.

  `assert(origin[ii] + shape[ii] <= lengths[ii]);`

  Specified by:
    `copyout` in interface `Accessor`
  Parameters:
    `origin` - int array specifying the starting index.
    `shape` - int array specifying the extents in each dimension. This becomes the shape of the return.
  Returns:
    the MultiArray with the specified shape
  See Also:
    `Accessor.copyout(int[], int[])`

### copyin

    public void copyin(int[] origin,
                       MultiArray src)
                throws IOException

  Description copied from interface: `Accessor`
  Aggregate write access. Given a MultiArray, copy it into this at the specified starting index. TODO: clearer specification.

  Hopefully this member can be optimized in various situations.

  `assert(origin[ii] + (source.getLengths())[ii] <= (getLengths())[ii]);`

  Specified by:
    `copyin` in interface `Accessor`
  Parameters:
    `origin` - int array specifying the starting index.
    `src` - MultiArray with the same componentType as this and shape smaller than `this.getLengths() - origin`
  Throws:
    `IOException`
  See Also:
    `Accessor.copyin(int[], ucar.multiarray.MultiArray)`

### toArray

    public Object toArray()

  TODO: fishy semantics.

  Specified by:
    `toArray` in interface `Accessor`
  Returns:
    a one dimensional Array containing all the elements in this MultiArray
  See Also:
    `Accessor.toArray()`

### getStorage

    public Object getStorage()

  TODO: fishy semantics.

  Specified by:
    `getStorage` in interface `MultiArray`
  Returns:
    a the original one dimensional Array containing all the elements in this MultiArray
  See Also:
    `Accessor.toArray()`

### toArray

    public Object toArray(Object oo,
                          int[] origin,
                          int[] shape)

  TODO: fishy semantics.

  Specified by:
    `toArray` in interface `Accessor`
  Returns:
    a one dimensional Array containing the specified elements
  See Also:
    `Accessor.toArray()`