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; 019import java.util.LinkedList; 020import java.util.List; 021 022/** 023 * <p> 024 * The <skipHours> element. 025 * </p> 026 * <p> 027 * From the <a href="http://cyber.law.harvard.edu/rss/rss.html">RSS 2.0 028 * specification</a>... 029 * </p> 030 * <p> 031 * A hint for aggregators telling them which hours they can skip. More info <a 032 * href 033 * ="http://cyber.law.harvard.edu/rss/skipHoursDays.html#skiphours">here</a>. 034 * </p> 035 * 036 * <p> 037 * skipHours 038 * </p> 039 * 040 * <p> 041 * An XML element that contains up to 24 <hour> sub-elements whose value is a 042 * number between 0 and 23, representing a time in GMT, when aggregators, if 043 * they support the feature, may not read the channel on hours listed in the 044 * <skipHours> element. 045 * </p> 046 * 047 * 048 * The hour beginning at midnight is hour zero. 049 * 050 * @author Bill Brown 051 * 052 */ 053public class SkipHours implements Serializable { 054 055 /** 056 * 057 */ 058 private static final long serialVersionUID = -7435503230975016475L; 059 060 private final List<Hour> skipHours; 061 062 SkipHours(List<Hour> skipHours) throws RSSpectException { 063 if (skipHours == null || skipHours.size() == 0) { 064 throw new RSSpectException( 065 "skipHours elements should contain at least one <hour> sub element."); 066 } 067 this.skipHours = new LinkedList<Hour>(); 068 for (Hour hour : skipHours) { 069 this.skipHours.add(new Hour(hour)); 070 } 071 } 072 073 SkipHours(SkipHours skipHours) { 074 this.skipHours = skipHours.getSkipHours(); 075 } 076 077 /** 078 * @return the list of hours to skip. 079 */ 080 public List<Hour> getSkipHours() { 081 List<Hour> skipHoursCopy = new LinkedList<Hour>(); 082 for (Hour hour : this.skipHours) { 083 skipHoursCopy.add(new Hour(hour)); 084 } 085 return skipHoursCopy; 086 } 087 088 /** 089 * @param skipHour 090 * the hour of the day. 091 * @return the hour object of null if not found. 092 */ 093 public Hour getSkipHour(String skipHour) { 094 for (Hour hour : this.skipHours) { 095 if (hour.getHour().equals(skipHour)) { 096 return new Hour(hour); 097 } 098 } 099 return null; 100 } 101 102 /** 103 * Shows the contents of the <skipHours> element. 104 */ 105 @Override 106 public String toString() { 107 StringBuilder sb = new StringBuilder("<skipHours>"); 108 for (Hour hour : this.skipHours) { 109 sb.append(hour); 110 } 111 sb.append("</skipHours>"); 112 return sb.toString(); 113 } 114 115 @Override 116 public boolean equals(Object obj) { 117 if (obj == this) { 118 return true; 119 } 120 if (!(obj instanceof SkipHours)) { 121 return false; 122 } 123 return this.toString().equals(obj.toString()); 124 } 125 126 @Override public int hashCode() { 127 return toString().hashCode(); 128 } 129}