Skip to content
flbulgarelli edited this page Jan 28, 2012 · 1 revision

Range

Introduction

Ranges are simple immutable, value objects that represent a closed interval of Comparable objects.

Usage samples

Overlapping

    Range.from(10, 400).overlaps(Range.from(60, 80)); //true
    Range.from(10, 400).overlaps(Range.from(5, 80)); //true
    Range.from(10, 400).overlaps(Range.from(500, 900)); //false

Interval Inclusion

 Range.from(9L, 65L).includes(Range.from(5L, 900L)); //false

Element Inclusion

 Range.from("Hello", "World").contains("Java"); //true "Java" is lexicographically between "Hello" & "World"
 Range.from(TimeUnit.SECONDS, TimeUnit.DAYS).contains(TimeUnit.HOURS); //true java.util.concurrent.TimeUnit.HOURS is between SECONDS & DAYS

Learn More

Check its Javadoc

Clone this wiki locally