import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.util.Collection;
+import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
+import gnu.trove.map.TLongObjectMap;
import gnu.trove.map.hash.TLongObjectHashMap;
/**
}
};
- protected transient Map<String, INode> children = createChildMap();
- private transient TLongObjectHashMap<String> childrenIdMap = new TLongObjectHashMap<>();
+ private static class ImmutableIdMap extends TLongObjectHashMap<String> {
+ private static final String MSG = "immutable singleton instance";
+
+ @Override
+ public String put(long key, String value) {
+ throw new UnsupportedOperationException(MSG);
+ }
+ @Override
+ public void putAll(Map<? extends Long, ? extends String> map) {
+ throw new UnsupportedOperationException(MSG);
+ }
+ @Override
+ public void putAll(TLongObjectMap<? extends String> map) {
+ throw new UnsupportedOperationException(MSG);
+ }
+ @Override
+ public String putIfAbsent(long key, String value) {
+ throw new UnsupportedOperationException(MSG);
+ }
+ }
+
+ /**
+ * This is the value given to {@link #children} when this node is disposed and
+ * cleaned up.
+ */
+ private static final Map<String, INode> DISPOSED_CHILDREN = Collections.emptyMap();
+
+ /**
+ * This is the value given to {@link #childrenIdMap} when this node is disposed
+ * and cleaned up.
+ */
+ private static final TLongObjectMap<String> DISPOSED_CHILDREN_ID_MAP = new ImmutableIdMap();
+
+ protected transient Map<String, INode> children = createChildMap();
+ private transient TLongObjectMap<String> childrenIdMap = new TLongObjectHashMap<>();
/**
* A cached value for the root node of this parent node. This makes it
@Override
public void cleanup() {
retractMapping();
- if (children != null) {
+ if (children != DISPOSED_CHILDREN) {
children.forEach((id, child) -> {
child.cleanup();
child.setParent(null);
});
children.clear();
childrenIdMap.clear();
- children = null;
- childrenIdMap = null;
+ children = DISPOSED_CHILDREN;
+ childrenIdMap = DISPOSED_CHILDREN_ID_MAP;
childrenChanged();
rootNodeCache = DISPOSED;
}