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 &lt;ttl> 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 * ttl stands for time to live. It's a number of minutes that indicates how long
030 * a channel can be cached before refreshing from the source. More info <a href=
031 * "http://cyber.law.harvard.edu/rss/rss.html#ltttlgtSubelementOfLtchannelgt"
032 * >here</a>.
033 * </p>
034 * 
035 * <p>
036 * &lt;ttl> is an optional sub-element of &lt;channel>.
037 * </p>
038 * 
039 * <p>
040 * ttl stands for time to live. It's a number of minutes that indicates how long
041 * a channel can be cached before refreshing from the source. This makes it
042 * possible for RSS sources to be managed by a file-sharing network such as
043 * Gnutella.
044 * </p>
045 * 
046 * <p>
047 * Example: <ttl>60</ttl>
048 * </p>
049 * 
050 * @author Bill Brown
051 * 
052 */
053public class TTL implements Serializable {
054
055        private static final long serialVersionUID = -6668886988682614060L;
056
057        private final String ttl;
058
059        TTL(String ttl) throws RSSpectException {
060                if (ttl == null || ttl.equals("")) {
061                        throw new RSSpectException("ttl SHOULD NOT be blank.");
062                }
063                this.ttl = ttl;
064        }
065
066        TTL(TTL ttl) {
067                this.ttl = ttl.ttl;
068        }
069
070        /**
071         * @return the time to live.
072         */
073        public String getTtl() {
074                return ttl;
075        }
076
077        /**
078         * Shows the contents of the &lt;ttl> element.
079         */
080        @Override
081        public String toString() {
082                return "<ttl>" + ttl + "</ttl>";
083        }
084        
085        @Override
086        public boolean equals(Object obj) {
087                if (obj == this) {
088                        return true;
089                }
090                if (!(obj instanceof TTL)) {
091                        return false;
092                }
093                return this.toString().equals(obj.toString());
094        }
095        
096        @Override public int hashCode() {
097                return toString().hashCode();
098        }
099}