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 */ 022package org.biojava.nbio.core.sequence.transcription; 023 024import org.biojava.nbio.core.sequence.compound.NucleotideCompound; 025import org.biojava.nbio.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 */ 031public class CaseInsensitiveCompound implements Compound { 032 033 private final NucleotideCompound compound; 034 035 public CaseInsensitiveCompound(NucleotideCompound compound) { 036 this.compound = compound; 037 } 038 039 @Override 040public boolean equalsIgnoreCase(Compound compound) { 041 if (compound == null) { 042 return false; 043 } 044 if (!(compound instanceof CaseInsensitiveCompound)) { 045 return false; 046 } 047 CaseInsensitiveCompound them = (CaseInsensitiveCompound) compound; 048 return toString().equalsIgnoreCase(them.toString()); 049 } 050 051 @Override 052public boolean equals(Object obj) { 053 if (obj == null) { 054 return false; 055 } 056 if (!(obj instanceof CaseInsensitiveCompound)) { 057 return false; 058 } 059 return equalsIgnoreCase((Compound)obj); 060 } 061 062 @Override 063public int hashCode() { 064 return toString().toUpperCase().hashCode(); 065 } 066 067 public NucleotideCompound getUnderlyingCompound() { 068 return this.compound; 069 } 070 071 @Override 072public String getDescription() { 073 return getUnderlyingCompound().getDescription(); 074 } 075 076 @Override 077public String getLongName() { 078 return getUnderlyingCompound().getLongName(); 079 } 080 081 @Override 082public Float getMolecularWeight() { 083 return getUnderlyingCompound().getMolecularWeight(); 084 } 085 086 @Override 087public String getShortName() { 088 return getUnderlyingCompound().getShortName(); 089 } 090 091 @Override 092public String toString() { 093 return getUnderlyingCompound().toString(); 094 } 095 096 @Override 097public void setDescription(String description) { 098 //Nothing 099 } 100 101 @Override 102public void setLongName(String longName) { 103 //Nothing 104 } 105 106 @Override 107public void setMolecularWeight(Float molecularWeight) { 108 //Nothing 109 } 110 111 @Override 112public void setShortName(String shortName) { 113 //Nothing 114 } 115}