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 java.io.Serializable;
031: import java.util.HashMap;
032: import java.util.HashSet;
033: import java.util.Map;
034: import java.util.Set;
035:
036: import net.sf.jasperreports.engine.JRConstants;
037:
038: /**
039: * Recorded values container used by elements with
040: * {@link net.sf.jasperreports.engine.JRExpression#EVALUATION_TIME_AUTO Auto evaluation time}.
041: *
042: * @author Lucian Chirita (lucianc@users.sourceforge.net)
043: * @version $Id: JRRecordedValues.java 1677 2007-03-29 11:44:30Z teodord $
044: */
045: public class JRRecordedValues implements Serializable {
046: /**
047: *
048: */
049: private static final long serialVersionUID = JRConstants.SERIAL_VERSION_UID;
050:
051: private Set evaluationTimes;
052: private Map recordedVariableValues;
053: private Map recordedFieldValues;
054:
055: /**
056: * Creates a recorded values set.
057: *
058: * @param evaluationTimes future times when the values will be recorded
059: */
060: public JRRecordedValues(Set evaluationTimes) {
061: this .evaluationTimes = new HashSet(evaluationTimes);
062: }
063:
064: /**
065: * Marks an evaluation time as done.
066: *
067: * @param evaluationTime the evaluation time
068: */
069: public void doneEvaluation(JREvaluationTime evaluationTime) {
070: evaluationTimes.remove(evaluationTime);
071: }
072:
073: /**
074: * Decides whether this is the last evaluation time.
075: *
076: * @return whether this is the last evaluation time
077: */
078: public boolean lastEvaluationTime() {
079: return evaluationTimes.size() == 1;
080: }
081:
082: /**
083: * Decides whether all required evaluations are done.
084: *
085: * @return whether all required evaluations are done
086: */
087: public boolean finishedEvaluations() {
088: return evaluationTimes.isEmpty();
089: }
090:
091: /**
092: * Records a variable value.
093: *
094: * @param variableName the variable name
095: * @param value the variable value to record
096: */
097: public void recordVariableValue(String variableName, Object value) {
098: if (recordedVariableValues == null) {
099: recordedVariableValues = new HashMap();
100: }
101: recordedVariableValues.put(variableName, value);
102: }
103:
104: /**
105: * Records a field value.
106: *
107: * @param fieldName the field name
108: * @param value the field value to record
109: */
110: public void recordFieldValue(String fieldName, Object value) {
111: if (recordedFieldValues == null) {
112: recordedFieldValues = new HashMap();
113: }
114: recordedFieldValues.put(fieldName, value);
115: }
116:
117: /**
118: * Returns the recorded variable values indexed by variable name.
119: *
120: * @return the recorded variable values
121: */
122: public Map getRecordedVariableValues() {
123: return recordedVariableValues;
124: }
125:
126: /**
127: * Returns the recorded field values indexed by field name.
128: *
129: * @return the recorded field values
130: */
131: public Map getRecordedFieldValues() {
132: return recordedFieldValues;
133: }
134: }
|