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 <day> 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 represents the day sub element of the <skipDays> element. 030 * </p> 031 * 032 * @author Bill Brown 033 * 034 */ 035public class Day implements Serializable { 036 037 private static final long serialVersionUID = 1428375851718959215L; 038 039 private final String day; 040 041 Day(String day) throws RSSpectException { 042 if (day == null || day.equals("")) { 043 throw new RSSpectException("day SHOULD NOT be blank."); 044 } 045 this.day = day; 046 if (!this.day.equals("Monday") && !this.day.equals("Tuesday") 047 && !this.day.equals("Wednesday") 048 && !this.day.equals("Thursday") && !this.day.equals("Friday") 049 && !this.day.equals("Saturday") && !this.day.equals("Sunday")) { 050 throw new RSSpectException( 051 "day elements must have a value of Monday, Tuesday, Wednesday, Thursday, Friday, Saturday or Sunday."); 052 } 053 054 } 055 056 Day(Day day) { 057 this.day = day.day; 058 } 059 060 /** 061 * @return the day of week; Monday, Tuesday, Wednesday, Thursday, Friday, 062 * Saturday or Sunday. 063 */ 064 public String getDay() { 065 return day; 066 } 067 068 /** 069 * Shows the contents of the <day> element. 070 */ 071 @Override 072 public String toString() { 073 return "<day>" + day + "</day>"; 074 } 075 076 @Override 077 public boolean equals(Object obj) { 078 if (obj == this) { 079 return true; 080 } 081 if (!(obj instanceof Day)) { 082 return false; 083 } 084 return this.toString().equals(obj.toString()); 085 } 086 087 @Override public int hashCode() { 088 return toString().hashCode(); 089 } 090}