001package org.apache.commons.jcs.engine.control.group; 002 003/* 004 * Licensed to the Apache Software Foundation (ASF) under one 005 * or more contributor license agreements. See the NOTICE file 006 * distributed with this work for additional information 007 * regarding copyright ownership. The ASF licenses this file 008 * to you under the Apache License, Version 2.0 (the 009 * "License"); you may not use this file except in compliance 010 * with the License. You may obtain a copy of the License at 011 * 012 * http://www.apache.org/licenses/LICENSE-2.0 013 * 014 * Unless required by applicable law or agreed to in writing, 015 * software distributed under the License is distributed on an 016 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 017 * KIND, either express or implied. See the License for the 018 * specific language governing permissions and limitations 019 * under the License. 020 */ 021 022import java.io.Serializable; 023 024/** 025 * Description of the Class 026 */ 027public class GroupAttrName<T> 028 implements Serializable 029{ 030 /** Don't change */ 031 private static final long serialVersionUID = 1586079686300744198L; 032 033 /** Description of the Field */ 034 public final GroupId groupId; 035 036 /** the name of the attribute */ 037 public final T attrName; 038 039 /** Cached toString value */ 040 private String toString; 041 042 /** 043 * Constructor for the GroupAttrName object 044 * @param groupId 045 * @param attrName 046 */ 047 public GroupAttrName( GroupId groupId, T attrName ) 048 { 049 this.groupId = groupId; 050 this.attrName = attrName; 051 052 if ( groupId == null ) 053 { 054 throw new IllegalArgumentException( "groupId must not be null." ); 055 } 056 } 057 058 /** 059 * Tests object equality. 060 * @param obj The <code>GroupAttrName</code> instance to test. 061 * @return Whether equal. 062 */ 063 @Override 064 public boolean equals( Object obj ) 065 { 066 if ( obj == null || !( obj instanceof GroupAttrName ) ) 067 { 068 return false; 069 } 070 GroupAttrName<?> to = (GroupAttrName<?>) obj; 071 072 if (groupId.equals( to.groupId )) 073 { 074 if (attrName == null && to.attrName == null) 075 { 076 return true; 077 } 078 else if (attrName == null || to.attrName == null) 079 { 080 return false; 081 } 082 083 return attrName.equals( to.attrName ); 084 } 085 086 return false; 087 } 088 089 /** 090 * @return A hash code based on the hash code of @ #groupid} and {@link #attrName}. 091 */ 092 @Override 093 public int hashCode() 094 { 095 if (attrName == null) 096 { 097 return groupId.hashCode(); 098 } 099 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}