public final class Interval extends Object implements Iterable<Integer>, XMLSerializable, XMLSerializable.OldVersionCompatible
XMLSerializable.OldVersionCompatible, XMLSerializable.VersionSupportTypeROOT_ELEMENT_NAME| Constructor and Description |
|---|
Interval(org.jdom.Element element)
Reconstructs this interval from a previously serialized element
|
Interval(int value)
Constructs a length 1 interval consisting of a single value.
|
Interval(int from,
int toExclusive) |
Interval(String intervalAsString)
Constructs an interval from its String representation.
|
| Modifier and Type | Method and Description |
|---|---|
Interval |
clipToRange(int minIndexInclusive,
int maxIndexExclusive)
Clips the ends of this interval so that it does not extend outside the range [minIndexInclusive,maxIndexExclusive).
|
boolean |
contains(int index) |
boolean |
contains(Interval otherInterval) |
static boolean |
contains(List<Interval> intervals,
int index)
Determine if at least one of the given intervals contains this index.
|
static Iterable<Integer> |
createIteratableForIntervalList(List<Interval> intervals)
Returns an Iterable that iterates over each value in each interval in a given list of intervals.
|
boolean |
equals(Object o) |
static Interval |
forInclusiveRange(int fromInclusive,
int toInclusive)
Constructs an interval where the 2nd value is inclusive rather than exclusive.
|
void |
fromXML(org.jdom.Element element)
Restore the object from the JDOM Element returned by
XMLSerializable.toXML(). |
List<Interval> |
getComplement(Interval otherIntervalContainedWithinThis) |
int |
getFrom() |
static List<Interval> |
getIntersection(List<List<Interval>> groups)
Returns a (merged) list of the intersecting intervals between groups of annotations.
|
Interval |
getIntersectionWith(Interval other) |
int |
getLength() |
int |
getMax()
Deprecated.
using
getMaxExclusive() or getMaxInclusive() instead is recommended as the code is easier to understand and less likely to contain bugs. |
int |
getMaxExclusive() |
int |
getMaxInclusive() |
int |
getMin() |
int |
getTo()
Deprecated.
using
getToExclusive() ()} or getToInclusive() ()} instead is recommended as the code is easier to understand and less likely to contain bugs. |
int |
getToExclusive() |
int |
getToInclusive() |
Geneious.MajorVersion |
getVersionSupport(XMLSerializable.VersionSupportType versionType)
Gets either the latest version this class can serialize to via
XMLSerializable.OldVersionCompatible.toXML(com.biomatters.geneious.publicapi.plugin.Geneious.MajorVersion, jebl.util.ProgressListener)
or the most recent version in which the XML returned from XMLSerializable.OldVersionCompatible.toXML(com.biomatters.geneious.publicapi.plugin.Geneious.MajorVersion, jebl.util.ProgressListener) last changed. |
int |
hashCode() |
boolean |
intersects(Interval interval) |
boolean |
isAdjacent(Interval otherInterval) |
boolean |
isDirectedLeft() |
Iterator<Integer> |
iterator() |
static List<Interval> |
merge(List<Interval> _intervals)
Merges a list of intervals, i.e.
|
Interval |
offsetBy(int amountToOffsetBy)
Creates a new interval, offset from this interval by the specified amount
|
Interval |
reverse() |
List<Interval> |
split(int... splitPositions)
Splits this interval into multiple intervals such that no splitPosition is contained within any of the intervals.
|
List<Interval> |
split(int splitPosition)
Splits this interval into 2 intervals such that everything <x is in one part of the interval and everything >=x is in the other part.
|
String |
toString() |
org.jdom.Element |
toXML()
Convert object to a JDOM element.
|
org.jdom.Element |
toXML(Geneious.MajorVersion majorVersion,
ProgressListener progressListener)
Serializes this class to XML format, potentially to a format readable by an earlier version of Geneious.
|
public Interval(int from,
int toExclusive)
from - 0 based index where the interval starts, inclusivetoExclusive - 0 based index where the interval finishes, exclusive - may be less than from for reverse directionpublic Interval(org.jdom.Element element)
throws XMLSerializationException
element - an element returned from a previous call to toXML().XMLSerializationException - if anything goes wrongpublic Interval(int value)
value - 0 based index of the only value to be contained in this intervalpublic Interval(String intervalAsString)
toString() method.intervalAsString - a value returned from Interval.toString().public org.jdom.Element toXML()
XMLSerializableXMLSerializable.fromXML(org.jdom.Element) can completely
restore the objects representation.
It is recommended that the returned element use XMLSerializable.ROOT_ELEMENT_NAME as its name,
in which case it must not define an attribute called "type". In this case,
fromXML, will be called with an element whose name may differ from the element
return from this function. This recommendation allows a more compact representation
of the XML can be stored.
This method generally should not be called directly. Instead, you should usually call
XMLSerializer.classToXML(String, XMLSerializable)
which calls this method internally.
PluginDocument implementations of this method may choose to throw an XMLSerializationException,
enclosed in a RuntimeException.toXML in interface XMLSerializablepublic Geneious.MajorVersion getVersionSupport(XMLSerializable.VersionSupportType versionType)
XMLSerializable.OldVersionCompatibleXMLSerializable.OldVersionCompatible.toXML(com.biomatters.geneious.publicapi.plugin.Geneious.MajorVersion, jebl.util.ProgressListener)
or the most recent version in which the XML returned from XMLSerializable.OldVersionCompatible.toXML(com.biomatters.geneious.publicapi.plugin.Geneious.MajorVersion, jebl.util.ProgressListener) last changed.getVersionSupport in interface XMLSerializable.OldVersionCompatibleversionType - specifies which version property to returnpublic org.jdom.Element toXML(Geneious.MajorVersion majorVersion, ProgressListener progressListener)
XMLSerializable.OldVersionCompatibleXMLSerializable.toXML() for a more
detailed description of what it means to serialize to XML.
All classes that implement this method must also implement XMLSerializable.toXML() and should delegate back to
this method using Geneious.getMajorVersion() and ProgressListener.EMPTY as parameters.toXML in interface XMLSerializable.OldVersionCompatiblemajorVersion - the major version of Geneious to serialize to XML for. For example "6.0" but not "6.0.0". This must be a version
returned greater or equal to a version returned from
getVersionSupport(VersionSupportType.OldestVersionSerializableTo)
and must never be greater than the current version (Geneious.getMajorVersion())progressListener - for reporting progress and cancellingpublic void fromXML(org.jdom.Element element)
throws XMLSerializationException
XMLSerializableXMLSerializable.toXML().
This method generally should not be called directly. Instead, you should usually call
XMLSerializer.classFromXML(org.jdom.Element)
or XMLSerializer.classFromXML(org.jdom.Element, Class)
which calls this method internally.
It is optional to implement this method. Instead of implementing an empty constructor and implementing
this method properly, the implementation may instead
throw an UnsupportedOperationException and implement a constructor
that takes a single Element as a parameter.
This allows for cleaner code such as support for final fields in the XMLSerializable class.
The element parameter should not be modified since it may be reused. If you need a modified version of it,
take a copy with Element.clone().fromXML in interface XMLSerializableelement - representation from a previous call to XMLSerializable.toXML()XMLSerializationException - if the Element can't be converted into this type of objectpublic static Interval forInclusiveRange(int fromInclusive, int toInclusive)
fromInclusive - 0 based index where the interval starts, inclusivetoInclusive - 0 based index where the interval finishes, inclusivepublic int getFrom()
public int getToExclusive()
@Deprecated public int getTo()
getToExclusive() ()} or getToInclusive() ()} instead is recommended as the code is easier to understand and less likely to contain bugs.public int getToInclusive()
public int getMin()
public int getMaxExclusive()
public int getMaxInclusive()
getMin(). This is equivalent to calling getMaxExclusive() -1.@Deprecated public int getMax()
getMaxExclusive() or getMaxInclusive() instead is recommended as the code is easier to understand and less likely to contain bugs.public List<Interval> getComplement(Interval otherIntervalContainedWithinThis)
otherIntervalContainedWithinThis - another interval, for which this.contains(otherIntervalContainedWithinThis) must be true.IllegalArgumentException - if otherIntervalContainedWithinThis was not contained by this.public boolean isDirectedLeft()
getToExclusive() < getFrom().)public int getLength()
public boolean contains(int index)
index - 0 based index to query whether or not it is in this interval.getMin() && index<getMaxExclusive()).public static Iterable<Integer> createIteratableForIntervalList(List<Interval> intervals)
intervals - the intervals to iterate over.public boolean intersects(Interval interval)
interval - another interval to test for intersection with this interval.public Interval getIntersectionWith(Interval other)
other - the other interval to get the intersection of with this.contains(Interval), then this returns a copy of the empty interval.public boolean contains(Interval otherInterval)
otherInterval - another interval to check whether it is contained in this interval.public boolean isAdjacent(Interval otherInterval)
otherInterval - the other interval.public List<Interval> split(int splitPosition)
splitPosition - the position to split this interval at.public Interval offsetBy(int amountToOffsetBy)
amountToOffsetBy - the amount to increment the start and end of this interval by. May be negative.public List<Interval> split(int... splitPositions)
splitPositions - the positions to split this interval at.public Interval reverse()
public static List<Interval> merge(List<Interval> _intervals)
_intervals - public static List<Interval> getIntersection(List<List<Interval>> groups)
groups - a list of lists of intervals, with each list of intervals being considered a group.public Interval clipToRange(int minIndexInclusive, int maxIndexExclusive)
minIndexInclusive - maxIndexExclusive - public static boolean contains(List<Interval> intervals, int index)
intervals - the intervals to check inindex - the index to check