an interface for an interval object and simple minimum implementation; note: in contrast to arachne, this is closed interval
git-svn-id: file:///humgen/gsa-scr1/gsa-engineering/svn_contents/trunk@108 348d0f76-0448-11de-a6fe-93d51630548a
This commit is contained in:
parent
29d2d460f3
commit
501e92d441
|
|
@ -0,0 +1,59 @@
|
|||
package org.broadinstitute.sting.utils;
|
||||
|
||||
/**
|
||||
* Created by IntelliJ IDEA.
|
||||
* User: asivache
|
||||
* Date: Mar 19, 2009
|
||||
* Time: 12:03:39 PM
|
||||
* To change this template use File | Settings | File Templates.
|
||||
*/
|
||||
|
||||
/** Abstraction of a closed interval [start,stop]
|
||||
*
|
||||
*/
|
||||
public interface Interval {
|
||||
/** Start position of the interval.
|
||||
*
|
||||
* @return <start> for the interval [start,stop]
|
||||
*/
|
||||
public long getStart();
|
||||
|
||||
/** Sets start position of the interval.
|
||||
*
|
||||
* @param s start coordinate
|
||||
*/
|
||||
public void setStart(long s);
|
||||
|
||||
/** End position of the interval.
|
||||
*
|
||||
* @return <stop> for the interval [start,stop]
|
||||
*/
|
||||
public long getStop();
|
||||
|
||||
/** Sets stop position of the interval.
|
||||
*
|
||||
* @param s stop coordinate
|
||||
*/
|
||||
public void setStop(long s);
|
||||
|
||||
/** Length of the interval. There is currently no contract, an implementation may return negative length
|
||||
* or a length inconsistent with getStop() - getStart() + 1 if it chooses so.
|
||||
*
|
||||
* @return a number representing the length of the interval according to specific implementation
|
||||
*/
|
||||
public long getLength();
|
||||
|
||||
/** Returns true if this interval overlaps with i as judjed by getStart() and getStop() positions of the
|
||||
* two interval objects.
|
||||
* @param i Another interval
|
||||
* @return true iff intervals overlap
|
||||
*/
|
||||
public boolean overlapsP(org.broadinstitute.sting.utils.Interval i);
|
||||
|
||||
/** Returns true if this interval does not overlap with i as judjed by getStart() and getStop() positions of the
|
||||
* two interval objects.
|
||||
* @param i Another interval
|
||||
* @return true iff intervals do not overlap
|
||||
*/
|
||||
public boolean disjointP(org.broadinstitute.sting.utils.Interval i);
|
||||
}
|
||||
|
|
@ -0,0 +1,75 @@
|
|||
package org.broadinstitute.sting.utils;
|
||||
|
||||
/**
|
||||
* Created by IntelliJ IDEA.
|
||||
* User: asivache
|
||||
* Date: Mar 19, 2009
|
||||
* Time: 12:44:37 PM
|
||||
* To change this template use File | Settings | File Templates.
|
||||
*/
|
||||
|
||||
/** Provides minimum complete implementation of Interval interface.
|
||||
*/
|
||||
public class SimpleInterval implements Interval {
|
||||
|
||||
private long m_start;
|
||||
private long m_stop;
|
||||
|
||||
public SimpleInterval(long start, long stop) { m_start = start; m_stop = stop; }
|
||||
|
||||
public SimpleInterval(Interval i) { m_start = i.getStart(); m_stop = i.getStop(); }
|
||||
// public SimpleInterval() { m_start = -1; m_stop = -2; }
|
||||
|
||||
/** Start position of the interval.
|
||||
*
|
||||
* @return <start> for the interval [start,stop]
|
||||
*/
|
||||
@Override
|
||||
public long getStart() { return m_start; }
|
||||
|
||||
/** Sets start position of the interval.
|
||||
*
|
||||
* @param s start coordinate
|
||||
*/
|
||||
public void setStart(long s) { m_start = s; }
|
||||
|
||||
/** End position of the interval.
|
||||
*
|
||||
* @return <stop> for the interval [start,stop]
|
||||
*/
|
||||
@Override
|
||||
public long getStop() { return m_stop; }
|
||||
|
||||
/** Sets stop position of the interval.
|
||||
*
|
||||
* @param s stop coordinate
|
||||
*/
|
||||
public void setStop(long s) { m_stop = s; }
|
||||
|
||||
/** Length of the interval. This default implementation returns getStop() - getStart() + 1.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public long getLength() { return (m_stop - m_start + 1); };
|
||||
|
||||
/** Returns true if this interval overlaps with i as judjed by getStart() and getStop() positions of the
|
||||
* two interval objects.
|
||||
* @param i Another interval
|
||||
* @return true iff intervals overlap
|
||||
*/
|
||||
@Override
|
||||
public boolean overlapsP(org.broadinstitute.sting.utils.Interval i) {
|
||||
return ! disjointP(i);
|
||||
}
|
||||
|
||||
/** Returns true if this interval does not overlap with i as judjed by getStart() and getStop() positions of the
|
||||
* two interval objects.
|
||||
* @param i Another interval
|
||||
* @return true iff intervals do not overlap
|
||||
*/
|
||||
@Override
|
||||
public boolean disjointP(org.broadinstitute.sting.utils.Interval i) {
|
||||
return ( i.getStop() < this.m_start || i.getStart() > this.m_stop );
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue