1 /***
2 * PercentFunction.java
3 *
4 * $Author: mballesteros $
5 * $Date: 2003/11/28 19:18:04 $
6 * $Revision: 1.1 $
7 */
8 package net.sf.jec.functions;
9
10 import net.sf.jec.Function;
11
12 /*** Direct and inverse maps between Date/Timestamps to String objects.
13 *
14 * @author mballesteros
15 */
16 public class PercentFunction extends Function {
17
18 /*** Creates a new instance of PercentFunction
19 */
20 public PercentFunction() {
21 }
22
23 /*** Inverse map: the inverse conversion
24 * @param object The source object
25 * @return The result object after applying the inverse map
26 */
27 public Object inverseMap(Object[] objects) {
28 Object object = objects[0];
29 if (object instanceof String) {
30 String number = (String) object;
31 if (number.indexOf("%") > 0)
32 number = number.substring(0, number.length() - 1);
33 Object out = new Double(number.trim());
34 return out;
35 } else {
36 return null;
37 }
38 }
39
40 /*** Direct map: the direct conversion
41 * @param object The source object
42 * @return The result object after applying the map
43 */
44 public Object directMap(Object[] objects) {
45 Object object = objects[0];
46 String out;
47 if (object instanceof Number) {
48 out = object.toString() + " %";
49 } else {
50 out = "unknown(" + object.toString() + ")";
51 }
52 return out;
53 }
54
55 }
This page was automatically generated by Maven