Class Region

  • All Implemented Interfaces:
    java.lang.Comparable<java.lang.Comparable>, AATreeSet.Node<java.lang.Comparable>

    public class Region
    extends AATreeSet.AbstractTreeNode<java.lang.Comparable>
    implements java.lang.Comparable<java.lang.Comparable>
    Class that represents the regions held within this set.
    Author:
    Chris Dennis
    • Constructor Summary

      Constructors 
      Constructor Description
      Region​(long value)
      Creates a region containing just the single given value
      Region​(long start, long end)
      Creates a region containing the given range of value (inclusive).
      Region​(Region r)
      Create a shallow copy of a region.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      int compareTo​(java.lang.Comparable other)
      Compare this node to the supplied 'data' object.
      long contiguous()
      Return the size of the largest region linked from this node.
      long end()
      Returns the end of this range (inclusive).
      Region getPayload()
      Return the 'value' object held within this node.
      protected boolean isNull()
      Return true if this region is null, i.e.
      protected void merge​(Region r)
      Merge the supplied region into this region (if they are adjoining).
      protected Region remove​(Region r)
      Remove the supplied region from this region.
      void setLeft​(AATreeSet.Node<java.lang.Comparable> l)
      Set this node's left child.
      void setRight​(AATreeSet.Node<java.lang.Comparable> r)
      Set this node's right child.
      long size()
      Returns the size of this range (the number of values within its bounds).
      long start()
      Returns the start of this range (inclusive).
      void swapPayload​(AATreeSet.Node<java.lang.Comparable> other)
      Swap the payload objects between this node and the supplied node.
      java.lang.String toString()
      • Methods inherited from class java.lang.Object

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

      • Region

        public Region​(long value)
        Creates a region containing just the single given value
        Parameters:
        value -
      • Region

        public Region​(long start,
                      long end)
        Creates a region containing the given range of value (inclusive).
      • Region

        public Region​(Region r)
        Create a shallow copy of a region.

        The new Region has NULL left and right children.

    • Method Detail

      • contiguous

        public long contiguous()
        Return the size of the largest region linked from this node.
      • toString

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

        public long size()
        Returns the size of this range (the number of values within its bounds).
      • isNull

        protected boolean isNull()
        Return true if this region is null, i.e. represents no valid range.
      • remove

        protected Region remove​(Region r)
                         throws java.lang.IllegalArgumentException
        Remove the supplied region from this region.
        Parameters:
        r - region to remove
        Returns:
        a possible extra region to be added, or null if none is required
        Throws:
        java.lang.IllegalArgumentException - if this region does not completely enclose the supplied region
      • merge

        protected void merge​(Region r)
                      throws java.lang.IllegalArgumentException
        Merge the supplied region into this region (if they are adjoining).
        Parameters:
        r - region to merge
        Throws:
        java.lang.IllegalArgumentException - if the regions are not adjoining
      • compareTo

        public int compareTo​(java.lang.Comparable other)
        Compare this node to the supplied 'data' object.
        Specified by:
        compareTo in interface AATreeSet.Node<java.lang.Comparable>
        Specified by:
        compareTo in interface java.lang.Comparable<java.lang.Comparable>
      • swapPayload

        public void swapPayload​(AATreeSet.Node<java.lang.Comparable> other)
        Swap the payload objects between this node and the supplied node.
        Specified by:
        swapPayload in interface AATreeSet.Node<java.lang.Comparable>
      • getPayload

        public Region getPayload()
        Return the 'value' object held within this node.
        Specified by:
        getPayload in interface AATreeSet.Node<java.lang.Comparable>
      • start

        public long start()
        Returns the start of this range (inclusive).
      • end

        public long end()
        Returns the end of this range (inclusive).