Class NdRange


  • public class NdRange
    extends java.lang.Object
    Describes a range in an N-dimensional space. Each dimension may have a minimum and maximum; each of these bounds is a Comparable object. Any or all of the bounds may be missing (null); this indicates that no bounds are in operation in that dimension, so that all values are effectively inside it.
    Since:
    21 Nov 2007
    Author:
    Mark Taylor
    • Constructor Summary

      Constructors 
      Constructor Description
      NdRange​(int ndim)
      Constructs a range with no bounds.
      NdRange​(java.lang.Comparable[] mins, java.lang.Comparable[] maxs)
      Constructs a range giving its bounds.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean equals​(java.lang.Object o)  
      java.lang.Comparable[] getMaxs()
      Returns the array of maximum values.
      java.lang.Comparable[] getMins()
      Returns the array of minimum values.
      int hashCode()  
      static NdRange intersection​(NdRange r1, NdRange r2)
      Returns a new range which is the intersection of two given ones.
      boolean isBounded()
      Indicates whether this range has any restrictions on inclusion at all.
      boolean isInside​(java.lang.Object[] coords)
      Determines whether a set of coordinates is within this range.
      static java.lang.Comparable max​(java.lang.Comparable c1, java.lang.Comparable c2, boolean failNull)
      Returns the greater of two objects, with explicit null handling.
      static java.lang.Comparable min​(java.lang.Comparable c1, java.lang.Comparable c2, boolean failNull)
      Returns the lesser of two objects, with explicit null handling.
      java.lang.String toString()
      Returns a human-readable description of this range.
      static NdRange union​(NdRange r1, NdRange r2)
      Returns a new range which is the union of two given ones.
      • Methods inherited from class java.lang.Object

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

      • NdRange

        public NdRange​(java.lang.Comparable[] mins,
                       java.lang.Comparable[] maxs)
        Constructs a range giving its bounds. The arrays are copied (cloned) by the constructor, so that subsequent changes to them will not be reflected in the state of this object. Any of the bounds may be null.
        Parameters:
        mins - minimum bounds
        maxs - maximum bounds
      • NdRange

        public NdRange​(int ndim)
        Constructs a range with no bounds. Nothing is excluded from it.
        Parameters:
        ndim - dimensionality
    • Method Detail

      • isBounded

        public boolean isBounded()
        Indicates whether this range has any restrictions on inclusion at all.
        Returns:
        true iff isInside(java.lang.Object[]) can ever return false
      • getMins

        public java.lang.Comparable[] getMins()
        Returns the array of minimum values. Unknown elements may be nulls.
        Returns:
        ndim-element array of minima, some may be null
      • getMaxs

        public java.lang.Comparable[] getMaxs()
        Returns the array of maximum values. Unknown elements may be nulls.
        Returns:
        ndim-element array of maxima, some may be null
      • isInside

        public boolean isInside​(java.lang.Object[] coords)
        Determines whether a set of coordinates is within this range. Objects on the bounds count as inside. This method will always return true if isBounded() returns false.
        Parameters:
        coords - point to assess
        Returns:
        false if the point is definitely outside this range
        Throws:
        java.lang.ClassCastException - if objects are not mutually comparable
      • equals

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

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

        public java.lang.String toString()
        Returns a human-readable description of this range.
        Overrides:
        toString in class java.lang.Object
      • intersection

        public static NdRange intersection​(NdRange r1,
                                           NdRange r2)
        Returns a new range which is the intersection of two given ones. If the intersection is empty (regions are disjoint) then null will be returned.
        Parameters:
        r1 - first range
        r2 - second range
        Returns:
        non-empty intersection, or null
      • union

        public static NdRange union​(NdRange r1,
                                    NdRange r2)
        Returns a new range which is the union of two given ones.
        Parameters:
        r1 - first range
        r2 - second range
        Returns:
        union
      • min

        public static java.lang.Comparable min​(java.lang.Comparable c1,
                                               java.lang.Comparable c2,
                                               boolean failNull)
        Returns the lesser of two objects, with explicit null handling.
        Parameters:
        c1 - first object
        c2 - second object
        failNull - what happens if c1 or c2 is null; if true null is returned, if false the non-null value is returned
        Returns:
        minimum
        Throws:
        java.lang.ClassCastException - if objects are not mutually comparable
      • max

        public static java.lang.Comparable max​(java.lang.Comparable c1,
                                               java.lang.Comparable c2,
                                               boolean failNull)
        Returns the greater of two objects, with explicit null handling.
        Parameters:
        c1 - first object
        c2 - second object
        failNull - what happens if c1 or c2 is null; if true null is returned, if false the non-null value is returned
        Returns:
        maximum
        Throws:
        java.lang.ClassCastException - if objects are not mutually comparable