Kotlin Range Sets

Implementation of set logic on the underlying values of Kotlin's Range classes.

License

License

Categories

Categories

Kotlin Languages
GroupId

GroupId

com.github.jonpeterson
ArtifactId

ArtifactId

kotlin-range-sets
Last Version

Last Version

1.0.0
Release Date

Release Date

Type

Type

jar
Description

Description

Kotlin Range Sets
Implementation of set logic on the underlying values of Kotlin's Range classes.
Project URL

Project URL

https://github.com/jonpeterson/kotlin-range-sets
Source Code Management

Source Code Management

https://github.com/jonpeterson/kotlin-range-sets

Download kotlin-range-sets

How to add to project

<!-- https://jarcasting.com/artifacts/com.github.jonpeterson/kotlin-range-sets/ -->
<dependency>
    <groupId>com.github.jonpeterson</groupId>
    <artifactId>kotlin-range-sets</artifactId>
    <version>1.0.0</version>
</dependency>
// https://jarcasting.com/artifacts/com.github.jonpeterson/kotlin-range-sets/
implementation 'com.github.jonpeterson:kotlin-range-sets:1.0.0'
// https://jarcasting.com/artifacts/com.github.jonpeterson/kotlin-range-sets/
implementation ("com.github.jonpeterson:kotlin-range-sets:1.0.0")
'com.github.jonpeterson:kotlin-range-sets:jar:1.0.0'
<dependency org="com.github.jonpeterson" name="kotlin-range-sets" rev="1.0.0">
  <artifact name="kotlin-range-sets" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.github.jonpeterson', module='kotlin-range-sets', version='1.0.0')
)
libraryDependencies += "com.github.jonpeterson" % "kotlin-range-sets" % "1.0.0"
[com.github.jonpeterson/kotlin-range-sets "1.0.0"]

Dependencies

compile (1)

Group / Artifact Type Version
org.jetbrains.kotlin : kotlin-stdlib jar 1.0.2

test (2)

Group / Artifact Type Version
org.spockframework : spock-core jar 1.0-groovy-2.4
org.codehaus.groovy : groovy-all jar 2.4.5

Project Modules

There are no modules declared in this project.

Kotlin Range Sets

Implementation of set logic on the underlying values of Kotlin's Range classes.

Compatibility

Compiled for Java 6 and Kotlin 1.0.2.

Getting Started with Gradle

dependencies {
    compile 'com.github.jonpeterson:kotlin-range-sets:1.0.0'
}

Getting Started with Maven

<dependency>
    <groupId>com.github.jonpeterson</groupId>
    <artifactId>kotlin-range-sets</artifactId>
    <version>1.0.0</version>
</dependency>

Documentation

Dokka

Examples

// create set with overlapped, out-of-order ranges
val set = IntRangeSet(5..9, 3..7, 13..16)

// set is kept in normalized form
assert(set == IntRangeSet(3..9, 13..16))


// set doesn't contain 10
assert(set.containsValue(10) == false)

// set contains 4, 5, 6, 7, 8
assert(set.contains(4..8) == true)

// set is missing 10, 11, 12
assert(set.contains(8..14) == false)


// nothing was added
assert(set.add(7..9) == false)

// 17 was added
assert(set.add(15..17) == true)
assert(set == IntRangeSet(3..9, 13..17))


// nothing was removed
assert(set.remove(10..12) == false)

// 9 was removed
assert(set.remove(9..11) == true)
assert(set == IntRangeSet(3..8, 13..17))


// everything was retained (nothing changed)
assert(set.retain(2..20) == false)

// 3, 4 were dropped
assert(set.retain(5..18) == true)
assert(set == IntRangeSet(5..8, 13..17))


// created new range set with the difference
assert(set.difference(7..19) == IntRangeSet(9..12, 18..19))

// created new range set with the gaps between the existing ranges
assert(set.gaps() == IntRangeSet(9..12))

Versions

Version
1.0.0