PObject This is the base class for several objects in the PCGen database.
| 45 | * This is the base class for several objects in the PCGen database. |
| 46 | */ |
| 47 | public class PObject extends CDOMObject |
| 48 | implements Cloneable, Serializable, Comparable<Object>, KeyedListContainer, QualifyingObject |
| 49 | { |
| 50 | |
| 51 | private HiddenTypeFacet hiddenTypeFacet = FacetLibrary.getFacet(HiddenTypeFacet.class); |
| 52 | |
| 53 | /** Standard serialVersionUID for Serializable objects */ |
| 54 | private static final long serialVersionUID = 1; |
| 55 | |
| 56 | private final Class<?> myClass = getClass(); |
| 57 | |
| 58 | /* ************ |
| 59 | * Methods |
| 60 | * ************/ |
| 61 | |
| 62 | /** |
| 63 | * if a class implements the Cloneable interface then it should have a |
| 64 | * public" 'clone ()' method It should be declared to throw |
| 65 | * CloneNotSupportedException', but subclasses do not need the "throws" |
| 66 | * declaration unless their 'clone ()' method will throw the exception |
| 67 | * Thus subclasses can decide to not support 'Cloneable' by implementing |
| 68 | * the 'clone ()' method to throw 'CloneNotSupportedException' |
| 69 | * If this rule were ignored and the parent did not have the "throws" |
| 70 | * declaration then subclasses that should not be cloned would be forced |
| 71 | * to implement a trivial 'clone ()' to satisfy inheritance |
| 72 | * final" classes implementing 'Cloneable' should not be declared to |
| 73 | * throw 'CloneNotSupportedException" because their implementation of |
| 74 | * clone ()' should be a fully functional method that will not |
| 75 | * throw the exception. |
| 76 | * @return cloned object |
| 77 | * @throws CloneNotSupportedException |
| 78 | */ |
| 79 | @Override |
| 80 | public PObject clone() throws CloneNotSupportedException |
| 81 | { |
| 82 | return (PObject) super.clone(); |
| 83 | } |
| 84 | |
| 85 | /** |
| 86 | * Compares the keys of the object. |
| 87 | */ |
| 88 | @Override |
| 89 | public int compareTo(final Object obj) |
| 90 | { |
| 91 | if (obj != null) |
| 92 | { |
| 93 | //this should throw a ClassCastException for non-PObjects, like the Comparable interface calls for |
| 94 | return this.getKeyName().compareToIgnoreCase(((PObject) obj).getKeyName()); |
| 95 | } |
| 96 | return 1; |
| 97 | } |
| 98 | |
| 99 | @Override |
| 100 | public boolean equals(final Object obj) |
| 101 | { |
| 102 | return obj instanceof PObject && getKeyName().equalsIgnoreCase(((PObject) obj).getKeyName()); |
| 103 | } |
| 104 |