Class TimeLine
java.lang.Object
overit.geocallapp.utilities.timeline.TimeLine
- All Implemented Interfaces:
Serializable
Timeline management class for creating and processing temporal ranges from
Uses configurable
TimeLineItem objects.Uses configurable
OverlapResolver and MergeResolver strategies for handling range conflicts and merging. - Since:
- 1.0
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected MergeResolverprotected OverlapResolverprotected List<TimeLineRange> -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddRange(TimeLineItem<?> item) Adds a new timeline item to this timeline.getAfterAdjacentRanges(TimeLineRange range, String name) Finds all timeline ranges that begin exactly when the specified range ends.getBeforeAdjacentRanges(TimeLineRange range, String name) Finds all timeline ranges that end exactly when the specified range begins.protected List<TimeLineRange> getOverlappingRanges(Date date) Finds all timeline ranges that intersect with the specified date.getOverlappingSortedRangesByType(Date date, String type) Finds all processed timeline ranges of a specific type that intersect with the given date.Calculates the processed timeline ranges after resolving overlaps and merging adjacent ranges.getRangesOfType(String name) Filters the processed timeline ranges to return only those of the specified type.getTotalDurationOfRangesOfType(String name, int unit) Calculates the total duration of all timeline ranges of a specific type.static TimeLineCreates a new TimeLine instance with default resolvers.protected List<TimeLineRange> mergeAdjacentRanges(List<TimeLineRange> allRanges) Merges adjacent ranges that can be combined according to the merge resolver.voidsetMergeResolver(MergeResolver mergeResolver) Sets the merge resolver.voidsetOverlapResolver(OverlapResolver overlapResolver) Sets the overlap resolver.toString()
-
Field Details
-
ranges
-
overlapResolver
-
mergeResolver
-
-
Constructor Details
-
TimeLine
public TimeLine()
-
-
Method Details
-
makeInstance
Creates a new TimeLine instance with default resolvers. UsesPriorityOverlapResolverfor overlap resolution andDefaultMergeResolverfor merging.- Returns:
- a new TimeLine instance with default configuration
-
addRange
Adds a new timeline item to this timeline. Creates aTimeLineRangefrom the item and adds it to the internal range collection.- Parameters:
item- theTimeLineItemto add to the timeline
-
setOverlapResolver
Sets the overlap resolver.- Parameters:
overlapResolver- theOverlapResolverto use for handling overlapping ranges
-
setMergeResolver
Sets the merge resolver.- Parameters:
mergeResolver- theMergeResolverto use for merging adjacent ranges
-
getRanges
Calculates the processed timeline ranges after resolving overlaps and merging adjacent ranges.- Returns:
- a list of processed and sorted
TimeLineRangeobjects representing the final timeline
-
getOverlappingRanges
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
TimeLineRangeobjects that intersect with the given date
-
getOverlappingSortedRangesByType
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 intersectionstype- the timeline item type name to filter by- Returns:
- a list of
TimeLineRangeobjects of the specified type that intersect with the date
-
mergeAdjacentRanges
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
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
TimeLineRangeobjects matching the specified type
-
getTotalDurationOfRangesOfType
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 forunit- the time unit for duration calculation- Returns:
- the total duration of all ranges of the specified type in the given unit
-
getBeforeAdjacentRanges
Finds all timeline ranges that end exactly when the specified range begins. Optionally filters results by timeline item type name.- Parameters:
range- the referenceTimeLineRangeto find predecessors forname- the timeline item type name to filter by, or null for all types- Returns:
- a list of
TimeLineRangeobjects that are adjacent before the given range
-
getAfterAdjacentRanges
Finds all timeline ranges that begin exactly when the specified range ends. Optionally filters results by timeline item type name.- Parameters:
range- the referenceTimeLineRangeto find successors forname- the timeline item type name to filter by, or null for all types- Returns:
- a list of
TimeLineRangeobjects that are adjacent after the given range
-
toString
-