You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@uima.apache.org by sc...@apache.org on 2018/01/23 20:13:32 UTC
svn commit: r1822046 -
/uima/uv3/uimaj-v3/trunk/uimaj-core/src/main/java/org/apache/uima/internal/util/Int2ObjHashMap.java
Author: schor
Date: Tue Jan 23 20:13:32 2018
New Revision: 1822046
URL: http://svn.apache.org/viewvc?rev=1822046&view=rev
Log:
no Jira, add putIfAbsent and computeIfAbsent methods
Modified:
uima/uv3/uimaj-v3/trunk/uimaj-core/src/main/java/org/apache/uima/internal/util/Int2ObjHashMap.java
Modified: uima/uv3/uimaj-v3/trunk/uimaj-core/src/main/java/org/apache/uima/internal/util/Int2ObjHashMap.java
URL: http://svn.apache.org/viewvc/uima/uv3/uimaj-v3/trunk/uimaj-core/src/main/java/org/apache/uima/internal/util/Int2ObjHashMap.java?rev=1822046&r1=1822045&r2=1822046&view=diff
==============================================================================
--- uima/uv3/uimaj-v3/trunk/uimaj-core/src/main/java/org/apache/uima/internal/util/Int2ObjHashMap.java (original)
+++ uima/uv3/uimaj-v3/trunk/uimaj-core/src/main/java/org/apache/uima/internal/util/Int2ObjHashMap.java Tue Jan 23 20:13:32 2018
@@ -26,6 +26,7 @@ import java.util.Iterator;
import java.util.NoSuchElementException;
import java.util.function.Consumer;
import java.util.function.IntConsumer;
+import java.util.function.IntFunction;
import org.apache.uima.util.IntEntry;
import org.apache.uima.util.impl.Constants;
@@ -427,6 +428,40 @@ public class Int2ObjHashMap<T, E extends
commonPutOrAddNotFound();
return prevValue;
}
+
+ public T computeIfAbsent(int key, IntFunction<T> mappingFunction) {
+ int i = findPosition(key);
+ if (keys[i] == 0) {
+ // key not found
+ if (found_removed != -1) {
+ i = found_removed; // use the removed slot for the new value
+ }
+ keys[i] = key;
+ values[i] = mappingFunction.apply(key);
+ commonPutOrAddNotFound();
+ return values[i];
+ }
+
+ // key found
+ return values[i];
+ }
+
+ public T putIfAbsent(int key, T value) {
+ int i = findPosition(key);
+ if (keys[i] == 0) {
+ // key not found
+ if (found_removed != -1) {
+ i = found_removed; // use the removed slot for the new value
+ }
+ keys[i] = key;
+ values[i] = value;
+ commonPutOrAddNotFound();
+ return value;
+ }
+
+ // key found
+ return values[i];
+ }
public void putInner(int key, T value) {
final int i = findPosition(key);