public class Span
extends java.lang.Object
implements java.io.Serializable, java.lang.Iterable<java.lang.Integer>
Constructor and Description |
---|
Span(int s,
int e)
This assumes that s <= e.
|
Span(Span... spans)
Creates a span that encloses all spans in the argument list.
|
Modifier and Type | Method and Description |
---|---|
boolean |
contains(int i)
Returns true if i is inside this span.
|
boolean |
contains(Span otherSpan)
Returns true if this span contains otherSpan.
|
static int |
distance(Span a,
Span b)
Returns the smallest distance between two spans.
|
int |
end() |
boolean |
equals(java.lang.Object other) |
void |
expandToInclude(Span otherSpan) |
static Span |
fromPair(IntPair span)
Another silly translation between a pair and a span.
|
static Span |
fromPair(Pair<java.lang.Integer,java.lang.Integer> span)
A silly translation between a pair and a span.
|
static Span |
fromPairOneIndexed(Pair<java.lang.Integer,java.lang.Integer> span)
A silly translation between a pair and a span.
|
static Span |
fromValues(int val1,
int val2)
Safe way to construct Spans if you're not sure which value is higher.
|
static Span |
fromValues(java.lang.Object... values) |
int |
hashCode() |
boolean |
isAfter(Span otherSpan)
Returns true if this span starts after the otherSpan's end.
|
boolean |
isBefore(Span otherSpan)
Returns true if this span ends before the otherSpan starts.
|
java.util.Iterator<java.lang.Integer> |
iterator() |
static int |
overlap(Span spanA,
Span spanB) |
static boolean |
overlaps(Span spanA,
java.util.Collection<Span> spanB) |
static boolean |
overlaps(Span spanA,
Span spanB) |
void |
setEnd(int e) |
void |
setStart(int s) |
int |
size() |
int |
start() |
Span |
toExclusive()
Convert an end-inclusive span to an end-exclusive span.
|
Span |
toInclusive()
Convert an end-exclusive span to an end-inclusive span.
|
java.lang.String |
toString() |
Span |
translate(int diff)
Move a span by the given amount.
|
static Span |
union(Span a,
Span b)
The union of two spans.
|
public Span(int s, int e)
public Span(Span... spans)
public static Span fromValues(int val1, int val2)
public static Span fromValues(java.lang.Object... values)
public int start()
public int end()
public void setStart(int s)
public void setEnd(int e)
public boolean equals(java.lang.Object other)
equals
in class java.lang.Object
public int hashCode()
hashCode
in class java.lang.Object
public java.lang.String toString()
toString
in class java.lang.Object
public void expandToInclude(Span otherSpan)
public boolean contains(Span otherSpan)
public boolean contains(int i)
public boolean isBefore(Span otherSpan)
java.lang.IllegalArgumentException
- if either span contains the other spanpublic boolean isAfter(Span otherSpan)
java.lang.IllegalArgumentException
- if either span contains the other spanpublic Span translate(int diff)
diff
- The difference to ADD to both the beginning and end of the span. So, -1 moves the span left by one.public Span toInclusive()
public Span toExclusive()
public java.util.Iterator<java.lang.Integer> iterator()
iterator
in interface java.lang.Iterable<java.lang.Integer>
public int size()
public static int distance(Span a, Span b)
public static Span fromPair(Pair<java.lang.Integer,java.lang.Integer> span)
public static Span fromPair(IntPair span)
public static Span fromPairOneIndexed(Pair<java.lang.Integer,java.lang.Integer> span)