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: JRComparableIncrementerFactory.java 1311 2006-06-23 09:19:26Z teodord $
035: */
036: public class JRComparableIncrementerFactory extends
037: JRAbstractExtendedIncrementerFactory {
038:
039: /**
040: *
041: */
042: private static JRComparableIncrementerFactory mainInstance = new JRComparableIncrementerFactory();
043:
044: /**
045: *
046: */
047: private JRComparableIncrementerFactory() {
048: }
049:
050: /**
051: *
052: */
053: public static JRComparableIncrementerFactory 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_LOWEST: {
065: incrementer = JRComparableLowestIncrementer.getInstance();
066: break;
067: }
068: case JRVariable.CALCULATION_HIGHEST: {
069: incrementer = JRComparableHighestIncrementer.getInstance();
070: break;
071: }
072: case JRVariable.CALCULATION_SYSTEM:
073: case JRVariable.CALCULATION_NOTHING:
074: case JRVariable.CALCULATION_COUNT:
075: case JRVariable.CALCULATION_SUM:
076: case JRVariable.CALCULATION_AVERAGE:
077: case JRVariable.CALCULATION_STANDARD_DEVIATION:
078: case JRVariable.CALCULATION_VARIANCE:
079: case JRVariable.CALCULATION_FIRST:
080: case JRVariable.CALCULATION_DISTINCT_COUNT:
081: default: {
082: incrementer = JRDefaultIncrementerFactory.getInstance()
083: .getExtendedIncrementer(calculation);
084: break;
085: }
086: }
087:
088: return incrementer;
089: }
090: }
091:
092: /**
093: *
094: */
095: class JRComparableLowestIncrementer extends
096: JRAbstractExtendedIncrementer {
097: /**
098: *
099: */
100: private static JRComparableLowestIncrementer mainInstance = new JRComparableLowestIncrementer();
101:
102: /**
103: *
104: */
105: private JRComparableLowestIncrementer() {
106: }
107:
108: /**
109: *
110: */
111: public static JRComparableLowestIncrementer getInstance() {
112: return mainInstance;
113: }
114:
115: /**
116: *
117: */
118: public Object increment(JRCalculable variable,
119: Object expressionValue, AbstractValueProvider valueProvider) {
120: Comparable value = (Comparable) variable.getIncrementedValue();
121: Comparable newValue = (Comparable) expressionValue;
122:
123: if (value != null && !variable.isInitialized()
124: && (newValue == null || value.compareTo(newValue) < 0)) {
125: newValue = value;
126: }
127:
128: return newValue;
129: }
130:
131: public Object initialValue() {
132: return null;
133: }
134: }
135:
136: /**
137: *
138: */
139: class JRComparableHighestIncrementer extends
140: JRAbstractExtendedIncrementer {
141: /**
142: *
143: */
144: private static JRComparableHighestIncrementer mainInstance = new JRComparableHighestIncrementer();
145:
146: /**
147: *
148: */
149: private JRComparableHighestIncrementer() {
150: }
151:
152: /**
153: *
154: */
155: public static JRComparableHighestIncrementer getInstance() {
156: return mainInstance;
157: }
158:
159: /**
160: *
161: */
162: public Object increment(JRCalculable variable,
163: Object expressionValue, AbstractValueProvider valueProvider) {
164: Comparable value = (Comparable) variable.getIncrementedValue();
165: Comparable newValue = (Comparable) expressionValue;
166:
167: if (value != null && !variable.isInitialized()
168: && (newValue == null || value.compareTo(newValue) > 0)) {
169: newValue = value;
170: }
171:
172: return newValue;
173: }
174:
175: public Object initialValue() {
176: return null;
177: }
178: }
|