http://www.jpicedt.org

jpicedt.format.input.util
Class Pool

java.lang.Object
  extended by jpicedt.format.input.util.Pool

public class Pool
extends Object

Offers a means for expressions belonging to the parser-tree to share variables across the tree. In addition to storing persistent data in some predefined public fields, this class also acts as a hashtable, and may thus store key/value pairs of objects of any class (these may be PicAttributeSet's, etc…), which may be shared across the whole parser-tree.

Since:
jpicedt 1.3
Version:
$Id: Pool.java,v 1.13 2013/07/26 06:10:46 vincentb1 Exp $
Author:
Sylvain Reynal

Nested Class Summary
static class Pool.Key<T>
          Enforces use of strong typing for keys being pushed in the map .
 
Field Summary
static Pool.Key<PicAttributeSet> CURRENT_OBJ_ATTRIBUTES
          Key used to fetch the attribute set attached to the current element "currentObj"
 PicGroup currentGroup
          either the main drawing, or a subgroup ; each new parsed Element should be added to this group
 Element currentObj
          Convenience used to share information (e.g. parameters, location, …) across expressions acting on the same element.
 StringBuffer notParsed
          A string that stores commands that couldn't be parsed in the current context (e.g. in the text file to be parsed) so that we can keep track of these commands (e.g. to be able to include them again when it comes to saving the text file to disk)
 Stack<PicGroup> picGroupStack
          A stack used to store the main drawing and its subgroups ; each time a "begin group" is encountered, the current PicGroup is pushed onto the stack, and a new PicGroup is instanciated, which then represents the current PicGroup ; the opposite operations are executed in the reverse order when a "end group" is found.
 
Constructor Summary
Pool()
          Simply call reinit()
 
Method Summary
<T> T
get(Pool.Key<T> key)
          Return the value associated with the given key
 PicAttributeSet getAttributeSet(Pool.Key<? extends PicAttributeSet> key)
          Convenience for retrieving a "PicAttributeSet" value ; can be used in conjunction with static methods defined in jpicedt.graphic.model.StyleConstants to retrieve attributes values with less burden.
<T> T
put(Pool.Key<T> key, T value)
          Associates the specified value with the given key in the pool's hashmap
 void reinit()
          Reset public fields values.
<T> void
setAttribute(Pool.Key<? extends PicAttributeSet> key, PicAttributeName<T> name, T value)
          Add a name/value attribute pair to the attribute set with the given key, i.e.
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

currentGroup

public PicGroup currentGroup
either the main drawing, or a subgroup ; each new parsed Element should be added to this group


picGroupStack

public Stack<PicGroup> picGroupStack
A stack used to store the main drawing and its subgroups ; each time a "begin group" is encountered, the current PicGroup is pushed onto the stack, and a new PicGroup is instanciated, which then represents the current PicGroup ; the opposite operations are executed in the reverse order when a "end group" is found.


currentObj

public Element currentObj
Convenience used to share information (e.g. parameters, location, …) across expressions acting on the same element. Generally, an InstanciationExpression reinits "currentObj" to an instance of an Element of the proper type, then ensuing expression modify this element's attributes and/or geometry.


notParsed

public StringBuffer notParsed
A string that stores commands that couldn't be parsed in the current context (e.g. in the text file to be parsed) so that we can keep track of these commands (e.g. to be able to include them again when it comes to saving the text file to disk)


CURRENT_OBJ_ATTRIBUTES

public static final Pool.Key<PicAttributeSet> CURRENT_OBJ_ATTRIBUTES
Key used to fetch the attribute set attached to the current element "currentObj"

See Also:
get(jpicedt.format.input.util.Pool.Key)
Constructor Detail

Pool

public Pool()
Simply call reinit()

Method Detail

reinit

public void reinit()
Reset public fields values.


put

public <T> T put(Pool.Key<T> key,
                 T value)
Associates the specified value with the given key in the pool's hashmap

Returns:
old value for the given key, if any.

get

public <T> T get(Pool.Key<T> key)
Return the value associated with the given key


getAttributeSet

public PicAttributeSet getAttributeSet(Pool.Key<? extends PicAttributeSet> key)
Convenience for retrieving a "PicAttributeSet" value ; can be used in conjunction with static methods defined in jpicedt.graphic.model.StyleConstants to retrieve attributes values with less burden.

Parameters:
key - if CURRENT_OBJ_ATTRIBUTES, retrieves the attribute set of the current Element in the pool ; any other key is acceptable as long as it corresponds to a valid entry in the Pool's hashtable, that is, it has been previously pushed in the Pool using put(key, value).

setAttribute

public <T> void setAttribute(Pool.Key<? extends PicAttributeSet> key,
                             PicAttributeName<T> name,
                             T value)
Add a name/value attribute pair to the attribute set with the given key, i.e. either CURRENT_OBJ_ATTRIBUTES for "currentObj", or any other key refering to an attribute set previously pushed in the Pool (e.g. PsTricks registers,…)


toString

public String toString()
Overrides:
toString in class Object
Returns:
a text description of this Pool for debugging purpose

http://www.jpicedt.org

Submit a bug : syd@jpicedt.org