package jalview.datamodel; /** * Holds the aligned column positions (base 0) for one codon in a nucleotide * sequence. The object is immutable once created. * * Example: in "G-AT-C-GA" the aligned codons are (0, 2, 3) and (5, 7, 8). * * @author gmcarstairs * */ public final class AlignedCodon { public final int pos1; public final int pos2; public final int pos3; public AlignedCodon(int i, int j, int k) { pos1 = i; pos2 = j; pos3 = k; } /** * Returns the column position for the given base (1, 2, 3). * * @param base * @return * @throws IllegalArgumentException * if an argument value other than 1, 2 or 3 is supplied */ public int getBaseColumn(int base) { if (base < 1 || base > 3) { throw new IllegalArgumentException(Integer.toString(base)); } return base == 1 ? pos1 : (base == 2 ? pos2 : pos3); } /** * Two aligned codons are equal if all their base positions are the same. */ @Override public boolean equals(Object o) { /* * Equality with null value required for consistency with * Dna.compareCodonPos */ if (o == null) { return true; } if (!(o instanceof AlignedCodon)) { return false; } AlignedCodon ac = (AlignedCodon) o; return (pos1 == ac.pos1 && pos2 == ac.pos2 && pos3 == ac.pos3); } @Override public String toString() { return "[" + pos1 + ", " + pos2 + ", " + pos3 + "]"; } }