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;width> 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 * Maximum value for width is 144, default value is 88.
030 * </p>
031 * 
032 * @author Bill Brown
033 * 
034 */
035public class Width implements Serializable {
036
037        /**
038         * 
039         */
040        private static final long serialVersionUID = 8591451698889716382L;
041
042        private final String width;
043
044        Width(String width) throws RSSpectException {
045
046                if (width == null || width.equals("")) {
047                        throw new RSSpectException("width SHOULD NOT be blank.");
048                }
049
050                try {
051                        int localWidth = Integer.parseInt(width);
052                        if (localWidth > 144) {
053                                throw new RSSpectException(
054                                                "width cannot be greater than 144px.");
055                        }
056                } catch (NumberFormatException n) {
057                        throw new RSSpectException("invalid number format for width.");
058                }
059
060                this.width = width;
061        }
062
063        Width(Width width) {
064                this.width = width.width;
065        }
066
067        /**
068         * @return the width.
069         */
070        public String getWidth() {
071                return width;
072        }
073
074        /**
075         * Shows the contents of the &lt;width> element.
076         */
077        @Override
078        public String toString() {
079                return "<width>" + width + "</width>";
080        }
081        
082        @Override
083        public boolean equals(Object obj) {
084                if (obj == this) {
085                        return true;
086                }
087                if (!(obj instanceof Width)) {
088                        return false;
089                }
090                return this.toString().equals(obj.toString());
091        }
092        
093        @Override public int hashCode() {
094                return toString().hashCode();
095        }
096}