Skip to content

Commit fe9b652

Browse files
committed
Merge branch 'develop'
2 parents 98b4a18 + 4e2a516 commit fe9b652

File tree

19 files changed

+1497
-379
lines changed

19 files changed

+1497
-379
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,6 @@ out/
99

1010
# Ignore files with secrets
1111
publish.properties
12+
13+
# Kotlin build files
14+
.kotlin

README.md

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,71 @@ val areIncluded = now + 50.seconds in interval // true
2626
val size: Duration = interval.size // 100 seconds
2727
```
2828

29+
## Interval Unions
30+
31+
Intervals are a subset of _interval unions_, which represent a collection of intervals.
32+
The result of operations on an interval can result in an interval union.
33+
Since operations are generally defined on the base interface, you can easily chain operations without caring about the concrete type.
34+
35+
```kotlin
36+
val start = interval( 0, 100 ) // Interval: [0, 100]
37+
val areIncluded = 50 in start && 100 in start // true
38+
val splitInTwo = start - interval( 25, 85 ) // Union: [[0, 25), (85, 100]]
39+
val areExcluded = 50 !in splitInTwo && 85 !in splitInTwo // true
40+
val unite = splitInTwo + interval( 10, 90 ) // Interval: [0, 100]
41+
val backToStart = start == unite // true
42+
```
43+
44+
An interval union contains any number of intervals.
45+
46+
| Intervals in a union | Description |
47+
|:--------------------:|:-----------------------------------:|
48+
| 0 | An empty set |
49+
| 1 | An interval |
50+
| > 1 | Disjoint and non-adjacent intervals |
51+
52+
Intervals in a union can be iterated over in order and don't intersect (are disjoint), and will always have _some_ values lying in between them (are non-adjacent).
53+
E.g., `[4, 5]` and `[6, 7]` are adjacent intervals in case they use integer types.
54+
Two non-intersecting intervals with a shared endpoint are also adjacent, regardless of type, if one of the intervals includes the endpoint.
55+
E.g., `[4.0, 5.0)` and `[5.0, 7.0]` are adjacent.
56+
Instead, these are represented as a single interval: `[4, 7]` and `[4.0, 7.0]` respectively.
57+
58+
## Operations
59+
60+
Intervals and interval unions are immutable.
61+
Operations don't modify the instance the operation is executed on.
62+
Instead, new instances are returned if the operation results in a different set of values.
63+
64+
The following operations are available for any `IntervalUnion<T, TSize>`:
65+
66+
| Operation | Description |
67+
|:-------------------:|:--------------------------------------------------------------------------------------------:|
68+
| `isEmpty()` | Determines whether this is an empty set. |
69+
| `getBounds()` | Gets the upper and lower bound of the set. |
70+
| `contains()` (`in`) | Determines whether a value lies in the set. |
71+
| `minus()` (`-`) | Subtract an interval from the set. |
72+
| `plus()` (`+`) | Add an interval from the set. |
73+
| `intersects()` | Determines whether another interval intersects with this set. |
74+
| `setEquals()` | Determines whether a set represents the same values. |
75+
| `iterator()` | Iterate over all intervals in the union, in order. |
76+
| `toString()` | Output as a string using common interval notation, e.g., `[0, 10]` or `[[0, 10), (10, 20]]`. |
77+
78+
The following operations are specific to `Interval<T, TSize>`:
79+
80+
| Operation | Description |
81+
|:----------------------------------------------:|:----------------------------------------------------------------------------------------------------------:|
82+
| `start`, `end` | The values originally passed as the start and end of the interval. |
83+
| `isStartIncluded`, `isEndIncluded` | Determines whether `start` and `end` respectively are included in the interval. |
84+
| `isClosedInterval` | Determines whether both `start` and `end` are included in the interval. |
85+
| `isOpenInterval` | Determines whether both `start` and `end` are excluded from the interval. |
86+
| `isReversed` | Determines whether `start` is greater than `end`. |
87+
| `lowerBound`, `upperBound` | Corresponds to `start` and `end`, but swapped if `isReversed`. |
88+
| `isLowerBoundIncluded`, `isUpperBoundIncluded` | Corresponds to `isStartIncluded` and `isEndIncluded`, but swapped if `isReversed`. |
89+
| `size` | The absolute difference between `start` and `end`. |
90+
| `nonReversed()` | `reverse()` the interval in case it `isReversed`. |
91+
| `reverse()` | Return an interval which swaps `start` with `end`, as well as boundary inclusions. |
92+
| `canonicalize()` | Return the interval in canonical form. E.g., The canonical form of `[5, 1)` is `[2, 5]` for integer types. |
93+
2994
## Interval Types
3095

3196
This library includes a generic base class `Interval<T, TSize>` which can be used to create intervals for any type.

build-logic/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@ repositories {
88
}
99

1010
dependencies {
11-
implementation("org.jetbrains.kotlin:kotlin-gradle-plugin:1.9.23")
11+
implementation("org.jetbrains.kotlin:kotlin-gradle-plugin:2.0.0")
1212
implementation("org.jetbrains.dokka:dokka-gradle-plugin:1.9.20")
1313
}

build-logic/src/main/kotlin/interval.library-conventions.gradle.kts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import java.io.FileInputStream
22
import java.util.Properties
33
import org.jetbrains.dokka.Platform
44
import org.jetbrains.dokka.gradle.DokkaTask
5+
import org.jetbrains.kotlin.gradle.ExperimentalKotlinGradlePluginApi
6+
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
57

68

79
plugins {
@@ -18,8 +20,9 @@ repositories {
1820

1921
kotlin {
2022
jvm {
21-
compilations.all {
22-
kotlinOptions.jvmTarget = "1.8"
23+
@OptIn(ExperimentalKotlinGradlePluginApi::class)
24+
compilerOptions {
25+
jvmTarget = JvmTarget.JVM_1_8
2326
}
2427
testRuns["test"].executionTask.configure {
2528
useJUnitPlatform()

build.gradle.kts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
plugins {
2-
id("io.github.gradle-nexus.publish-plugin") version "1.1.0"
2+
id("io.github.gradle-nexus.publish-plugin") version "2.0.0"
33
}
44

55
repositories {
@@ -21,7 +21,7 @@ if (publishPropertiesFile.exists()) {
2121
publishProperties.load(java.io.FileInputStream(publishPropertiesFile))
2222
}
2323
group = "io.github.whathecode.kotlinx.interval"
24-
version = "1.0.0-alpha.5"
24+
version = "1.0.0"
2525
nexusPublishing {
2626
repositories {
2727
sonatype {
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-bin.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.9-bin.zip
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists

0 commit comments

Comments
 (0)