Class BadHandler


  • public abstract class BadHandler
    extends java.lang.Object
    Handles bad pixel values. Instances of this class can detect and write values in an array with a `magic' bad value. Since its methods reference values within arrays, client code does not need to be written in a primitive-type-specific fashion.

    Obtain an instance of this class using the getHandler(uk.ac.starlink.array.Type, java.lang.Number) static method.

    It is not expected to be necessary to extend this class for normal purposes, but there is a protected constructor in case this is required. Such subclassing might be useful to provided specialised bad value handlers in which, for instance, floating NaN values do not count as bad, or infinite values do. Such subclassing should be done and used with care.

    Version:
    $Id$
    Author:
    Mark Taylor (Starlink)
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static interface  BadHandler.ArrayHandler
      Class provided for testing and setting bad values in a given primitive array.
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      protected BadHandler​(Type type, java.lang.Number badValue)
      Constructor which may be used for subclassing.
    • Method Summary

      All Methods Static Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      abstract BadHandler.ArrayHandler arrayHandler​(java.lang.Object array)
      Returns an ArrayHandler object for testing/setting bad values in a given primitive array according to the bad value handling rules of this BadHandler.
      boolean equals​(java.lang.Object other)  
      java.lang.Number getBadValue()
      Gets the bad data value.
      static BadHandler getHandler​(Type type, java.lang.Number badValue)
      Returns an instance of this class capable of dealing with primitives of a given type and using a given bad value.
      Type getType()
      Gets the Type of this handler.
      int hashCode()  
      abstract boolean isBad​(java.lang.Object array, int pos)
      Indicates whether an element of an array represents a bad value for this NDArray.
      abstract java.lang.Number makeNumber​(java.lang.Object array, int pos)
      Turns a single element of an array into a Number object of the appropriate type.
      abstract void putBad​(java.lang.Object array, int pos)
      Writes a single bad value into an array.
      abstract void putBad​(java.lang.Object array, int start, int size)
      Writes a sequence of bad values into an array.
      java.lang.String toString()  
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, wait, wait, wait
    • Constructor Detail

      • BadHandler

        protected BadHandler​(Type type,
                             java.lang.Number badValue)
        Constructor which may be used for subclassing.
    • Method Detail

      • isBad

        public abstract boolean isBad​(java.lang.Object array,
                                      int pos)
        Indicates whether an element of an array represents a bad value for this NDArray.
        Parameters:
        array - the array in which the pixel resides
        pos - the position in array of the pixel to be tested.
        Throws:
        java.lang.ClassCastException - if array is not an array of primitives with type matching the type of this handler
        java.lang.IndexOutOfBoundsException - if pos is outside the bounds of array
      • putBad

        public abstract void putBad​(java.lang.Object array,
                                    int start,
                                    int size)
        Writes a sequence of bad values into an array.
        Parameters:
        array - array into which to write bad values, which must be an array of primitive type matching this handler's Type with at least start+length elements
        start - the position in array at which to start writing bad values
        size - the number of elements of array to write bad values to
        Throws:
        java.lang.ClassCastException - if array is not an array of primitives with type matching the type of this handler
        java.lang.IndexOutOfBoundsException - if access outside the bounds of the array is attempted
      • putBad

        public abstract void putBad​(java.lang.Object array,
                                    int pos)
        Writes a single bad value into an array.
        Parameters:
        array - array into which to write a bad value; it must be an array of primitive type matching this handler's Type with at least pos-1 elements
        pos - the position at which to write the bad value
        Throws:
        java.lang.ClassCastException - if array is not an array of primitives with type matching the type of this handler
        java.lang.IndexOutOfBoundsException - if access outside the bounds of the array is attempted
      • makeNumber

        public abstract java.lang.Number makeNumber​(java.lang.Object array,
                                                    int pos)
        Turns a single element of an array into a Number object of the appropriate type. The return value will be one of the wrapper types Byte, Short, Integer, Float or Double wrapping the value in question, unless the array element is bad, in which case the null value will be returned.
        Parameters:
        array - array containing the value to be converted
        pos - the index into array at which the element of interest is to be found
        Returns:
        a Number object wrapping the pos'th element of array, or null if that element is bad
        Throws:
        java.lang.IndexOutOfBoundsException - if access outside the bounds of the array is attempted
      • arrayHandler

        public abstract BadHandler.ArrayHandler arrayHandler​(java.lang.Object array)
        Returns an ArrayHandler object for testing/setting bad values in a given primitive array according to the bad value handling rules of this BadHandler. The same functionality can be achieved by use of the isBad(java.lang.Object, int) and putBad(Object,int) methods of this class, but using an ArrayHandler can avoid repeated typecasts and provide better performance.
        Throws:
        java.lang.ClassCastException - if array is not an array of primitives with type matching the type of this handler
      • getType

        public Type getType()
        Gets the Type of this handler.
        Returns:
        the type
      • getBadValue

        public java.lang.Number getBadValue()
        Gets the bad data value. This will be an instance of the primitive wrapper class corresponding to this array's type. Any elements matching the number thus represented will be considered to be bad; calling the isBad method on them will return true. The value may be null, in which case no data of integer type is considered bad, but floating point values which are NaN still are.
        Returns:
        a Number object of appropriate type wrapping the bad data value. May be null.
      • getHandler

        public static BadHandler getHandler​(Type type,
                                            java.lang.Number badValue)
        Returns an instance of this class capable of dealing with primitives of a given type and using a given bad value.
        Parameters:
        type - a Type object determining what kind of primitive data this handler will deal with
        badValue - a Number object giving the magic bad value. This will be an instance of the primitive wrapper class corresponding to this array's type. The value may be null, in which case no data of integer type is considered bad, but floating point values which are NaN still are. In this case a default bad value will be written if the putBad methods are invoked
        Returns:
        a suitable BadHandler
      • equals

        public boolean equals​(java.lang.Object other)
        Overrides:
        equals in class java.lang.Object
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • toString

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