From: Jim Procter Date: Fri, 31 Aug 2018 15:56:56 +0000 (+0100) Subject: JAL-2996 JAL-3053 ~ | : [] {} () treated as gap characters. X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=384b9ce126634ac0c7a9fef5b1788d3fe8fc91cb;p=jalview.git JAL-2996 JAL-3053 ~ | : [] {} () treated as gap characters. --- diff --git a/src/jalview/util/Comparison.java b/src/jalview/util/Comparison.java index d4fc233..aa6bcd4 100644 --- a/src/jalview/util/Comparison.java +++ b/src/jalview/util/Comparison.java @@ -40,9 +40,29 @@ public class Comparison public static final char GAP_DASH = '-'; + public static final char GAP_TILDE = '~'; + + public static final char GAP_PIPE = '|'; + + public static final char GAP_COLON = ':'; + + public static final char GAP_LPAREN = '('; + + public static final char GAP_RPAREN = ')'; + + public static final char GAP_LSQBR = '['; + + public static final char GAP_RSQBR = ']'; + + public static final char GAP_LBRACE = '{'; + + public static final char GAP_RBRACE = '}'; + public static final String GapChars = new String( new char[] - { GAP_SPACE, GAP_DOT, GAP_DASH }); + { GAP_SPACE, GAP_DOT, GAP_DASH, GAP_TILDE, GAP_PIPE, GAP_COLON, + GAP_LPAREN, + GAP_RPAREN, GAP_LSQBR, GAP_RSQBR, GAP_LBRACE, GAP_RBRACE }); /** * DOCUMENT ME! @@ -256,7 +276,24 @@ public class Comparison */ public static final boolean isGap(char c) { - return (c == GAP_DASH || c == GAP_DOT || c == GAP_SPACE) ? true : false; + switch (c) + { + case GAP_SPACE: + case GAP_DOT: + case GAP_DASH: + case GAP_TILDE: + case GAP_PIPE: + case GAP_COLON: + case GAP_LPAREN: + case GAP_RPAREN: + case GAP_LSQBR: + case GAP_RSQBR: + case GAP_LBRACE: + case GAP_RBRACE: + return true; + default: + return false; + } } /** @@ -391,7 +428,7 @@ public class Comparison { return false; } - List flattened = new ArrayList(); + List flattened = new ArrayList<>(); for (SequenceI[] ss : seqs) { for (SequenceI s : ss) diff --git a/test/jalview/util/ComparisonTest.java b/test/jalview/util/ComparisonTest.java index 6f6841d..bd3b52e 100644 --- a/test/jalview/util/ComparisonTest.java +++ b/test/jalview/util/ComparisonTest.java @@ -28,6 +28,7 @@ import jalview.datamodel.Sequence; import jalview.datamodel.SequenceI; import jalview.gui.JvOptionPane; +import org.testng.Assert; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; @@ -51,6 +52,23 @@ public class ComparisonTest assertFalse(Comparison.isGap('x')); assertFalse(Comparison.isGap('*')); assertFalse(Comparison.isGap('G')); + + // consistency - test Comparison.isGap covers all gapChars + StringBuilder missing = new StringBuilder(); + for (int i = 0, iSize = Comparison.GapChars.length(); i < iSize; i++) + { + char gc = Comparison.GapChars.charAt(i); + if (!Comparison.isGap(gc)) + { + missing.append(gc); + } + } + if (missing.length() > 0) + { + Assert.fail( + "Comparison.GapChars contains symbols not covered by Comparison.isGap: '" + + missing.toString() + "'"); + } } /**