JAL-98 performance tweaks to use of SparseIntArray
[jalview.git] / src / jalview / ext / android / SparseIntArray.java
index 0602d50..0e05803 100644 (file)
@@ -346,4 +346,23 @@ public class SparseIntArray implements Cloneable
     buffer.append('}');
     return buffer.toString();
   }
+
+  /**
+   * Method added for Jalview to increment a key's value if present, else add it
+   * with the value 1
+   * 
+   * @param key
+   */
+  public void increment(int key)
+  {
+    int i = ContainerHelpers.binarySearch(mKeys, mSize, key);
+    if (i >= 0)
+    {
+      mValues[i]++;
+    }
+    else
+    {
+      put(key, 1);
+    }
+  }
 }