public class Interval<E extends java.lang.Comparable<E>> extends Pair<E,E> implements HasInterval<E>, java.io.Serializable
Modifier and Type | Class and Description |
---|---|
static class |
Interval.RelType
RelType gives the basic types of relations between two intervals
|
Pair.ByFirstPairComparator<T1,T2>, Pair.ByFirstReversePairComparator<T1,T2>, Pair.BySecondPairComparator<T1,T2>, Pair.BySecondReversePairComparator<T1,T2>
Modifier and Type | Field and Description |
---|---|
static int |
INTERVAL_OPEN_BEGIN
Flag indicating that an interval's begin point is not inclusive
(by default, begin points are inclusive)
|
static int |
INTERVAL_OPEN_END
Flag indicating that an interval's end point is not inclusive
(by default, begin points are inclusive)
|
static java.util.function.ToDoubleFunction<HasInterval<java.lang.Integer>> |
LENGTH_SCORER |
protected static int |
REL_FLAGS_AFTER |
protected static int |
REL_FLAGS_BEFORE |
static int |
REL_FLAGS_EE_AFTER
The first interval ends after the second ends
|
static int |
REL_FLAGS_EE_BEFORE
The first interval ends before the second ends
|
static int |
REL_FLAGS_EE_SAME
Both intervals have the same end point
|
protected static int |
REL_FLAGS_EE_SHIFT |
static int |
REL_FLAGS_EE_UNKNOWN
The relationship between the end points of the
two intervals is unknown (used for fuzzy intervals)
|
static int |
REL_FLAGS_ES_AFTER
The end point of the first interval is after
the start point of the second interval
(the two intervals overlap)
|
static int |
REL_FLAGS_ES_BEFORE
The end point of the first interval is before
the start point of the second interval
(the first interval is before the second)
|
static int |
REL_FLAGS_ES_SAME
The end point of the first interval is the same
as the start point of the second interval
(the first interval is before the second)
|
protected static int |
REL_FLAGS_ES_SHIFT |
static int |
REL_FLAGS_ES_UNKNOWN
The relationship between the end point of the first
interval and the start point of the second interval
is unknown (used for fuzzy intervals)
|
static int |
REL_FLAGS_INTERVAL_AFTER
The first interval is entirely after the second interval
(the start of the first interval happens after the end of the second)
|
static int |
REL_FLAGS_INTERVAL_ALMOST_AFTER |
static int |
REL_FLAGS_INTERVAL_ALMOST_BEFORE |
static int |
REL_FLAGS_INTERVAL_ALMOST_SAME |
static int |
REL_FLAGS_INTERVAL_BEFORE
The first interval is entirely before the second interval
(the end of the first interval happens before the start of the second)
|
static int |
REL_FLAGS_INTERVAL_CONTAIN
The first interval contains the second interval.
|
static int |
REL_FLAGS_INTERVAL_FUZZY |
static int |
REL_FLAGS_INTERVAL_INSIDE
The first interval is inside the second interval.
|
static int |
REL_FLAGS_INTERVAL_OVERLAP
The first interval overlaps with the second interval.
|
static int |
REL_FLAGS_INTERVAL_SAME
The intervals are the same (have the same start and end points).
|
static int |
REL_FLAGS_INTERVAL_UNKNOWN
It is uncertain what the relationship between the
two intervals are...
|
protected static int |
REL_FLAGS_SAME |
static int |
REL_FLAGS_SE_AFTER
The start point of the first interval is after
the end point of the second interval
(the second interval is before the first)
|
static int |
REL_FLAGS_SE_BEFORE
The start point of the first interval is before
the end point of the second interval
(the two intervals overlap)
|
static int |
REL_FLAGS_SE_SAME
The start point of the first interval is the same
as the end point of the second interval
(the second interval is before the first)
|
protected static int |
REL_FLAGS_SE_SHIFT |
static int |
REL_FLAGS_SE_UNKNOWN
The relationship between the start point of the first
interval and the end point of the second interval
is unknown (used for fuzzy intervals)
|
static int |
REL_FLAGS_SS_AFTER
The first interval starts after the second starts
|
static int |
REL_FLAGS_SS_BEFORE
The first interval starts before the second starts
|
static int |
REL_FLAGS_SS_SAME
Both intervals have the same start point
|
protected static int |
REL_FLAGS_SS_SHIFT |
static int |
REL_FLAGS_SS_UNKNOWN
The relationship between the start points of the
two intervals is unknown (used for fuzzy intervals)
|
protected static int |
REL_FLAGS_UNKNOWN |
CONTAINS_FIRST_ENDPOINTS_COMPARATOR, ENDPOINTS_COMPARATOR, LENGTH_ENDPOINTS_COMPARATOR, LENGTH_GT_COMPARATOR, LENGTH_LT_COMPARATOR, NESTED_FIRST_ENDPOINTS_COMPARATOR
Modifier | Constructor and Description |
---|---|
protected |
Interval(E a,
E b,
int flags) |
Modifier and Type | Method and Description |
---|---|
protected static int |
addIntervalRelationFlags(int flags,
boolean checkFuzzy) |
static boolean |
checkFlagExclusiveSet(int flags,
int flag,
int mask)
Utility function to check if a particular flag is set exclusively
given a particular set of flags and a mask.
|
static boolean |
checkFlagSet(int flags,
int flag)
Utility function to check if a particular flag is set
given a particular set of flags.
|
static boolean |
checkMultipleBitSet(int flags)
Utility function to check if multiple bits are set for flags
|
int |
compareIntervalOrder(Interval<E> other)
Returns order of another interval compared to this one
|
boolean |
contains(E p)
Checks whether the point p is contained inside this interval.
|
boolean |
contains(Interval<E> other) |
boolean |
containsOpen(E p) |
boolean |
equals(java.lang.Object o) |
Interval |
expand(Interval<E> other)
Returns (smallest) interval that contains both this and the other interval
|
static int |
extractRelationSubflags(int flags,
int shift) |
E |
getBegin()
Returns the start point.
|
E |
getEnd()
Returns the end point.
|
Interval<E> |
getInterval()
Returns this interval.
|
static double |
getMidPoint(Interval<java.lang.Integer> interval) |
static double |
getRadius(Interval<java.lang.Integer> interval) |
Interval.RelType |
getRelation(Interval<E> other)
Returns the relationship of this interval to the other interval
The most specific relationship from the following is returned.
|
int |
getRelationFlags(Interval<E> other)
Return set of flags indicating possible relationships between
this interval and another interval.
|
int |
hashCode() |
boolean |
includesBegin()
Returns whether the start endpoint is included in the interval
|
boolean |
includesEnd()
Returns whether the end endpoint is included in the interval
|
Interval |
intersect(Interval<E> other)
Returns interval that is the intersection of this and the other interval
Returns null if intersect is null
|
boolean |
isIntervalComparable(Interval<E> other)
Checks whether this interval is comparable with another interval
comes before or after
|
static <T extends HasInterval<java.lang.Integer>> |
lengthEndpointsComparator() |
static <T extends HasInterval<java.lang.Integer>> |
lengthScorer() |
protected static <E extends java.lang.Comparable<E>> |
max(E a,
E b) |
protected static <E extends java.lang.Comparable<E>> |
min(E a,
E b) |
boolean |
overlaps(Interval<E> other)
Check whether this interval overlaps with the other interval.
|
static <E extends java.lang.Comparable<E>> |
toInterval(E a,
E b)
Create an interval with the specified endpoints in the specified order.
|
static <E extends java.lang.Comparable<E>> |
toInterval(E a,
E b,
int flags)
Create an interval with the specified endpoints in the specified order,
using the specified flags.
|
protected static int |
toRelFlags(int comp,
int shift) |
static <E extends java.lang.Comparable<E>> |
toValidInterval(E a,
E b)
Create an interval with the specified endpoints, reordering them as needed
|
static <E extends java.lang.Comparable<E>> |
toValidInterval(E a,
E b,
int flags)
Create an interval with the specified endpoints, reordering them as needed,
using the specified flags
|
public static final int INTERVAL_OPEN_BEGIN
public static final int INTERVAL_OPEN_END
protected static final int REL_FLAGS_SAME
protected static final int REL_FLAGS_BEFORE
protected static final int REL_FLAGS_AFTER
protected static final int REL_FLAGS_UNKNOWN
protected static final int REL_FLAGS_SS_SHIFT
protected static final int REL_FLAGS_SE_SHIFT
protected static final int REL_FLAGS_ES_SHIFT
protected static final int REL_FLAGS_EE_SHIFT
public static final int REL_FLAGS_SS_SAME
|---- interval 1 ----? |---- interval 2 ----?
public static final int REL_FLAGS_SS_BEFORE
|---- interval 1 ----? |---- interval 2 ----? or |-- interval 1 --? |---- interval 2 ----?
public static final int REL_FLAGS_SS_AFTER
|---- interval 1 ----? |---- interval 2 ----? or |---- interval 1 ----? |-- interval 2 --?
public static final int REL_FLAGS_SS_UNKNOWN
public static final int REL_FLAGS_SE_SAME
|---- interval 1 ----? ?---- interval 2 ---|
public static final int REL_FLAGS_SE_BEFORE
|---- interval 1 ----? ?---- interval 2 ---|
public static final int REL_FLAGS_SE_AFTER
|---- interval 1 ---? ?-- interval 2 ---|
public static final int REL_FLAGS_SE_UNKNOWN
public static final int REL_FLAGS_ES_SAME
?---- interval 1 ---| |---- interval 2 ----?
public static final int REL_FLAGS_ES_BEFORE
?-- interval 1 ---| |---- interval 2 ---?
public static final int REL_FLAGS_ES_AFTER
?---- interval 1 ---| |---- interval 2 ----?
public static final int REL_FLAGS_ES_UNKNOWN
public static final int REL_FLAGS_EE_SAME
?---- interval 1 ----| ?---- interval 2 ----|
public static final int REL_FLAGS_EE_BEFORE
?---- interval 1 ----| ?---- interval 2 ----| or ?-- interval 1 --| ?---- interval 2 ----|
public static final int REL_FLAGS_EE_AFTER
?---- interval 1 ----| ?---- interval 2 ----| or ?---- interval 1 ----| ?-- interval 2 --|
public static final int REL_FLAGS_EE_UNKNOWN
public static final int REL_FLAGS_INTERVAL_SAME
|---- interval 1 ----| |---- interval 2 ----|
public static final int REL_FLAGS_INTERVAL_BEFORE
?---- interval 1 ----| |---- interval 2 ----?
public static final int REL_FLAGS_INTERVAL_AFTER
|---- interval 1 ----? ?---- interval 2 ----|
public static final int REL_FLAGS_INTERVAL_OVERLAP
public static final int REL_FLAGS_INTERVAL_INSIDE
|---- interval 1 ----| |---- interval 2 -----------|
public static final int REL_FLAGS_INTERVAL_CONTAIN
|---- interval 1 -----------| |---- interval 2 ----|
public static final int REL_FLAGS_INTERVAL_UNKNOWN
public static final int REL_FLAGS_INTERVAL_ALMOST_SAME
public static final int REL_FLAGS_INTERVAL_ALMOST_BEFORE
public static final int REL_FLAGS_INTERVAL_ALMOST_AFTER
public static final int REL_FLAGS_INTERVAL_FUZZY
public static final java.util.function.ToDoubleFunction<HasInterval<java.lang.Integer>> LENGTH_SCORER
public static <E extends java.lang.Comparable<E>> Interval<E> toInterval(E a, E b)
E
- type of the interval endpointsa
- start endpointsb
- end endpointpublic static <E extends java.lang.Comparable<E>> Interval<E> toInterval(E a, E b, int flags)
E
- type of the interval endpointsa
- start endpointsb
- end endpointflags
- flags characterizing the intervalpublic static <E extends java.lang.Comparable<E>> Interval<E> toValidInterval(E a, E b)
E
- type of the interval endpointsa
- one of the endpointsb
- the other endpointpublic static <E extends java.lang.Comparable<E>> Interval<E> toValidInterval(E a, E b, int flags)
E
- type of the interval endpointsa
- one of the endpointsb
- the other endpointflags
- flags characterizing the intervalpublic Interval<E> getInterval()
getInterval
in interface HasInterval<E extends java.lang.Comparable<E>>
public E getBegin()
public E getEnd()
protected static <E extends java.lang.Comparable<E>> E max(E a, E b)
protected static <E extends java.lang.Comparable<E>> E min(E a, E b)
public boolean contains(E p)
p
- point to checkpublic boolean containsOpen(E p)
public Interval expand(Interval<E> other)
other
- - Other interval to includepublic Interval intersect(Interval<E> other)
other
- interval with which to intersectpublic boolean overlaps(Interval<E> other)
other
- interval to compare withpublic boolean includesBegin()
public boolean includesEnd()
public boolean isIntervalComparable(Interval<E> other)
other
- interval to compare withpublic int compareIntervalOrder(Interval<E> other)
other
- Interval to compare withprotected static int toRelFlags(int comp, int shift)
public int getRelationFlags(Interval<E> other)
other
- Interval with which to compare withprotected static int addIntervalRelationFlags(int flags, boolean checkFuzzy)
public static int extractRelationSubflags(int flags, int shift)
public static boolean checkMultipleBitSet(int flags)
flags
- flags to checkpublic static boolean checkFlagSet(int flags, int flag)
flags
- flags to checkflag
- bit for flag of interest (is this flag set or not)public static boolean checkFlagExclusiveSet(int flags, int flag, int mask)
flags
- flags to checkflag
- bit for flag of interest (is this flag set or not)mask
- bitmask of bits to checkpublic Interval.RelType getRelation(Interval<E> other)
other
- The other interval with which to compare withpublic boolean equals(java.lang.Object o)
public int hashCode()
public static double getMidPoint(Interval<java.lang.Integer> interval)
public static double getRadius(Interval<java.lang.Integer> interval)
public static <T extends HasInterval<java.lang.Integer>> java.util.Comparator<T> lengthEndpointsComparator()
public static <T extends HasInterval<java.lang.Integer>> java.util.function.ToDoubleFunction<T> lengthScorer()