From 501e92d4410c82a734172ece60ea55a55fe2e267 Mon Sep 17 00:00:00 2001 From: asivache Date: Fri, 20 Mar 2009 05:09:56 +0000 Subject: [PATCH] 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 --- .../broadinstitute/sting/utils/Interval.java | 59 +++++++++++++++ .../sting/utils/SimpleInterval.java | 75 +++++++++++++++++++ 2 files changed, 134 insertions(+) create mode 100644 playground/java/src/org/broadinstitute/sting/utils/Interval.java create mode 100644 playground/java/src/org/broadinstitute/sting/utils/SimpleInterval.java diff --git a/playground/java/src/org/broadinstitute/sting/utils/Interval.java b/playground/java/src/org/broadinstitute/sting/utils/Interval.java new file mode 100644 index 000000000..b5d2cbe96 --- /dev/null +++ b/playground/java/src/org/broadinstitute/sting/utils/Interval.java @@ -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 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 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); +} diff --git a/playground/java/src/org/broadinstitute/sting/utils/SimpleInterval.java b/playground/java/src/org/broadinstitute/sting/utils/SimpleInterval.java new file mode 100644 index 000000000..d3a1b0519 --- /dev/null +++ b/playground/java/src/org/broadinstitute/sting/utils/SimpleInterval.java @@ -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 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 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 ); + } +}