JAL-3215 extract method, unit test, bug fix
[jalview.git] / src / jalview / schemes / ScoreColourScheme.java
index 66bb5b4..aef5f22 100755 (executable)
@@ -53,13 +53,18 @@ public class ScoreColourScheme extends ResidueColourScheme
   /**
    * Constructor
    * 
+   * @param name
    * @param symbolIndex
    *          a lookup where the index is a char e.g. 'R' or 'r', and the value
    *          is its position in the colour table lookup
-   * @param scores
+   * @param theScores
    *          per residue, with indices corresponding to those for colour lookup
+   * @param minColour
+   *          graduated colour at minimum score value
+   * @param maxColour
+   *          graduated colour at maximum score value
    */
-  public ScoreColourScheme(String name, int[] symbolIndex, double[] scores,
+  public ScoreColourScheme(String name, int[] symbolIndex, double[] theScores,
           Color minColour, Color maxColour)
   {
     super(symbolIndex);
@@ -67,14 +72,24 @@ public class ScoreColourScheme extends ResidueColourScheme
     this.minColour = minColour;
     this.maxColour = maxColour;
 
-    setMinMax(scores);
-    this.scores = scores;
+    setMinMax(theScores);
+    computeColours(theScores);
+  }
+
+  /**
+   * Calculates and saves a graduated score based colour for each residue
+   * 
+   * @param theScores
+   */
+  protected void computeColours(double[] theScores)
+  {
+    this.scores = theScores;
 
-    int iSize = scores.length;
-    colors = new Color[scores.length];
+    int iSize = theScores.length;
+    colors = new Color[theScores.length];
     for (int i = 0; i < iSize; i++)
     {
-      colors[i] = getScoreColour(scores[i]);
+      colors[i] = getScoreColour(theScores[i]);
     }
   }
 
@@ -117,7 +132,7 @@ public class ScoreColourScheme extends ResidueColourScheme
     double dMin = Double.MAX_VALUE;
     double dMax = -Double.MAX_VALUE;
 
-    for (int i = 0; i < vals.length - 1; i++)
+    for (int i = 0; i < vals.length; i++)
     {
       dMin = Math.min(dMin, vals[i]);
       dMax = Math.max(dMax, vals[i]);