public Map makeEmptyMap() { ReferenceMap map = new ReferenceMap(ReferenceMap.WEAK, ReferenceMap.WEAK); return map; }
/** * Read the map in using a custom routine. */ private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException { in.defaultReadObject(); doReadObject(in); }
/** * Write the map out using a custom routine. */ private void writeObject(ObjectOutputStream out) throws IOException { out.defaultWriteObject(); doWriteObject(out); }
@Override public Admin<T> split() { final B_NL_O_S_SE_SL_Traverser<T> clone = (B_NL_O_S_SE_SL_Traverser<T>) super.split(); clone.nestedLoops = new Stack<>(); for(LabelledCounter lc : this.nestedLoops) clone.nestedLoops.push((LabelledCounter) lc.clone()); if (this.loopNames != null) { clone.loopNames = new ReferenceMap(ReferenceMap.HARD, ReferenceMap.WEAK); final Iterator loopNamesIterator = this.loopNames.entrySet().iterator(); while (loopNamesIterator.hasNext()) { final ReferenceMap.Entry pair = (ReferenceMap.Entry) loopNamesIterator.next(); final int idx = this.nestedLoops.indexOf(pair.getValue()); if (idx != -1) clone.loopNames.put(pair.getKey(), clone.nestedLoops.get(idx)); } } return clone; }
/** * Cache some node. * * @param data data to cache */ public void cache(AbstractNodeData data) { NodeId id = data.getNodeState().getNodeId(); ReferenceMap map = (ReferenceMap) cache.get(id); if (map == null) { map = new ReferenceMap(ReferenceMap.HARD, ReferenceMap.WEAK); cache.put(id, map); } Object old = map.put(data.getPrimaryParentId(), data); if (old != null) { log.debug("overwriting cached item: " + old); } }
@Override public int loops(final String loopName) { if (loopName == null) return loops(); else if (this.loopNames.containsKey(loopName)) return ((LabelledCounter) this.loopNames.get(loopName)).count(); else throw new IllegalArgumentException("Loop name not defined: " + loopName); }
@Override public void initialiseLoops(final String stepLabel, final String loopName) { if (this.nestedLoops.empty() || !this.nestedLoops.peek().hasLabel(stepLabel)) { final LabelledCounter lc = new LabelledCounter(stepLabel, (short) 0); this.nestedLoops.push(lc); if (loopName != null) this.loopNames.put(loopName, lc); } }
/** * Returns the {@link AbstractFile} instance mapped onto the given key if there is one, * <code>null</code> otherwise * * @param key key of the file instance to retrieve * @return the {@link AbstractFile} instance mapped onto the given key if there is one, * <code>null</code> otherwise */ public synchronized AbstractFile get(Object key) { return (AbstractFile)hashMap.get(key); }
@Override public <R> Admin<R> split(final R r, final Step<T, R> step) { final B_LP_NL_O_S_SE_SL_Traverser<R> clone = (B_LP_NL_O_S_SE_SL_Traverser<R>) super.split(r, step); clone.nestedLoops = new Stack<>(); for(LabelledCounter lc : this.nestedLoops) clone.nestedLoops.push((LabelledCounter) lc.clone()); if (this.loopNames != null) { clone.loopNames = new ReferenceMap(ReferenceMap.HARD, ReferenceMap.WEAK); final Iterator loopNamesIterator = this.loopNames.entrySet().iterator(); while (loopNamesIterator.hasNext()) { final ReferenceMap.Entry pair = (ReferenceMap.Entry) loopNamesIterator.next(); final int idx = this.nestedLoops.indexOf(pair.getValue()); if (idx != -1) clone.loopNames.put(pair.getKey(), clone.nestedLoops.get(idx)); } } return clone; }
/** * Cache some node. * * @param data data to cache */ public void cache(AbstractNodeData data) { NodeId id = data.getNodeState().getNodeId(); ReferenceMap map = (ReferenceMap) cache.get(id); if (map == null) { map = new ReferenceMap(ReferenceMap.HARD, ReferenceMap.WEAK); cache.put(id, map); } Object old = map.put(data.getPrimaryParentId(), data); if (old != null) { log.debug("overwriting cached item: " + old); } }
@Override public int loops(final String loopName) { if (loopName == null) return loops(); else if (this.loopNames.containsKey(loopName)) return ((LabelledCounter) this.loopNames.get(loopName)).count(); else throw new IllegalArgumentException("Loop name not defined: " + loopName); }
@Override public void initialiseLoops(final String stepLabel, final String loopName) { if (this.nestedLoops.empty() || !this.nestedLoops.peek().hasLabel(stepLabel)) { final LabelledCounter lc = new LabelledCounter(stepLabel, (short) 0); this.nestedLoops.push(lc); if (loopName != null) this.loopNames.put(loopName, lc); } }
/** * Returns the {@link Icon} instance mapped onto the given key if there is one, * <code>null</code> otherwise * * @param key key of the icon instance to retrieve * @return the {@link Icon} instance mapped onto the given key if there is one, * <code>null</code> otherwise */ public synchronized Icon get(Object key) { return (Icon)hashMap.get(key); }
@Override public Admin<T> split() { final B_LP_NL_O_P_S_SE_SL_Traverser<T> clone = (B_LP_NL_O_P_S_SE_SL_Traverser<T>) super.split(); clone.nestedLoops = new Stack<>(); for(LabelledCounter lc : this.nestedLoops) clone.nestedLoops.push((LabelledCounter) lc.clone()); if (this.loopNames != null) { clone.loopNames = new ReferenceMap(ReferenceMap.HARD, ReferenceMap.WEAK); final Iterator loopNamesIterator = this.loopNames.entrySet().iterator(); while (loopNamesIterator.hasNext()) { final ReferenceMap.Entry pair = (ReferenceMap.Entry) loopNamesIterator.next(); final int idx = this.nestedLoops.indexOf(pair.getValue()); if (idx != -1) clone.loopNames.put(pair.getKey(), clone.nestedLoops.get(idx)); } } return clone; }
public Map buildRefMap() { Object key = new Object(); Object value = new Object(); keyReference = new WeakReference(key); valueReference = new WeakReference(value); Map testMap = new ReferenceMap(ReferenceMap.WEAK, ReferenceMap.HARD, true); testMap.put(key, value); assertEquals("In map", value, testMap.get(key)); assertNotNull("Weak reference released early (1)", keyReference.get()); assertNotNull("Weak reference released early (2)", valueReference.get()); return testMap; }
@Override public int loops(final String loopName) { if (loopName == null) return loops(); else if (this.loopNames.containsKey(loopName)) return ((LabelledCounter) this.loopNames.get(loopName)).count(); else throw new IllegalArgumentException("Loop name not defined: " + loopName); }