KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sf > jasperreports > engine > fill > JREvaluationTime


1 /*
2  * ============================================================================
3  * GNU Lesser General Public License
4  * ============================================================================
5  *
6  * JasperReports - Free Java report-generating library.
7  * Copyright (C) 2001-2006 JasperSoft Corporation http://www.jaspersoft.com
8  *
9  * This library is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public
11  * License as published by the Free Software Foundation; either
12  * version 2.1 of the License, or (at your option) any later version.
13  *
14  * This library is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  * Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with this library; if not, write to the Free Software
21  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
22  *
23  * JasperSoft Corporation
24  * 303 Second Street, Suite 450 North
25  * San Francisco, CA 94107
26  * http://www.jaspersoft.com
27  */

28 package net.sf.jasperreports.engine.fill;
29
30 import java.io.Serializable JavaDoc;
31
32 import net.sf.jasperreports.engine.JRExpression;
33 import net.sf.jasperreports.engine.JRGroup;
34
35
36 /**
37  * An evaluation time during the report fill process.
38  *
39  * @author Lucian Chirita (lucianc@users.sourceforge.net)
40  * @version $Id: JREvaluationTime.java 1229 2006-04-19 13:27:35 +0300 (Wed, 19 Apr 2006) teodord $
41  */

42 public class JREvaluationTime implements Serializable JavaDoc
43 {
44     /**
45      * Evaluation time corresponding to {@link JRExpression#EVALUATION_TIME_REPORT JRExpression.EVALUATION_TIME_REPORT}.
46      */

47     public static final JREvaluationTime EVALUATION_TIME_REPORT = new JREvaluationTime(JRExpression.EVALUATION_TIME_REPORT, null, null);
48     /**
49      * Evaluation time corresponding to {@link JRExpression#EVALUATION_TIME_PAGE JRExpression.EVALUATION_TIME_PAGE}.
50      */

51     public static final JREvaluationTime EVALUATION_TIME_PAGE = new JREvaluationTime(JRExpression.EVALUATION_TIME_PAGE, null, null);
52     /**
53      * Evaluation time corresponding to {@link JRExpression#EVALUATION_TIME_COLUMN JRExpression.EVALUATION_TIME_COLUMN}.
54      */

55     public static final JREvaluationTime EVALUATION_TIME_COLUMN = new JREvaluationTime(JRExpression.EVALUATION_TIME_COLUMN, null, null);
56     /**
57      * Evaluation time corresponding to {@link JRExpression#EVALUATION_TIME_NOW JRExpression.EVALUATION_TIME_NOW}.
58      */

59     public static final JREvaluationTime EVALUATION_TIME_NOW = new JREvaluationTime(JRExpression.EVALUATION_TIME_NOW, null, null);
60     
61     
62     /**
63      * Returns the evaluation time corresponding to
64      * {@link JRExpression#EVALUATION_TIME_GROUP JRExpression.EVALUATION_TIME_GROUP} for a specific group.
65      *
66      * @param groupName the group name
67      * @return corresponding group evaluation time
68      */

69     public static JREvaluationTime getGroupEvaluationTime(String JavaDoc groupName)
70     {
71         return new JREvaluationTime(JRExpression.EVALUATION_TIME_GROUP, groupName, null);
72     }
73     
74     /**
75      * Returns the evaluation time corresponding to
76      * {@link JRExpression#EVALUATION_TIME_BAND JRExpression.EVALUATION_TIME_BAND} for a specific band.
77      *
78      * @param band the band
79      * @return corresponding band evaluation time
80      */

81     public static JREvaluationTime getBandEvaluationTime(JRFillBand band)
82     {
83         return new JREvaluationTime(JRExpression.EVALUATION_TIME_BAND, null, band);
84     }
85     
86     
87     /**
88      * Returns the evaluation time corresponding to an evaluation time type.
89      *
90      * @param type the evaluation time type
91      * @param group the group used for {@link JRExpression#EVALUATION_TIME_GROUP JRExpression.EVALUATION_TIME_GROUP}
92      * evaluation time type
93      * @param band the band used for {@link JRExpression#EVALUATION_TIME_BAND JRExpression.EVALUATION_TIME_BAND}
94      * evaluation time type
95      * @return the evaluation time corresponding to an evaluation time type
96      */

97     public static JREvaluationTime getEvaluationTime(byte type, JRGroup group, JRFillBand band)
98     {
99         JREvaluationTime evaluationTime;
100         
101         switch (type)
102         {
103             case JRExpression.EVALUATION_TIME_REPORT:
104                 evaluationTime = EVALUATION_TIME_REPORT;
105                 break;
106             case JRExpression.EVALUATION_TIME_PAGE:
107                 evaluationTime = EVALUATION_TIME_PAGE;
108                 break;
109             case JRExpression.EVALUATION_TIME_COLUMN:
110                 evaluationTime = EVALUATION_TIME_COLUMN;
111                 break;
112             case JRExpression.EVALUATION_TIME_GROUP:
113                 evaluationTime = getGroupEvaluationTime(group.getName());
114                 break;
115             case JRExpression.EVALUATION_TIME_BAND:
116                 evaluationTime = getBandEvaluationTime(band);
117                 break;
118             default:
119                 evaluationTime = null;
120                 break;
121         }
122         
123         return evaluationTime;
124     }
125     
126     private final byte type;
127     private final String JavaDoc groupName;
128     private final int bandId;
129     private final int hash;
130     
131     
132     private JREvaluationTime(byte type, String JavaDoc groupName, JRFillBand band)
133     {
134         this.type = type;
135         this.groupName = groupName;
136         this.bandId = band == null ? 0 : band.getId();
137         
138         this.hash = computeHash();
139     }
140
141
142     private int computeHash()
143     {
144         int hashCode = type;
145         hashCode = 31*hashCode + (groupName == null ? 0 : groupName.hashCode());
146         hashCode = 31*hashCode + bandId;
147         return hashCode;
148     }
149
150
151     public boolean equals(Object JavaDoc obj)
152     {
153         if (obj == this)
154         {
155             return true;
156         }
157         
158         JREvaluationTime e = (JREvaluationTime) obj;
159         
160         boolean eq = e.type == type;
161         
162         if (eq)
163         {
164             switch (type)
165             {
166                 case JRExpression.EVALUATION_TIME_GROUP:
167                     eq = groupName.equals(e.groupName);
168                     break;
169                 case JRExpression.EVALUATION_TIME_BAND:
170                     eq = bandId == e.bandId;
171                     break;
172             }
173         }
174         
175         return eq;
176     }
177
178
179     public int hashCode()
180     {
181         return hash;
182     }
183 }
184
Popular Tags