01: /*
02: * Copyright 2006-2007 Pentaho Corporation. All rights reserved.
03: * This software was developed by Pentaho Corporation and is provided under the terms
04: * of the Mozilla Public License, Version 1.1, or any later version. You may not use
05: * this file except in compliance with the license. If you need a copy of the license,
06: * please go to http://www.mozilla.org/MPL/MPL-1.1.txt.
07: *
08: * Software distributed under the Mozilla Public License is distributed on an "AS IS"
09: * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. Please refer to
10: * the license for the specific language governing your rights and limitations.
11: *
12: * Additional Contributor(s): Martin Schmid gridvision engineering GmbH
13: */
14: package org.pentaho.jfreereport.legacy;
15:
16: import org.jetbrains.annotations.NotNull;
17: import org.jetbrains.annotations.Nullable;
18: import org.jfree.report.event.ReportEvent;
19: import org.jfree.report.function.AbstractFunction;
20: import org.jfree.report.function.Expression;
21:
22: @Deprecated
23: public class TimeDiffFormatFunction extends AbstractFunction {
24: @Nullable
25: private String field;
26: @Nullable
27: private String formatted;
28:
29: public TimeDiffFormatFunction() {
30: }
31:
32: public TimeDiffFormatFunction(@NotNull
33: final String name) {
34: this ();
35: setName(name);
36: }
37:
38: @Nullable
39: public String getField() {
40: return field;
41: }
42:
43: public void setField(@Nullable
44: String field) {
45: this .field = field;
46: }
47:
48: public void itemsAdvanced(@NotNull
49: final ReportEvent event) {
50: formatted = null;
51:
52: final Object fieldValue1 = getDataRow().get(getField());
53: if (!(fieldValue1 instanceof Number)) {
54: return;
55: }
56: long value1 = ((Number) fieldValue1).longValue();
57: format(value1);
58: }
59:
60: private void format(long value1) {
61: long hours = value1 / (60 * 60 * 1000);
62: long rest = value1 - (hours * 60 * 60 * 1000);
63: long minutes = rest / (60 * 1000);
64: rest -= minutes * 60 * 1000;
65: long seconds = rest / 1000;
66:
67: String min = String.valueOf(minutes);
68: String sec = String.valueOf(seconds);
69: if (min.length() < 2) {
70: min = "0" + min;
71: }
72: if (sec.length() < 2) {
73: sec = "0" + sec;
74: }
75: formatted = hours + ":" + min + ":" + sec;
76: }
77:
78: @Nullable
79: public Object getValue() {
80: return formatted;
81: }
82:
83: @NotNull
84: public Expression getInstance() {
85: return super.getInstance();
86: }
87:
88: }
|