1 /*
2 * JasperReports - Free Java Reporting Library.
3 * Copyright (C) 2001 - 2019 TIBCO Software Inc. All rights reserved.
4 * http://www.jaspersoft.com
5 *
6 * Unless you have purchased a commercial license agreement from Jaspersoft,
7 * the following license terms apply:
8 *
9 * This program is part of JasperReports.
10 *
11 * JasperReports is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License as published by
13 * the Free Software Foundation, either version 3 of the License, or
14 * (at your option) any later version.
15 *
16 * JasperReports is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License for more details.
20 *
21 * You should have received a copy of the GNU Lesser General Public License
22 * along with JasperReports. If not, see <http://www.gnu.org/licenses/>.
23 */
24 package net.sf.jasperreports.engine.type;
25
26
27 /**
28 * @author Sanda Zaharia (shertage@users.sourceforge.net)
29 */
30 public enum CalculationEnum implements JREnum
31 {
32 /**
33 * The value is calculated by simply evaluating the variable expression.
34 */
35 NOTHING((byte)0, "Nothing"),
36
37 /**
38 * The value is calculated by counting the non-null values of the variable expression with every iteration in the data source.
39 * The count variable must be numeric, but the variable expression needs not, since its value is not important.
40 * On the other hand, the initial value expression must be numeric since it will be the count variable initial value.
41 */
42 COUNT((byte)1, "Count"),
43
44 /**
45 * The value is calculated by summing up the values returned by the variable's expression. Both the main expression and initial
46 * expression must have numeric type.
47 *
48 */
49 SUM((byte)2, "Sum"),
50
51 /**
52 * The value is obtained by calculating the average for the series of values obtained by evaluating the variable's
53 * expression for each record in the data source. Both the main expression and initial expression must have numeric type.
54 * <p>
55 * In order to calculate the average, the engine creates behind the scenes a helper report variable that calculates
56 * the sum of the values and uses it to calculate the average for those values. This helper sum variable gets its
57 * name from the corresponding average variable suffixed with "_SUM" sequence. This helper variable can be used
58 * in other report expressions just like any normal variable.
59 */
60 AVERAGE((byte)3, "Average"),
61
62 /**
63 * The value of the variable represents the lowest in the series of values obtained by evaluating the variable's
64 * expression for each data source record.
65 */
66 LOWEST((byte)4, "Lowest"),
67
68 /**
69 * The value of the variable represents the highest in the series of values obtained by evaluating the variable's
70 * expression for each data source record.
71 */
72 HIGHEST((byte)5, "Highest"),
73
74 /**
75 * The value is obtained by calculating the standard deviation for the series of values returned by evaluating the
76 * variable's expression.
77 * <p>
78 * Just like for the variables that calculate the average, the engine creates and uses helper report variables
79 * for first obtaining the sum and the count that correspond to your current series of values. The name for
80 * those helper variables that are created behind the scenes is obtained by suffixing the user variable with
81 * the "_SUM" or "_COUNT" suffix and they can be used in other report expressions like any other report variable.
82 * <p>
83 * For variables that calculate the standard deviation, there is always a helper variable present, that first
84 * calculates the variance for the series of values and it has the "_VARIANCE" suffix added to its name.
85 */
86 STANDARD_DEVIATION((byte)6, "StandardDeviation"),
87
88 /**
89 * The value is obtained by calculating the variance for the series of values returned by evaluating the
90 * variable's expression.
91 */
92 VARIANCE((byte)7, "Variance"),
93
94 /**
95 * The value is not calculated by JasperReports. The user must calculate the value of the variable, almost
96 * certainly using the scriptlets functionality. For this type of calculation, the only thing the engine does is
97 * to conserve the value users have calculated, from one iteration in the data source to the next.
98 */
99 SYSTEM((byte)8, "System"),
100
101 /**
102 * The variable keeps the first value and does not increment it on subsequent iterations.
103 */
104 FIRST((byte)9, "First"),
105
106 /**
107 * The value is calculated by counting the distinct non-null values of the variable expression with every iteration in the data source.
108 * The count variable must be numeric, but the variable expression needs not, since its value is not important.
109 * On the other hand, the initial value expression must be numeric since it will be the count variable initial value.
110 */
111 DISTINCT_COUNT((byte)10, "DistinctCount");
112
113 /**
114 *
115 */
116 private final transient byte value;
117 private final transient String name;
118
119 private CalculationEnum(byte value, String name)
120 {
121 this.value = value;
122 this.name = name;
123 }
124
125 /**
126 * @deprecated Used only by deprecated serialized fields.
127 */
128 @Override
129 public Byte getValueByte()
130 {
131 return value;
132 }
133
134 @Override
135 @SuppressWarnings("deprecation")
136 public final byte getValue()
137 {
138 return value;
139 }
140
141 @Override
142 public String getName()
143 {
144 return name;
145 }
146
147 /**
148 *
149 */
150 public static CalculationEnum getByName(String name)
151 {
152 return EnumUtil.getEnumByName(values(), name);
153 }
154
155 /**
156 * @deprecated Used only by deprecated serialized fields.
157 */
158 public static CalculationEnum getByValue(Byte value)
159 {
160 return (CalculationEnum)EnumUtil.getByValue(values(), value);
161 }
162
163 /**
164 * @deprecated Used only by deprecated serialized fields.
165 */
166 public static CalculationEnum getByValue(byte value)
167 {
168 return getByValue((Byte)value);
169 }
170 }
171