001: /**
002: * ========================================
003: * JFreeReport : a free Java report library
004: * ========================================
005: *
006: * Project Info: http://reporting.pentaho.org/
007: *
008: * (C) Copyright 2000-2007, by Object Refinery Limited, Pentaho Corporation and Contributors.
009: *
010: * This library is free software; you can redistribute it and/or modify it under the terms
011: * of the GNU Lesser General Public License as published by the Free Software Foundation;
012: * either 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, but WITHOUT ANY WARRANTY;
015: * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
016: * See the GNU Lesser General Public License for more details.
017: *
018: * You should have received a copy of the GNU Lesser General Public License along with this
019: * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
020: * Boston, MA 02111-1307, USA.
021: *
022: * [Java is a trademark or registered trademark of Sun Microsystems, Inc.
023: * in the United States and other countries.]
024: *
025: * ------------
026: * $Id: GroupByExpression.java 3525 2007-10-16 11:43:48Z tmorgner $
027: * ------------
028: * (C) Copyright 2000-2005, by Object Refinery Limited.
029: * (C) Copyright 2005-2007, by Pentaho Corporation.
030: */package org.jfree.report.expressions.sys;
031:
032: import java.util.ArrayList;
033: import java.util.Arrays;
034:
035: import org.jfree.report.DataFlags;
036: import org.jfree.report.DataRow;
037: import org.jfree.report.DataSourceException;
038: import org.jfree.report.expressions.AbstractExpression;
039:
040: /**
041: * Creation-Date: 08.10.2006, 16:28:37
042: *
043: * @author Thomas Morgner
044: */
045: public class GroupByExpression extends AbstractExpression {
046: private ArrayList fields;
047: private transient String[] fieldsCached;
048:
049: public GroupByExpression() {
050: this .fields = new ArrayList();
051: }
052:
053: /**
054: * Return the current expression value. <P> The value depends (obviously) on
055: * the expression implementation.
056: *
057: * @return the value of the function.
058: */
059: public Object computeValue() throws DataSourceException {
060: final DataRow dr = getDataRow();
061: final String[] columns = getField();
062: for (int i = 0; i < columns.length; i++) {
063: final String column = columns[i];
064: final DataFlags df = dr.getFlags(column);
065: if (df == null) {
066: // invalid column or invalid implementation ...
067: continue;
068: }
069: if (df.isChanged()) {
070: //Log.debug ("Field: " + df.getName() + " has changed to " + df.getValue());
071: return Boolean.TRUE;
072: }
073: }
074: return Boolean.FALSE;
075: }
076:
077: public void setField(final int index, final String field) {
078: if (fields.size() == index) {
079: fields.add(field);
080: } else {
081: fields.set(index, field);
082: }
083: fieldsCached = null;
084: }
085:
086: public String getField(final int index) {
087: return (String) fields.get(index);
088: }
089:
090: public int getFieldCount() {
091: return fields.size();
092: }
093:
094: public String[] getField() {
095: if (fieldsCached == null) {
096: fieldsCached = (String[]) fields.toArray(new String[fields
097: .size()]);
098: }
099: return (String[]) fieldsCached.clone();
100: }
101:
102: public void setField(final String[] fields) {
103: this .fields.clear();
104: this .fields.addAll(Arrays.asList(fields));
105: this .fieldsCached = (String[]) fields.clone();
106: }
107:
108: public Object clone() throws CloneNotSupportedException {
109: final GroupByExpression co = (GroupByExpression) super .clone();
110: co.fields = (ArrayList) fields.clone();
111: co.fieldsCached = fieldsCached;
112: return co;
113: }
114: }
|