1 package org.apache.commons.jcs.engine.control.group;
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 java.io.Serializable;
23
24 /**
25 * Description of the Class
26 */
27 public class GroupAttrName<T>
28 implements Serializable
29 {
30 /** Don't change */
31 private static final long serialVersionUID = 1586079686300744198L;
32
33 /** Description of the Field */
34 public final GroupId groupId;
35
36 /** the name of the attribute */
37 public final T attrName;
38
39 /** Cached toString value */
40 private String toString;
41
42 /**
43 * Constructor for the GroupAttrName object
44 * @param groupId
45 * @param attrName
46 */
47 public GroupAttrName( GroupId groupId, T attrName )
48 {
49 this.groupId = groupId;
50 this.attrName = attrName;
51
52 if ( groupId == null )
53 {
54 throw new IllegalArgumentException( "groupId must not be null." );
55 }
56 }
57
58 /**
59 * Tests object equality.
60 * @param obj The <code>GroupAttrName</code> instance to test.
61 * @return Whether equal.
62 */
63 @Override
64 public boolean equals( Object obj )
65 {
66 if ( obj == null || !( obj instanceof GroupAttrName ) )
67 {
68 return false;
69 }
70 GroupAttrName<?> to = (GroupAttrName<?>) obj;
71
72 if (groupId.equals( to.groupId ))
73 {
74 if (attrName == null && to.attrName == null)
75 {
76 return true;
77 }
78 else if (attrName == null || to.attrName == null)
79 {
80 return false;
81 }
82
83 return attrName.equals( to.attrName );
84 }
85
86 return false;
87 }
88
89 /**
90 * @return A hash code based on the hash code of @ #groupid} and {@link #attrName}.
91 */
92 @Override
93 public int hashCode()
94 {
95 if (attrName == null)
96 {
97 return groupId.hashCode();
98 }
99
100 return groupId.hashCode() ^ attrName.hashCode();
101 }
102
103 /**
104 * @return the cached value.
105 */
106 @Override
107 public String toString()
108 {
109 if ( toString == null )
110 {
111 toString = "[GAN: groupId=" + groupId + ", attrName=" + attrName + "]";
112 }
113
114 return toString;
115 }
116
117 }