001: /*
002: * Copyright 2006-2007 Pentaho Corporation. All rights reserved.
003: * This software was developed by Pentaho Corporation and is provided under the terms
004: * of the Mozilla Public License, Version 1.1, or any later version. You may not use
005: * this file except in compliance with the license. If you need a copy of the license,
006: * please go to http://www.mozilla.org/MPL/MPL-1.1.txt.
007: *
008: * Software distributed under the Mozilla Public License is distributed on an "AS IS"
009: * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. Please refer to
010: * the license for the specific language governing your rights and limitations.
011: *
012: * Additional Contributor(s): Martin Schmid gridvision engineering GmbH
013: */
014: package org.pentaho.jfreereport.legacy;
015:
016: import org.jetbrains.annotations.NotNull;
017: import org.jetbrains.annotations.Nullable;
018: import org.jfree.report.event.ReportEvent;
019: import org.jfree.report.function.AbstractFunction;
020: import org.jfree.report.function.Expression;
021:
022: import java.util.Date;
023:
024: @Deprecated
025: public class TimeDiffFunction extends AbstractFunction {
026: private long diff;
027: private boolean valid;
028:
029: @Nullable
030: private String field1;
031: @Nullable
032: private String field2;
033:
034: public TimeDiffFunction() {
035: diff = 0;
036: }
037:
038: public TimeDiffFunction(@NotNull
039: final String name) {
040: this ();
041: setName(name);
042: }
043:
044: @Nullable
045: public String getField1() {
046: return field1;
047: }
048:
049: public void setField1(@Nullable
050: String field1) {
051: this .field1 = field1;
052: }
053:
054: @Nullable
055: public String getField2() {
056: return field2;
057: }
058:
059: public void setField2(@Nullable
060: String field2) {
061: this .field2 = field2;
062: }
063:
064: public void itemsAdvanced(@NotNull
065: final ReportEvent event) {
066: valid = false;
067:
068: final Object fieldValue1 = getDataRow().get(getField1());
069: final Object fieldValue2 = getDataRow().get(getField2());
070: long value1;
071: if (fieldValue1 instanceof Number) {
072: Number number = (Number) fieldValue1;
073: value1 = number.longValue();
074: } else if (fieldValue1 instanceof Date) {
075: Date date = (Date) fieldValue1;
076: value1 = date.getTime();
077: } else {
078: return;
079: }
080:
081: long value2;
082: if (fieldValue2 instanceof Number) {
083: Number number = (Number) fieldValue2;
084: value2 = number.longValue();
085: } else if (fieldValue2 instanceof Date) {
086: Date date = (Date) fieldValue2;
087: value2 = date.getTime();
088: } else {
089: return;
090: }
091:
092: diff = value1 - value2;
093: valid = true;
094: }
095:
096: @Nullable
097: public Object getValue() {
098: if (valid) {
099: return new Long(diff);
100: }
101: return null;
102: }
103:
104: @NotNull
105: public Expression getInstance() {
106: return super.getInstance();
107: }
108:
109: }
|