Package uk.ac.starlink.array
Class WrapperArrayImpl
- java.lang.Object
-
- uk.ac.starlink.array.WrapperArrayImpl
-
- All Implemented Interfaces:
ArrayImpl
- Direct Known Subclasses:
ConvertArrayImpl
,MouldArrayImpl
,PixelMapArrayImpl
,WindowArrayImpl
public class WrapperArrayImpl extends java.lang.Object implements ArrayImpl
Base class for NDArray-wrapping implementations of ArrayImpl. Instances of this class present an ArrayImpl interface based on an NDArray object; in a sense doing the reverse of what BridgeNDArray does. On its own this is not useful, but subclasses of this class can arrange to modify some of the method implementations to represent an array object with different qualities based on the wrapped NDArray. The resulting object can then be turned into a new NDArray by passing it to the BridgeNDArray constructor. In this way it is quite easy to produce a new NDArray from a base NDArray (typically with data generated on the fly from the accessor of the base), giving a virtual view of the base NDArray with modified properties such as shape or type. Doing it via an ArrayImpl rather than wrapping the NDArray directly makes the implementation much less effort; for instance tile read/write methods do not need to be implemented and guarantees about the validity of many method parameters can be assumed.- Author:
- Mark Taylor (Starlink)
- See Also:
BridgeNDArray
-
-
Constructor Summary
Constructors Constructor Description WrapperArrayImpl(NDArray nda)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
canMap()
Indicates whether mapped access is available.void
close()
Shuts down this ArrayImpl for pixel access.AccessImpl
getAccess()
Returns an object which can access the pixels of this ArrayImpl.java.lang.Number
getBadValue()
The magic bad value for data.java.lang.Object
getMapped()
Returns a single primitive array holding all the pixel data of this array.OrderedNDShape
getShape()
Returns an object representing the shape (origin and dimensions) and pixel sequence of this object.Type
getType()
Returns the primitive type of the data held by this object.NDArray
getWrapped()
Returns the NDArray which this Wrapper is wrapping.boolean
isRandom()
Indicates whether random access is possible.boolean
isReadable()
Indicates whether read access is possible.boolean
isWritable()
Indicates whether write access is possible.boolean
multipleAccess()
Indicates whether the getAccess method may be called more than once.void
open()
Prepares this ArrayImpl for pixel access.java.lang.String
toString()
-
-
-
Constructor Detail
-
WrapperArrayImpl
public WrapperArrayImpl(NDArray nda)
-
-
Method Detail
-
getShape
public OrderedNDShape getShape()
Description copied from interface:ArrayImpl
Returns an object representing the shape (origin and dimensions) and pixel sequence of this object. The return value must not change over the lifetime of the object.
-
getType
public Type getType()
Description copied from interface:ArrayImpl
Returns the primitive type of the data held by this object. The return value must not change over the lifetime of the object.
-
getBadValue
public java.lang.Number getBadValue()
Description copied from interface:ArrayImpl
The magic bad value for data. The returned type should be one of the primitive wrapper types, Byte, Short, Integer, Float, Double as appropriate for the type of this array. It may be null if there is no bad value. The return value must not change over the lifetime of the object.- Specified by:
getBadValue
in interfaceArrayImpl
- Returns:
- the bad value
-
isReadable
public boolean isReadable()
Description copied from interface:ArrayImpl
Indicates whether read access is possible. Reads will only be attempted if this method returns true. The return value must not change over the lifetime of the object.- Specified by:
isReadable
in interfaceArrayImpl
- Returns:
- whether read access is available
-
isWritable
public boolean isWritable()
Description copied from interface:ArrayImpl
Indicates whether write access is possible. Writes will only be attempted if this method returns true. The return value must not change over the lifetime of the object.- Specified by:
isWritable
in interfaceArrayImpl
- Returns:
- whether write access is available
-
isRandom
public boolean isRandom()
Description copied from interface:ArrayImpl
Indicates whether random access is possible. If this method returns true, then it is permissible to set the offset to a value lower than its current value. If it is false, then no such invocations will be attempted. The return value must not change over the lifetime of the object.
-
multipleAccess
public boolean multipleAccess()
Description copied from interface:ArrayImpl
Indicates whether the getAccess method may be called more than once.- Specified by:
multipleAccess
in interfaceArrayImpl
- Returns:
- true if getAccess may be called more than once
-
open
public void open()
Description copied from interface:ArrayImpl
Prepares this ArrayImpl for pixel access. This method will be called no more than once, and it will be called prior to any calls of the getAccess method.
-
canMap
public boolean canMap()
Description copied from interface:ArrayImpl
Indicates whether mapped access is available. If true, then following an open call, the getMapped method will return a reference to the java primitive array containing all the pixels of this array.Will only be called after an open call, and before any close call.
-
getMapped
public java.lang.Object getMapped()
Description copied from interface:ArrayImpl
Returns a single primitive array holding all the pixel data of this array. This should be a cheap operation, returning a reference to an existing array rather than doing work to generate one. In the case of a writable accessor, making changes to the returned primitive array will result in changes to the accessor pixel data. In the case of an NDArray which is not writable, the effect of making changes to the returned array is undefined; in particular it may result in an exception.Will only be called if canMap returns true, and only after an open call and before any close call.
-
getAccess
public AccessImpl getAccess() throws java.io.IOException
Description copied from interface:ArrayImpl
Returns an object which can access the pixels of this ArrayImpl. Each call to this method returns a new and independent AccessImpl, with an offset initialised to 0 (the start of the array data).This method will only be called after the sole call to open and before the sole call to close.
This method will only be called more than once if the multipleAccess method returns true.
It is the responsibility of the caller to close the returned AccessImpl when it is no longer required; this enables resources it may hold to be released.
-
close
public void close() throws java.io.IOException
Description copied from interface:ArrayImpl
Shuts down this ArrayImpl for pixel access. This method will be called no more than once. No calls to getAccess, getMapped or open will be made after it is called. If the user makes proper use of the NDArray classes, it will be called after any AccessImpl objects and references to the mapped array are no longer required. If the user misbehaves however it may not get called at all, so an effort should be made to realease non-memory resources and flush buffers where appropriate in the finalizer.
-
getWrapped
public NDArray getWrapped()
Returns the NDArray which this Wrapper is wrapping.- Returns:
- the underlying NDArray
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-