1 package org.codehaus.mojo.jaxb2.schemageneration.postprocessing.javadoc.location;
2
3 /*
4 * Licensed to the Apache Software Foundation (ASF) under one
5 * or more contributor license agreements. See the NOTICE file
6 * distributed with this work for additional information
7 * regarding copyright ownership. The ASF licenses this file
8 * to you under the Apache License, Version 2.0 (the
9 * "License"); you may not use this file except in compliance
10 * with the License. You may obtain a copy of the License at
11 *
12 * http://www.apache.org/licenses/LICENSE-2.0
13 *
14 * Unless required by applicable law or agreed to in writing,
15 * software distributed under the License is distributed on an
16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 * KIND, either express or implied. See the License for the
18 * specific language governing permissions and limitations
19 * under the License.
20 */
21
22 import org.codehaus.mojo.jaxb2.schemageneration.postprocessing.javadoc.SortableLocation;
23 import org.codehaus.mojo.jaxb2.shared.Validate;
24
25 /**
26 * Comparable path structure to locate a particular package within compilation unit.
27 *
28 * @author <a href="mailto:lj@jguru.se">Lennart Jörelid</a>, jGuru Europe AB
29 * @since 2.0
30 */
31 public class PackageLocation implements SortableLocation {
32
33 // Internal state
34 private String packageName;
35
36 /**
37 * Creates a new PackageLocation with the supplied package name.
38 *
39 * @param packageName The name of the package potentially holding JavaDoc. Cannot be {@code null}.
40 */
41 public PackageLocation(final String packageName) {
42
43 // Check sanity
44 Validate.notNull(packageName, "packageName");
45
46 // Assign internal state
47 this.packageName = packageName;
48 }
49
50 /**
51 * Retrieves the name of the package potentially holding JavaDoc.
52 *
53 * @return The name of the package potentially holding JavaDoc. Can be empty, but never {@code null}.
54 */
55 public String getPackageName() {
56 return packageName;
57 }
58
59 /**
60 * {@inheritDoc}
61 */
62 @Override
63 public boolean equals(final Object obj) {
64
65 // Check sanity
66 if (obj == this) {
67 return true;
68 }
69
70 // Delegate
71 return obj instanceof PackageLocation
72 && toString().equals(obj.toString());
73 }
74
75 /**
76 * {@inheritDoc}
77 */
78 @Override
79 public int hashCode() {
80 return toString().hashCode();
81 }
82
83 /**
84 * <strong>Note:</strong> Packages cannot be renamed from a JAXB annotation.
85 * {@inheritDoc}
86 */
87 @Override
88 public String getAnnotationRenamedTo() {
89 return null;
90 }
91
92 /**
93 * {@inheritDoc}
94 */
95 @Override
96 public String getPath() {
97 return toString();
98 }
99
100 /**
101 * {@inheritDoc}
102 */
103 @Override
104 public String toString() {
105 return packageName;
106 }
107
108 /**
109 * {@inheritDoc}
110 */
111 @Override
112 public boolean isEqualToPath(final String path) {
113
114 // Check sanity
115 Validate.notNull(path, "path");
116
117 // All done.
118 return toString().equals(path);
119 }
120
121 /**
122 * <p>Compares the string representations of this PackageLocation and the supplied SortableLocation.</p>
123 * {@inheritDoc}
124 */
125 @Override
126 public int compareTo(final SortableLocation that) {
127
128 // Check sanity
129 Validate.notNull(that, "that");
130 if (this == that) {
131 return 0;
132 }
133
134 // Delegate
135 return this.toString().compareTo(that.toString());
136 }
137 }