From 2d87a86ac0dbbcb50622156ccd4292545121ca2c Mon Sep 17 00:00:00 2001 From: gmungoc Date: Thu, 4 Jun 2020 17:21:29 +0100 Subject: [PATCH] JAL-3446 post-merge unit test fixes, formatting --- .../datamodel/features/FeatureAttributes.java | 38 ++++++++++++++++---- src/jalview/gui/Preferences.java | 4 +-- .../structure/StructureSelectionManager.java | 16 ++++----- .../datamodel/features/FeatureAttributesTest.java | 30 ++++++++++------ .../structure/StructureSelectionManagerTest.java | 10 +++--- 5 files changed, 66 insertions(+), 32 deletions(-) diff --git a/src/jalview/datamodel/features/FeatureAttributes.java b/src/jalview/datamodel/features/FeatureAttributes.java index 655d1eb..a57fd55 100644 --- a/src/jalview/datamodel/features/FeatureAttributes.java +++ b/src/jalview/datamodel/features/FeatureAttributes.java @@ -132,12 +132,17 @@ public class FeatureAttributes implements ApplicationSingletonI if (value != null) { value = value.trim(); + if (value.isEmpty()) + { + return; + } /* * Parse numeric value unless we have previously * seen text data for this attribute type */ - if (type == null && couldBeNumber(value) || type == Datatype.Number) + if ((type == null && couldBeNumber(value)) + || type == Datatype.Number) { try { @@ -161,11 +166,23 @@ public class FeatureAttributes implements ApplicationSingletonI hasValue = false; } } + else + { + /* + * if not a number, and not seen before... + */ + type = Datatype.Character; + min = 0f; + max = 0f; + hasValue = false; + } } } /** - * Answers the description of the attribute, if recorded and unique, or null if either no, or more than description is recorded + * Answers the description of the attribute, if recorded and unique, or null + * if either no, or more than description is recorded + * * @return */ public String getDescription() @@ -224,24 +241,31 @@ public class FeatureAttributes implements ApplicationSingletonI } /** - * This quick check will save significant time avoiding numerous NumberFormatExceptions. + * A partial check that the string is numeric - only checks the first + * character. Returns true if the first character is a digit, or if it is '.', + * '+' or '-' and not the only character. Otherwise returns false (including + * for an empty string). Note this is not a complete check as it returns true + * for (e.g.) "1A". * * @param f * @return */ - public boolean couldBeNumber(String f) + public static boolean couldBeNumber(String f) { int len = f.length(); if (len == 0) + { return false; + } char ch = f.charAt(0); - switch (ch) { + switch (ch) + { case '.': case '+': case '-': return len > 1; } - return (ch <= '9' && ch >= '0'); + return (ch <= '9' && ch >= '0'); } /** @@ -372,7 +396,7 @@ public class FeatureAttributes implements ApplicationSingletonI { return; } - + Map atts = attributes.get(featureType); if (atts == null) { diff --git a/src/jalview/gui/Preferences.java b/src/jalview/gui/Preferences.java index ce3c29d..4030afa 100755 --- a/src/jalview/gui/Preferences.java +++ b/src/jalview/gui/Preferences.java @@ -809,8 +809,8 @@ public class Preferences extends GPreferences Boolean.toString(structFromPdb.isSelected())); if (!Platform.isJS()) { - Cache.setPropertyNoSave(STRUCTURE_DISPLAY, - structViewer.getSelectedItem().toString()); + Cache.setPropertyNoSave(STRUCTURE_DISPLAY, + structViewer.getSelectedItem().toString()); } Cache.setOrRemove(CHIMERA_PATH, chimeraPath.getText()); Cache.setPropertyNoSave("MAP_WITH_SIFTS", diff --git a/src/jalview/structure/StructureSelectionManager.java b/src/jalview/structure/StructureSelectionManager.java index bb1bb94..0f8157b 100644 --- a/src/jalview/structure/StructureSelectionManager.java +++ b/src/jalview/structure/StructureSelectionManager.java @@ -1275,35 +1275,35 @@ public class StructureSelectionManager implements ApplicationSingletonI { if (mappings != null) { - mappings.clear(); + mappings.clear(); } if (seqmappings != null) { - seqmappings.clear(); + seqmappings.clear(); } if (sel_listeners != null) { - sel_listeners.clear(); + sel_listeners.clear(); } if (listeners != null) { - listeners.clear(); + listeners.clear(); } if (commandListeners != null) { - commandListeners.clear(); + commandListeners.clear(); } if (view_listeners != null) { - view_listeners.clear(); + view_listeners.clear(); } if (pdbFileNameId != null) { - pdbFileNameId.clear(); + pdbFileNameId.clear(); } if (pdbIdFileName != null) { - pdbIdFileName.clear(); + pdbIdFileName.clear(); } } diff --git a/test/jalview/datamodel/features/FeatureAttributesTest.java b/test/jalview/datamodel/features/FeatureAttributesTest.java index 0846ec2..d9efa23 100644 --- a/test/jalview/datamodel/features/FeatureAttributesTest.java +++ b/test/jalview/datamodel/features/FeatureAttributesTest.java @@ -44,7 +44,7 @@ public class FeatureAttributesTest * Test the method that keeps attribute names in non-case-sensitive order, * including handling of 'compound' names */ - @Test(groups="Functional") + @Test(groups = "Functional") public void testAttributeNameComparator() { FeatureAttributes fa = FeatureAttributes.getInstance(); @@ -52,19 +52,24 @@ public class FeatureAttributesTest "comparator"); assertEquals( - comp.compare(new String[] { "CSQ" }, new String[] { "csq" }), 0); + comp.compare(new String[] + { "CSQ" }, new String[] { "csq" }), 0); - assertTrue(comp.compare(new String[] { "CSQ", "a" }, - new String[] { "csq" }) > 0); + assertTrue( + comp.compare(new String[] + { "CSQ", "a" }, new String[] { "csq" }) > 0); - assertTrue(comp.compare(new String[] { "CSQ" }, new String[] { "csq", - "b" }) < 0); + assertTrue( + comp.compare(new String[] + { "CSQ" }, new String[] { "csq", "b" }) < 0); - assertTrue(comp.compare(new String[] { "CSQ", "AF" }, new String[] { - "csq", "ac" }) > 0); + assertTrue( + comp.compare(new String[] + { "CSQ", "AF" }, new String[] { "csq", "ac" }) > 0); - assertTrue(comp.compare(new String[] { "CSQ", "ac" }, new String[] { - "csq", "AF" }) < 0); + assertTrue( + comp.compare(new String[] + { "CSQ", "ac" }, new String[] { "csq", "AF" }) < 0); } @Test(groups = "Functional") @@ -124,10 +129,13 @@ public class FeatureAttributesTest "group"); sf.setValue("kd", "-1"); sf.setValue("domain", "Metal"); + sf.setValue("foo", " "); sf.setValue("phase", "1"); - sf.setValue("phase", "reverse"); + sf.setValue("phase", "1reverse"); assertEquals(fa.getDatatype("Pfam", "kd"), Datatype.Number); assertEquals(fa.getDatatype("Pfam", "domain"), Datatype.Character); assertEquals(fa.getDatatype("Pfam", "phase"), Datatype.Mixed); + assertNull(fa.getDatatype("Pfam", "unobserved")); + assertNull(fa.getDatatype("Pfam", "foo"));// empty values are ignored } } diff --git a/test/jalview/structure/StructureSelectionManagerTest.java b/test/jalview/structure/StructureSelectionManagerTest.java index 8108cd8..044cbc7 100644 --- a/test/jalview/structure/StructureSelectionManagerTest.java +++ b/test/jalview/structure/StructureSelectionManagerTest.java @@ -81,6 +81,7 @@ public class StructureSelectionManagerTest extends Jalview2xmlBase { StructureImportSettings.setShowSeqFeatures(true); ssm = StructureSelectionManager.getStructureSelectionManager(null); + ssm.resetAll(); } @Test(groups = { "Functional" }) @@ -139,10 +140,11 @@ public class StructureSelectionManagerTest extends Jalview2xmlBase ssm.registerMappings(set2); ssm.registerMappings(set2); - assertEquals(3, ssm.getSequenceMappings().size()); - assertTrue(ssm.getSequenceMappings().contains(acf1)); - assertTrue(ssm.getSequenceMappings().contains(acf2)); - assertTrue(ssm.getSequenceMappings().contains(acf3)); + List mappings = ssm.getSequenceMappings(); + assertEquals(3, mappings.size()); + assertTrue(mappings.contains(acf1)); + assertTrue(mappings.contains(acf2)); + assertTrue(mappings.contains(acf3)); } /** -- 1.7.10.2