/** * Gets the node meta data. * * @param key - the meta data key * @return the node meta data value for this key */ public <T> T getNodeMetaData(Object key) { if (metaDataMap == null) { return (T) null; } return (T) metaDataMap.get(key); }
@SuppressWarnings("unchecked") public Set<java.util.Map.Entry<K, V>> entrySet() { Map m = innerMap!=null?innerMap:makeMap(); return m.entrySet(); }
public V remove(Object key) { if (innerMap==null) { for (int i=0; i<size; i++) { if (listKeys[i].equals(key)) { V old = (V) listValues[i]; size--; // If last element is not being removed shift the last element into this slot if (i < size) { listValues[i] = listValues[size]; listKeys[i] = listKeys[size]; } listValues[size] = null; listKeys[size] = null; return old; } } return null; } else { V old = innerMap.remove(key); size = innerMap.size(); if (size<=maxListFill) { mapToList(); } return old; } }
/** * Copies all node meta data from the other node to this one * @param other - the other node */ public void copyNodeMetaData(ASTNode other) { if (other.metaDataMap == null) { return; } if (metaDataMap == null) { metaDataMap = new ListHashMap(); } metaDataMap.putAll(other.metaDataMap); }
/** * Sets the node meta data but allows overwriting values. * * @param key - the meta data key * @param value - the meta data value * @return the old node meta data value for this key * @throws GroovyBugError if key is null */ public Object putNodeMetaData(Object key, Object value) { if (key == null) throw new GroovyBugError("Tried to set meta data with null key on " + this + "."); if (metaDataMap == null) { metaDataMap = new ListHashMap(); } return metaDataMap.put(key, value); }
@SuppressWarnings("unchecked") public V put(K key, V value) { if (innerMap==null) { for (int i=0; i<size; i++) { if (listKeys[i].equals(key)) { V old = (V) listValues[i]; listValues[i] = value; return old; } } if (size<maxListFill) { listKeys[size] = key; listValues[size] = value; size++; return null; } else { innerMap = makeMap(); // Switched over to Map so need to clear array references clearArrays(); } } V val = (V) innerMap.put(key, value); size = innerMap.size(); return val; }
public void putAll(Map<? extends K, ? extends V> m) { for (Entry<? extends K, ? extends V> entry : m.entrySet()) { put(entry.getKey(), entry.getValue()); } }
/** * Removes a node meta data entry. * * @param key - the meta data key * @throws GroovyBugError if the key is null */ public void removeNodeMetaData(Object key) { if (key==null) throw new GroovyBugError("Tried to remove meta data with null key "+this+"."); if (metaDataMap == null) { return; } metaDataMap.remove(key); }
/** * Copies all node meta data from one node to the other * @param other - the other node */ public void copyNodeMetaData(ASTNode other) { metaDataMap.putAll(other.metaDataMap); }
/** * Provides a collection of all the nodes in the tree * using a depth-first preorder traversal. * * @param c the closure to run for each node (a one or two parameter can be used; if one parameter is given the * closure will be passed the node, for a two param closure the second parameter will be the level). * @since 2.5.0 */ public void depthFirst(Closure c) { Map<String, Object> options = new ListHashMap<String, Object>(); options.put("preorder", true); depthFirst(options, c); }
public void clear() { innerMap = null; clearArrays(); size = 0; }
/** * Sets the node meta data but allows overwriting values. * * @param key - the meta data key * @param value - the meta data value * @return the old node meta data value for this key * @throws GroovyBugError if key is null */ public Object putNodeMetaData(Object key, Object value) { if (key == null) throw new GroovyBugError("Tried to set meta data with null key on " + this + "."); if (metaDataMap == null) { metaDataMap = new ListHashMap(); } return metaDataMap.put(key, value); }
/** * Sets the node meta data but allows overwriting values. * * @param key - the meta data key * @param value - the meta data value * @return the old node meta data value for this key * @throws GroovyBugError if key is null */ public Object putNodeMetaData(Object key, Object value) { if (key == null) throw new GroovyBugError("Tried to set meta data with null key on " + this + "."); return metaDataMap.put(key, value); }
/** * Removes a node meta data entry. * * @param key - the meta data key * @throws GroovyBugError if the key is null */ public void removeNodeMetaData(Object key) { if (key==null) throw new GroovyBugError("Tried to remove meta data with null key "+this+"."); if (metaDataMap == null) { return; } metaDataMap.remove(key); }
/** * Calls the provided closure for all the nodes in the tree * using a breadth-first preorder traversal. * * @param c the closure to run for each node (a one or two parameter can be used; if one parameter is given the * closure will be passed the node, for a two param closure the second parameter will be the level). * @since 2.5.0 */ public void breadthFirst(Closure c) { Map<String, Object> options = new ListHashMap<String, Object>(); options.put("preorder", true); breadthFirst(options, c); }
/** * Sets the node meta data for the provided key. * * @param key - the meta data key * @param value - the meta data value * @throws GroovyBugError if key is null or there is already meta * data under that key */ public void setNodeMetaData(Object key, Object value) { if (key==null) throw new GroovyBugError("Tried to set meta data with null key on "+this+"."); if (metaDataMap == null) { metaDataMap = new ListHashMap(); } Object old = metaDataMap.put(key,value); if (old!=null) throw new GroovyBugError("Tried to overwrite existing meta data "+this+"."); }
public Set<K> keySet() { Map m = innerMap!=null?innerMap:makeMap(); return m.keySet(); }
/** * Gets the node meta data for the provided key. * * @param key - the meta data key * @return the node meta data value for this key */ public <T> T getNodeMetaData(Object key) { if (metaDataMap == null) { return (T) null; } return (T) metaDataMap.get(key); }
/** * Sets the node meta data. * * @param key - the meta data key * @param value - the meta data value * @throws GroovyBugError if key is null or there is already meta * data under that key */ public void setNodeMetaData(Object key, Object value) { if (key==null) throw new GroovyBugError("Tried to set meta data with null key on "+this+"."); Object old = metaDataMap.put(key,value); if (old!=null) throw new GroovyBugError("Tried to overwrite existing meta data "+this+"."); }
/** * Removes a node meta data entry. * * @param key - the meta data key * @throws GroovyBugError if the key is null */ public void removeNodeMetaData(Object key) { if (key==null) throw new GroovyBugError("Tried to remove meta data with null key "+this+"."); metaDataMap.remove(key); } }