001/** 002 * Copyright 2011 Bill Brown 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package com.colorfulsoftware.rss; 017 018import java.io.Serializable; 019 020/** 021 * <p> 022 * The <hour> element. 023 * </p> 024 * <p> 025 * From the <a href="http://cyber.law.harvard.edu/rss/rss.html">RSS 2.0 026 * specification</a>... 027 * </p> 028 * <p> 029 * This class returns the hour sub element of the <skipHours> element. Valid 030 * values are 0 - 23. 031 * </p> 032 * 033 * @author bill 034 * 035 */ 036public class Hour implements Serializable { 037 038 private static final long serialVersionUID = -6736105071042205154L; 039 040 private final String hour; 041 042 Hour(String hour) throws RSSpectException { 043 044 if (hour == null || hour.equals("")) { 045 throw new RSSpectException("hour SHOULD NOT be blank."); 046 } 047 048 try { 049 int localHour = Integer.parseInt(hour); 050 if (localHour > 23 || localHour < 0) { 051 throw new RSSpectException( 052 "hour elements must be between 0 and 23 inclusive."); 053 } 054 } catch (NumberFormatException n) { 055 throw new RSSpectException("invalid number format for hour."); 056 } 057 058 this.hour = hour; 059 } 060 061 Hour(Hour hour) { 062 this.hour = hour.hour; 063 } 064 065 /** 066 * @return the hour. 067 */ 068 public String getHour() { 069 return hour; 070 } 071 072 /** 073 * Shows the contents of the <hour> element. 074 */ 075 @Override 076 public String toString() { 077 return "<hour>" + hour + "</hour>"; 078 } 079 080 @Override 081 public boolean equals(Object obj) { 082 if (obj == this) { 083 return true; 084 } 085 if (!(obj instanceof Hour)) { 086 return false; 087 } 088 return this.toString().equals(obj.toString()); 089 } 090 091 @Override public int hashCode() { 092 return toString().hashCode(); 093 } 094}