Ranides Atterwim il y a 4 ans
Parent
commit
00877bef51

+ 12 - 11
assira.core/src/main/java/net/ranides/assira/collection/maps/AOpenMap.java

@@ -16,12 +16,7 @@ import net.ranides.assira.generic.CompareUtils;
 import net.ranides.assira.generic.HashUtils;
 import net.ranides.assira.math.MathUtils;
 
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Iterator;
-import java.util.Map;
-import java.util.NoSuchElementException;
-import java.util.Set;
+import java.util.*;
 
 /**
  * Generic hash map implementation.
@@ -535,25 +530,32 @@ public abstract class AOpenMap<K,V> extends AMap<K, V> implements BlockMap<K, V>
     
     private final class PEntry extends AEntry<K, V> {
 
-        int index;
+        private final int index;
+        private final K k;
+        private V v;
 
         PEntry(int index) {
             this.index = index;
+            this.k = keys[index];
+            this.v = values[index];
         }
 
         @Override
         public K getKey() {
-            return keys[index];
+            return k;
         }
 
         @Override
         public V getValue() {
-            return values[index];
+            return v;
         }
 
         @Override
         public V setValue(V value) {
-            return ireplace(index, value);
+            if(keys[index] != k && values[index] != v) {
+                throw new ConcurrentModificationException();
+            }
+            return ireplace(index, v = value);
         }
 
     }
@@ -679,7 +681,6 @@ public abstract class AOpenMap<K,V> extends AMap<K, V> implements BlockMap<K, V>
         @Override
         public void remove() {
             super.remove();
-            entry.index = -1; // You cannot use a deleted entry.
         }
     }
 

+ 4 - 5
assira.core/src/main/java/net/ranides/assira/collection/prototype/PrototypeMap.java

@@ -38,7 +38,7 @@ public class PrototypeMap extends AMap<Object, Object> implements Map<Object, Ob
      * Creates new map without prototype
      */
     public PrototypeMap() {
-        this(null, new HashMap<>());
+        this(null, new OpenMap<>());
     }
 
     /**
@@ -47,7 +47,7 @@ public class PrototypeMap extends AMap<Object, Object> implements Map<Object, Ob
      * @param parent parent
      */
     public PrototypeMap(PrototypeMap parent) {
-        this(parent, new HashMap<>());
+        this(parent, new OpenMap<>());
     }
 
     /**
@@ -56,7 +56,7 @@ public class PrototypeMap extends AMap<Object, Object> implements Map<Object, Ob
      * @param content content
      */
     public PrototypeMap(Map<Object, ?> content) {
-        this(null, new HashMap<>(content));
+        this(null, new OpenMap<>(content));
     }
 
     /**
@@ -67,7 +67,7 @@ public class PrototypeMap extends AMap<Object, Object> implements Map<Object, Ob
      */
     public PrototypeMap(PrototypeMap parent, Map<Object, ?> content) {
         this.parent = parent;
-        this.declared = new HashMap<>(content);
+        this.declared = new OpenMap<>(content);
     }
 
     private PrototypeMap(boolean empty) {
@@ -433,7 +433,6 @@ public class PrototypeMap extends AMap<Object, Object> implements Map<Object, Ob
 
         @Override
         public Iterator<Map.Entry<Object, Object>> iterator() {
-            // @todo #82 fix bug inside "AOpenMap.PEntry" and then replace HashMap by OpenMap
             return new RemoveIterator<>(aggregate().iterator(), this::remove);
         }