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 <skipDays> 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 days they can skip. More info <a 032 * href 033 * ="http://cyber.law.harvard.edu/rss/skipHoursDays.html#skipdays">here</a>. 034 * </p> 035 * 036 * <p> 037 * An XML element that contains up to seven <day> sub-elements whose value is 038 * Monday, Tuesday, Wednesday, Thursday, Friday, Saturday or Sunday. Aggregators 039 * may not read the channel during days listed in the <skipDays> element. 040 * </p> 041 * 042 * @author Bill Brown 043 * 044 */ 045public class SkipDays implements Serializable { 046 047 private static final long serialVersionUID = -2480844569809695010L; 048 049 private final List<Day> skipDays; 050 051 SkipDays(List<Day> skipDays) throws RSSpectException { 052 if (skipDays == null || skipDays.size() == 0) { 053 throw new RSSpectException( 054 "skipDays elements should contain at least one <day> sub element."); 055 } 056 this.skipDays = new LinkedList<Day>(); 057 for (Day day : skipDays) { 058 this.skipDays.add(new Day(day)); 059 } 060 } 061 062 SkipDays(SkipDays skipDays) { 063 this.skipDays = skipDays.getSkipDays(); 064 } 065 066 /** 067 * @return the list of days to skip. 068 */ 069 public List<Day> getSkipDays() { 070 List<Day> skipDaysCopy = new LinkedList<Day>(); 071 for (Day day : this.skipDays) { 072 skipDaysCopy.add(new Day(day)); 073 } 074 return skipDaysCopy; 075 } 076 077 /** 078 * @param skipDay 079 * the day of the week. 080 * @return the day object of null if not found. 081 */ 082 public Day getSkipDay(String skipDay) { 083 for (Day day : this.skipDays) { 084 if (day.getDay().equals(skipDay)) { 085 return new Day(day); 086 } 087 } 088 return null; 089 } 090 091 /** 092 * Shows the contents of the <skipDays> element. 093 */ 094 @Override 095 public String toString() { 096 StringBuilder sb = new StringBuilder("<skipDays>"); 097 for (Day day : this.skipDays) { 098 sb.append(day); 099 } 100 sb.append("</skipDays>"); 101 return sb.toString(); 102 } 103 104 @Override 105 public boolean equals(Object obj) { 106 if (obj == this) { 107 return true; 108 } 109 if (!(obj instanceof SkipDays)) { 110 return false; 111 } 112 return this.toString().equals(obj.toString()); 113 } 114 115 @Override public int hashCode() { 116 return toString().hashCode(); 117 } 118}