View Javadoc
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&ouml;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       * {@inheritDoc}
85       */
86      @Override
87      public String getPath() {
88          return toString();
89      }
90  
91      /**
92       * {@inheritDoc}
93       */
94      @Override
95      public String toString() {
96          return packageName;
97      }
98  
99      /**
100      * {@inheritDoc}
101      */
102     @Override
103     public boolean isEqualToPath(final String path) {
104 
105         // Check sanity
106         Validate.notNull(path, "path");
107 
108         // All done.
109         return toString().equals(path);
110     }
111 
112     /**
113      * <p>Compares the string representations of this PackageLocation and the supplied SortableLocation.</p>
114      * {@inheritDoc}
115      */
116     @Override
117     public int compareTo(final SortableLocation that) {
118 
119         // Check sanity
120         Validate.notNull(that, "that");
121         if (this == that) {
122             return 0;
123         }
124 
125         // Delegate
126         return this.toString().compareTo(that.toString());
127     }
128 }