View Javadoc

1   /*
2    PlantUMLClassesDiagramAnnotationElementImpl.java
3    Creation date : 11/07/2013
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.ANNOTATION_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.PlantUMLClassesDiagramAnnotationElement;
31  import net.sourceforge.plantumldependency.cli.plantumldiagram.classes.element.PlantUMLClassesDiagramElement;
32  import net.sourceforge.plantumldependency.cli.plantumldiagram.classes.element.stereotype.PlantUMLStereotype;
33  
34  /**
35   * The default {@link PlantUMLClassesDiagramAnnotationElement} implementation.
36   *
37   * @author Benjamin Croizet (<a href="mailto:graffity2199@yahoo.fr>graffity2199@yahoo.fr</a>)
38   * @since 1.2.0
39   * @version 1.3.0
40   */
41  public class PlantUMLClassesDiagramAnnotationElementImpl extends AbstractPlantUMLClassesDiagramElement implements
42          PlantUMLClassesDiagramAnnotationElement {
43  
44      /** Serial version UID. */
45      private static final long serialVersionUID = 7052622862581013574L;
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.2.0
56       */
57      public PlantUMLClassesDiagramAnnotationElementImpl(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.2.0
69       */
70      public PlantUMLClassesDiagramAnnotationElementImpl(final String fullName, final PlantUMLStereotype stereotyp) {
71          super(fullName, ANNOTATION_TAG);
72          stereotype = stereotyp;
73      }
74  
75      /**
76       * {@inheritDoc}
77       *
78       * @since 1.2.0
79       */
80      @Override
81      public PlantUMLClassesDiagramElement deepClone() {
82          final PlantUMLClassesDiagramAnnotationElementImpl p = (PlantUMLClassesDiagramAnnotationElementImpl) super
83                  .deepClone();
84          p.stereotype = getStereotype() == null ? null : getStereotype().deepClone();
85          return p;
86      }
87  
88      /**
89       * {@inheritDoc}
90       *
91       * @since 1.2.0
92       */
93      @Override
94      public boolean equals(final Object obj) {
95          if (this == obj) {
96              return true;
97          }
98          if (!super.equals(obj)) {
99              return false;
100         }
101         if (getClass() != obj.getClass()) {
102             return false;
103         }
104         final PlantUMLClassesDiagramAnnotationElementImpl other = (PlantUMLClassesDiagramAnnotationElementImpl) obj;
105         if (stereotype == null) {
106             if (other.stereotype != null) {
107                 return false;
108             }
109         } else if (!stereotype.equals(other.stereotype)) {
110             return false;
111         }
112         return true;
113     }
114 
115     /**
116      * {@inheritDoc}
117      *
118      * @since 1.2.0
119      */
120     @Override
121     protected String getAdditionalPlantUMLTextDescription() {
122         return getStereotype() != null ? getStereotype().getPlantUMLTextDescription() : BLANK_STRING;
123     }
124 
125     /**
126      * {@inheritDoc}
127      *
128      * @since 1.2.0
129      */
130     @Override
131     public PlantUMLStereotype getStereotype() {
132         return stereotype;
133     }
134 
135     /**
136      * {@inheritDoc}
137      *
138      * @since 1.2.0
139      */
140     @Override
141     public int hashCode() {
142         final int prime = 31;
143         int result = super.hashCode();
144         result = prime * result + ((stereotype == null) ? 0 : stereotype.hashCode());
145         return result;
146     }
147 
148     /**
149      * {@inheritDoc}
150      *
151      * @since 1.2.0
152      */
153     @Override
154     public String toString() {
155         return getClass().getSimpleName() + " [" + super.toString() + ",stereotype=" + stereotype + "]";
156     }
157 }