TwoColoredRange

Two colored range - range that is filled completely with subranges of one of two colors. It provides features for painting and requesting subranges.

A newly created colored range looks like this (assuming range is 0..12 and defaultColor is c1):

0 4 8 12

[ c1 ]

Example of colored range:

0 4 8 12

[ c2 ][ c1 ][ c2 ]

All mutating and requesting functions are supposed to make smart subranges joining and splitting. For example, having colored range:

0 4 8 12

[ c2 ][ c1 ]

and applying color 2 to subrange 5..8 should change colored range to:

0 4 8 12

[ c2 ][ c1 ]

and a consequent call of getSubrangeOfColor(c2, 2, 4..10) should return 4..5.

Parameters

BoundType

the type of colored range bounds.

LengthType

the type of length between bounds. Usually it is the same as BoundType, but it may be different, for example: BoundType = LocalDate, LengthType = DatePeriod.

ColorType

the type of range colors.

Inheritors

Properties

Link copied to clipboard
abstract val defaultColor: ColorType

the default color, a colored range is supposed to be fully colored with it right after constructor call.

Link copied to clipboard
abstract val length: LengthType

the length of colored range.

Link copied to clipboard

the math used for calculating lengths and distances of subranges.

Link copied to clipboard
abstract val otherColor: ColorType

the second color.

Link copied to clipboard
abstract val range: ClosedRange<BoundType>

a regular range marking bounds of colored range.

Link copied to clipboard

the factory for ranges, it is used for custom ranges type. For example IntRange is more convenient than ClosedRange<BoundType> for equality checks outside the interface or class.

Link copied to clipboard
abstract val step: LengthType

the minimal non-zero length of a subrange and distance between two neighbour subranges. Usually it has a value of 1 for integer types of BoundType.

Functions

Link copied to clipboard
abstract fun getColor(bound: BoundType): ColorType

Looks for a subrange containing bound and returns its color.

Link copied to clipboard

getSubrangeOfColor called with maxLength = step and limitByRange = range.

abstract fun getSubrangeOfColor(color: ColorType, maxLength: LengthType): ClosedRange<BoundType>?

getSubrangeOfColor called with limitByRange = range.

abstract fun getSubrangeOfColor(color: ColorType, limitByRange: ClosedRange<BoundType>): ClosedRange<BoundType>?

getSubrangeOfColor called with maxLength = step.

abstract fun getSubrangeOfColor(color: ColorType, maxLength: LengthType, limitByRange: ClosedRange<BoundType>): ClosedRange<BoundType>?

Performs a search for a subrange with color color limited by limitByRange. If a subrange with length >= maxLength was found then returns a subrange from foundSubrange.start to foundSubrange.start + maxLength (involving math and rangeFactory). Otherwise returns first non-empty subrange with color color inside limitByRange or null.

Link copied to clipboard

Returns list of subranges colored with color.

Link copied to clipboard

Returns list of subranges colored with defaultColor.

Link copied to clipboard

Returns list of subranges colored with otherColor.

Link copied to clipboard
abstract operator fun iterator(): Iterator<Pair<ClosedRange<BoundType>, ColorType>>
Link copied to clipboard

Iterator limited by limitByRange.