View Javadoc

1   /*
2    PlantUMLEnumElementImpl.java
3    Creation date : 6/12/2011
4    Copyright © Benjamin Croizet (graffity2199@yahoo.fr)
5   
6    This program is free software; you can redistribute it and/or
7    modify it under the terms of the GNU General Public License
8    or GNU Lesser General Public License as published by the
9    Free Software Foundation; either version 3 of the License,
10   or (at your option) any later version.
11  
12   This program is distributed in the hope that it will be useful,
13   but WITHOUT ANY WARRANTY; without even the implied warranty of
14   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15   GNU General Public License for more details.
16  
17   You should have received copies of the GNU General Public License
18   and GNU Lesser General Public License along with this program;
19   if not, write to the Free Software Foundation, Inc.,
20   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
21   http://www.fsf.org/licensing/licenses/gpl.html
22   http://www.gnu.org/licenses/lgpl.html
23   */
24  
25  package net.sourceforge.plantumldependency.cli.plantumldiagram.classes.element.impl;
26  
27  import static net.sourceforge.plantumldependency.cli.plantumldiagram.classes.element.tag.PlantUMLClassesDiagramElementTag.ENUM_TAG;
28  import static net.sourceforge.plantumldependency.common.constants.CommonConstants.BLANK_STRING;
29  import net.sourceforge.plantumldependency.cli.plantumldiagram.classes.element.AbstractPlantUMLClassesDiagramElement;
30  import net.sourceforge.plantumldependency.cli.plantumldiagram.classes.element.PlantUMLClassesDiagramElement;
31  import net.sourceforge.plantumldependency.cli.plantumldiagram.classes.element.PlantUMLClassesDiagramEnumElement;
32  import net.sourceforge.plantumldependency.cli.plantumldiagram.classes.element.stereotype.PlantUMLStereotype;
33  
34  /**
35   * The default {@link PlantUMLClassesDiagramEnumElement} implementation.
36   *
37   * @author Benjamin Croizet (<a href="mailto:graffity2199@yahoo.fr>graffity2199@yahoo.fr</a>)
38   * @since 1.1.1
39   * @version 1.3.0
40   */
41  public class PlantUMLClassesDiagramEnumElementImpl extends AbstractPlantUMLClassesDiagramElement implements
42          PlantUMLClassesDiagramEnumElement {
43  
44      /** Serial version UID. */
45      private static final long serialVersionUID = -880278043290474038L;
46  
47      /** The element stereotype, if any. */
48      private PlantUMLStereotype stereotype;
49  
50      /**
51       * Medium constructor.
52       *
53       * @param fullName
54       *            the element full name, mustn't be <code>null</code>.
55       * @since 1.1.1
56       */
57      public PlantUMLClassesDiagramEnumElementImpl(final String fullName) {
58          this(fullName, null);
59      }
60  
61      /**
62       * Full constructor.
63       *
64       * @param fullName
65       *            the element full name, mustn't be <code>null</code>.
66       * @param stereotyp
67       *            the element stereotype, if any, may be <code>null</code>.
68       * @since 1.1.1
69       */
70      public PlantUMLClassesDiagramEnumElementImpl(final String fullName, final PlantUMLStereotype stereotyp) {
71          super(fullName, ENUM_TAG);
72          stereotype = stereotyp;
73      }
74  
75      /**
76       * {@inheritDoc}
77       *
78       * @since 1.1.1
79       */
80      @Override
81      public PlantUMLClassesDiagramElement deepClone() {
82          final PlantUMLClassesDiagramEnumElementImpl p = (PlantUMLClassesDiagramEnumElementImpl) super.deepClone();
83          p.stereotype = getStereotype() == null ? null : getStereotype().deepClone();
84          return p;
85      }
86  
87      /**
88       * {@inheritDoc}
89       *
90       * @since 1.1.1
91       */
92      @Override
93      public boolean equals(final Object obj) {
94          if (this == obj) {
95              return true;
96          }
97          if (!super.equals(obj)) {
98              return false;
99          }
100         if (getClass() != obj.getClass()) {
101             return false;
102         }
103         final PlantUMLClassesDiagramEnumElementImpl other = (PlantUMLClassesDiagramEnumElementImpl) obj;
104         if (stereotype == null) {
105             if (other.stereotype != null) {
106                 return false;
107             }
108         } else if (!stereotype.equals(other.stereotype)) {
109             return false;
110         }
111         return true;
112     }
113 
114     /**
115      * {@inheritDoc}
116      *
117      * @since 1.1.1
118      */
119     @Override
120     protected String getAdditionalPlantUMLTextDescription() {
121         return getStereotype() != null ? getStereotype().getPlantUMLTextDescription() : BLANK_STRING;
122     }
123 
124     /**
125      * {@inheritDoc}
126      *
127      * @since 1.1.1
128      */
129     @Override
130     public PlantUMLStereotype getStereotype() {
131         return stereotype;
132     }
133 
134     /**
135      * {@inheritDoc}
136      *
137      * @since 1.1.1
138      */
139     @Override
140     public int hashCode() {
141         final int prime = 31;
142         int result = super.hashCode();
143         result = prime * result + ((stereotype == null) ? 0 : stereotype.hashCode());
144         return result;
145     }
146 
147     /**
148      * {@inheritDoc}
149      *
150      * @since 1.1.1
151      */
152     @Override
153     public String toString() {
154         return getClass().getSimpleName() + " [" + super.toString() + ",stereotype=" + stereotype + "]";
155     }
156 }