HCOLL-119 removed the use of " public <K, V> SharedHashMap<K, V> create(File file, Class<K> kClass, Class<V> vClass) "

This commit is contained in:
Rob Austin
2014-07-24 14:19:51 +01:00
parent ca899a90e2
commit 006a874ae2
4 changed files with 34 additions and 9 deletions
@@ -106,7 +106,8 @@ public interface ChronicleMap<K, V> extends SharedHashMap<K, V>, ConcurrentMapLa
*/
default void replaceAll(BiFunction<? super K, ? super V, ? extends V> function) {
Objects.requireNonNull(function);
forEach((k, v) -> {
final BiConsumer<K, V> action = (k, v) -> {
while (!replace(k, v, function.apply(k, v))) {
// v changed or k is gone
if ((v = get(k)) == null) {
@@ -114,7 +115,9 @@ public interface ChronicleMap<K, V> extends SharedHashMap<K, V>, ConcurrentMapLa
break;
}
}
});
};
forEach(action);
}
/**
@@ -1470,7 +1470,7 @@ public class ConcurrentHashMap<K, V> extends AbstractMap<K, V>
return (v = get(key)) == null ? defaultValue : v;
}
public void forEach(BiConsumer<? super K, ? super V> action) {
/* public void forEach(BiConsumer<? super K, ? super V> action) {
if (action == null) throw new NullPointerException();
Node<K, V>[] t;
if ((t = table) != null) {
@@ -1479,9 +1479,9 @@ public class ConcurrentHashMap<K, V> extends AbstractMap<K, V>
action.accept(p.key, p.val);
}
}
}
}*/
public void replaceAll(BiFunction<? super K, ? super V, ? extends V> function) {
/* public void replaceAll(BiFunction<? super K, ? super V, ? extends V> function) {
if (function == null) throw new NullPointerException();
Node<K, V>[] t;
if ((t = table) != null) {
@@ -1498,7 +1498,7 @@ public class ConcurrentHashMap<K, V> extends AbstractMap<K, V>
}
}
}
}
}*/
/**
* If the specified key is not already associated with a value, attempts to compute its value using the
@@ -38,6 +38,7 @@ import java.io.IOException;
import java.lang.reflect.Array;
import java.nio.channels.FileChannel;
import java.util.*;
import java.util.function.BiConsumer;
import static java.lang.Thread.currentThread;
@@ -68,6 +69,20 @@ abstract class AbstractVanillaSharedMap<K, V> extends net.openhft.collections.Co
private final ObjectSerializer objectSerializer;
private SharedHashMapBuilder builder;
// todo consider a better way to do this so that is is not creating an entry object each time
public void forEach(BiConsumer<? super K, ? super V> action) {
if (action == null) throw new NullPointerException();
final EntryIterator entryIterator = new EntryIterator();
for (Entry<K, V> e = entryIterator.next(); entryIterator.hasNext(); e = entryIterator.next()) {
action.accept(e.getKey(), e.getValue());
}
}
private static int figureBufferAllocationFactor(SharedHashMapBuilder builder) {
// if expected map size is about 1000, seems rather wasteful to allocate
// key and value serialization buffers each x64 of expected entry size..
@@ -322,6 +337,7 @@ abstract class AbstractVanillaSharedMap<K, V> extends net.openhft.collections.Co
*/
@Override
public V put(K key, V value) {
super.put(key, value);
return put0(key, value, true);
}
@@ -201,7 +201,10 @@ public class ChronicleMap8Test extends JSR166TestCase {
@Test
public void testCompute4() {
ChronicleMap map = map5();
map.compute(one, (x, y) -> null);
final BiFunction remappingFunction = (x, y) -> {
return null;
};
map.compute(one, remappingFunction);
assertFalse(map.containsKey(one));
}
@@ -259,9 +262,12 @@ public class ChronicleMap8Test extends JSR166TestCase {
@Test
public void testReplaceAll() {
ChronicleMap<Integer, String> map = map5();
map.replaceAll((x, y) -> {
final BiFunction<Integer, String, String> function = (x, y) -> {
return x > 3 ? "Z" : y;
});
};
map.replaceAll(function);
assertEquals("A", map.get(one));
assertEquals("B", map.get(two));
assertEquals("C", map.get(three));