Package rasj

Class RasSInterval


  • public class RasSInterval
    extends java.lang.Object
    
     PURPOSE:
     The class represents an interval with lower and upper bound.
     Operations on the interval are defined according to the
     ODMG-93 standard.
     The operations union, difference, and intersection are
     defined according to the following table:
    
        | ...  fixed bound
        -* ...  open bound
    
     class   orientation       union    difference  intersection
     -----------------------------------------------------------
       1     |-a-| |-b-|       error    a           error
    
       2     |-a-|             [a1,b2]  [a1,b1]     [b1,a2]
       2        |-b-|
    
       3     |--a--|           a        error       b
       3      |-b-|
    
       4     |-b-|             [b1,a2]  [b2,a2]     [a1,b2]
       4        |-a-|
    
       5     |--b--|           b        error       a
       5      |-a-|
    
       6     |-b-| |-a-|       error    a           error
    
       7     |-a-|-b-|         [a1,b2]  a           [a2,a2]
    
       8     |-b-|-a-|         [b1,a2]  a           [b2,b2]
    
       9     |--a--|           a        [a1,b1]     b
       9       |-b-|
    
      10     |--a--|           a        [b2,a2]     b
      10     |-b-|
    
      11     |-a-|             a        error       a
      11     |-b-|
    
      12     |--b--|           b        error       a
      12     |-a-|
    
      13     |--b--|           b        error       a
      13       |-a-|
    
      -----------------------------------------------------
    
      14     |--a--*           a        error       b
      14      |-b-|
    
      15     |--a--*           a        [b2,a2]     b
      15     |-b-|
    
      16     |-b-| |-a-*       error    a           error
    
      17     |-b-|-a-*         [b1,a2]  a           [b2,b2]
    
      18      |--a--*          [b1,a2]  [b2,a2]     [a1,b2]
      18     |-b-|
    
      -----------------------------------------------------
    
      19     *--a--|           a        error       b
      19      |-b-|
    
      20     *--a--|           a        [a1,b1]     b
      20       |-b-|
    
      21     *-a-| |-b-|       error    a           error
    
      22     *-a-|-b-|         [a1,b2]  a           [a2,a2]
    
      23     *--a--|           [a1,b2]  [a1,b1]     [b1,a2]
      23        |-b-|
    
      -----------------------------------------------------
    
      24     |--b--*           b        error       a
      24      |-a-|
    
      25     |--b--*           b        error       a
      25     |-a-|
    
      26     |-a-| |-b-*       error    a           error
    
      27     |-a-|-b-*         [a1,b2]  a           [a2,a2]
    
      28      |--b--*          [a1,b2]  [a1,b1]     [b1,a2]
      28     |-a-|
    
      -----------------------------------------------------
    
      29     *--b--|           b        error       a
      29      |-a-|
    
      30     *--b--|           b        error       a
      30       |-a-|
    
      31     *-b-| |-a-|       error    a           error
    
      32     *-b-|-a-|         [b1,a2]  a           [b2,b2]
    
      33     *--b--|           [b1,a2]  [b2,a2]     [a1,b2]
      33        |-a-|
    
      -----------------------------------------------------
    
      34     *-a-| |-b-*       error    a           error
    
      35     *-a-|-b-*         [a1,b2]  a           [a2,a2]
    
      36     *-a-|             [a1,b2]  [a1,b1]     [b1,a2]
      36        |-b-*
    
      -----------------------------------------------------
    
      37     *-b-| |-a-*       error    a           error
    
      38     *-b-|-a-*         [b1,a2]  a           [b2,b2]
    
      39     *-b-|             [b1,a2]  [a1,b1]     [a1,b2]
      39        |-a-*
    
      -----------------------------------------------------
    
      40     *-a-|             b        error       a
      40      *-b-|
    
      41     *-a-|             a        error       a
      41     *-b-|
    
      42     *-b-|             a        [b2,a2]     b
      42      *-a-|
    
      -----------------------------------------------------
    
      43     |-a-*             a        [a1,b1]     b
      43      |-b-*
    
      44     |-a-*             a        error       a
      44     |-b-*
    
      45     |-b-*             b        error       a
      45      |-a-*
    
      -----------------------------------------------------
      46     *-a-* |-b-|       a        error       b
    
      47     *-b-* |-a-|       b        error       a
    
      48     *-a-*             a        [b2,a2]     b
      48      *-b-|
    
      49     *-a-*             a        [a1,b1]     b
      49      |-b-*
    
      50     *-b-*             b        error       a
      50      *-a-|
    
      51     *-b-*             b        error       a
      51      |-a-*
    
      52     *-a-*             a        error       a
      52     *-b-*
    
     Attention: The difference operation has to be reconsidered in future
     concerning a discrete interpretation of the intervals.
    
     The closure operation defines an interval which is the smallest
     interval containing the two operands.
     The method intersectsWith() returns 0 in the error cases of the
     intersection operation and 1 otherwise.
    • Constructor Detail

      • RasSInterval

        public RasSInterval()
        The default constructor creates an interval with open bounds.
      • RasSInterval

        public RasSInterval​(RasSInterval sint)
        Copy constructor.
        Parameters:
        sint - SInterval to be copied
      • RasSInterval

        public RasSInterval​(char c,
                            long high)
        Constructor for an SInterval with an open lower bound.
        Parameters:
        c - arbitrary character, usually '*'. The value of this parameter is meaningless, it's only needed in order to provide a constructor similar to the one for fixed bounds.
        high - the upper bound
      • RasSInterval

        public RasSInterval​(long low,
                            char c)
        Constructor for an SInterval with an open upper bound.
        Parameters:
        c - arbitrary character, usually '*'. The value of this parameter is meaningless, it's only needed in order to provide a constructor similar to the one for fixed bounds.
        low - the lower bound
      • RasSInterval

        public RasSInterval​(char c1,
                            char c2)
        Constructor for an SInterval with an open bounds. For both parameters, arbitrary characters (usually '*') can be specified. The values of these parameters are meaningless, they are only needed in order to provide a constructor similar to the one for fixed bounds.
        Parameters:
        c1 - arbitrary character
        c2 - arbitrary character
    • Method Detail

      • equals

        public boolean equals​(RasSInterval interval)
        Method for testing equality of two SIntervals. Two SIntervals are equal if they have the same lower and upper bounds.
        Parameters:
        interval - the SInterval that is compared to this SInterval
        Returns:
        true if the two SIntervals are equal
      • notEquals

        public boolean notEquals​(RasSInterval interval)
        Method for testing inequality of two SIntervals. Two SIntervals are inequal if they have different lower or upper bounds.
        Parameters:
        interval - the SInterval that is compared to this SInterval
        Returns:
        true if the two SIntervals are not equal
      • low

        public long low()
        Gets the lower bound of the interval.
        Returns:
        the lower bound
      • high

        public long high()
        Gets the upper bound of the interval.
        Returns:
        the upper bound
      • isLowFixed

        public boolean isLowFixed()
        Checks if the lower bound is fix.
        Returns:
        true if the lower bound is fix, false otherwise
      • isHighFixed

        public boolean isHighFixed()
        Checks if the upper bound is fix.
        Returns:
        true if the lower bound is fix, false otherwise
      • setLow

        public void setLow​(char c)
        Sets the lower bound open.
        Parameters:
        c - arbitrary character (usually '*')
      • setHigh

        public void setHigh​(char c)
        Sets the upper bound open.
        Parameters:
        c - arbitrary character (usually '*')
      • setInterval

        public void setInterval​(char c,
                                long high)
        Sets the lower bound open and the upper bound to a fixed value.
        Parameters:
        c - arbitrary character (usually '*')
        high - the new upper bound
      • setInterval

        public void setInterval​(long low,
                                char c)
        Sets the upper bound open and the lower bound to a fixed value.
        Parameters:
        c - arbitrary character (usually '*')
        low - the new lower bound
      • setInterval

        public void setInterval​(char c1,
                                char c2)
        Sets both bounds open.
        Parameters:
        c1 - arbitrary character (usually '*')
        c2 - arbitrary character (usually '*')
      • intersectsWith

        public int intersectsWith​(RasSInterval interval)
        Determines if the current interval intersects with the given one.
        Parameters:
        interval - the interval to be compared
        Returns:
        -1 if the intervals do not intersect
        <classNo> if the intervals do intersect, where <classNo> is one of the classes specified in the description for class RasSInterval.
      • differenceWith

        public RasSInterval differenceWith​(RasSInterval interval)
                                    throws RasResultIsNoIntervalException
        Calculates the difference of the current SInterval and the given one.

        Note that this operation modifies the current object. If you want to get a new SInterval, use createDifference instead.

        Parameters:
        interval - the SInterval used for building the difference
        Returns:
        the current SInterval (representing the difference of this SInterval and interval)
        Throws:
        RasResultIsNoIntervalException
      • intersectionWith

        public RasSInterval intersectionWith​(RasSInterval interval)
                                      throws RasResultIsNoIntervalException
        Calculates the intersection of the current SInterval and the given one.

        Note that this operation modifies the current object. If you want to get a new SInterval, use createIntersection instead.

        Parameters:
        interval - the SInterval used for building the intersection
        Returns:
        the current SInterval (representing the intersection of this SInterval and interval)
        Throws:
        RasResultIsNoIntervalException
      • createIntersection

        public RasSInterval createIntersection​(RasSInterval interval)
                                        throws RasResultIsNoIntervalException
        Returns a new SInterval calculated from the intersection of the current SInterval and the given one.
        Parameters:
        interval - the SInterval used for calculating the intersection with the current SInterval
        Returns:
        the intersection of this SInterval and interval
        Throws:
        RasResultIsNoIntervalException
      • closureWith

        public RasSInterval closureWith​(RasSInterval interval)
                                 throws RasResultIsNoIntervalException
        Calculates the closure of the current SInterval and the given one.

        Note that this operation modifies the current object. If you want to get a new SInterval, use createClosure instead.

        Parameters:
        interval - the SInterval used for building the closure
        Returns:
        the current SInterval (representing the closure of this SInterval and interval)
        Throws:
        RasResultIsNoIntervalException
      • toString

        public java.lang.String toString()
        gives back the string representation
        Overrides:
        toString in class java.lang.Object