/* * 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; /** * Time interval. */ public class TimeInterval { /** * Begin time. */ private Time _begin; /** * End time. */ private Time _end; /** * Construts the interval. * @param aBegin Start time. * @param aEnd End time. */ public TimeInterval(Time aBegin, Time aEnd) { _begin = aBegin; _end = aEnd; } /** * Gets the begin time. * @return Begin time. */ public Time getBegin() { return _begin; } /** * Gets the end time. * @return End time. */ 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(); } /* (non-Javadoc) * @see java.lang.Object#equals(java.lang.Object)j */ @Override public boolean equals(Object obj) { if ( !(obj instanceof TimeInterval)) { return false; } return obj.toString().equals(obj.toString()); } /* (non-Javadoc) * @see java.lang.Object#hashCode() */ @Override public int hashCode() { return _begin.hashCode(); } }