View Javadoc

1   /*
2    PlantUMLClassElementImpl.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.CLASS_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.PlantUMLClassesDiagramClassElement;
31  import net.sourceforge.plantumldependency.cli.plantumldiagram.classes.element.PlantUMLClassesDiagramElement;
32  import net.sourceforge.plantumldependency.cli.plantumldiagram.classes.element.stereotype.PlantUMLStereotype;
33  import net.sourceforge.plantumldependency.cli.plantumldiagram.classes.element.tag.PlantUMLClassesDiagramElementTag;
34  
35  /**
36   * The default {@link PlantUMLClassesDiagramClassElement} implementation.
37   *
38   * @author Benjamin Croizet (<a href="mailto:graffity2199@yahoo.fr>graffity2199@yahoo.fr</a>)
39   * @since 1.1.1
40   * @version 1.3.0
41   */
42  public class PlantUMLClassesDiagramClassElementImpl extends AbstractPlantUMLClassesDiagramElement implements
43          PlantUMLClassesDiagramClassElement {
44  
45      /** Serial version UID. */
46      private static final long serialVersionUID = 9113761739200276659L;
47  
48      /** The element stereotype, if any. */
49      private PlantUMLStereotype stereotype;
50  
51      /**
52       * Medium constructor.
53       *
54       * @param fullName
55       *            the element full name, mustn't be <code>null</code>.
56       * @since 1.1.1
57       */
58      public PlantUMLClassesDiagramClassElementImpl(final String fullName) {
59          this(fullName, null);
60      }
61  
62      /**
63       * Full constructor.
64       *
65       * @param fullName
66       *            the element full name, mustn't be <code>null</code>.
67       * @param tag
68       *            the plantUML element tag available in the plantUML classes diagram language,
69       *            mustn't be <code>null</code>.
70       * @param stereotyp
71       *            the element stereotype, if any, may be <code>null</code>.
72       * @since 1.1.1
73       */
74      public PlantUMLClassesDiagramClassElementImpl(final String fullName, final PlantUMLClassesDiagramElementTag tag,
75              final PlantUMLStereotype stereotyp) {
76          super(fullName, tag);
77          stereotype = stereotyp;
78      }
79  
80      /**
81       * Full constructor.
82       *
83       * @param fullName
84       *            the element full name, mustn't be <code>null</code>.
85       * @param stereotyp
86       *            the element stereotype, if any, may be <code>null</code>.
87       * @since 1.1.1
88       */
89      public PlantUMLClassesDiagramClassElementImpl(final String fullName, final PlantUMLStereotype stereotyp) {
90          super(fullName, CLASS_TAG);
91          stereotype = stereotyp;
92      }
93  
94      /**
95       * {@inheritDoc}
96       *
97       * @since 1.1.1
98       */
99      @Override
100     public PlantUMLClassesDiagramElement deepClone() {
101         final PlantUMLClassesDiagramClassElementImpl p = (PlantUMLClassesDiagramClassElementImpl) super.deepClone();
102         p.stereotype = getStereotype() == null ? null : getStereotype().deepClone();
103         return p;
104     }
105 
106     /**
107      * {@inheritDoc}
108      *
109      * @since 1.1.1
110      */
111     @Override
112     public boolean equals(final Object obj) {
113         if (this == obj) {
114             return true;
115         }
116         if (!super.equals(obj)) {
117             return false;
118         }
119         if (getClass() != obj.getClass()) {
120             return false;
121         }
122         final PlantUMLClassesDiagramClassElementImpl other = (PlantUMLClassesDiagramClassElementImpl) obj;
123         if (stereotype == null) {
124             if (other.stereotype != null) {
125                 return false;
126             }
127         } else if (!stereotype.equals(other.stereotype)) {
128             return false;
129         }
130         return true;
131     }
132 
133     /**
134      * {@inheritDoc}
135      *
136      * @since 1.1.1
137      */
138     @Override
139     protected String getAdditionalPlantUMLTextDescription() {
140         return getStereotype() != null ? getStereotype().getPlantUMLTextDescription() : BLANK_STRING;
141     }
142 
143     /**
144      * {@inheritDoc}
145      *
146      * @since 1.1.1
147      */
148     @Override
149     public PlantUMLStereotype getStereotype() {
150         return stereotype;
151     }
152 
153     /**
154      * {@inheritDoc}
155      *
156      * @since 1.1.1
157      */
158     @Override
159     public int hashCode() {
160         final int prime = 31;
161         int result = super.hashCode();
162         result = prime * result + ((stereotype == null) ? 0 : stereotype.hashCode());
163         return result;
164     }
165 
166     /**
167      * {@inheritDoc}
168      *
169      * @since 1.1.1
170      */
171     @Override
172     public String toString() {
173         return getClass().getSimpleName() + " [" + super.toString() + ",stereotype=" + stereotype + "]";
174     }
175 }