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;
19 import java.text.DecimalFormat;
20 import java.text.NumberFormat;
23 * TIme at which a program starts or ends.
25 public class Time implements Comparable {
28 * Number of seconds per minute.
30 private static final double SECONDS_PER_MINUTE = 60.0;
43 * Constructs the time.
50 public Time(int aHour, int aMinute) {
60 public int getHour() {
69 public int getMinute() {
76 * @see java.lang.Object#toString()
79 public String toString() {
80 NumberFormat format = new DecimalFormat("00");
81 return format.format(_hour) + ":" + format.format(_minute);
85 * Convert time to floating point value. Useful for comparing two times.
87 * @return Converted value.
90 return (float) _hour + (float) _minute / (float) SECONDS_PER_MINUTE;
96 * @see java.lang.Object#equals(java.lang.Object)
99 public boolean equals(Object obj) {
100 if ( !(obj instanceof Time )) {
103 return toString().equals(obj.toString());
107 * @see java.lang.Comparable#compareTo(T)
109 public int compareTo(Object o) {
110 if ( !(o instanceof Time)) {
111 throw new RuntimeException("object not an instance of Time");
114 return new Float(asFloat()).compareTo(new Float(time.asFloat()));
118 * @see java.lang.Object#hashCode()
121 public int hashCode() {
122 return toString().hashCode();