(no commit message)
[utils] / crawler / kiss / src / org / wamblee / crawler / kiss / TimeInterval.java
1 /*
2  * Copyright 2005 the original author or authors.
3  * 
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
7  * 
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  * 
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.
15  */ 
16
17 package org.wamblee.crawler.kiss;
18
19 /**
20  * 
21  */
22 public class TimeInterval {
23     
24     private Time _begin; 
25     private Time _end; 
26     
27     public TimeInterval(Time aBegin, Time aEnd) { 
28         _begin = aBegin; 
29         _end = aEnd; 
30     }
31     
32     public Time getBegin() { 
33         return _begin; 
34     }
35     
36     public Time getEnd() { 
37         return _end; 
38     }
39
40     /* (non-Javadoc)
41      * @see java.lang.Object#toString()
42      */
43     @Override
44     public String toString() {
45         return _begin + " - " + _end; 
46     }
47     
48     /**
49      * Determines if there is an overlap between the current interval and given one.
50      * 
51      * @param aInterval Interval to compare with. 
52      * @return True iff there is overlap
53      */
54     public boolean overlap(TimeInterval aInterval) { 
55      
56         if ( isUncertain() || aInterval.isUncertain()) {
57             // Optimistic assume there is no overlap if one of the intervals is uncertain. 
58             return false; 
59         }
60         
61         if ( _end.asFloat() <= aInterval._begin.asFloat()  ||
62              aInterval._end.asFloat() <= _begin.asFloat() ) { 
63             return false; 
64         }
65         
66         return true;
67     }
68     
69     /**
70      * Determines if the actual time that the program corresponds to is uncertain due to 
71      * the representation of a period of more than 24 hours using a 24 hour clock. 
72      * @return True iff the interval is uncertain. 
73      */
74     boolean isUncertain() { 
75         return _begin.asFloat() > _end.asFloat(); 
76     }
77 }