View Javadoc
1   /*******************************************************************************
2    * Copyright 2012 pw999
3    * 
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    * 
8    *   http://www.apache.org/licenses/LICENSE-2.0
9    * 
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   ******************************************************************************/
16  package net.sf.oqt.model;
17  
18  import java.io.Serializable;
19  import java.util.ArrayList;
20  import java.util.List;
21  
22  /**
23   * Models a java package.
24   * 
25   * @author phillip
26   * 
27   */
28  public class PackageVO implements Serializable, Comparable<PackageVO> {
29  
30      /**
31       * UID
32       */
33      private static final long serialVersionUID = -7053438277422696830L;
34  
35      private final String name;
36  
37      private final List<EntityVO> entities = new ArrayList<EntityVO>();
38  
39      public PackageVO(final String name) {
40          this.name = name;
41      }
42  
43      public final String getName() {
44          return name;
45      }
46  
47      public final List<EntityVO> getEntities() {
48          return entities;
49      }
50  
51      public boolean isSubpackage(final PackageVO subPackage) {
52          return (subPackage.getName().startsWith(getName() + ".")) && (subPackage.getName().length() > getName().length());
53      }
54  
55      @Override
56      public int compareTo(final PackageVO o) {
57          return getName().compareToIgnoreCase(o.getName());
58      }
59  
60      @Override
61      public String toString() {
62          return getClass().getSimpleName() + "/" + getName();
63      }
64  
65      @Override
66      public int hashCode() {
67          final int prime = 31;
68          int result = 1;
69          result = prime * result + ((name == null) ? 0 : name.hashCode());
70          return result;
71      }
72  
73      @Override
74      public boolean equals(final Object obj) {
75          if (obj instanceof PackageVO) {
76              return ((PackageVO) obj).getName().equalsIgnoreCase(getName());
77          }
78          return super.equals(obj);
79      }
80  
81      
82      
83  }