From 8e2d11189e14700f721dc0cf17c462352883ef97 Mon Sep 17 00:00:00 2001 From: gmungoc Date: Mon, 19 Dec 2016 11:21:47 +0000 Subject: [PATCH] JAL-2360 amended toAppletParameter() for reproducible behaviour --- src/jalview/schemes/UserColourScheme.java | 23 +++++++++++++++++------ test/jalview/schemes/UserColourSchemeTest.java | 2 +- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/src/jalview/schemes/UserColourScheme.java b/src/jalview/schemes/UserColourScheme.java index 7bf02c1..218c285 100755 --- a/src/jalview/schemes/UserColourScheme.java +++ b/src/jalview/schemes/UserColourScheme.java @@ -24,9 +24,11 @@ import jalview.datamodel.AnnotatedCollectionI; import jalview.datamodel.SequenceCollectionI; import jalview.datamodel.SequenceI; import jalview.util.ColorUtils; +import jalview.util.StringUtils; import java.awt.Color; import java.util.ArrayList; +import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -302,6 +304,9 @@ public class UserColourScheme extends ResidueColourScheme */ public String toAppletParameter() { + /* + * step 1: build a map from colours to the symbol(s) that have the colour + */ Map> colours = new HashMap>(); for (char symbol = 'A'; symbol <= 'Z'; symbol++) @@ -331,14 +336,15 @@ public class UserColourScheme extends ResidueColourScheme } } } - StringBuilder sb = new StringBuilder(); + + /* + * step 2: make a list of { A,G,R=12f9d6 } residues/colour specs + */ + List residueColours = new ArrayList(); for (Entry> cols : colours.entrySet()) { - if (sb.length() > 0) - { - sb.append(";"); - } boolean first = true; + StringBuilder sb = new StringBuilder(); for (String residue : cols.getValue()) { if (!first) @@ -355,8 +361,13 @@ public class UserColourScheme extends ResidueColourScheme String hexString = Integer.toHexString(cols.getKey().getRGB()) .substring(2); sb.append(hexString); + residueColours.add(sb.toString()); } - return sb.toString(); + /* + * sort and output + */ + Collections.sort(residueColours); + return StringUtils.listToDelimitedString(residueColours, ";"); } } diff --git a/test/jalview/schemes/UserColourSchemeTest.java b/test/jalview/schemes/UserColourSchemeTest.java index 151462b..497014e 100644 --- a/test/jalview/schemes/UserColourSchemeTest.java +++ b/test/jalview/schemes/UserColourSchemeTest.java @@ -78,6 +78,6 @@ public class UserColourSchemeTest UserColourScheme cs = new UserColourScheme( "E,D=red; K,R,H=0022FF; c=10 , 20,30"); String param = cs.toAppletParameter(); - assertEquals("H,K,R=0022ff;c=0a141e;D,E=ff0000", param); + assertEquals("D,E=ff0000;H,K,R=0022ff;c=0a141e", param); } } -- 1.7.10.2