X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=datamodel%2Fcompbio%2Fdata%2Fsequence%2FMultiAnnotatedSequence.java;h=1a889e38d3de77155b8844473950fed056a1a9b8;hb=fab6bab770b548a0c99ed6f5dfb46f5aa99f67c7;hp=580a22e8614aab0afbf930747a230295e420d812;hpb=cb02e8a08893701386c270a8bf9d0f08b9cbc4db;p=jabaws.git diff --git a/datamodel/compbio/data/sequence/MultiAnnotatedSequence.java b/datamodel/compbio/data/sequence/MultiAnnotatedSequence.java index 580a22e..1a889e3 100644 --- a/datamodel/compbio/data/sequence/MultiAnnotatedSequence.java +++ b/datamodel/compbio/data/sequence/MultiAnnotatedSequence.java @@ -2,6 +2,9 @@ package compbio.data.sequence; import java.util.EnumMap; import java.util.List; +import java.util.Map; + +import compbio.util.annotation.NotThreadSafe; /** * TODO complete @@ -11,23 +14,67 @@ import java.util.List; * @param * enum type */ +@NotThreadSafe public class MultiAnnotatedSequence> { - private final EnumMap> annotation; + private final Map> annotations; + + public MultiAnnotatedSequence(Class enumeration) { + this.annotations = new EnumMap>(enumeration); + } + + public void addAnnotation(T type, List annotation) { + assert type != null : "Type is expected"; + assert annotation != null : "Not empty value is expected!"; + if (!annotations.isEmpty()) { + assert annotations.values().iterator().next().size() == annotation + .size() : "Annotations must contain the same number of elements!"; + } + this.annotations.put(type, annotation); + } + + public Map> getAnnotations() { + return new EnumMap>(this.annotations); + } - private MultiAnnotatedSequence(Class type) { - this.annotation = new EnumMap>(type); - } + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + + ((annotations == null) ? 0 : annotations.hashCode()); + return result; + } - // public MultiAnnotatedSequence getFloatInstance(FastaSequence fsequence) { - // return null; - //} + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + MultiAnnotatedSequence other = (MultiAnnotatedSequence) obj; + if (annotations == null) { + if (other.annotations != null) + return false; + } else if (!annotations.equals(other.annotations)) + return false; + return true; + } - public EnumMap> getIntegerInstance(Class enumeration) { - return new EnumMap>(enumeration); - } + @Override + public String toString() { + String value = ""; + for (Map.Entry> annt : annotations.entrySet()) { + value += annt.getKey() + " "; + value += annt.getValue() + "\n"; + } + return value; + } - public EnumMap> getFloatInstance(Class enumeration) { - return new EnumMap>(enumeration); - } + public JalviewAnnotation toJalviewAnnotation() { + // TODO Auto-generated method stub + return null; + } }