001    /*
002     * This file is part of the Echo Point Project.  This project is a
003     * collection of Components that have extended the Echo Web Application
004     * Framework Version 3.
005     *
006     * Version: MPL 1.1
007     *
008     * The contents of this file are subject to the Mozilla Public License Version
009     * 1.1 (the "License"); you may not use this file except in compliance with
010     * the License. You may obtain a copy of the License at
011     * http://www.mozilla.org/MPL/
012     *
013     * Software distributed under the License is distributed on an "AS IS" basis,
014     * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
015     * for the specific language governing rights and limitations under the
016     * License.
017     */
018    
019    package echopoint.model;
020    
021    import com.thoughtworks.xstream.annotations.XStreamAlias;
022    
023    import java.io.Serializable;
024    
025    /**
026     * The model object for use in the {@link echopoint.TagCloud} component.
027     *
028     * @author Rakesh 2008-07-20
029     * @version $Id: Tag.java 120 2009-02-20 15:43:33Z sptrakesh $
030     */
031    @XStreamAlias( "tag" )
032    public class Tag implements Serializable
033    {
034      private static final long serialVersionUID = 1l;
035    
036      /** The name/title for the tag. */
037      private String name;
038    
039      /** The number of occurances of the name represented in this tag. */
040      private int count;
041    
042      /** Default constructor. */
043      public Tag() {}
044    
045      /**
046       * Create a new tag with the specified values.
047       *
048       * @param name The {@link #name} to use.
049       * @param count The {@link #count} to use.
050       */
051      public Tag( final String name, final int count )
052      {
053        this.name = name;
054        this.count = count;
055      }
056    
057      /**
058       * Compares the specified object with this instance for equality.
059       *
060       * @param object The object to be compared.
061       * @return Returns <code>true</code> if the specified object is of the
062       *   same type and has the same values.
063       */
064      @Override
065      public boolean equals( final Object object )
066      {
067        if ( this == object ) return true;
068        if ( object == null ) return false;
069    
070        boolean result = false;
071        if ( object instanceof Tag )
072        {
073          final Tag tag = (Tag) object;
074          result = ( this.name ==  tag.name ) || ( ( this.name != null ) &&
075              this.name.equals( tag.name ) );
076        }
077    
078        return result;
079      }
080    
081      /**
082       * Calculates a hash code for this object using the class fields.
083       *
084       * @return The hash code for this instance.
085       */
086      @Override
087      public int hashCode()
088      {
089        int result = 31 * 7;
090        result += ( name != null ? name.hashCode() : 0 );
091        return result;
092      }
093    
094      /**
095       * Accessor for property 'name'.
096       *
097       * @return Value for property 'name'.
098       */
099      public String getName()
100      {
101        return name;
102      }
103    
104      /**
105       * Mutator for property 'name'.
106       *
107       * @param name Value to set for property 'name'.
108       */
109      public void setName( final String name )
110      {
111        this.name = name;
112      }
113    
114      /**
115       * Accessor for property 'count'.
116       *
117       * @return Value for property 'count'.
118       */
119      public int getCount()
120      {
121        return count;
122      }
123    
124      /**
125       * Mutator for property 'count'.
126       *
127       * @param count Value to set for property 'count'.
128       */
129      public void setCount( final int count )
130      {
131        this.count = count;
132      }
133    }