01: /**
02: * ===========================================
03: * JFreeReport : a free Java reporting library
04: * ===========================================
05: *
06: * Project Info: http://reporting.pentaho.org/
07: *
08: * (C) Copyright 2001-2007, by Object Refinery Ltd, Pentaho Corporation and Contributors.
09: *
10: * This library is free software; you can redistribute it and/or modify it under the terms
11: * of the GNU Lesser General Public License as published by the Free Software Foundation;
12: * either 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, but WITHOUT ANY WARRANTY;
15: * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16: * See the GNU Lesser General Public License for more details.
17: *
18: * You should have received a copy of the GNU Lesser General Public License along with this
19: * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
20: * Boston, MA 02111-1307, USA.
21: *
22: * [Java is a trademark or registered trademark of Sun Microsystems, Inc.
23: * in the United States and other countries.]
24: *
25: * ------------
26: * ColumnMinimumExpression.java
27: * ------------
28: * (C) Copyright 2001-2007, by Object Refinery Ltd, Pentaho Corporation and Contributors.
29: */package org.jfree.report.function;
30:
31: /**
32: * Computes the minimum of all data-row columns defined in the field-list. This computes the horizontal
33: * minimum, to compute the minimum value in a group, use the ItemMinFunction instead.
34: *
35: * @author Thomas Morgner
36: */
37: public class ColumnMinimumExpression extends
38: ColumnAggregationExpression {
39: /**
40: * Default Constructor.
41: */
42: public ColumnMinimumExpression() {
43: }
44:
45: /**
46: * Returns the minimum value. Non-comparable values are ignored.
47: *
48: * @return the minimum value computed by the function.
49: */
50: public Object getValue() {
51: final Object[] values = getFieldValues();
52: Comparable computedResult = null;
53: for (int i = 0; i < values.length; i++) {
54: final Object value = values[i];
55: if (value instanceof Comparable == false) {
56: continue;
57: }
58:
59: final Comparable n = (Comparable) value;
60: if (computedResult == null) {
61: computedResult = n;
62: } else if (computedResult.compareTo(n) < 0) {
63: computedResult = n;
64: }
65: }
66: return computedResult;
67: }
68: }
|