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
026import org.biojava.utils.SingletonList;
027
028/**
029 * <p>
030 * Encapsulates an edit operation on a SymbolList.
031 * See {@link org.biojava.bio.symbol.SymbolList
032 * SymbolList} for a full description.
033 * </p>
034 *
035 * @author Matthew Pocock
036 */
037public final class Edit implements Serializable {
038  public final int pos;
039  public final int length;
040  public final SymbolList replacement;
041
042  /**
043   * Create a new Edit.
044   *
045   * @param pos the start of the edit
046   * @param length the length of the edit
047   * @param replacement a SymbolList representing the symbols that replace those from pos to
048   *        pos + length-1 inclusive
049   */
050  public Edit(int pos, int length, SymbolList replacement) {
051    this.pos = pos;
052    this.length = length;
053    this.replacement = replacement;
054  }
055
056  /**
057   * Convenience construtor for making single residue changes
058   *
059   * @param pos the position of the change
060   * @param alpha the <code>Alphabet</code> of the replacement <code>Symbol</code>
061   * @param replacement the replacement <code>Symbol</code>
062   * @throws IllegalSymbolException if the replacement <code>Symbol</code> is not contained in <code>alpha</code>
063   */
064  public Edit(int pos, Alphabet alpha, Symbol replacement) throws IllegalSymbolException{
065    this.pos = pos;
066    this.length = 1;
067    SymbolList sl = new SimpleSymbolList(
068        alpha, new SingletonList(replacement));
069    this.replacement = sl;
070  }
071}