1:
31: package ;
32:
33: import ;
34: import ;
35: import ;
36: import ;
37:
38:
41: public class NumberSequence
42: {
43: private int rowCursor = 0;
44: private int columnCursor = 0;
45: private Number number;
46: private ArrayCallback array;
47: private FormulaContext context;
48:
49:
52: public NumberSequence(final FormulaContext context)
53: {
54: this.context = context;
55: }
56:
57:
62: public NumberSequence(final Number n, final FormulaContext context)
63: {
64: number = n;
65: this.context = context;
66: }
67:
68:
73: public NumberSequence(final ArrayCallback array, final FormulaContext context)
74: {
75: this.array = array;
76: this.context = context;
77: }
78:
79: public boolean hasNext() throws EvaluationException
80: {
81:
82: if (number == null && array == null)
83: {
84: return false;
85: }
86:
87: if (number != null && rowCursor == 0)
88: {
89: return true;
90: }
91:
92:
93: if (array != null)
94: {
95: final int rowCount = array.getRowCount();
96: final int columnCount = array.getColumnCount();
97: if (array != null && rowCursor < rowCount && columnCursor < columnCount)
98: {
99: for (; rowCursor < rowCount; rowCursor++)
100: {
101: for (; columnCursor < columnCount; columnCursor++)
102: {
103: final Type type = array.getType(rowCursor, columnCursor);
104: final boolean b = type.isFlagSet(Type.NUMERIC_TYPE);
105:
106: if (b)
107: {
108: return true;
109: }
110: }
111: columnCursor = 0;
112: }
113: }
114: }
115:
116: return false;
117: }
118:
119: public Number nextNumber() throws EvaluationException
120: {
121: if (number != null && rowCursor == 0)
122: {
123: rowCursor++;
124: return number;
125: }
126: if (array != null)
127: {
128: final Type type = array.getType(rowCursor, columnCursor);
129: final Object value = array.getValue(rowCursor, columnCursor);
130: final Number number = context.getTypeRegistry().convertToNumber(type, value);
131:
132: if (columnCursor == array.getColumnCount() - 1)
133: {
134: rowCursor++;
135: columnCursor = 0;
136: }
137: else
138: {
139: columnCursor++;
140: }
141: return number;
142:
143: }
144: return null;
145: }
146:
147: }