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.transcription;
023
024 import org.biojava3.core.sequence.compound.NucleotideCompound;
025 import org.biojava3.core.sequence.template.Compound;
026
027 /**
028 * Attempts to wrap compounds so it is possible to view them
029 * in a case insensitive manner
030 */
031 public class CaseInsensitiveCompound implements Compound {
032
033 private final NucleotideCompound compound;
034
035 public CaseInsensitiveCompound(NucleotideCompound compound) {
036 this.compound = compound;
037 }
038
039 public boolean equalsIgnoreCase(Compound compound) {
040 if (compound == null) {
041 return false;
042 }
043 if (!(compound instanceof CaseInsensitiveCompound)) {
044 return false;
045 }
046 CaseInsensitiveCompound them = (CaseInsensitiveCompound) compound;
047 return toString().equalsIgnoreCase(them.toString());
048 }
049
050 public boolean equals(Object obj) {
051 if (obj == null) {
052 return false;
053 }
054 if (!(obj instanceof CaseInsensitiveCompound)) {
055 return false;
056 }
057 return equalsIgnoreCase((Compound)obj);
058 }
059
060 public int hashCode() {
061 return toString().toUpperCase().hashCode();
062 }
063
064 public NucleotideCompound getUnderlyingCompound() {
065 return this.compound;
066 }
067
068 public String getDescription() {
069 return getUnderlyingCompound().getDescription();
070 }
071
072 public String getLongName() {
073 return getUnderlyingCompound().getLongName();
074 }
075
076 public Float getMolecularWeight() {
077 return getUnderlyingCompound().getMolecularWeight();
078 }
079
080 public String getShortName() {
081 return getUnderlyingCompound().getShortName();
082 }
083
084 public String toString() {
085 return getUnderlyingCompound().toString();
086 }
087
088 public void setDescription(String description) {
089 //Nothing
090 }
091
092 public void setLongName(String longName) {
093 //Nothing
094 }
095
096 public void setMolecularWeight(Float molecularWeight) {
097 //Nothing
098 }
099
100 public void setShortName(String shortName) {
101 //Nothing
102 }
103 }