Class BridgeNDArray
- java.lang.Object
-
- uk.ac.starlink.array.DefaultArrayDescription
-
- uk.ac.starlink.array.BridgeNDArray
-
- All Implemented Interfaces:
ArrayDescription
,NDArray
- Direct Known Subclasses:
DummyNDArray
,ScratchNDArray
public class BridgeNDArray extends DefaultArrayDescription implements NDArray
Class providing anNDArray
implementation based on an implementation of theArrayImpl
interface. The idea is that all the implementation work common to any underlying implementation of array functionality is contained in this class, while the details specific to different underlying array types can be contained in different implementations of the ArrayImpl interface. In particular, this class does extensive validation on method parameters and takes care of throwing the right exceptions so that the burden of worrying about invalid parameters is removed from the ArrayImpl implementations.This exemplifies the Bridge Pattern.
- Author:
- Mark Taylor (Starlink)
-
-
Field Summary
-
Fields inherited from class uk.ac.starlink.array.DefaultArrayDescription
arrayDims, arrayHandler, arrayIsRandom, arrayIsReadable, arrayIsWritable, arrayNdim, arrayNpix, arrayOrder, arrayOrigin, arrayShape, arrayType
-
-
Constructor Summary
Constructors Constructor Description BridgeNDArray(ArrayImpl impl)
Constructs a non-persistent BridgeNDArray (one without a URL) from an ArrayImpl.BridgeNDArray(ArrayImpl impl, java.net.URL url)
Constructs a BridgeNDArray from an ArrayImpl with a given URL.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
Declares that this NDArray will not be required for further use; in particular that no further invocations will be made of the getAccess method.ArrayAccess
getAccess()
Returns an object which can read and/or write the pixels of this NDArray.ArrayImpl
getImpl()
Returns the ArrayImpl object supplying the implementation for this BridgeNDArray.java.net.URL
getURL()
Returns the URL of this NDArray, or null if it does not have one.boolean
multipleAccess()
Indicates whether multiple calls to the getAccess method may be made.java.lang.String
toString()
-
Methods inherited from class uk.ac.starlink.array.DefaultArrayDescription
getBadHandler, getShape, getType, isRandom, isReadable, isWritable
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface uk.ac.starlink.array.ArrayDescription
getBadHandler, getShape, getType, isRandom, isReadable, isWritable
-
-
-
-
Constructor Detail
-
BridgeNDArray
public BridgeNDArray(ArrayImpl impl, java.net.URL url)
Constructs a BridgeNDArray from an ArrayImpl with a given URL.- Parameters:
impl
- an ArrayImpl on which this BridgeNDArray will be basedurl
- the URL at which this NDArray can be found. It is only used to dispense via the getURL method. May be null if the NDArray represented by impl is not persistent
-
BridgeNDArray
public BridgeNDArray(ArrayImpl impl)
Constructs a non-persistent BridgeNDArray (one without a URL) from an ArrayImpl.- Parameters:
impl
- an ArrayImpl on which this BridgeNDArray will be based
-
-
Method Detail
-
getURL
public java.net.URL getURL()
Description copied from interface:NDArray
Returns the URL of this NDArray, or null if it does not have one. An NDArray will normally only have a URL if it has been created using one of the calls to NDArrayFactory which takes a URL argument. Feeding the returned URL to the NDArrayFactory will obtain the same NDArray as this one. Scratch NDArrays, and virtual NDArrays created by wrapping another to give access using different characteristics (type, shape etc) will in general not have a URL. The return value must not change over the lifetime of this object.
-
multipleAccess
public boolean multipleAccess()
Description copied from interface:NDArray
Indicates whether multiple calls to the getAccess method may be made. This method will always return true if theArrayDescription.isRandom()
method returns true, but may do so even for non-random arrays.- Specified by:
multipleAccess
in interfaceNDArray
- Returns:
- true if multiple independent accessor objects are available
-
getAccess
public ArrayAccess getAccess() throws java.io.IOException
Description copied from interface:NDArray
Returns an object which can read and/or write the pixels of this NDArray. The returned ArrayReader should be closed when it is no longer required; this enables resources it may hold to be released.Each call to this method returns a new and independent ArrayAccess object. However it may or may not be possible to call it more than once; the
NDArray.multipleAccess()
method indicates whether this is the case.
-
close
public void close() throws java.io.IOException
Description copied from interface:NDArray
Declares that this NDArray will not be required for further use; in particular that no further invocations will be made of the getAccess method.This method should be invoked on an NDArray when it is no longer required for pixel access. This allows reclamation of non-memory resources, and in the case of writable arrays it may also be required to ensure that data is flushed from buffers back to the actual pixel array.
An array should not however be closed if some other object might still require pixel access to it via a retained reference. The general rule is that an application which obtains a new NDArray from a URL should arrange for close to be called on it at the end of its lifetime, but that utility routines which perform operations on an NDArray should not close it after use (though they should close any ArrayAccess objects which they take out). Note that closing an NDArray will normally result in closing any arrays which it wraps.
Multiple calls of this method may harmlessly be made.
-
getImpl
public ArrayImpl getImpl()
Returns the ArrayImpl object supplying the implementation for this BridgeNDArray.- Returns:
- the object which supplies services to this BridgeNDArray
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-