View Javadoc

1   /*
2   
3       dsh-codegen  Source code generation suite.
4       Copyright (c) 2004-2013 held jointly by the individual authors.
5   
6       This library is free software; you can redistribute it and/or modify it
7       under the terms of the GNU Lesser General Public License as published
8       by the Free Software Foundation; either version 3 of the License, or (at
9       your option) any later version.
10  
11      This library is distributed in the hope that it will be useful, but WITHOUT
12      ANY WARRANTY; with out even the implied warranty of MERCHANTABILITY or
13      FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
14      License for more details.
15  
16      You should have received a copy of the GNU Lesser General Public License
17      along with this library;  if not, write to the Free Software Foundation,
18      Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA.
19  
20      > http://www.fsf.org/licensing/licenses/lgpl.html
21      > http://www.opensource.org/licenses/lgpl-license.php
22  
23  */
24  package org.dishevelled.codegen;
25  
26  import java.util.Set;
27  import java.util.LinkedHashSet;
28  import java.util.Collections;
29  
30  /**
31   * A description of the attributes and associations for a class.
32   *
33   * @author  Michael Heuer
34   */
35  public final class ClassDescription
36  {
37      /** License for this class description. */
38      private String license;
39  
40      /** Package name for this class description. */
41      private String packageName;
42  
43      /** Lowercase name for this class description. */
44      private String lower;
45  
46      /** Mixed-case name for this class description. */
47      private String mixed;
48  
49      /** Uppercase name for this class description. */
50      private String upper;
51  
52      /** Author for this class description. */
53      private String author;
54  
55      /** Version for this class description. */
56      private String version;
57  
58      /** Description for this class description. */
59      private String description;
60  
61      /** Set of classes this class description specializes. */
62      private final Set<ClassDescription> specializes;
63  
64      /** Set of interfaces this class description realizes. */
65      private final Set<InterfaceDescription> realizes;
66  
67      /** Set of attributes for this class description. */
68      private final Set<Attribute> attributes;
69  
70      /** Set of associations for this class description. */
71      private final Set<Association> associations;
72  
73  
74      /**
75       * Create a new class description with the specified package name
76       * and name.
77       *
78       * @param packageName package name for this class description
79       * @param name name of this class description
80       */
81      public ClassDescription(final String packageName, final String name)
82      {
83          this.packageName = packageName;
84          this.lower = CodegenUtils.makeLowercase(name);
85          this.mixed = CodegenUtils.makeMixedCase(name);
86          this.upper = CodegenUtils.makeUppercase(name);
87          this.description = CodegenUtils.makeSentenceCaseDescription(name);
88          this.author = " codegen";
89          this.version = "$" + "Revision$ $" + "Date$";  // split to prevent svn expansion
90          this.specializes = new LinkedHashSet<ClassDescription>();
91          this.realizes = new LinkedHashSet<InterfaceDescription>();
92          this.attributes = new LinkedHashSet<Attribute>();
93          this.associations = new LinkedHashSet<Association>();
94      }
95  
96      /**
97       * Create a new class description with the specified package name
98       * and name.
99       *
100      * @param license license for this class description
101      * @param packageName package name for this class description
102      * @param name name of this class description
103      */
104     public ClassDescription(final String license, final String packageName, final String name)
105     {
106         this.license = license;
107         this.packageName = packageName;
108         this.lower = CodegenUtils.makeLowercase(name);
109         this.mixed = CodegenUtils.makeMixedCase(name);
110         this.upper = CodegenUtils.makeUppercase(name);
111         this.description = CodegenUtils.makeSentenceCaseDescription(name);
112         this.author = " codegen";
113         this.version = "$" + "Revision$ $" + "Date$";  // split to prevent svn expansion
114         this.specializes = new LinkedHashSet<ClassDescription>();
115         this.realizes = new LinkedHashSet<InterfaceDescription>();
116         this.attributes = new LinkedHashSet<Attribute>();
117         this.associations = new LinkedHashSet<Association>();
118     }
119 
120     /**
121      * Create a new class description from the specified parameters.
122      *
123      * @param packageName package name for this class description
124      * @param name name of this class description
125      * @param author author for this class description
126      * @param version version for this class description
127      * @param description description for this class description
128      */
129     public ClassDescription(final String packageName, final String name,
130                             final String author, final String version, final String description)
131     {
132         this.packageName = packageName;
133         this.lower = CodegenUtils.makeLowercase(name);
134         this.mixed = CodegenUtils.makeMixedCase(name);
135         this.upper = CodegenUtils.makeUppercase(name);
136         this.author = author;
137         this.version = version;
138         this.description = description;
139         this.specializes = new LinkedHashSet<ClassDescription>();
140         this.realizes = new LinkedHashSet<InterfaceDescription>();
141         this.attributes = new LinkedHashSet<Attribute>();
142         this.associations = new LinkedHashSet<Association>();
143     }
144 
145     /**
146      * Create a new class description from the specified parameters.
147      *
148      * @param packageName package name for this class description
149      * @param lower lowercase name for this class description
150      * @param mixed mixed-case name for this class description
151      * @param upper uppercase name for this class description
152      * @param author author for this class description
153      * @param version version for this class description
154      * @param description description for this class description
155      */
156     public ClassDescription(final String packageName, final String lower, final String mixed, final String upper,
157                             final String author, final String version, final String description)
158     {
159         this.packageName = packageName;
160         this.lower = lower;
161         this.mixed = mixed;
162         this.upper = upper;
163         this.author = author;
164         this.version = version;
165         this.description = description;
166         this.specializes = new LinkedHashSet<ClassDescription>();
167         this.realizes = new LinkedHashSet<InterfaceDescription>();
168         this.attributes = new LinkedHashSet<Attribute>();
169         this.associations = new LinkedHashSet<Association>();
170     }
171 
172     /**
173      * Create a new class description from the specified parameters.
174      *
175      * <p>The classes this class description specializes in <code>specializes</code> are copied defensively
176      * into this class.</p>
177      *
178      * <p>The interfaces this class description realizes in <code>realizes</code> are copied defensively
179      * into this class.</p>
180      *
181      * <p>The attributes in <code>attributes</code> are copied defensively
182      * into this class.</p>
183      *
184      * <p>The associations in <code>associations</code> are copied defensively
185      * into this class.</p>
186      *
187      * @param packageName package name for this class description
188      * @param lower lowercase name for this class description
189      * @param mixed mixed-case name for this class description
190      * @param upper uppercase name for this class description
191      * @param author author for this class description
192      * @param version version for this class description
193      * @param description description for this class description
194      * @param specializes set of classes this class description specializes, must not be null
195      * @param realizes set of interfaces this class description realizes, must not be null
196      * @param attributes set of attributes, must not be null
197      * @param associations set of associations, must not be null
198      */
199     public ClassDescription(final String packageName,
200                             final String lower,
201                             final String mixed,
202                             final String upper,
203                             final String author,
204                             final String version,
205                             final String description,
206                             final Set<ClassDescription> specializes,
207                             final Set<InterfaceDescription> realizes,
208                             final Set<Attribute> attributes,
209                             final Set<Association> associations)
210     {
211 
212         this.packageName = packageName;
213         this.lower = lower;
214         this.mixed = mixed;
215         this.upper = upper;
216         this.author = author;
217         this.version = version;
218         this.description = description;
219 
220         this.specializes = new LinkedHashSet<ClassDescription>(specializes.size());
221         this.specializes.addAll(specializes);
222 
223         this.realizes = new LinkedHashSet<InterfaceDescription>(realizes.size());
224         this.realizes.addAll(realizes);
225 
226         this.attributes = new LinkedHashSet<Attribute>(attributes.size());
227         this.attributes.addAll(attributes);
228 
229         this.associations = new LinkedHashSet<Association>(associations.size());
230         this.associations.addAll(associations);
231     }
232 
233 
234     /**
235      * Return the license for this class description.
236      *
237      * @return the license for this class description
238      */
239     public String getLicense()
240     {
241         return license;
242     }
243 
244     /**
245      * Return the package name for this class description.
246      *
247      * @return the package name for this class description
248      */
249     public String getPackageName()
250     {
251         return packageName;
252     }
253 
254     /**
255      * Return the lowercase name for this class description.
256      *
257      * @return the lowercase name for this class description
258      */
259     public String getLower()
260     {
261         return lower;
262     }
263 
264     /**
265      * Return the mixed-case name for this class description.
266      *
267      * @return the mixed-case name for this class description
268      */
269     public String getMixed()
270     {
271         return mixed;
272     }
273 
274     /**
275      * Return the uppercase name for this class description.
276      *
277      * @return the uppercase name for this class description
278      */
279     public String getUpper()
280     {
281         return upper;
282     }
283 
284     /**
285      * Return the author for this class description.
286      *
287      * @return the author for this class description
288      */
289     public String getAuthor()
290     {
291         return author;
292     }
293 
294     /**
295      * Return the version for this class description.
296      *
297      * @return the version for this class description
298      */
299     public String getVersion()
300     {
301         return version;
302     }
303 
304     /**
305      * Return the description for this class description.
306      *
307      * @return the description for this class description
308      */
309     public String getDescription()
310     {
311         return description;
312     }
313 
314     /**
315      * Return an unmodifiable set of classes this class description specializes.
316      *
317      * @return an unmodifiable set of classes this class description specializes
318      */
319     public Set<ClassDescription> getSpecializes()
320     {
321         return Collections.unmodifiableSet(specializes);
322     }
323 
324     /**
325      * Add the specified class description to the set of classes this class description
326      * specializes.  Return <code>true</code> if the set of classes this class description
327      * specializes changed as a result of this call.
328      *
329      * @param specializes class description to add, must not be null
330      * @return <code>true</code> if the set of classes this class description specializes
331      *    changed as a result of this call
332      */
333     public boolean addSpecializes(final ClassDescription specializes)
334     {
335         if (specializes == null)
336         {
337             throw new IllegalArgumentException("specializes must not be null");
338         }
339 
340         boolean rv = this.specializes.add(specializes);
341 
342         if (rv)
343         {
344             for (Attribute a : specializes.getAttributes())
345             {
346                 addAttribute(a);
347             }
348             for (Association a : specializes.getAssociations())
349             {
350                 addAssociation(a);
351             }
352         }
353         return rv;
354     }
355 
356     /**
357      * Add the specified class description to the set of classes this class description
358      * specializes.  Return <code>true</code> if the set of classes this class description
359      * specializes changed as a result of this call.
360      *
361      * @param specializes class description to add, must not be null
362      * @return <code>true</code> if the set of classes this class description specializes
363      *    changed as a result of this call
364      */
365     public boolean specializes(final ClassDescription specializes)
366     {
367         return addSpecializes(specializes);
368     }
369 
370     /**
371      * Return an unmodifiable set of interfaces this class description realizes.
372      *
373      * @return an unmodifiable set of interfaces this class description realizes
374      */
375     public Set<InterfaceDescription> getRealizes()
376     {
377         return Collections.unmodifiableSet(realizes);
378     }
379 
380     /**
381      * Add the specified interface description to the set of interfaces this class
382      * description realizes.  Return <code>true</code> if the set of interfaces this
383      * class description realizes changed as a result of this call.
384      *
385      * @param realizes interface description to add, must not be null
386      * @return <code>true</code> if the set of interfaces this class description realizes
387      *    changed as a result of this call
388      */
389     public boolean addRealizes(final InterfaceDescription realizes)
390     {
391         if (realizes == null)
392         {
393             throw new IllegalArgumentException("realizes must not be null");
394         }
395         boolean rv = this.realizes.add(realizes);
396 
397         if (rv)
398         {
399             for (Attribute a : realizes.getAttributes())
400             {
401                 addAttribute(a);
402             }
403             for (Association a : realizes.getAssociations())
404             {
405                 addAssociation(a);
406             }
407         }
408         return rv;
409     }
410 
411     /**
412      * Add the specified interface description to the set of interfaces this class
413      * description realizes.  Return <code>true</code> if the set of interfaces this
414      * class description realizes changed as a result of this call.
415      *
416      * @param realizes interface description to add, must not be null
417      * @return <code>true</code> if the set of interfaces this class description realizes
418      *    changed as a result of this call
419      */
420     public boolean realizes(final InterfaceDescription realizes)
421     {
422         return addRealizes(realizes);
423     }
424 
425     /**
426      * Return an unmodifiable set of attributes for this class description.
427      *
428      * @return an unmodifiable set of attributes for this class description
429      */
430     public Set<Attribute> getAttributes()
431     {
432         return Collections.unmodifiableSet(attributes);
433     }
434 
435     /**
436      * Add the specified attribute to the set of attributes
437      * for this class description.  Return <code>true</code> if the set
438      * of attributes changed as a result of this call.
439      *
440      * @param attribute attribute to add, must not be null
441      * @return <code>true</code> if the set of attributes
442      *    changed as a result of this call
443      */
444     public boolean addAttribute(final Attribute attribute)
445     {
446         if (attribute == null)
447         {
448             throw new IllegalArgumentException("attribute must not be null");
449         }
450         return attributes.add(attribute);
451     }
452 
453     /**
454      * Add the specified attribute to the set of attributes
455      * for this class description.  Return <code>true</code> if the set
456      * of attributes changed as a result of this call.
457      *
458      * @param attribute attribute to add, must not be null
459      * @return <code>true</code> if the set of attributes
460      *    changed as a result of this call
461      */
462     public boolean attribute(final Attribute attribute)
463     {
464         return addAttribute(attribute);
465     }
466 
467     /**
468      * Add a new attribute to the set of attributes for this
469      * class description with the specified name, role name,
470      * and cardinality.  The cardinality must be one of <b>Cardinality.ZeroToOne</b>
471      * or <b>Cardinality.StrictlyOne</b>.  Return <code>true</code> if
472      * the set of attributes changed as a result of this call.
473      *
474      * @param name attribute name
475      * @param roleName role name
476      * @param cardinality cardinality, must not be null and must be
477      *    one of <b>Cardinality.ZeroToOne</b> or <b>Cardinality.StrictlyOne</b>
478      * @return <code>true</code> if the set of attributes
479      *    changed as a result of this call
480      */
481     public boolean attribute(final String name, final String roleName, final Cardinality cardinality)
482     {
483         Attribute a = new Attribute(name, roleName, cardinality);
484         return addAttribute(a);
485     }
486 
487     /**
488      * Add a new attribute to the set of attributes for this
489      * class description with the specified name, role name,
490      * cardinality, and bound flag.  The cardinality must be one of <b>Cardinality.ZeroToOne</b>
491      * or <b>Cardinality.StrictlyOne</b>.  Return <code>true</code> if
492      * the set of attributes changed as a result of this call.
493      *
494      * @param name attribute name
495      * @param roleName role name
496      * @param cardinality cardinality, must not be null and must be
497      *    one of <b>Cardinality.ZeroToOne</b> or <b>Cardinality.StrictlyOne</b>
498      * @param bound true if the attribute is to be a "bound" attribute
499      * @return <code>true</code> if the set of attributes
500      *    changed as a result of this call
501      */
502     public boolean attribute(final String name, final String roleName,
503                                    final Cardinality cardinality, final boolean bound)
504     {
505         Attribute a = new Attribute(name, roleName, cardinality, bound);
506         return addAttribute(a);
507     }
508 
509     /**
510      * Add a new attribute to the set of attributes for this
511      * class description with the specified parameters.
512      * Return <code>true</code> if the set of attributes changed as
513      * a result of this call.
514      *
515      * @param name attribute name
516      * @param roleName role name
517      * @param cardinality cardinality, must not be null
518      * @param indexed true if the collection should be indexed
519      * @param unique true if the collection should not allow duplicate elements
520      * @param ordered true if the collection should iterate over elements in <i>insertion-order</i>
521      * @param sorted true if the collection should iterate over elements in ascending element order,
522      *    sorted according to the <i>natural ordering</i> of its elements (see Comparable), or by a Comparator
523      *    provided at creation time
524      * @return <code>true</code> if the set of attributes
525      *    changed as a result of this call
526      */
527     public boolean attribute(final String name, final String roleName, final Cardinality cardinality,
528                              final boolean indexed, final boolean unique, final boolean ordered, final boolean sorted)
529     {
530         Attribute a = new Attribute(name, roleName, cardinality, indexed, unique, ordered, sorted);
531         return addAttribute(a);
532     }
533 
534     /**
535      * Add a new attribute to the set of attributes for this
536      * class description with the specified parameters.
537      * Return <code>true</code> if the set of attributes changed as
538      * a result of this call.
539      *
540      * @param name attribute name
541      * @param roleName role name
542      * @param cardinality cardinality, must not be null
543      * @param bound true if the attribute is to be a "bound" attribute
544      * @param indexed true if the collection should be indexed
545      * @param unique true if the collection should not allow duplicate elements
546      * @param ordered true if the collection should iterate over elements in <i>insertion-order</i>
547      * @param sorted true if the collection should iterate over elements in ascending element order,
548      *    sorted according to the <i>natural ordering</i> of its elements (see Comparable), or by a Comparator
549      *    provided at creation time
550      * @return <code>true</code> if the set of attributes
551      *    changed as a result of this call
552      */
553     public boolean attribute(final String name, final String roleName, final Cardinality cardinality,
554                              final boolean bound,
555                              final boolean indexed, final boolean unique, final boolean ordered, final boolean sorted)
556     {
557         Attribute a = new Attribute(name, roleName, cardinality, bound, indexed, unique, ordered, sorted);
558         return addAttribute(a);
559     }
560 
561     /**
562      * Return an unmodifiable set of associations for this class description.
563      *
564      * @return an unmodifiable set of associations for this class description
565      */
566     public Set<Association> getAssociations()
567     {
568         return Collections.unmodifiableSet(associations);
569     }
570 
571     /**
572      * Add the specified association to the set of associations
573      * for this class description.  Return <code>true</code> if the set
574      * of associations changed as a result of this call.
575      *
576      * @param association association to add, must not be null
577      * @return <code>true</code> if the set of associations
578      *    changed as a result of this call
579      */
580     public boolean addAssociation(final Association association)
581     {
582         if (association == null)
583         {
584             throw new IllegalArgumentException("association must not be null");
585         }
586         return associations.add(association);
587     }
588 
589     /**
590      * Add the specified association to the set of associations
591      * for this class description.  Return <code>true</code> if the set
592      * of associations changed as a result of this call.
593      *
594      * @param association association to add, must not be null
595      * @return <code>true</code> if the set of associations
596      *    changed as a result of this call
597      */
598     public boolean associate(final Association association)
599     {
600         return addAssociation(association);
601     }
602 
603     /**
604      * Add a new association to the set of associations for this
605      * class description to the specified class with the
606      * specified cardinality.  The assocation's role name will be
607      * the same as the class' name.  The cardinality must be one of
608      * <b>Cardinality.ZeroToOne</b> or <b>Cardinality.StrictlyOne</b>.
609      * Return <code>true</code> if the set of associations changed as a result of
610      * this call.
611      *
612      * @param cd class description, must not be null
613      * @param cardinality cardinality, must not be null and must be
614      *    one of <b>Cardinality.ZeroToOne</b> or <b>Cardinality.StrictlyOne</b>
615      * @return <code>true</code> if the set of associations
616      *    changed as a result of this call
617      */
618     public boolean associate(final ClassDescription cd, final Cardinality cardinality)
619     {
620         Association a = new Association(cd, cd.getUpper(), cardinality);
621         return addAssociation(a);
622     }
623 
624     /**
625      * Add a new association to the set of associations for this
626      * class description to the specified class with the
627      * specified cardinality and bound flag.  The assocation's role name will be
628      * the same as the class' name.  The cardinality must be one of
629      * <b>Cardinality.ZeroToOne</b> or <b>Cardinality.StrictlyOne</b>.
630      * Return <code>true</code> if the set of associations changed as a result of
631      * this call.
632      *
633      * @param cd class description, must not be null
634      * @param cardinality cardinality, must not be null and must be
635      *    one of <b>Cardinality.ZeroToOne</b> or <b>Cardinality.StrictlyOne</b>
636      * @param bound true if the association is to be a "bound" association
637      * @return <code>true</code> if the set of associations
638      *    changed as a result of this call
639      */
640     public boolean associate(final ClassDescription cd, final Cardinality cardinality, final boolean bound)
641     {
642         Association a = new Association(cd, cd.getUpper(), cardinality, bound);
643         return addAssociation(a);
644     }
645 
646     /**
647      * Add a new association to the set of attributes for this
648      * class description to the specified class with the
649      * specified role name and cardinality.  The cardinality must be one of
650      * <b>Cardinality.ZeroToOne</b> or <b>Cardinality.StrictlyOne</b>.
651      * Return <code>true</code> if the set of associations changed as a result of
652      * this call.
653      *
654      * @param cd class description, must not be null
655      * @param roleName role name
656      * @param cardinality cardinality, must not be null and must be
657      *    one of <b>Cardinality.ZeroToOne</b> or <b>Cardinality.StrictlyOne</b>
658      * @return <code>true</code> if the set of associations
659      *    changed as a result of this call
660      */
661     public boolean associate(final ClassDescription cd, final String roleName, final Cardinality cardinality)
662     {
663         Association a = new Association(cd, roleName, cardinality);
664         return addAssociation(a);
665     }
666 
667     /**
668      * Add a new association to the set of attributes for this
669      * class description to the specified class with the
670      * specified role name, cardinality, and bound flag.  The cardinality must be one of
671      * <b>Cardinality.ZeroToOne</b> or <b>Cardinality.StrictlyOne</b>.
672      * Return <code>true</code> if the set of associations changed as a result of
673      * this call.
674      *
675      * @param cd class description, must not be null
676      * @param roleName role name
677      * @param cardinality cardinality, must not be null and must be
678      *    one of <b>Cardinality.ZeroToOne</b> or <b>Cardinality.StrictlyOne</b>
679      * @param bound true if the association is to be a "bound" association
680      * @return <code>true</code> if the set of associations
681      *    changed as a result of this call
682      */
683     public boolean associate(final ClassDescription cd, final String roleName,
684                              final Cardinality cardinality, final boolean bound)
685     {
686         Association a = new Association(cd, roleName, cardinality, bound);
687         return addAssociation(a);
688     }
689 
690     /**
691      * Add a new association to the set of associations for this
692      * class description to the specified class with the specified
693      * parameters.  The association's role name will be the same as
694      * the class' name.
695      *
696      * @param cd class description, must not be null
697      * @param cardinality cardinality, must not be null
698      * @param indexed true if the collection should be indexed
699      * @param unique true if the collection should not allow duplicate elements
700      * @param ordered true if the collection should iterate over elements in <i>insertion-order</i>
701      * @param sorted true if the collection should iterate over elements in ascending element order,
702      *    sorted according to the <i>natural ordering</i> of its elements (see Comparable), or by a Comparator
703      *    provided at creation time
704      * @return <code>true</code> if the set of associations
705      *    changed as a result of this call
706      */
707     public boolean associate(final ClassDescription cd, final Cardinality cardinality,
708                              final boolean indexed, final boolean unique, final boolean ordered, final boolean sorted)
709     {
710         Association a = new Association(cd, cd.getUpper(), cardinality, indexed, unique, ordered, sorted);
711         return addAssociation(a);
712     }
713 
714     /**
715      * Add a new association to the set of associations for this
716      * class description to the specified class with the specified
717      * parameters.  The association's role name will be the same as
718      * the class' name.
719      *
720      * @param cd class description, must not be null
721      * @param cardinality cardinality, must not be null
722      * @param bound true if the assocation is to be a "bound" association
723      * @param indexed true if the collection should be indexed
724      * @param unique true if the collection should not allow duplicate elements
725      * @param ordered true if the collection should iterate over elements in <i>insertion-order</i>
726      * @param sorted true if the collection should iterate over elements in ascending element order,
727      *    sorted according to the <i>natural ordering</i> of its elements (see Comparable), or by a Comparator
728      *    provided at creation time
729      * @return <code>true</code> if the set of associations
730      *    changed as a result of this call
731      */
732     public boolean associate(final ClassDescription cd, final Cardinality cardinality, final boolean bound,
733                              final boolean indexed, final boolean unique, final boolean ordered, final boolean sorted)
734     {
735         Association a = new Association(cd, cd.getUpper(), cardinality, bound, indexed, unique, ordered, sorted);
736         return addAssociation(a);
737     }
738 
739     /**
740      * Add a new association to the set of associations for this
741      * class description to the specified class with the specified
742      * parameters.
743      *
744      * @param cd class description, must not be null
745      * @param roleName role name
746      * @param cardinality cardinality, must not be null
747      * @param indexed true if the collection should be indexed
748      * @param unique true if the collection should not allow duplicate elements
749      * @param ordered true if the collection should iterate over elements in <i>insertion-order</i>
750      * @param sorted true if the collection should iterate over elements in ascending element order,
751      *    sorted according to the <i>natural ordering</i> of its elements (see Comparable), or by a Comparator
752      *    provided at creation time
753      * @return <code>true</code> if the set of associations
754      *    changed as a result of this call
755      */
756     public boolean associate(final ClassDescription cd, final String roleName, final Cardinality cardinality,
757                              final boolean indexed, final boolean unique, final boolean ordered, final boolean sorted)
758     {
759         Association a = new Association(cd, roleName, cardinality, indexed, unique, ordered, sorted);
760         return addAssociation(a);
761     }
762 
763     /**
764      * Add a new association to the set of associations for this
765      * class description to the specified class with the specified
766      * parameters.
767      *
768      * @param cd class description, must not be null
769      * @param roleName role name
770      * @param cardinality cardinality, must not be null
771      * @param bound true if the association is to be a "bound" association
772      * @param indexed true if the collection should be indexed
773      * @param unique true if the collection should not allow duplicate elements
774      * @param ordered true if the collection should iterate over elements in <i>insertion-order</i>
775      * @param sorted true if the collection should iterate over elements in ascending element order,
776      *    sorted according to the <i>natural ordering</i> of its elements (see Comparable), or by a Comparator
777      *    provided at creation time
778      * @return <code>true</code> if the set of associations
779      *    changed as a result of this call
780      */
781     public boolean associate(final ClassDescription cd, final String roleName, final Cardinality cardinality,
782                              final boolean bound,
783                              final boolean indexed, final boolean unique, final boolean ordered, final boolean sorted)
784     {
785         Association a = new Association(cd, roleName, cardinality, bound, indexed, unique, ordered, sorted);
786         return addAssociation(a);
787     }
788 
789     /**
790      * Add a new association to the set of associations for this
791      * class description to the specified interface with the
792      * specified cardinality.  The assocation's role name will be
793      * the same as the interface's name.  The cardinality must be one of
794      * <b>Cardinality.ZeroToOne</b> or <b>Cardinality.StrictlyOne</b>.
795      * Return <code>true</code> if the set of associations changed as a result of
796      * this call.
797      *
798      * @param id interface description, must not be null
799      * @param cardinality cardinality, must not be null and must be
800      *    one of <b>Cardinality.ZeroToOne</b> or <b>Cardinality.StrictlyOne</b>
801      * @return <code>true</code> if the set of associations
802      *    changed as a result of this call
803      */
804     public boolean associate(final InterfaceDescription id, final Cardinality cardinality)
805     {
806         Association a = new Association(id, id.getUpper(), cardinality);
807         return addAssociation(a);
808     }
809 
810     /**
811      * Add a new association to the set of associations for this
812      * class description to the specified interface with the
813      * specified cardinality and bound flag.  The assocation's role name will be
814      * the same as the interface's name.  The cardinality must be one of
815      * <b>Cardinality.ZeroToOne</b> or <b>Cardinality.StrictlyOne</b>.
816      * Return <code>true</code> if the set of associations changed as a result of
817      * this call.
818      *
819      * @param id interface description, must not be null
820      * @param cardinality cardinality, must not be null and must be
821      *    one of <b>Cardinality.ZeroToOne</b> or <b>Cardinality.StrictlyOne</b>
822      * @param bound true if the assocation is to be a "bound" association
823      * @return <code>true</code> if the set of associations
824      *    changed as a result of this call
825      */
826     public boolean associate(final InterfaceDescription id, final Cardinality cardinality, final boolean bound)
827     {
828         Association a = new Association(id, id.getUpper(), cardinality, bound);
829         return addAssociation(a);
830     }
831 
832     /**
833      * Add a new association to the set of attributes for this
834      * class description to the specified interface with the
835      * specified role name and cardinality.  The cardinality must be one of
836      * <b>Cardinality.ZeroToOne</b> or <b>Cardinality.StrictlyOne</b>.
837      * Return <code>true</code> if the set of associations changed as a result of
838      * this call.
839      *
840      * @param id interface description, must not be null
841      * @param roleName role name
842      * @param cardinality cardinality, must not be null and must be
843      *    one of <b>Cardinality.ZeroToOne</b> or <b>Cardinality.StrictlyOne</b>
844      * @return <code>true</code> if the set of associations
845      *    changed as a result of this call
846      */
847     public boolean associate(final InterfaceDescription id, final String roleName, final Cardinality cardinality)
848     {
849         Association a = new Association(id, roleName, cardinality);
850         return addAssociation(a);
851     }
852 
853     /**
854      * Add a new association to the set of attributes for this
855      * class description to the specified interface with the
856      * specified role name, cardinality, and bound flag.  The cardinality must be one of
857      * <b>Cardinality.ZeroToOne</b> or <b>Cardinality.StrictlyOne</b>.
858      * Return <code>true</code> if the set of associations changed as a result of
859      * this call.
860      *
861      * @param id interface description, must not be null
862      * @param roleName role name
863      * @param cardinality cardinality, must not be null and must be
864      *    one of <b>Cardinality.ZeroToOne</b> or <b>Cardinality.StrictlyOne</b>
865      * @param bound true if the association is to be a "bound" association
866      * @return <code>true</code> if the set of associations
867      *    changed as a result of this call
868      */
869     public boolean associate(final InterfaceDescription id, final String roleName,
870                              final Cardinality cardinality, final boolean bound)
871     {
872         Association a = new Association(id, roleName, cardinality, bound);
873         return addAssociation(a);
874     }
875 
876    /**
877      * Add a new association to the set of associations for this
878      * class description to the specified interface with the specified
879      * parameters.  The association's role name will be the same as
880      * the interface's name.
881      *
882      * @param id interface description, must not be null
883      * @param cardinality cardinality, must not be null
884      * @param indexed true if the collection should be indexed
885      * @param unique true if the collection should not allow duplicate elements
886      * @param ordered true if the collection should iterate over elements in <i>insertion-order</i>
887      * @param sorted true if the collection should iterate over elements in ascending element order,
888      *    sorted according to the <i>natural ordering</i> of its elements (see Comparable), or by a Comparator
889      *    provided at creation time
890      * @return <code>true</code> if the set of associations
891      *    changed as a result of this call
892      */
893     public boolean associate(final InterfaceDescription id, final Cardinality cardinality,
894                              final boolean indexed, final boolean unique, final boolean ordered, final boolean sorted)
895     {
896         Association a = new Association(id, id.getUpper(), cardinality, indexed, unique, ordered, sorted);
897         return addAssociation(a);
898     }
899 
900    /**
901      * Add a new association to the set of associations for this
902      * class description to the specified interface with the specified
903      * parameters.  The association's role name will be the same as
904      * the interface's name.
905      *
906      * @param id interface description, must not be null
907      * @param cardinality cardinality, must not be null
908      * @param bound true if the association is to be a "bound" association
909      * @param indexed true if the collection should be indexed
910      * @param unique true if the collection should not allow duplicate elements
911      * @param ordered true if the collection should iterate over elements in <i>insertion-order</i>
912      * @param sorted true if the collection should iterate over elements in ascending element order,
913      *    sorted according to the <i>natural ordering</i> of its elements (see Comparable), or by a Comparator
914      *    provided at creation time
915      * @return <code>true</code> if the set of associations
916      *    changed as a result of this call
917      */
918     public boolean associate(final InterfaceDescription id, final Cardinality cardinality, final boolean bound,
919                              final boolean indexed, final boolean unique, final boolean ordered, final boolean sorted)
920     {
921         Association a = new Association(id, id.getUpper(), cardinality, bound, indexed, unique, ordered, sorted);
922         return addAssociation(a);
923     }
924 
925     /**
926      * Add a new association to the set of associations for this
927      * class description to the specified interface with the specified
928      * parameters.
929      *
930      * @param id interface description, must not be null
931      * @param roleName role name
932      * @param cardinality cardinality, must not be null
933      * @param indexed true if the collection should be indexed
934      * @param unique true if the collection should not allow duplicate elements
935      * @param ordered true if the collection should iterate over elements in <i>insertion-order</i>
936      * @param sorted true if the collection should iterate over elements in ascending element order,
937      *    sorted according to the <i>natural ordering</i> of its elements (see Comparable), or by a Comparator
938      *    provided at creation time
939      * @return <code>true</code> if the set of associations
940      *    changed as a result of this call
941      */
942     public boolean associate(final InterfaceDescription id, final String roleName, final Cardinality cardinality,
943                              final boolean indexed, final boolean unique, final boolean ordered, final boolean sorted)
944     {
945         Association a = new Association(id, roleName, cardinality, indexed, unique, ordered, sorted);
946         return addAssociation(a);
947     }
948 
949     /**
950      * Add a new association to the set of associations for this
951      * class description to the specified interface with the specified
952      * parameters.
953      *
954      * @param id interface description, must not be null
955      * @param roleName role name
956      * @param cardinality cardinality, must not be null
957      * @param bound true if the association is to be a "bound" association
958      * @param indexed true if the collection should be indexed
959      * @param unique true if the collection should not allow duplicate elements
960      * @param ordered true if the collection should iterate over elements in <i>insertion-order</i>
961      * @param sorted true if the collection should iterate over elements in ascending element order,
962      *    sorted according to the <i>natural ordering</i> of its elements (see Comparable), or by a Comparator
963      *    provided at creation time
964      * @return <code>true</code> if the set of associations
965      *    changed as a result of this call
966      */
967     public boolean associate(final InterfaceDescription id, final String roleName, final Cardinality cardinality,
968                              final boolean bound,
969                              final boolean indexed, final boolean unique, final boolean ordered, final boolean sorted)
970     {
971         Association a = new Association(id, roleName, cardinality, bound, indexed, unique, ordered, sorted);
972         return addAssociation(a);
973     }
974 }