X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.scl.compiler%2Fsrc%2Forg%2Fcojen%2Futil%2FReferencedValueHashMap.java;h=cf2772f408d349d7745d894876e9ddb2e827ec37;hp=d854fafecc77582743c1707f31c8be94c4fc14de;hb=a8758de5bc19e5adb3f618d3038743a164f09912;hpb=12d9af17384d960b75d58c3935d2b7b46d93e87b diff --git a/bundles/org.simantics.scl.compiler/src/org/cojen/util/ReferencedValueHashMap.java b/bundles/org.simantics.scl.compiler/src/org/cojen/util/ReferencedValueHashMap.java index d854fafec..cf2772f40 100644 --- a/bundles/org.simantics.scl.compiler/src/org/cojen/util/ReferencedValueHashMap.java +++ b/bundles/org.simantics.scl.compiler/src/org/cojen/util/ReferencedValueHashMap.java @@ -46,6 +46,12 @@ import java.util.Set; public abstract class ReferencedValueHashMap extends AbstractMap implements Map, Cloneable { + static final Object NULL = new Comparable() { + public int compareTo(Object obj) { + return obj == this || obj == null ? 0 : 1; + } + }; + private transient Entry[] table; private transient int count; private int threshold; @@ -128,7 +134,7 @@ public abstract class ReferencedValueHashMap extends AbstractMap public boolean containsValue(Object value) { if (value == null) { - value = KeyFactory.NULL; + value = NULL; } Entry[] tab = this.table; @@ -221,7 +227,7 @@ public abstract class ReferencedValueHashMap extends AbstractMap } count--; } else if (e.hash == hash && key.equals(e.key)) { - return (entryValue == KeyFactory.NULL) ? null : entryValue; + return (entryValue == NULL) ? null : entryValue; } else { prev = e; } @@ -241,7 +247,7 @@ public abstract class ReferencedValueHashMap extends AbstractMap } this.count--; } else if (e.key == null) { - return (entryValue == KeyFactory.NULL) ? null : entryValue; + return (entryValue == NULL) ? null : entryValue; } else { prev = e; } @@ -311,7 +317,7 @@ public abstract class ReferencedValueHashMap extends AbstractMap public V put(K key, V value) { if (value == null) { - value = (V) KeyFactory.NULL; + value = (V) NULL; } // Makes sure the key is not already in the HashMap. @@ -336,7 +342,7 @@ public abstract class ReferencedValueHashMap extends AbstractMap this.count--; } else if (e.hash == hash && key.equals(e.key)) { e.setValue(value); - return (entryValue == KeyFactory.NULL) ? null : entryValue; + return (entryValue == NULL) ? null : entryValue; } else { prev = e; } @@ -358,7 +364,7 @@ public abstract class ReferencedValueHashMap extends AbstractMap this.count--; } else if (e.key == null) { e.setValue(value); - return (entryValue == KeyFactory.NULL) ? null : entryValue; + return (entryValue == NULL) ? null : entryValue; } else { prev = e; } @@ -415,7 +421,7 @@ public abstract class ReferencedValueHashMap extends AbstractMap this.count--; e.setValue(null); - return (entryValue == KeyFactory.NULL) ? null : entryValue; + return (entryValue == NULL) ? null : entryValue; } else { prev = e; } @@ -443,7 +449,7 @@ public abstract class ReferencedValueHashMap extends AbstractMap this.count--; e.setValue(null); - return (entryValue == KeyFactory.NULL) ? null : entryValue; + return (entryValue == NULL) ? null : entryValue; } else { prev = e; } @@ -693,12 +699,12 @@ public abstract class ReferencedValueHashMap extends AbstractMap public V getValue() { V value = this.value.get(); - return value == KeyFactory.NULL ? null : value; + return value == NULL ? null : value; } public V setValue(V value) { V oldValue = getValue(); - this.value = newReference(value == null ? ((V) KeyFactory.NULL) : value); + this.value = newReference(value == null ? ((V) NULL) : value); return oldValue; } @@ -713,7 +719,7 @@ public abstract class ReferencedValueHashMap extends AbstractMap Object thisValue = get(); if (thisValue == null) { return false; - } else if (thisValue == KeyFactory.NULL) { + } else if (thisValue == NULL) { thisValue = null; } return (this.key == null ? e.getKey() == null : this.key.equals(e.getKey())) &&