From e1f338c93c71e08dfd1e20347826cf38c5625371 Mon Sep 17 00:00:00 2001
From: brinn <brinn>
Date: Tue, 5 Feb 2008 21:31:19 +0000
Subject: [PATCH] change: optimize method add()

SVN: 4030
---
 .../cisd/common/collections/TableMap.java       | 17 ++++-------------
 1 file changed, 4 insertions(+), 13 deletions(-)

diff --git a/common/source/java/ch/systemsx/cisd/common/collections/TableMap.java b/common/source/java/ch/systemsx/cisd/common/collections/TableMap.java
index 333e141b7ad..84ce6d333b2 100644
--- a/common/source/java/ch/systemsx/cisd/common/collections/TableMap.java
+++ b/common/source/java/ch/systemsx/cisd/common/collections/TableMap.java
@@ -106,21 +106,12 @@ public class TableMap<K, E> implements Iterable<E>
     public final void add(final E row)
     {
         final K key = extractor.getKey(row);
-        if (map.get(key) != null)
-        {
-            switch (uniqueKeyViolationStrategy)
-            {
-                case KEEP_FIRST:
-                    break;
-                case KEEP_LAST:
-                    map.put(key, row);
-                    break;
-                case ERROR:
-                    throw new UniqueKeyViolationException("Key '" + key.toString() + "' already in the map.");
-            }
-        } else
+        if (uniqueKeyViolationStrategy == UniqueKeyViolationStrategy.KEEP_LAST || map.get(key) == null)
         {
             map.put(key, row);
+        } else if (uniqueKeyViolationStrategy == UniqueKeyViolationStrategy.ERROR)
+        {
+            throw new UniqueKeyViolationException("Key '" + key.toString() + "' already in the map.");
         }
     }
 
-- 
GitLab