X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=datamodel%2Fcompbio%2Fdata%2Fsequence%2FScore.java;h=f28bd0d6a34934551efb015baaa8290939a63e28;hb=aca9c5503b812c9c96aebb408748dc15728f9ad7;hp=8a110eea95f59e43f2732ffe6da58b44298a5f7b;hpb=8033a51860de2200a54e64add0809d6780f5b092;p=jabaws.git diff --git a/datamodel/compbio/data/sequence/Score.java b/datamodel/compbio/data/sequence/Score.java index 8a110ee..f28bd0d 100644 --- a/datamodel/compbio/data/sequence/Score.java +++ b/datamodel/compbio/data/sequence/Score.java @@ -6,10 +6,9 @@ import java.io.OutputStream; import java.io.OutputStreamWriter; import java.text.NumberFormat; import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; import java.util.Locale; import java.util.Set; +import java.util.TreeSet; import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; @@ -33,13 +32,16 @@ public class Score { NUMBER_FORMAT.setGroupingUsed(false); NUMBER_FORMAT.setMaximumFractionDigits(3); } + // This should be Enum but JAXB cannot serialize it. + private final String method; - private Enum method; + private TreeSet ranges = new TreeSet(); - private List scores; + private ArrayList scores = new ArrayList(0); private Score() { // JaXB default constructor + method = null; } /** @@ -52,18 +54,40 @@ public class Score { * the actual conservation values for each column of the * alignment */ - public Score(Enum method, List scores) { - this.method = method; + public Score(Enum method, ArrayList scores) { + this.method = method.toString(); this.scores = new ArrayList(scores); } + /** + * @param method + * the ConservationMethod with which {@code scores} were + * calculated + * @param scores + * the actual conservation values for each column of the + * alignment + * @param ranges + * The set of ranges i.e. parts of the sequence with specific + * function, usually can be calculated based on scores + */ + public Score(Enum method, ArrayList scores, TreeSet ranges) { + this.method = method.toString(); + this.ranges = ranges; + this.scores = scores; + } + + public Score(Enum method, TreeSet ranges) { + this.method = method.toString(); + this.ranges = ranges; + } + public Score(Enum method, float[] scores) { - this.method = method; + this.method = method.toString(); this.scores = toList(scores); } - private List toList(float[] values) { - List vlist = new ArrayList(); + private ArrayList toList(float[] values) { + ArrayList vlist = new ArrayList(); for (float v : values) { vlist.add(new Float(v)); } @@ -74,7 +98,7 @@ public class Score { * * @return the ConservationMethod */ - public Enum getMethod() { + public String getMethod() { return method; } @@ -83,29 +107,39 @@ public class Score { * * @return the column scores for the alignment */ - public List getScores() { + public ArrayList getScores() { return scores; } + /** + * Return Ranges if any Collections.EMPTY_SET otherwise + * + * @return + */ + public TreeSet getRanges() { + return ranges; + } + + public void setRanges(TreeSet ranges) { + this.ranges = ranges; + } + @Override public String toString() { - return "Score [method=" + method + ", scores=" + scores + "]"; + return "Score [method=" + method + ", ranges=" + ranges + ", scores=" + + scores + "]"; } @Override public int hashCode() { - final int prime = 31; + final int prime = 7; int result = 1; result = prime * result + ((method == null) ? 0 : method.hashCode()); + result = prime * result + ((ranges == null) ? 0 : ranges.hashCode()); result = prime * result + ((scores == null) ? 0 : scores.hashCode()); return result; } - /* - * TODO test ! (non-Javadoc) - * - * @see java.lang.Object#equals(java.lang.Object) - */ @Override public boolean equals(Object obj) { if (this == obj) @@ -115,15 +149,20 @@ public class Score { if (getClass() != obj.getClass()) return false; Score other = (Score) obj; - if (method != other.method) + if (method == null) { + if (other.method != null) + return false; + } else if (!method.equals(other.method)) return false; - if (scores == other.scores) { - return true; - } - if (scores == null) { + if (ranges == null) { + if (other.ranges != null) + return false; + } else if (!ranges.equals(other.ranges)) return false; - } - if (!Arrays.deepEquals(scores.toArray(), other.scores.toArray())) + if (scores == null) { + if (other.scores != null) + return false; + } else if (!scores.equals(other.scores)) return false; return true; }