2 * Copyright 2005 the original author or authors.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package org.wamblee.crawler.kiss;
22 public class TimeInterval {
35 * Construts the interval.
36 * @param aBegin Start time.
37 * @param aEnd End time.
39 public TimeInterval(Time aBegin, Time aEnd) {
45 * Gets the begin time.
48 public Time getBegin() {
56 public Time getEnd() {
63 * @see java.lang.Object#toString()
66 public String toString() {
67 return _begin + " - " + _end;
71 * Determines if there is an overlap between the current interval and given
75 * Interval to compare with.
76 * @return True iff there is overlap
78 public boolean overlap(TimeInterval aInterval) {
80 if (isUncertain() || aInterval.isUncertain()) {
81 // Optimistic assume there is no overlap if one of the intervals is
86 if (_end.asFloat() <= aInterval._begin.asFloat()
87 || aInterval._end.asFloat() <= _begin.asFloat()) {
95 * Determines if the actual time that the program corresponds to is
96 * uncertain due to the representation of a period of more than 24 hours
97 * using a 24 hour clock.
99 * @return True iff the interval is uncertain.
101 boolean isUncertain() {
102 return _begin.asFloat() > _end.asFloat();
106 * @see java.lang.Object#equals(java.lang.Object)j
109 public boolean equals(Object obj) {
110 if ( !(obj instanceof TimeInterval)) {
113 return obj.toString().equals(obj.toString());
117 * @see java.lang.Object#hashCode()
120 public int hashCode() {
121 return _begin.hashCode();