From d3108041cecaaa06d6b71dbe718cfc88bcb457d4 Mon Sep 17 00:00:00 2001 From: mdb Date: Wed, 19 Jan 2005 21:47:33 +0000 Subject: [PATCH] Added increment(). git-svn-id: https://samskivert.googlecode.com/svn/trunk@1576 6335cc39-0255-0410-8fd6-9bcaacd3b74c --- .../src/java/com/samskivert/util/IntIntMap.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/projects/samskivert/src/java/com/samskivert/util/IntIntMap.java b/projects/samskivert/src/java/com/samskivert/util/IntIntMap.java index e0b186f3..805afa36 100644 --- a/projects/samskivert/src/java/com/samskivert/util/IntIntMap.java +++ b/projects/samskivert/src/java/com/samskivert/util/IntIntMap.java @@ -89,6 +89,20 @@ public class IntIntMap return -1; } + /** + * Increments the value associated with the specified key by the + * specified amount. If the key has no previously assigned value, it + * will be set to the amount specified (as if incrementing from zero). + */ + public void increment (int key, int amount) + { + if (contains(key)) { + put(key, get(key) + amount); + } else { + put(key, amount); + } + } + public boolean contains (int key) { int index = Math.abs(key)%_buckets.length;