1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18 package org.apache.jetspeed.capabilities.impl;
19
20 import org.apache.jetspeed.capabilities.Capability;
21
22 /***
23 * Capability implementation class.
24 *
25 * @author <a href="mailto:roger.ruttimann@earthlink.net">Roger Ruttimann</a>
26 * @version $Id: CapabilityImpl.java 517719 2007-03-13 15:05:48Z ate $
27 */
28
29 public class CapabilityImpl implements Capability
30 {
31 private int capabilityId;
32 private String name;
33
34 /* (non-Javadoc)
35 * @see org.apache.jetspeed.om.registry.Capability#setCapabilityId(int)
36 */
37 public void setCapabilityId(int id)
38 {
39 this.capabilityId = id;
40 }
41
42 /* (non-Javadoc)
43 * @see org.apache.jetspeed.om.registry.Capability#getCapabilityId()
44 */
45 public int getCapabilityId()
46 {
47 return this.capabilityId;
48 }
49
50 /* (non-Javadoc)
51 * @see org.apache.jetspeed.om.registry.Capability#setName(java.lang.String)
52 */
53 public void setName(String name)
54 {
55 this.name = name;
56 }
57
58 /* (non-Javadoc)
59 * @see org.apache.jetspeed.om.registry.Capability#getName()
60 */
61 public String getName()
62 {
63 return this.name;
64 }
65
66
67 /***
68 * Implements the hashCode calculation so two different objects with the content return the same hashcode....
69 */
70 public int hashCode()
71 {
72 return name.hashCode();
73 }
74
75 /***
76 * Implements the equals operation so that 2 elements are equal if
77 * all their member values are equal.
78 *
79 *
80 * @param object to compare this one with
81 * @return true if both objects represent the same (logical) content
82 */
83 public boolean equals(Object object)
84 {
85 if (!(object instanceof Capability))
86 {
87 return false;
88 }
89 if (this == object)
90 return true;
91 // Don't check the ID - id is only set through OJB so this would not recognize equality correctly
92 /* if (this.capabilityId != ((Capability)object).getCapabilityId())
93 return false;
94 */
95 String oName = ((Capability)object).getName();
96 if (
97 (oName == null) && (name == null)
98 ||
99 (oName == name)
100 ||
101 ((oName != null) && (oName.equals(name)))
102 )
103 return true;
104 return false;
105 }
106
107 }