1:
31: package ;
32:
33: import ;
34: import ;
35: import ;
36: import ;
37: import ;
38: import ;
39:
40:
46: public class DefaultDataTable extends ObjectTable implements DataTable
47: {
48: private transient Boolean constant;
49:
50:
53: public DefaultDataTable()
54: {
55: }
56:
57: public DefaultDataTable(LValue[][] array)
58: {
59: if(array != null && array.length > 0)
60: {
61: int colCount = array[0].length;
62:
63: setData(array, colCount);
64: }
65: }
66:
67: public String getColumnName(int column)
68: {
69: StringBuffer result = new StringBuffer();
70: for (; column >= 0; column = column / 26 - 1)
71: {
72: final int colChar = (char) (column % 26) + 'A';
73: result.append(colChar);
74: }
75: return result.toString();
76: }
77:
78:
86: public void setObject(final int row, final int column, final LValue object)
87: {
88: super.setObject(row, column, object);
89: }
90:
91: public LValue getValueAt(int row, int column)
92: {
93: return (LValue) getObject(row, column);
94: }
95:
96: public void initialize(FormulaContext context) throws EvaluationException
97: {
98: final int rows = getRowCount();
99: final int cols = getColumnCount();
100: for (int row = 0; row < rows; row++)
101: {
102: for (int col = 0; col < cols; col++)
103: {
104: LValue value = getValueAt(row, col);
105: if(value != null)
106: {
107: value.initialize(context);
108: }
109: }
110: }
111: }
112:
113: public TypeValuePair evaluate() throws EvaluationException
114: {
115: int colCount = -1;
116: LValue[][] array = (LValue[][])getData();
117: for(int i=0; i<array.length; i++)
118: {
119: LValue[] row = array[i];
120: if(colCount > 0 && row.length != colCount)
121: {
122:
123: throw new EvaluationException(LibFormulaErrorValue.ERROR_ILLEGAL_ARRAY_VALUE);
124: }
125: else
126: {
127: colCount = row.length;
128: }
129: }
130: return new TypeValuePair(DataTableType.TYPE, this);
131: }
132:
133: public Object clone() throws CloneNotSupportedException
134: {
135: final DefaultDataTable table = (DefaultDataTable) super.clone();
136: final Object[][] data = getData();
137: final Object[][] targetData = (Object[][]) data.clone();
138: for (int i = 0; i < targetData.length; i++)
139: {
140: final Object[] objects = targetData[i];
141: if (objects == null)
142: {
143: continue;
144: }
145:
146: targetData[i] = (Object[]) objects.clone();
147: for (int j = 0; j < objects.length; j++)
148: {
149: final LValue object = (LValue) objects[j];
150: if (object == null)
151: {
152: continue;
153: }
154: objects[j] = object.clone();
155: }
156: }
157:
158: table.setData(targetData, getColumnCount());
159: return table;
160: }
161:
162:
168: public Type getValueType()
169: {
170: return DataTableType.TYPE;
171: }
172:
173:
178: public LValue[] getChildValues()
179: {
180:
181: return new LValue[0];
182: }
183:
184:
190: public boolean isConstant()
191: {
192: if (constant == null)
193: {
194: if (computeConstantValue())
195: {
196: constant = Boolean.TRUE;
197: }
198: else
199: {
200: constant = Boolean.FALSE;
201: }
202: }
203:
204: return Boolean.TRUE.equals(constant);
205: }
206:
207: private boolean computeConstantValue()
208: {
209: final int rows = getRowCount();
210: final int cols = getColumnCount();
211: for (int row = 0; row < rows; row++)
212: {
213: for (int col = 0; col < cols; col++)
214: {
215: LValue value = getValueAt(row, col);
216: if (value.isConstant() == false)
217: {
218: return false;
219: }
220: }
221: }
222: return true;
223: }
224: }