Package com.iizix

Class TimeInterval

java.lang.Object
com.iizix.TimeInterval

public final class TimeInterval extends Object
Class holding a start and end time. The start time may be unset, or the end time. The time is a time value in milliseconds since the epoch in UMT.
Author:
Christopher Mindus
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final TimeInterval[]
    Empty array of time intervals.
  • Method Summary

    Modifier and Type
    Method
    Description
    between(long startTime, long endTime)
    Creates a new instance of the time interval with only a end time set.
    endingAt(long endTime)
    Creates a new instance of the time interval with only a end time set.
    boolean
    equals(Object other)
    Checks for equality.
    int
    Gets the hash code of the time interval.
    boolean
    isIncluded(long time)
    Verifies if the time is between included in the time interval.
    startingAt(long startTime)
    Creates a new instance of the time interval with only a start time set.
    Get a string representation of the time interval.

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Field Details

    • NO_INTERVALS

      public static final TimeInterval[] NO_INTERVALS
      Empty array of time intervals.
  • Method Details

    • startingAt

      public static TimeInterval startingAt(long startTime)
      Creates a new instance of the time interval with only a start time set.
      Parameters:
      startTime - The starting time in milliseconds since the epoch in UMT.
      Returns:
      A new instance of the time interval.
      Throws:
      IllegalArgumentException - If the startTime is zero or negative.
    • endingAt

      public static TimeInterval endingAt(long endTime)
      Creates a new instance of the time interval with only a end time set.
      Parameters:
      endTime - The end time in milliseconds since the epoch in UMT.
      Returns:
      A new instance of the time interval.
      Throws:
      IllegalArgumentException - If the endTime is zero or negative.
    • between

      public static TimeInterval between(long startTime, long endTime)
      Creates a new instance of the time interval with only a end time set.
      Parameters:
      startTime - The starting time in milliseconds since the epoch in UMT.
      endTime - The end time in milliseconds since the epoch in UMT.
      Returns:
      A new instance of the time interval.
      Throws:
      IllegalArgumentException - If the startTime is zero or negative, endTime is zero or negative or startTime is larger or equal to endTime.
    • isIncluded

      public boolean isIncluded(long time)
      Verifies if the time is between included in the time interval.
      Parameters:
      time - The time in milliseconds since the epoch in GMT.
      Returns:
      true if the time is included, false if not.
    • hashCode

      public int hashCode()
      Gets the hash code of the time interval.
      Overrides:
      hashCode in class Object
      Returns:
      The hash code.
    • equals

      public boolean equals(Object other)
      Checks for equality.
      Overrides:
      equals in class Object
      Parameters:
      other - The other object.
      Returns:
      The equality flag.
    • toString

      public String toString()
      Get a string representation of the time interval.
      Overrides:
      toString in class Object
      Returns:
      A string as [startTime-endTime], [startTime-] or [-endTime].