/* * Copyright 2005 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.wamblee.crawler.kiss; /** * */ public class TimeInterval { private Time _begin; private Time _end; public TimeInterval(Time aBegin, Time aEnd) { _begin = aBegin; _end = aEnd; } public Time getBegin() { return _begin; } public Time getEnd() { return _end; } /* (non-Javadoc) * @see java.lang.Object#toString() */ @Override public String toString() { return _begin + " - " + _end; } /** * Determines if there is an overlap between the current interval and given one. * * @param aInterval Interval to compare with. * @return True iff there is overlap */ public boolean overlap(TimeInterval aInterval) { if ( isUncertain() || aInterval.isUncertain()) { // Optimistic assume there is no overlap if one of the intervals is uncertain. return false; } if ( _end.asFloat() <= aInterval._begin.asFloat() || aInterval._end.asFloat() <= _begin.asFloat() ) { return false; } return true; } /** * Determines if the actual time that the program corresponds to is uncertain due to * the representation of a period of more than 24 hours using a 24 hour clock. * @return True iff the interval is uncertain. */ boolean isUncertain() { return _begin.asFloat() > _end.asFloat(); } }