001 package org.rakeshv.xml.album;
002
003 import java.util.Map;
004 import java.util.TreeMap;
005
006 /**
007 * A Java bean that represents one photo album entry in the
008 * photo albums XML file.
009 *
010 * <p>© Copyright 2003 Rakesh Vidyadharan</p>
011 *
012 * @author Rakesh Vidyadharan 2003 October 31
013 * @version $Id: Album.java,v 1.2 2004/05/26 11:42:40 rakesh Exp $
014 */
015 public class Album extends Object implements java.io.Serializable
016 {
017 /**
018 * The <code>name</code> attribute for an album.
019 */
020 private String name = null;
021
022 /**
023 * A <code>Map</code> of {@link Photo} java bean instances that
024 * represent all the <code>photo</code> elements in the XML file.
025 */
026 Map photos = null;
027
028 /**
029 * The <code>description</code> element for the album.
030 */
031 private String description = null;
032
033 /**
034 * Default constructor. Just initialise the {@link #photos} map.
035 * This method cannot be directly involved. New instances of this
036 * class should always be created with a proper {@link #name} value.
037 */
038 private Album()
039 {
040 super();
041 photos = new TreeMap();
042 }
043
044 /**
045 * The only public constructor that is supported. Set the value of
046 * the instance variable {@link #name} to the specified value.
047 *
048 * @param name - The name value to use for this album.
049 */
050 public Album( String name )
051 {
052 this();
053 this.name = name;
054 }
055
056 /**
057 * Add the specified {@link Photo} instance to the {@link #photos}
058 * map.
059 */
060 public void addPhoto( Photo photo )
061 {
062 photos.put( photo.getPhotoId(), photo );
063 }
064
065 /**
066 * Indicates whether some other object is "equal to" this one.
067 * Returns <code>true</code> if the specified object is an instance
068 * of {@link Album}, and the values of {@link Album#name} are the
069 * same.
070 *
071 * @param object - The object that is to be compared with
072 * this instance.
073 */
074 public boolean equals( Object object )
075 {
076 if ( this.getClass().equals( object.getClass() ) )
077 {
078 Album that = (Album) object;
079 return ( this.name.equals( that.name ) );
080 }
081
082 return false;
083 }
084
085 /**
086 * Returns a hash code value for the object. Returns the hash code
087 * associated with the {@link #name} instance variable.
088 *
089 * @return int - The hash code value.
090 */
091 public int hashCode()
092 {
093 return name.hashCode();
094 }
095
096 /**
097 * Returns a string representation of the object. Return the value
098 * of {@link #name}.
099 *
100 * @return String - The string represenetation of this instance.
101 */
102 public String toString() { return name; }
103
104 /**
105 * Returns {@link #photos}.
106 *
107 * @return Map - The value/reference of/to photos.
108 */
109 public final Map getPhotos()
110 {
111 return photos;
112 }
113
114 /**
115 * Returns {@link #description}.
116 *
117 * @return String - The value/reference of/to description.
118 */
119 public final String getDescription()
120 {
121 return description;
122 }
123
124 /**
125 * Set {@link #description}.
126 *
127 * @param description - The value to set.
128 */
129 public final void setDescription( String description )
130 {
131 this.description = description;
132 }
133
134 /**
135 * Returns {@link #name}.
136 *
137 * @return String - The value/reference of/to name.
138 */
139 public final String getName()
140 {
141 return name;
142 }
143 }