001/*
002 *                    BioJava development code
003 *
004 * This code may be freely distributed and modified under the
005 * terms of the GNU Lesser General Public Licence.  This should
006 * be distributed with the code.  If you do not have a copy,
007 * see:
008 *
009 *      http://www.gnu.org/copyleft/lesser.html
010 *
011 * Copyright for this code is held jointly by the individual
012 * authors.  These should be listed in @author doc comments.
013 *
014 * For more information on the BioJava project and its aims,
015 * or to join the biojava-l mailing list, visit the home page
016 * at:
017 *
018 *      http://www.biojava.org/
019 *
020 */
021
022package org.biojava.bio.symbol;
023
024import java.io.Serializable;
025
026/**
027 * A simple implementation of Location that contains all points between
028 * getMin and getMax inclusive.
029 * <p>
030 * This will in practice be the most commonly used pure-java implementation.
031 *
032 * @author Matthew Pocock
033 */
034public class RangeLocation
035extends AbstractRangeLocation
036implements Serializable {
037  /**
038   * The minimum point contained.
039   */
040  private int min;
041
042  /**
043   * The maximum point contained.
044   */
045  private int max;
046
047  public int getMin() {
048    return min;
049  }
050
051  public int getMax() {
052    return max;
053  }
054
055  /**
056   * Construct a new RangeLocation from <code>min</code> to <code>max</code>.
057   */
058  
059  public RangeLocation(int min, int max) throws IndexOutOfBoundsException {
060    if(max < min) {
061      throw new IndexOutOfBoundsException(
062        "max must exceed min: min=" + min + ", max=" + max
063      );
064    }
065    this.min = min;
066    this.max = max;
067  }
068
069  public Location translate(int dist) {
070    return new RangeLocation(min + dist, max + dist);
071  }
072
073  public String toString() {
074    return "[" + getMin() + "," + getMax() + "]";
075  }
076}