public class Range extends Object
| Constructor and Description |
|---|
Range(int min,
int max)
Note that both min and max are inclusive
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
after(int x)
returns true if this range is after given number
|
boolean |
before(int x)
return true if this range is before given number
|
boolean |
contains(int x)
returns true if this range contains given number
|
boolean |
equals(Object obj) |
int |
hashCode() |
static List<Range> |
intersection(List<Range> list1,
List<Range> list2) |
Range |
intersection(Range that)
return the portion of range that is common to this range and given range.
If there is nothing common, then null is returned. |
static List<Range> |
minus(List<Range> list1,
List<Range> list2) |
Range[] |
minus(Range that)
returns the portion(s) of this range that are not present in given range.
|
boolean[] |
position(Range that)
tells the position this range with respect to given range.
|
static boolean |
same(List<Range> list1,
List<Range> list2) |
Range[] |
split(Range that)
this method splits this range into 3 regions with respect to given range
|
String |
toString() |
static List<Range> |
union(List<Range> ranges) |
Range[] |
union(Range that)
returns union of this range with given range.
if both ranges are adjacent/intersecting to each other, then the returned array will have only one range. |
public boolean before(int x)
------------ o
public boolean after(int x)
o --------------
public boolean contains(int x)
------o--------
public boolean[] position(Range that)
the return value is boolean array of size 3.
1st boolean ==> true if some portion of this range is before given rangeideally, you can remebers these boolean as { before, inside, after }
2nd boolean ==> true if this range intersects with given range
3rd boolean ==> true if some portion of this range is after given range
public Range[] split(Range that)
the return value is Range array of size 3.
1st range ==> the portion of this range that is before given rangeNote that the values in returned array can be null, if there is no range satifying the requirement.
2nd range ==> the portion of range that is common to this range and given range
3rd range ==> the portion of this range that is after given range.
public Range intersection(Range that)
public Range[] union(Range that)
public Range[] minus(Range that)
Copyright © 2021. All rights reserved.