Skip to content

Method: addName(String)

1: package de.fhdw.wtf.generator.java.generatorModel;
2:
3: /**
4: * A GenQualifiedPackage represents a full qualified package. It is a concatenation of multiple GenPackages.
5: */
6: public final class GenQualifiedPackage extends GenPackage {
7:         
8:         /**
9:          * The beginning of this qualified package.
10:          */
11:         private final GenUnqualifiedPackage first;
12:         
13:         /**
14:          * The rest of this qualified package.
15:          */
16:         private final GenPackage rest;
17:         
18:         /**
19:          * The symbol to separate unqualified packages.
20:          */
21:         private static final String JAVA_PACKAGE_SEPARATOR = ".";
22:         
23:         /**
24:          * Instantiates a new GenQualifiedPackage with the given parameters.
25:          *
26:          * @param first
27:          * The {@link GenUnqualifiedPackage} that is the begin of this package.
28:          * @param rest
29:          * The rest of this qualified package.
30:          */
31:         private GenQualifiedPackage(final GenUnqualifiedPackage first, final GenPackage rest) {
32:                 super();
33:                 this.first = first;
34:                 this.rest = rest;
35:         }
36:         
37:         /**
38:          * Returns a new instance of {@link GenQualifiedPackage} and copies all attribute-values from
39:          * <code>packageToCopy</code>.
40:          *
41:          * @param packageToCopy
42:          * The {@link GenQualifiedPackage} to copy attribute-values from.
43:          */
44:         private GenQualifiedPackage(final GenQualifiedPackage packageToCopy) {
45:                 super();
46:                 this.first = (GenUnqualifiedPackage) packageToCopy.getFirst().copy();
47:                 this.rest = packageToCopy.getRest().copy();
48:         }
49:         
50:         /**
51:          * Creates a new GenQualifiedPackage with the given parameters.
52:          *
53:          * @param first
54:          * The {@link GenUnqualifiedPackage} that is the begin of this package.
55:          * @param rest
56:          * The rest of this qualified package.
57:          * @return {@link GenQualifiedPackage}
58:          */
59:         public static GenQualifiedPackage create(final GenUnqualifiedPackage first, final GenPackage rest) {
60:                 return new GenQualifiedPackage(first, rest);
61:         }
62:         
63:         @Override
64:         public GenPackage addName(final String name) {
65:                 return this.addPackage(GenUnqualifiedPackage.create(name));
66:         }
67:         
68:         @Override
69:         public String toString() {
70:                 String result = this.getFirst().toString();
71:                 result += JAVA_PACKAGE_SEPARATOR;
72:                 result += this.getRest().toString();
73:                 return result;
74:         }
75:         
76:         @Override
77:         public GenPackage addPackage(final GenPackage packag) {
78:                 return GenQualifiedPackage.create(this.getFirst(), this.getRest().addPackage(packag));
79:         }
80:         
81:         /**
82:          * Returns the beginning of this qualified package.
83:          *
84:          * @return {@link GenUnqualifiedPackage}
85:          */
86:         public GenUnqualifiedPackage getFirst() {
87:                 return this.first;
88:         }
89:         
90:         /**
91:          * Returns the rest of this qualified package.
92:          *
93:          * @return {@link GenPackage}
94:          */
95:         public GenPackage getRest() {
96:                 return this.rest;
97:         }
98:         
99:         @Override
100:         public GenPackage copy() {
101:                 return new GenQualifiedPackage(this);
102:         }
103:         
104: }