001: /*
002: * ============================================================================
003: * GNU Lesser General Public License
004: * ============================================================================
005: *
006: * JasperReports - Free Java report-generating library.
007: * Copyright (C) 2001-2006 JasperSoft Corporation http://www.jaspersoft.com
008: *
009: * This library is free software; you can redistribute it and/or
010: * modify it under the terms of the GNU Lesser General Public
011: * License as published by the Free Software Foundation; either
012: * version 2.1 of the License, or (at your option) any later version.
013: *
014: * This library is distributed in the hope that it will be useful,
015: * but WITHOUT ANY WARRANTY; without even the implied warranty of
016: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
017: * Lesser General Public License for more details.
018: *
019: * You should have received a copy of the GNU Lesser General Public
020: * License along with this library; if not, write to the Free Software
021: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
022: *
023: * JasperSoft Corporation
024: * 303 Second Street, Suite 450 North
025: * San Francisco, CA 94107
026: * http://www.jaspersoft.com
027: */
028: package net.sf.jasperreports.engine.fill;
029:
030: import net.sf.jasperreports.engine.JRVariable;
031:
032: /**
033: * @author Teodor Danciu (teodord@users.sourceforge.net)
034: * @version $Id: JRDefaultIncrementerFactory.java 1311 2006-06-23 09:19:26Z teodord $
035: */
036: public class JRDefaultIncrementerFactory extends
037: JRAbstractExtendedIncrementerFactory {
038:
039: /**
040: *
041: */
042: private static JRDefaultIncrementerFactory mainInstance = new JRDefaultIncrementerFactory();
043:
044: /**
045: *
046: */
047: private JRDefaultIncrementerFactory() {
048: }
049:
050: /**
051: *
052: */
053: public static JRDefaultIncrementerFactory getInstance() {
054: return mainInstance;
055: }
056:
057: /**
058: *
059: */
060: public JRExtendedIncrementer getExtendedIncrementer(byte calculation) {
061: JRExtendedIncrementer incrementer = null;
062:
063: switch (calculation) {
064: case JRVariable.CALCULATION_SYSTEM: {
065: incrementer = JRDefaultSystemIncrementer.getInstance();
066: break;
067: }
068: case JRVariable.CALCULATION_FIRST: {
069: incrementer = JRDefaultFirstIncrementer.getInstance();
070: break;
071: }
072: case JRVariable.CALCULATION_NOTHING:
073: case JRVariable.CALCULATION_COUNT:
074: case JRVariable.CALCULATION_SUM:
075: case JRVariable.CALCULATION_AVERAGE:
076: case JRVariable.CALCULATION_LOWEST:
077: case JRVariable.CALCULATION_HIGHEST:
078: case JRVariable.CALCULATION_STANDARD_DEVIATION:
079: case JRVariable.CALCULATION_VARIANCE:
080: case JRVariable.CALCULATION_DISTINCT_COUNT:
081: default: {
082: incrementer = JRDefaultNothingIncrementer.getInstance();
083: break;
084: }
085: }
086:
087: return incrementer;
088: }
089:
090: public static JRExtendedIncrementerFactory getFactory(
091: Class valueClass) {
092: JRExtendedIncrementerFactory factory;
093:
094: if (java.math.BigDecimal.class.equals(valueClass)) {
095: factory = JRBigDecimalIncrementerFactory.getInstance();
096: } else if (java.lang.Number.class.equals(valueClass)
097: || java.lang.Double.class.equals(valueClass)) {
098: factory = JRDoubleIncrementerFactory.getInstance();
099: } else if (java.lang.Float.class.equals(valueClass)) {
100: factory = JRFloatIncrementerFactory.getInstance();
101: } else if (java.lang.Long.class.equals(valueClass)) {
102: factory = JRLongIncrementerFactory.getInstance();
103: } else if (java.lang.Integer.class.equals(valueClass)) {
104: factory = JRIntegerIncrementerFactory.getInstance();
105: } else if (java.lang.Short.class.equals(valueClass)) {
106: factory = JRShortIncrementerFactory.getInstance();
107: } else if (java.lang.Byte.class.equals(valueClass)) {
108: factory = JRByteIncrementerFactory.getInstance();
109: } else if (java.lang.Comparable.class
110: .isAssignableFrom(valueClass)) {
111: factory = JRComparableIncrementerFactory.getInstance();
112: } else {
113: factory = JRDefaultIncrementerFactory.getInstance();
114: }
115:
116: return factory;
117: }
118: }
119:
120: /**
121: *
122: */
123: class JRDefaultNothingIncrementer extends JRAbstractExtendedIncrementer {
124:
125: /**
126: *
127: */
128: private static JRDefaultNothingIncrementer mainInstance = new JRDefaultNothingIncrementer();
129:
130: /**
131: *
132: */
133: private JRDefaultNothingIncrementer() {
134: }
135:
136: /**
137: *
138: */
139: public static JRDefaultNothingIncrementer getInstance() {
140: return mainInstance;
141: }
142:
143: /**
144: *
145: */
146: public Object increment(JRCalculable variable,
147: Object expressionValue, AbstractValueProvider valueProvider) {
148: return expressionValue;
149: }
150:
151: public Object combine(JRCalculable calculable,
152: JRCalculable calculableValue,
153: AbstractValueProvider valueProvider) {
154: if (!calculableValue.isInitialized()) {
155: return calculableValue.getValue();
156: }
157:
158: if (!calculable.isInitialized()) {
159: return calculable.getValue();
160: }
161:
162: return null;
163: }
164:
165: public Object initialValue() {
166: return null;
167: }
168: }
169:
170: /**
171: *
172: */
173: class JRDefaultSystemIncrementer extends JRAbstractExtendedIncrementer {
174: /**
175: *
176: */
177: private static JRDefaultSystemIncrementer mainInstance = new JRDefaultSystemIncrementer();
178:
179: /**
180: *
181: */
182: private JRDefaultSystemIncrementer() {
183: }
184:
185: /**
186: *
187: */
188: public static JRDefaultSystemIncrementer getInstance() {
189: return mainInstance;
190: }
191:
192: /**
193: *
194: */
195: public Object increment(JRCalculable variable,
196: Object expressionValue, AbstractValueProvider valueProvider) {
197: return variable.getValue();
198: }
199:
200: public Object combine(JRCalculable calculable,
201: JRCalculable calculableValue,
202: AbstractValueProvider valueProvider) {
203: return calculable.getValue();
204: }
205:
206: public Object initialValue() {
207: return null;
208: }
209: }
210:
211: class JRDefaultFirstIncrementer extends JRAbstractExtendedIncrementer {
212: private static final JRDefaultFirstIncrementer instance = new JRDefaultFirstIncrementer();
213:
214: private JRDefaultFirstIncrementer() {
215: }
216:
217: public static JRDefaultFirstIncrementer getInstance() {
218: return instance;
219: }
220:
221: public Object initialValue() {
222: return null;
223: }
224:
225: public Object combine(JRCalculable calculable,
226: JRCalculable calculableValue,
227: AbstractValueProvider valueProvider) {
228: if (!calculable.isInitialized()) {
229: return calculable.getValue();
230: }
231:
232: if (!calculableValue.isInitialized()) {
233: return calculableValue.getValue();
234: }
235:
236: return null;
237: }
238:
239: public Object increment(JRCalculable calculable,
240: Object expressionValue, AbstractValueProvider valueProvider) {
241: if (calculable.isInitialized()) {
242: return expressionValue;
243: }
244:
245: return calculable.getIncrementedValue();
246: }
247: }
|