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