1:
31:
32: package ;
33:
34: import ;
35:
36:
45: public class PrecomputeNodeImpl implements PrecomputeNode
46: {
47: private PrecomputeNodeImpl parent;
48: private PrecomputeNodeImpl next;
49: private PrecomputeNodeImpl firstChild;
50: private PrecomputeNodeImpl lastChild;
51:
52: private PrecomputeNodeKey key;
53: private ArrayList functionResults;
54: private ArrayList functionNames;
55:
56: public PrecomputeNodeImpl(final PrecomputeNodeKey key)
57: {
58: if (key == null)
59: {
60: throw new NullPointerException();
61: }
62: this.key = key;
63: }
64:
65: public PrecomputeNodeKey getKey()
66: {
67: return key;
68: }
69:
70: public PrecomputeNode getParent()
71: {
72: return parent;
73: }
74:
75: protected void setParent(final PrecomputeNodeImpl parent)
76: {
77: this.parent = parent;
78: }
79:
80: public PrecomputeNode getNext()
81: {
82: return next;
83: }
84:
85: protected void setNext(final PrecomputeNodeImpl next)
86: {
87: this.next = next;
88: }
89:
90: public PrecomputeNode getFirstChild()
91: {
92: return firstChild;
93: }
94:
95: protected void setFirstChild(final PrecomputeNodeImpl firstChild)
96: {
97: this.firstChild = firstChild;
98: }
99:
100: public PrecomputeNode getLastChild()
101: {
102: return lastChild;
103: }
104:
105: protected void setLastChild(final PrecomputeNodeImpl lastChild)
106: {
107: this.lastChild = lastChild;
108: }
109:
110: public void add(final PrecomputeNodeImpl node)
111: {
112: if (firstChild == null)
113: {
114: firstChild = node;
115: firstChild.setParent(this);
116: lastChild = node;
117: return;
118: }
119:
120: lastChild.setNext(node);
121: lastChild.setParent(this);
122: }
123:
124: public void addFunction(final String name, final Object value)
125: {
126: if (this.functionNames == null)
127: {
128: functionNames = new ArrayList();
129: functionResults = new ArrayList();
130: }
131:
132: this.functionNames.add(name);
133: this.functionResults.add(value);
134: }
135:
136: public int getFunctionCount()
137: {
138: if (functionNames == null)
139: {
140: return 0;
141: }
142: return functionNames.size();
143: }
144:
145: public String getFunctionName(final int idx)
146: {
147: if (functionNames == null)
148: {
149: throw new IndexOutOfBoundsException();
150: }
151: return (String) functionNames.get(idx);
152: }
153:
154: public Object getFunctionResult(final int idx)
155: {
156: if (functionResults == null)
157: {
158: throw new IndexOutOfBoundsException();
159: }
160: return functionResults.get(idx);
161: }
162:
163: public void prune()
164: {
165: if (parent == null)
166: {
167: return;
168: }
169:
170: if (parent.getLastChild() != this)
171: {
172: throw new IllegalStateException("Cannot prune. Not the last child.");
173: }
174: if (parent.getFirstChild() == this)
175: {
176: parent.setFirstChild(null);
177: }
178: parent.setLastChild(null);
179: }
180: }