From: gmungoc Date: Mon, 6 Nov 2017 16:38:53 +0000 (+0000) Subject: JAL-2808 small tweak to getString to quote the pattern value X-Git-Tag: Release_2_11_0~153 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=61854b0061f5c35c770d9ca1dcf837261e811d99;p=jalview.git JAL-2808 small tweak to getString to quote the pattern value --- diff --git a/src/jalview/util/matcher/KeyedMatcher.java b/src/jalview/util/matcher/KeyedMatcher.java index 5e42e1c..cd952e7 100644 --- a/src/jalview/util/matcher/KeyedMatcher.java +++ b/src/jalview/util/matcher/KeyedMatcher.java @@ -79,7 +79,15 @@ public class KeyedMatcher implements KeyedMatcherI { StringBuilder sb = new StringBuilder(); sb.append(key).append(" ").append(matcher.getCondition().toString()) - .append(" ").append(matcher.getPattern()); + .append(" "); + if (matcher.getCondition().isNumeric()) + { + sb.append(matcher.getPattern()); + } + else + { + sb.append("'").append(matcher.getPattern()).append("'"); + } return sb.toString(); } diff --git a/src/jalview/util/matcher/Matcher.java b/src/jalview/util/matcher/Matcher.java index d8c9361..a213a17 100644 --- a/src/jalview/util/matcher/Matcher.java +++ b/src/jalview/util/matcher/Matcher.java @@ -213,6 +213,17 @@ public class Matcher implements MatcherI @Override public String toString() { - return condition.name() + " " + pattern; + StringBuilder sb = new StringBuilder(); + sb.append(condition.name()).append(" "); + if (condition.isNumeric()) + { + sb.append(pattern); + } + else + { + sb.append("'").append(pattern).append("'"); + } + + return sb.toString(); } } diff --git a/test/jalview/util/matcher/KeyedMatcherSetTest.java b/test/jalview/util/matcher/KeyedMatcherSetTest.java index 0d2767d..b7ff006 100644 --- a/test/jalview/util/matcher/KeyedMatcherSetTest.java +++ b/test/jalview/util/matcher/KeyedMatcherSetTest.java @@ -66,7 +66,7 @@ public class KeyedMatcherSetTest assertEquals(km1.toString(), "AF < 1.2"); KeyedMatcher km2 = new KeyedMatcher("CLIN_SIG", Condition.NotContains, "path"); - assertEquals(km2.toString(), "CLIN_SIG Does not contain PATH"); + assertEquals(km2.toString(), "CLIN_SIG Does not contain 'PATH'"); /* * AND them @@ -77,7 +77,7 @@ public class KeyedMatcherSetTest assertEquals(kms.toString(), "(AF < 1.2)"); kms.and(km2); assertEquals(kms.toString(), - "(AF < 1.2) AND (CLIN_SIG Does not contain PATH)"); + "(AF < 1.2) AND (CLIN_SIG Does not contain 'PATH')"); /* * OR them @@ -88,7 +88,7 @@ public class KeyedMatcherSetTest assertEquals(kms.toString(), "(AF < 1.2)"); kms.or(km2); assertEquals(kms.toString(), - "(AF < 1.2) OR (CLIN_SIG Does not contain PATH)"); + "(AF < 1.2) OR (CLIN_SIG Does not contain 'PATH')"); } @Test diff --git a/test/jalview/util/matcher/MatcherTest.java b/test/jalview/util/matcher/MatcherTest.java index d988c3a..489cdce 100644 --- a/test/jalview/util/matcher/MatcherTest.java +++ b/test/jalview/util/matcher/MatcherTest.java @@ -196,10 +196,10 @@ public class MatcherTest assertEquals(m.toString(), "LT 1.2E-6"); m = new Matcher(Condition.NotMatches, "ABC"); - assertEquals(m.toString(), "NotMatches ABC"); + assertEquals(m.toString(), "NotMatches 'ABC'"); m = new Matcher(Condition.Contains, -1.2f); - assertEquals(m.toString(), "Contains -1.2"); + assertEquals(m.toString(), "Contains '-1.2'"); } @Test