001: package org.drools.rule;
002:
003: /*
004: * Copyright 2005 JBoss Inc
005: *
006: * Licensed under the Apache License, Version 2.0 (the "License");
007: * you may not use this file except in compliance with the License.
008: * You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing, software
013: * distributed under the License is distributed on an "AS IS" BASIS,
014: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015: * See the License for the specific language governing permissions and
016: * limitations under the License.
017: */
018:
019: import org.drools.spi.Duration;
020: import org.drools.spi.Tuple;
021:
022: /**
023: * A fixed truthness duration.
024: *
025: * @see Rule#setDuration
026: * @see Rule#getDuration
027: *
028: * @author <a href="mailto:bob@werken.com">bob mcwhirter </a>
029: *
030: * @version $Id: FixedDuration.java,v 1.2 2005/08/14 22:34:41 mproctor Exp $
031: */
032: public class FixedDuration implements Duration {
033: // ------------------------------------------------------------
034: // Instance members
035: // ------------------------------------------------------------
036:
037: /**
038: *
039: */
040: private static final long serialVersionUID = 400L;
041: /** Duration, in seconds. */
042: private long duration;
043:
044: // ------------------------------------------------------------
045: // Constructors
046: // ------------------------------------------------------------
047:
048: /**
049: * Construct.
050: */
051: public FixedDuration() {
052: this .duration = 0;
053: }
054:
055: /**
056: * Construct.
057: *
058: * @param seconds
059: * Number of seconds.
060: */
061: public FixedDuration(final long ms) {
062: this .duration = ms;
063: }
064:
065: // ------------------------------------------------------------
066: // Instance methods
067: // ------------------------------------------------------------
068:
069: /**
070: * Add seconds.
071: *
072: * @param seconds
073: * Number of seconds.
074: */
075: public void addSeconds(final long seconds) {
076: this .duration += (seconds * 1000);
077: }
078:
079: /**
080: * Add minutes.
081: *
082: * @param minutes
083: * Number of minutes.
084: */
085: public void addMinutes(final long minutes) {
086: this .duration += ((minutes * 60) * 1000);
087: }
088:
089: /**
090: * Add hours.
091: *
092: * @param hours
093: * Number of hours.
094: */
095: public void addHours(final long hours) {
096: this .duration += ((hours * 60 * 60) * 1000);
097: }
098:
099: /**
100: * Add days.
101: *
102: * @param days
103: * Number of days.
104: */
105: public void addDays(final long days) {
106: this .duration += ((days * 60 * 60 * 24) * 1000);
107: }
108:
109: /**
110: * Add weeks.
111: *
112: * @param weeks
113: * Number of weeks.
114: */
115: public void addWeeks(final long weeks) {
116: this .duration += ((weeks * 60 * 60 * 24 * 7) * 1000);
117: }
118:
119: // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
120:
121: /**
122: * @see Duration
123: */
124: public long getDuration(final Tuple tuple) {
125: return this.duration;
126: }
127: }
|