com.h3c.util

## Class Interval<D extends Comparable<D>>

- java.lang.Object
- - com.h3c.util.Interval<D>

- Type Parameters:
    `D` - Interval domain.
  All Implemented Interfaces:
    Serializable

      public final class Interval<D extends Comparable<D>>
      extends Object
      implements Serializable

  Intervals (of real numbers ) can be classified into different types. Let `a` and `b` be real numbers where with `a < b`:
  - Empty: `(a, a) = (a, a] = [a, a) = {} = empty`. `[b, a]` is considered as an empty interval in the literature, but this class do not support it
  - Degenerate: `[a, a] = {a}`
  - Open: `(a, b) = {x | a < x < b}`
  - Closed: `[a, b] = {x | a <= x <= b}`
  - Left-closed, right-open: `[a, b) = {x | a <= x < b}`
  - Left-open, right-closed: `(a, b] = {x | a < x <= b}`
  - Left open right unbounded: `(a, infinite) = {x | x > a}`
  - Left closed right unbounded: `[a, infinite) = {x | x >= a}`
  - Left unbounded right open: `(infinite, b) = {x | x < b}`
  - Left unbounded right closed: `(infinite, b] = {x | x <= b}`
  - Unbounded: `(infinite, infinite) = {x | x is a real number}`
  See Also:
    Serialized Form

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class and Description
    --- | ---
    `static class` | `Interval.Type`

  - ### Constructor Summary

    Constructors
    Modifier | Constructor and Description
    --- | ---
    `protected` | `Interval(D leftEndpoint, D rightEndpoint, Interval.Type type)` Constructs an interval.

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `boolean` | `contains(D element)` Verifies whether the given element belongs to the interval.
    `static <T extends Comparable<T>> Interval<T>` | `createClosed(T leftEndpoint, T rightEndpoint)` Creates a closed-type interval based on the nullability of `leftEndpoint` and `rightEndpoint`: Closed: if neither `leftEndpoint` and `rightEndpoint` are `null` Left unbounded right closed: if `leftEndpoint` is `null` but `rightEndpoint` isn't Left closed right unbounded: if `leftEndpoint` is not `null` but `rightEndpoint` is Unbounded: if both `leftEndpoint` and `rightEndpoint` are `null`
    `static <T extends Comparable<T>> Interval<T>` | `createOpen(T leftEndpoint, T rightEndpoint)` Creates an open-type interval based on the nullability of `leftEndpoint` and `rightEndpoint`: Open: if neither `leftEndpoint` and `rightEndpoint` are `null` Left unbounded right open: if `leftEndpoint` is `null` but `rightEndpoint` isn't Left open right unbounded: if `leftEndpoint` is not `null` but `rightEndpoint` is Unbounded: if both `leftEndpoint` and `rightEndpoint` are `null`
    `boolean` | `equals(Object obj)`
    `D` | `getLeftEndpoint()` Gets the interval left end point.
    `D` | `getRightEndpoint()` Gets the interval right end point.
    `Interval.Type` | `getType()` Gets the interval type.
    `int` | `hashCode()`
    `boolean` | `isEmpty()` Returns whether this interval is empty or not:
    `String` | `toString()`
    `static <T extends Comparable<T>> Interval<T>` | `valueOfClosed(T leftEndpoint, T rightEndpoint)` Creates a closed interval: `[a, b] = {x | a <= x <= b}`
    `static <T extends Comparable<T>> Interval<T>` | `valueOfLeftClosedRightOpen(T leftEndpoint, T rightEndpoint)` Creates a left-closed right-open interval: `(a, b] = {x | a < x <= b}`
    `static <T extends Comparable<T>> Interval<T>` | `valueOfLeftClosedRightUnbounded(T leftEndpoint)` Creates a Left closed right unbounded interval: `[a, infinite) = {x | x >= a}`
    `static <T extends Comparable<T>> Interval<T>` | `valueOfLeftOpenRightClosed(T leftEndpoint, T rightEndpoint)` Creates a left-open right-closed interval: `(a, b] = {x | a <= x < b}`
    `static <T extends Comparable<T>> Interval<T>` | `valueOfLeftOpenRightUnbounded(T leftEndpoint)` Creates a left open right unbounded interval: `(a, infinite) = {x | x > a}`
    `static <T extends Comparable<T>> Interval<T>` | `valueOfLeftUnboundedRightClosed(T rightEndpoint)` Creates a left unbounded right closed interval: `(infinite, b] = {x | x <= b}`
    `static <T extends Comparable<T>> Interval<T>` | `valueOfLeftUnboundedRightOpen(T rightEndpoint)` Creates a left unbounded right open interval: `(infinite, b) = {x | x < b}`
    `static <T extends Comparable<T>> Interval<T>` | `valueOfOpen(T leftEndpoint, T rightEndpoint)` Creates a open interval: `(a, b) = {x | a < x < b}`
    `static <T extends Comparable<T>> Interval<T>` | `valueOfUnbounded()` Creates an unbounded interval: `(infinite, infinite) = {x | x is a real number}`

    - ### Methods inherited from class java.lang.Object

      `clone, finalize, getClass, notify, notifyAll, wait, wait, wait`

- - ### Constructor Detail

    - #### Interval

          protected Interval(D leftEndpoint,
                  D rightEndpoint,
                  Interval.Type type)
                      throws NullPointerException,
                             IllegalArgumentException

      Constructs an interval.
      Parameters:
        `leftEndpoint` - Left end point.
        `rightEndpoint` - Right end point.
        `type` - Interval type.
      Throws:
        `NullPointerException` - If interval type is null.
        `IllegalArgumentException` - If interval validation fails based on the interval type.

  - ### Method Detail

    - #### valueOfOpen

          public static <T extends Comparable<T>> Interval<T> valueOfOpen(T leftEndpoint,
                                                          T rightEndpoint)

      Creates a open interval: `(a, b) = {x | a < x < b}`
      Parameters:
        `leftEndpoint` - Left end point.
        `rightEndpoint` - Right end point.
      Returns:
        interval

    - #### valueOfClosed

          public static <T extends Comparable<T>> Interval<T> valueOfClosed(T leftEndpoint,
                                                            T rightEndpoint)

      Creates a closed interval: `[a, b] = {x | a <= x <= b}`
      Parameters:
        `leftEndpoint` - Left end point.
        `rightEndpoint` - Right end point.
      Returns:
        interval

    - #### valueOfLeftClosedRightOpen

          public static <T extends Comparable<T>> Interval<T> valueOfLeftClosedRightOpen(T leftEndpoint,
                                                                         T rightEndpoint)

      Creates a left-closed right-open interval: `(a, b] = {x | a < x <= b}`
      Parameters:
        `leftEndpoint` - Left end point.
        `rightEndpoint` - Right end point.
      Returns:
        interval

    - #### valueOfLeftOpenRightClosed

          public static <T extends Comparable<T>> Interval<T> valueOfLeftOpenRightClosed(T leftEndpoint,
                                                                         T rightEndpoint)

      Creates a left-open right-closed interval: `(a, b] = {x | a <= x < b}`
      Parameters:
        `leftEndpoint` - Left end point.
        `rightEndpoint` - Right end point.
      Returns:
        interval

    - #### valueOfLeftOpenRightUnbounded

          public static <T extends Comparable<T>> Interval<T> valueOfLeftOpenRightUnbounded(T leftEndpoint)

      Creates a left open right unbounded interval: `(a, infinite) = {x | x > a}`
      Parameters:
        `leftEndpoint` - Left end point.
      Returns:
        interval

    - #### valueOfLeftClosedRightUnbounded

          public static <T extends Comparable<T>> Interval<T> valueOfLeftClosedRightUnbounded(T leftEndpoint)

      Creates a Left closed right unbounded interval: `[a, infinite) = {x | x >= a}`
      Parameters:
        `leftEndpoint` - Left end point.
      Returns:
        interval

    - #### valueOfLeftUnboundedRightOpen

          public static <T extends Comparable<T>> Interval<T> valueOfLeftUnboundedRightOpen(T rightEndpoint)

      Creates a left unbounded right open interval: `(infinite, b) = {x | x < b}`
      Parameters:
        `rightEndpoint` - Right end point.
      Returns:
        interval

    - #### valueOfLeftUnboundedRightClosed

          public static <T extends Comparable<T>> Interval<T> valueOfLeftUnboundedRightClosed(T rightEndpoint)

      Creates a left unbounded right closed interval: `(infinite, b] = {x | x <= b}`
      Parameters:
        `rightEndpoint` - Right end point.
      Returns:
        interval

    - #### valueOfUnbounded

          public static <T extends Comparable<T>> Interval<T> valueOfUnbounded()

      Creates an unbounded interval: `(infinite, infinite) = {x | x is a real number}`
      Returns:
        interval

    - #### createOpen

          public static <T extends Comparable<T>> Interval<T> createOpen(T leftEndpoint,
                                                         T rightEndpoint)
                                                              throws IllegalArgumentException

      Creates an open-type interval based on the nullability of `leftEndpoint` and `rightEndpoint`:
      - Open: if neither `leftEndpoint` and `rightEndpoint` are `null`
      - Left unbounded right open: if `leftEndpoint` is `null` but `rightEndpoint` isn't
      - Left open right unbounded: if `leftEndpoint` is not `null` but `rightEndpoint` is
      - Unbounded: if both `leftEndpoint` and `rightEndpoint` are `null`
      Parameters:
        `leftEndpoint` - left endpoint
        `rightEndpoint` - right endpoint
      Returns:
        one of the open-type intervals
      Throws:
        `IllegalArgumentException` - if neither `leftEndpoint` and `rightEndpoint` are `null` and `leftEndpoint` is be greater than `rightEndpoint`

    - #### createClosed

          public static <T extends Comparable<T>> Interval<T> createClosed(T leftEndpoint,
                                                           T rightEndpoint)
                                                                throws IllegalArgumentException

      Creates a closed-type interval based on the nullability of `leftEndpoint` and `rightEndpoint`:
      - Closed: if neither `leftEndpoint` and `rightEndpoint` are `null`
      - Left unbounded right closed: if `leftEndpoint` is `null` but `rightEndpoint` isn't
      - Left closed right unbounded: if `leftEndpoint` is not `null` but `rightEndpoint` is
      - Unbounded: if both `leftEndpoint` and `rightEndpoint` are `null`
      Parameters:
        `leftEndpoint` - left endpoint
        `rightEndpoint` - right endpoint
      Returns:
        one of the closed-type intervals
      Throws:
        `IllegalArgumentException` - if neither `leftEndpoint` and `rightEndpoint` are `null` and `leftEndpoint` is be greater than `rightEndpoint`

    - #### getLeftEndpoint

          public D getLeftEndpoint()

      Gets the interval left end point.
      Returns:
        the interval left end point or null

    - #### getRightEndpoint

          public D getRightEndpoint()

      Gets the interval right end point.
      Returns:
        the interval right end point or null

    - #### getType

          public Interval.Type getType()

      Gets the interval type.
      Returns:
        the interval type.

    - #### contains

          public boolean contains(D element)

      Verifies whether the given element belongs to the interval.
      Parameters:
        `element` - Element to verify.
      Returns:
        `true` if `element` belongs is inside the interval, `false` otherwise.

    - #### isEmpty

          public boolean isEmpty()

      Returns whether this interval is empty or not:

      a, b are real numbers with a < b

      empty: `[b, a] = (a, a) = [a, a) = (a, a] = {}`

      Returns:
        True if this interval is empty, false otherwise.

    - #### equals

          public boolean equals(Object obj)

      Overrides:
        `equals` in class `Object`

    - #### hashCode

          public int hashCode()

      Overrides:
        `hashCode` in class `Object`

    - #### toString

          public String toString()

      Overrides:
        `toString` in class `Object`

Copyright © 2014. All Rights Reserved.