getMap();
+
+ /**
+ * Removes all of the elements from this view, by removing all the mappings from the map backing this
+ * view.
+ */
+ void clear();
+
+ int size();
+
+
+ boolean isEmpty();
+
+ // implementations below rely on concrete classes supplying these
+ // abstract methods
+
+ /**
+ * Returns an iterator over the elements in this collection.
+ *
+ * The returned iterator is weakly consistent.
+ *
+ * @return an iterator over the elements in this collection
+ */
+ Iterator iterator();
+
+ boolean contains(Object o);
+
+ boolean remove(Object o);
+
+ static final String oomeMsg = "Required array size too large";
+
+ Object[] toArray();
+
+ @SuppressWarnings("unchecked")
+ T[] toArray(T[] a);
+
+ /**
+ * Returns a string representation of this collection. The string representation consists of the string
+ * representations of the collection's elements in the order they are returned by its iterator, enclosed
+ * in square brackets ({@code "[]"}). Adjacent elements are separated by the characters {@code ", "}
+ * (comma and space). Elements are converted to strings as by {@link String#valueOf(Object)}.
+ *
+ * @return a string representation of this collection
+ */
+ String toString();
+
+ boolean containsAll(Collection> c);
+
+ boolean removeAll(Collection> c);
+
+ boolean retainAll(Collection> c);
+}
diff --git a/src/main/java/net/openhft/collections/ConcurrentMapLamdadSupport.java b/src/main/java/net/openhft/collections/ConcurrentMapLamdadSupport.java
index 8567e5023..ea31db616 100644
--- a/src/main/java/net/openhft/collections/ConcurrentMapLamdadSupport.java
+++ b/src/main/java/net/openhft/collections/ConcurrentMapLamdadSupport.java
@@ -42,7 +42,7 @@ public interface ConcurrentMapLamdadSupport {
*
* @return the set view
*/
- AbstractVanillaSharedMap.KeySetView keySet();
+ net.openhft.collections.KeySetView keySet();
long mappingCount();
diff --git a/src/main/java/net/openhft/collections/KeySetView.java b/src/main/java/net/openhft/collections/KeySetView.java
index 74d49bfe9..589e8dbb4 100644
--- a/src/main/java/net/openhft/collections/KeySetView.java
+++ b/src/main/java/net/openhft/collections/KeySetView.java
@@ -27,7 +27,8 @@ import java.util.function.Consumer;
/**
* @author Rob Austin.
*/
-public interface KeySetView extends Collection, java.io.Serializable, Set {
+public interface KeySetView extends Collection, java.io.Serializable, Set, CollectionView {
/**
* Returns the default mapped value for additions, or {@code null} if additions are not supported.
*
diff --git a/src/main/java/net/openhft/collections/VanillaSharedMap.java b/src/main/java/net/openhft/collections/VanillaSharedMap.java
index 165991d2b..65a0784ec 100644
--- a/src/main/java/net/openhft/collections/VanillaSharedMap.java
+++ b/src/main/java/net/openhft/collections/VanillaSharedMap.java
@@ -84,7 +84,7 @@ abstract class AbstractVanillaSharedMap extends net.openhft.collections.Co
* Base class for views.
*/
abstract static class CollectionView
- implements Collection, java.io.Serializable {
+ implements Collection, net.openhft.collections.CollectionView, java.io.Serializable {
private static final long serialVersionUID = 7249069246763182397L;
final AbstractVanillaSharedMap map;
@@ -452,6 +452,7 @@ abstract class AbstractVanillaSharedMap extends net.openhft.collections.Co
return new KeySetView(this, mappedValue);
}
+
/**
* A view of a ConcurrentHashMap as a {@link Set} of keys, in which additions may optionally be enabled by
* mapping to a common value. This class cannot be directly instantiated. See {@link #keySet() keySet()},
@@ -462,6 +463,7 @@ abstract class AbstractVanillaSharedMap extends net.openhft.collections.Co
*/
public static class KeySetView extends CollectionView
implements Set, java.io.Serializable, net.openhft.collections.KeySetView {
+
private static final long serialVersionUID = 7249069246763182397L;
private final V value;
@@ -1639,7 +1641,11 @@ abstract class AbstractVanillaSharedMap extends net.openhft.collections.Co
return putVal(key, value, false);
}
- V putVal(K key, V value, boolean replaceIfPresent) {
+ V putVal(K key, V value, boolean onlyIfAbsent) {
+ return put0(key, value, !onlyIfAbsent);
+ }
+
+ V put0(K key, V value, boolean replaceIfPresent) {
super.putVal(key, value, replaceIfPresent);
checkKey(key);
checkValue(value);
@@ -2731,7 +2737,6 @@ abstract class AbstractVanillaSharedMap extends net.openhft.collections.Co
}
-
Entry nextSegmentEntry() {
while (segmentIndex >= 0) {
if (segmentPositions.isEmpty()) {
diff --git a/src/test/java/net/openhft/chronicle/map/ChronicleMap8Test.java b/src/test/java/net/openhft/chronicle/map/ChronicleMap8Test.java
index 6d2c7ceef..5158a878d 100644
--- a/src/test/java/net/openhft/chronicle/map/ChronicleMap8Test.java
+++ b/src/test/java/net/openhft/chronicle/map/ChronicleMap8Test.java
@@ -25,6 +25,7 @@ package net.openhft.chronicle.map;/*
/*import junit.framework.Test;
import junit.framework.TestSuite;*/
+import net.openhft.collections.KeySetView;
import net.openhft.collections.SharedHashMapBuilder;
import net.openhft.collections.jrs166.JSR166TestCase;
import org.junit.Test;
@@ -111,7 +112,7 @@ public class ChronicleMap8Test extends JSR166TestCase {
* Returns a new map from Integers 1-5 to Strings "A"-"E".
*/
private static ConcurrentHashMap map5ConcurrentHashMap() {
- ConcurrentHashMap map = new ConcurrentHashMap(5);
+ ConcurrentHashMap map = new ConcurrentHashMap(5);
assertTrue(map.isEmpty());
map.put(one, "A");
map.put(two, "B");
@@ -305,15 +306,15 @@ public class ChronicleMap8Test extends JSR166TestCase {
*/
@Test
public void testKeySetAddRemove() {
- ChronicleMap map = map5();
- Set set1 = map.keySet();
- Set set2 = map.keySet(true);
+ ChronicleMap map = map5();
+ final KeySetView set1 = map.keySet();
+ final KeySetView set2 = map.keySet("true");
set2.add(six);
- assertTrue(((ConcurrentHashMap.KeySetView) set2).getMap() == map);
- assertTrue(((ConcurrentHashMap.KeySetView) set1).getMap() == map);
+ assertTrue(set2.getMap() == map);
+ assertTrue(set1.getMap() == map);
assertEquals(set2.size(), map.size());
assertEquals(set1.size(), map.size());
- assertTrue((Boolean) map.get(six));
+ assertTrue((Boolean.parseBoolean(map.get(six))));
assertTrue(set1.contains(six));
assertTrue(set2.contains(six));
set2.remove(six);
@@ -398,8 +399,6 @@ public class ChronicleMap8Test extends JSR166TestCase {
}
-
-
/**
* KeySetView.getMappedValue returns the map's mapped value
*/
@@ -413,38 +412,39 @@ public class ChronicleMap8Test extends JSR166TestCase {
} catch (NullPointerException e) {
}
- final net.openhft.collections.KeySetView set = map.keySet("1");
+ final net.openhft.collections.KeySetView set = map.keySet("A");
set.add(one);
set.add(six);
set.add(seven);
- assertTrue(set.getMappedValue() == "1");
- assertTrue(map.get(one) != "1");
- assertTrue(map.get(six) == "1");
- assertTrue(map.get(seven) == "1");
+ assertTrue(set.getMappedValue().equals("A"));
+ assertTrue(map.get(one).equals("A"));
+ assertTrue(map.get(six).equals("A"));
+ assertTrue(map.get(seven).equals("A"));
}
- @Test
- public void testConcurrentHashMapGetMappedValue() {
- ConcurrentHashMap map = map5ConcurrentHashMap();
- assertNull(map.keySet().getMappedValue());
- try {
- map.keySet(null);
- shouldThrow();
- } catch (NullPointerException e) {
- }
+ /* @Test
+ public void testConcurrentHashMapGetMappedValue() {
+ ConcurrentHashMap map = map5ConcurrentHashMap();
+ assertNull(map.keySet().getMappedValue());
+ try {
+ map.keySet(null);
+ shouldThrow();
+ } catch (NullPointerException e) {
+ }
- final ConcurrentHashMap.KeySetView set = map.keySet("1");
+ final ConcurrentHashMap.KeySetView set = map.keySet("A");
- set.add(one);
- set.add(six);
- set.add(seven);
- assertTrue(set.getMappedValue() == "1");
- assertTrue(map.get(one) != "1");
- assertTrue(map.get(six) == "1");
- assertTrue(map.get(seven) == "1");
- }
+ set.add(one);
+ set.add(six);
+ set.add(seven);
+ assertTrue(set.getMappedValue() == "A");
+ assertTrue(map.get(one) == "A");
+ assertTrue(map.get(six) == "A");
+ assertTrue(map.get(seven) == "A");
+ }
+ */
void checkSpliteratorCharacteristics(Spliterator> sp,
int requiredCharacteristics) {
assertEquals(requiredCharacteristics,