JAL-2805 added static method for logging duplications when using map.put
authorkjvdheide <kjvanderheide@dundee.ac.uk>
Tue, 14 Nov 2017 16:57:36 +0000 (16:57 +0000)
committerkjvdheide <kjvanderheide@dundee.ac.uk>
Tue, 14 Nov 2017 17:17:57 +0000 (17:17 +0000)
src/jalview/ext/archaeopteryx/AptxNodeAssociation.java
src/jalview/ext/archaeopteryx/ExternalTreeBuilderI.java

index 5d126f3..d5262c5 100644 (file)
@@ -50,8 +50,6 @@ public class AptxNodeAssociation
   {
     SequenceIdMatcher algnIds = new SequenceIdMatcher(alignSequences);
 
-
-
     List<PhylogenyNode> leaves = tree.getExternalNodes();
     SequenceI nodeSequence;
     String nodeSequenceName;
@@ -67,8 +65,12 @@ public class AptxNodeAssociation
                 .createForesterSequence(nodeSequence, true);
         treeNode.getNodeData().setSequence(foresterNodeSeq);
 
-        alignmentWithNodes.put(nodeSequence, treeNode);
-        nodesWithAlignment.put(treeNode, nodeSequence);
+        ExternalTreeBuilderI.putWithDuplicationCheck(alignmentWithNodes,
+                nodeSequence, treeNode);
+        ExternalTreeBuilderI.putWithDuplicationCheck(nodesWithAlignment,
+                treeNode, nodeSequence);
+
+
       }
 
     }
index 17ae7f8..d30be0e 100644 (file)
@@ -28,4 +28,30 @@ interface ExternalTreeBuilderI<T, N>
 
   public String generateTreeName();
 
+  /**
+   * probably move
+   * 
+   * @param map
+   * @param key
+   * @param value
+   * @return
+   */
+  static <K, V> Map<K, V> putWithDuplicationCheck(Map<K, V> map, K key,
+          V value)
+  {
+    if (!map.containsKey(key))
+    {
+      map.put(key, value);
+    }
+    else
+    {
+      jalview.bin.Cache.log.warn(
+              "Attempt to add duplicate entry detected for map with key: "
+                      + key.toString() + " and value: " + value.toString());
+    }
+
+    return map;
+    
+  }
+
 }