001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: package org.netbeans.modules.uml.core.reverseengineering.reframework.parsingframework;
043:
044: /**
045: *
046: * @author treyspiva
047: */
048: public class CollectionType {
049: private String name = "";
050: private String packageName = "";
051: private boolean userDefined = false;
052: private boolean defaultType = false;
053:
054: /** Creates a new instance of CollectionTypes */
055: public CollectionType() {
056: }
057:
058: /** Creates a new instance of CollectionTypes
059: * @param name The name of the type
060: * @param packName The package of the type
061: * @param user is the type a user defined type
062: * @param defaultType is the type the default collection type
063: */
064: public CollectionType(String name, String packName, boolean user,
065: boolean defaultType) {
066: setDefaultType(defaultType);
067: setUserDefined(user);
068: setPackageName(packName);
069: setName(name);
070: }
071:
072: /**
073: * Set the default type property. The default collection type is the
074: * default type to use when generating code for an attribute with 0..*
075: * multiplicity
076: *
077: * @param defaultType true if the type is the default type
078: */
079: public void setDefaultType(boolean defaultType) {
080: this .defaultType = defaultType;
081: }
082:
083: /**
084: * Retrieves if the default type property. The default collection type is the
085: * default type to use when generating code for an attribute with 0..*
086: * multiplicity
087: *
088: * @return true if the type is the default type
089: */
090: public boolean isDefaultType() {
091: return defaultType;
092: }
093:
094: /**
095: * Sets if the collection type is a user defined type or a type defined by
096: * the language.
097: *
098: * @param userDefined true if the type is a user type.
099: */
100: public void setUserDefined(boolean userDefined) {
101: this .userDefined = userDefined;
102: }
103:
104: /**
105: * Retrieves if the collection type is a user defined type or a type defined by
106: * the language.
107: *
108: * @return true if the type is a user type.
109: */
110: public boolean isUserDefined() {
111: return userDefined;
112: }
113:
114: /**
115: * Sets the package that owns the collection type.
116: *
117: * @param packageName the owning package name.
118: */
119: public void setPackageName(String packageName) {
120: this .packageName = packageName;
121: }
122:
123: /**
124: * Retrieves the package that owns the collection type.
125: *
126: * @return the owning package name.
127: */
128: public String getPackageName() {
129: return packageName;
130: }
131:
132: /**
133: * Sets the name of the collection type.
134: *
135: * @param name the type name
136: */
137: public void setName(String name) {
138: this .name = name;
139: }
140:
141: /**
142: * Retrieves the name of the collection type.
143: *
144: * @return the name of the collection type.
145: */
146: public String getName() {
147: return name;
148: }
149:
150: public String getFullName() {
151: return getPackageName().replace(".", "::") + "::" + getName();
152: }
153:
154: /**
155: * Test if two types are the same. If a String is passed in it tries to
156: * determine if the package and name equals the string value.
157: *
158: * @param obj The object to test.
159: * @return true if the objects are equal, false otherwise.
160: */
161: public boolean equals(Object obj) {
162: if (obj == null) {
163: return false;
164: }
165:
166: if (getClass() == obj.getClass()) {
167: final CollectionType other = (CollectionType) obj;
168:
169: if (this .name != other.name
170: && (this .name == null || !this .name
171: .equals(other.name))) {
172: return false;
173: }
174:
175: if (this .packageName != other.packageName
176: && (this .packageName == null || !this .packageName
177: .equals(other.packageName))) {
178: return false;
179: }
180:
181: return true;
182: } else if (obj instanceof String) {
183: // Check if we are checking if the name is the same. There are two
184: // possibilities. First we may have just the name of the class.
185: // Second, we could have a fully qualified name.
186:
187: String wantedName = (String) obj;
188: int umlSeperator = wantedName.lastIndexOf(":");
189: int javaSeperator = wantedName.lastIndexOf(".");
190:
191: String collectionName = "";
192: if (umlSeperator >= 0) {
193: // First make sure that the name is in the correct format.
194: collectionName = getPackageName().replaceAll(".", "::");
195: if (collectionName.charAt(collectionName.length() - 1) != ':') {
196: collectionName += "::";
197: }
198: collectionName += getName();
199: } else if (javaSeperator >= 0) {
200: // First make sure that the name is in the correct format.
201: collectionName = getPackageName().replaceAll("::", ".");
202: if (collectionName.charAt(collectionName.length() - 1) != '.') {
203: collectionName += ".";
204: }
205: collectionName += getName();
206: } else {
207: collectionName = getName();
208: }
209:
210: return wantedName.equals(collectionName);
211: }
212:
213: return false;
214: }
215:
216: /**
217: * Calculates a hashcode
218: *
219: * @return the hashcode value.
220: */
221: public int hashCode() {
222: int hash = 5;
223:
224: hash = 29 * hash
225: + (this .name != null ? this .name.hashCode() : 0);
226: hash = 29
227: * hash
228: + (this .packageName != null ? this .packageName
229: .hashCode() : 0);
230: hash = 29 * hash + (this .userDefined ? 1 : 0);
231: hash = 29 * hash + (this .defaultType ? 1 : 0);
232: return hash;
233: }
234: }
|