+/* Copyright (c) 2011 Peter Troshin\r
+ * \r
+ * JAva Bioinformatics Analysis Web Services (JABAWS) @version: 2.0 \r
+ * \r
+ * This library is free software; you can redistribute it and/or modify it under the terms of the\r
+ * Apache License version 2 as published by the Apache Software Foundation\r
+ * \r
+ * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without\r
+ * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the Apache \r
+ * License for more details.\r
+ * \r
+ * A copy of the license is in apache_license.txt. It is also available here:\r
+ * @see: http://www.apache.org/licenses/LICENSE-2.0.txt\r
+ * \r
+ * Any republication or derived work distributed in source code form\r
+ * must include this copyright and license notice.\r
+ */\r
package compbio.data.sequence;\r
\r
-import java.io.BufferedWriter;\r
import java.io.IOException;\r
-import java.io.OutputStream;\r
-import java.io.OutputStreamWriter;\r
+import java.io.Writer;\r
import java.text.NumberFormat;\r
import java.util.ArrayList;\r
import java.util.Locale;\r
-import java.util.Set;\r
import java.util.TreeSet;\r
\r
import javax.xml.bind.annotation.XmlAccessType;\r
*/\r
@XmlAccessorType(XmlAccessType.FIELD)\r
@Immutable\r
-public class Score {\r
+public class Score implements Comparable<Score> {\r
\r
static final NumberFormat NUMBER_FORMAT = NumberFormat\r
.getNumberInstance(Locale.UK);\r
\r
private Score() {\r
// JaXB default constructor\r
- method = null;\r
+ method = "";\r
}\r
\r
/**\r
/**\r
* Return Ranges if any Collections.EMPTY_SET otherwise\r
* \r
- * @return\r
+ * @return ordered set of Range\r
*/\r
public TreeSet<Range> getRanges() {\r
return ranges;\r
* \r
* @param scores\r
* the list of scores to output\r
- * @param output\r
- * the stream to output the data to\r
+ * @param writer\r
* @throws IOException\r
* if the OutputStream cannot be written into\r
* @throws NullPointerException\r
* if the output stream is null\r
*/\r
- public static void write(Set<Score> scores, OutputStream output)\r
+ public static void write(TreeSet<Score> scores, Writer writer)\r
throws IOException {\r
- if (output == null) {\r
- throw new NullPointerException("OutputStream must be provided!");\r
+ if (writer == null) {\r
+ throw new NullPointerException("Writer must be provided!");\r
}\r
- BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(\r
- output));\r
for (Score score : scores) {\r
writer.write("#" + score.method + " ");\r
- for (Float scoreVal : score.getScores()) {\r
+ int count = score.ranges.size();\r
+ for (Range range : score.ranges) {\r
+ count--;\r
+ writer.write(range.toString());\r
+ if (count != 0) {\r
+ writer.write(", ");\r
+ }\r
+ }\r
+ for (Float scoreVal : score.scores) {\r
writer.write(NUMBER_FORMAT.format(scoreVal) + " ");\r
}\r
writer.write("\n");\r
+ writer.flush();\r
}\r
writer.flush();\r
}\r
+\r
+ @Override\r
+ public int compareTo(Score o) {\r
+ return this.method.compareTo(o.method);\r
+ }\r
}\r