01: /*
02: * <copyright>
03: *
04: * Copyright 1997-2004 BBNT Solutions, LLC
05: * under sponsorship of the Defense Advanced Research Projects
06: * Agency (DARPA).
07: *
08: * You can redistribute this software and/or modify it under the
09: * terms of the Cougaar Open Source License as published on the
10: * Cougaar Open Source Website (www.cougaar.org).
11: *
12: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
13: * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
14: * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
15: * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
16: * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
17: * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
18: * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
19: * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
20: * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
21: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
22: * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23: *
24: * </copyright>
25: */
26:
27: package org.cougaar.util;
28:
29: import java.io.Serializable;
30:
31: /** Collection of utility methods for manipulation and
32: * construction of TimeSpan objects.
33: **/
34: public abstract class TimeSpans {
35: /** make uninstantiable **/
36: private TimeSpans() {
37: }
38:
39: /** construct a TimeSpan at a specific point for minimum duration **/
40: public static TimeSpan getPoint(long t) {
41: return new TimeSpan.Point(t);
42: }
43:
44: /** construct a TimeSpan object using the specified times.
45: * The resulting span is closed at the beginning and open at the end, e.g.
46: * t0 is in the span and t1 is not. This is the preferred method as
47: * it allows for cleaner temporal arithmetic.
48: **/
49: public static TimeSpan getSpan(long t0, long t1) {
50: return new TimeSpan.Span(t0, t1);
51: }
52:
53: /** construct the smalled TimeSpan which includes
54: * both time points. This span will be one millisecond longer
55: * than what #getSpan(long, long) would have returned.
56: **/
57: public static TimeSpan getClosedSpan(long t0, long t1) {
58: return new TimeSpan.Span(t0, t1 + TimeSpan.EPSILON);
59: }
60:
61: /** construct a TimeSpan which begins at the dawn of time and ends just before the
62: * specified time (the specified time is <b>not</b> in the span)..
63: **/
64: public static TimeSpan getBeforeSpan(long t) {
65: return new TimeSpan.Span(TimeSpan.MIN_VALUE, t);
66: }
67:
68: /** construct a TimeSpan which begins at the dawn of time and ends at the
69: * specified time (the specified time <b>is</b> in the span).
70: **/
71: public static TimeSpan getEndsAtSpan(long t) {
72: return new TimeSpan.Span(TimeSpan.MIN_VALUE, t
73: + TimeSpan.EPSILON);
74: }
75:
76: /** construct a TimeSpan which starts after the specified time and lasts
77: * until the heat death of the universe (the specified time is <b>not</b> in the span).
78: **/
79: public static TimeSpan getAfterSpan(long t) {
80: return new TimeSpan.Span(t + TimeSpan.EPSILON,
81: TimeSpan.MAX_VALUE);
82: }
83:
84: /** construct a TimeSpan which starts after the specified time and lasts
85: * until the heat death of the universe (the specified time <b>is</b> in the span).
86: **/
87: public static TimeSpan getStartsAtSpan(long t) {
88: return new TimeSpan.Span(t, TimeSpan.MAX_VALUE);
89: }
90:
91: /** return a TimeSpan which starts at the big bang and ends at the heat death
92: * of the universe.
93: **/
94: public static TimeSpan getForever() {
95: return TimeSpan.FOREVER;
96: }
97:
98: }
|