Class TimeLine

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

public class TimeLine extends Object implements Serializable
Timeline management class for creating and processing temporal ranges from TimeLineItem objects.
Uses configurable OverlapResolver and MergeResolver strategies for handling range conflicts and merging.
Since:
1.0
See Also:
  • Field Details

  • Constructor Details

    • TimeLine

      public TimeLine()
  • Method Details

    • makeInstance

      public static TimeLine makeInstance()
      Creates a new TimeLine instance with default resolvers. Uses PriorityOverlapResolver for overlap resolution and DefaultMergeResolver for merging.
      Returns:
      a new TimeLine instance with default configuration
    • addRange

      public void addRange(TimeLineItem<?> item)
      Adds a new timeline item to this timeline. Creates a TimeLineRange from the item and adds it to the internal range collection.
      Parameters:
      item - the TimeLineItem to add to the timeline
    • setOverlapResolver

      public void setOverlapResolver(OverlapResolver overlapResolver)
      Sets the overlap resolver.
      Parameters:
      overlapResolver - the OverlapResolver to use for handling overlapping ranges
    • setMergeResolver

      public void setMergeResolver(MergeResolver mergeResolver)
      Sets the merge resolver.
      Parameters:
      mergeResolver - the MergeResolver to use for merging adjacent ranges
    • getRanges

      public List<TimeLineRange> getRanges()
      Calculates the processed timeline ranges after resolving overlaps and merging adjacent ranges.
      Returns:
      a list of processed and sorted TimeLineRange objects representing the final timeline
    • getOverlappingRanges

      protected List<TimeLineRange> getOverlappingRanges(Date date)
      Finds all timeline ranges that intersect with the specified date. End dates are excluded from intersection detection (ranges ending exactly at the date are not included).
      Parameters:
      date - the date to check for intersections
      Returns:
      a list of TimeLineRange objects that intersect with the given date
    • getOverlappingSortedRangesByType

      public List<TimeLineRange> getOverlappingSortedRangesByType(Date date, String type)
      Finds all processed timeline ranges of a specific type that intersect with the given date. Filters the final timeline results by type name and then by date intersection.
      Parameters:
      date - the date to check for intersections
      type - the timeline item type name to filter by
      Returns:
      a list of TimeLineRange objects of the specified type that intersect with the date
    • mergeAdjacentRanges

      protected List<TimeLineRange> mergeAdjacentRanges(List<TimeLineRange> allRanges)
      Merges adjacent ranges that can be combined according to the merge resolver. Sequential ranges that are adjacent and mergeable are combined into single ranges.
      Parameters:
      allRanges - the list of ranges to process for merging
      Returns:
      a new list with adjacent ranges merged where possible
    • getRangesOfType

      public List<TimeLineRange> getRangesOfType(String name)
      Filters the processed timeline ranges to return only those of the specified type. Processes the full timeline and then filters by timeline item name.
      Parameters:
      name - the timeline item type name to filter by
      Returns:
      a list of TimeLineRange objects matching the specified type
    • getTotalDurationOfRangesOfType

      public Integer getTotalDurationOfRangesOfType(String name, int unit)
      Calculates the total duration of all timeline ranges of a specific type. Sums the durations of all ranges matching the specified type name.
      Parameters:
      name - the timeline item type name to calculate duration for
      unit - the time unit for duration calculation
      Returns:
      the total duration of all ranges of the specified type in the given unit
    • getBeforeAdjacentRanges

      public List<TimeLineRange> getBeforeAdjacentRanges(TimeLineRange range, String name)
      Finds all timeline ranges that end exactly when the specified range begins. Optionally filters results by timeline item type name.
      Parameters:
      range - the reference TimeLineRange to find predecessors for
      name - the timeline item type name to filter by, or null for all types
      Returns:
      a list of TimeLineRange objects that are adjacent before the given range
    • getAfterAdjacentRanges

      public List<TimeLineRange> getAfterAdjacentRanges(TimeLineRange range, String name)
      Finds all timeline ranges that begin exactly when the specified range ends. Optionally filters results by timeline item type name.
      Parameters:
      range - the reference TimeLineRange to find successors for
      name - the timeline item type name to filter by, or null for all types
      Returns:
      a list of TimeLineRange objects that are adjacent after the given range
    • toString

      public String toString()
      Overrides:
      toString in class Object