Class TimeLineRange

java.lang.Object
overit.geocallapp.utilities.timeline.TimeLineRange
All Implemented Interfaces:
Serializable

public class TimeLineRange extends Object implements Serializable
Represents a time range associated with a TimeLineItem for timeline operations.
A timeline range defines a specific time period with begin and end dates, linked to a timeline item.
Provides functionality for overlap detection, intersection calculation, and adjacency checking between ranges.
Since:
1.0
See Also:
  • Constructor Details

    • TimeLineRange

      public TimeLineRange()
  • Method Details

    • buildTimeLineRange

      public static TimeLineRange buildTimeLineRange(TimeLineItem<?> item)
      Creates a new TimeLineRange using the dates from the provided TimeLineItem. The begin and end dates are extracted directly from the item.
      Parameters:
      item - the TimeLineItem to create the range from
      Returns:
      a new TimeLineRange with dates from the item
      Throws:
      IllegalArgumentException - if item is null
    • buildTimeLineRange

      public static TimeLineRange buildTimeLineRange(TimeLineItem<?> item, Date begin, Date end)
      Creates a new TimeLineRange with custom begin and end dates for the provided TimeLineItem. Allows overriding the item's natural date boundaries with specific range dates.
      Parameters:
      item - the TimeLineItem to associate with the range
      begin - the custom begin date for the range
      end - the custom end date for the range
      Returns:
      a new TimeLineRange with the specified dates
      Throws:
      IllegalArgumentException - if item is null or both begin and end are null
    • getBegin

      public Date getBegin()
      Gets the start date of this timeline range. Returns DATE_MIN if the begin date is null, representing an open-ended start.
      Returns:
      the begin date of the range, or DATE_MIN if null
    • getEnd

      public Date getEnd()
      Gets the end date of this timeline range. Returns DATE_MAX if the end date is null, representing an open-ended end.
      Returns:
      the end date of the range, or DATE_MAX if null
    • getItem

      public TimeLineItem<?> getItem()
      Gets the timeline item associated with this range.
      Returns:
      the TimeLineItem associated with this range
    • isOverlapping

      public boolean isOverlapping(TimeLineRange range)
      Checks if the specified range overlaps with this timeline range. Uses edge-inclusive overlap detection by default.
      Parameters:
      range - the TimeLineRange to check for overlap
      Returns:
      true if the ranges overlap, false otherwise
    • isOverlapping

      public boolean isOverlapping(TimeLineRange range, boolean considerEdges)
      Checks if this timeline range overlaps with another range. Provides control over whether range edges (start and end points) are considered in overlap detection.
      Parameters:
      range - the TimeLineRange to check for overlap
      considerEdges - if true, ranges touching at edges are considered overlapping; if false, edges are excluded
      Returns:
      true if the ranges overlap according to the edge consideration setting, false otherwise
    • getOverlappingRanges

      public List<TimeLineRange> getOverlappingRanges(List<TimeLineRange> ranges)
      Filters a list of ranges to return only those that overlap with this range. Uses edge-inclusive overlap detection by default.
      Parameters:
      ranges - the list of TimeLineRange objects to filter
      Returns:
      a list containing only the ranges that overlap with this range
    • getOverlappingRanges

      public List<TimeLineRange> getOverlappingRanges(List<TimeLineRange> ranges, boolean considerEdges)
      Filters a list of ranges to return only those that overlap with this range. Provides control over edge consideration in overlap detection.
      Parameters:
      ranges - the list of TimeLineRange objects to filter
      considerEdges - if true, ranges touching at edges are considered overlapping; if false, edges are excluded
      Returns:
      a list containing only the ranges that overlap with this range
    • intersect

      public Date[] intersect(TimeLineRange other)
      Calculates the intersection between this range and another range. Returns the overlapping time period as a date array, or null if no intersection exists.
      Parameters:
      other - the TimeLineRange to intersect with
      Returns:
      an array containing [begin, end] dates of the intersection, or null if no intersection
    • contains

      public boolean contains(Date date, boolean excludeEndDate)
      Checks if the specified date falls within this timeline range. Provides control over whether the end date boundary is included in the containment check.
      Parameters:
      date - the date to check for containment
      excludeEndDate - if true, the end date is excluded from containment; if false, it's included
      Returns:
      true if the date is contained within the range according to the end date exclusion setting
    • isAdjacent

      public boolean isAdjacent(TimeLineRange range)
      Checks if this range is adjacent to another range. Ranges are adjacent if one ends exactly when the other begins.
      Parameters:
      range - the TimeLineRange to check for adjacency
      Returns:
      true if the ranges are adjacent, false otherwise
    • getDuration

      public int getDuration(int unit)
      Calculates the duration of this timeline range in the specified time unit.
      Parameters:
      unit - the time unit for duration calculation
      Returns:
      the duration of the range in the specified unit
    • toString

      public String toString()
      Overrides:
      toString in class Object