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     * Created on 01-21-2010
021     */
022    package org.biojava3.core.sequence.views;
023    
024    import org.biojava3.core.sequence.template.ComplementCompound;
025    import org.biojava3.core.sequence.template.Sequence;
026    import org.biojava3.core.sequence.template.SequenceMixin;
027    import org.biojava3.core.sequence.template.SequenceProxyView;
028    
029    /**
030     * For a given sequence this class will create a view over the top of it
031     * and for every request the code will return the complement of the underlying
032     * base e.g. base A will become base T
033     *
034     * @author Andy Yates
035     * @param <C> Must be a subtype of @{link ComplementCompound} since
036     * only those support complements
037     */
038    public class ComplementSequenceView<C extends ComplementCompound> extends SequenceProxyView<C> {
039    
040        public ComplementSequenceView(Sequence<C> sequence) {
041            super(sequence);
042        }
043    
044        @Override
045        public String getSequenceAsString() {
046            return SequenceMixin.toString(this);
047        }
048    
049        @SuppressWarnings("unchecked")
050        @Override
051        public C getCompoundAt(int position) {
052            return (C) super.getCompoundAt(position).getComplement();
053        }
054    
055        @SuppressWarnings("unchecked")
056        @Override
057        public int getIndexOf(C compound) {
058            return super.getIndexOf((C) compound.getComplement());
059        }
060    
061        @SuppressWarnings("unchecked")
062        @Override
063        public int getLastIndexOf(C compound) {
064            return super.getLastIndexOf((C) compound.getComplement());
065        }
066    }