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 * Used to avoid name conflict when group cache items are mixed with non-group cache items in the 026 * same cache. 027 */ 028public class GroupId 029 implements Serializable 030{ 031 /** Don't change. */ 032 private static final long serialVersionUID = 4626368486444860133L; 033 034 /** Description of the Field */ 035 public final String groupName; 036 037 /** the name of the region. */ 038 public final String cacheName; 039 040 /** Cached toString value. */ 041 private String toString; 042 043 /** 044 * Constructor for the GroupId object 045 * <p> 046 * @param cacheName 047 * @param groupName 048 */ 049 public GroupId( String cacheName, String groupName ) 050 { 051 this.cacheName = cacheName; 052 this.groupName = groupName; 053 054 if ( cacheName == null ) 055 { 056 throw new IllegalArgumentException( "cacheName must not be null." ); 057 } 058 if ( groupName == null ) 059 { 060 throw new IllegalArgumentException( "groupName must not be null." ); 061 } 062 } 063 064 /** 065 * @param obj 066 * @return cacheName.equals( g.cacheName ) &&groupName.equals( g.groupName ); 067 */ 068 @Override 069 public boolean equals( Object obj ) 070 { 071 if ( obj == null || !( obj instanceof GroupId ) ) 072 { 073 return false; 074 } 075 GroupId g = (GroupId) obj; 076 return cacheName.equals( g.cacheName ) && groupName.equals( g.groupName ); 077 } 078 079 /** 080 * @return cacheName.hashCode() + groupName.hashCode(); 081 */ 082 @Override 083 public int hashCode() 084 { 085 return cacheName.hashCode() + groupName.hashCode(); 086 } 087 088 /** 089 * Caches the value. 090 * <p> 091 * @return debugging string. 092 */ 093 @Override 094 public String toString() 095 { 096 if ( toString == null ) 097 { 098 toString = "[groupId=" + cacheName + ", " + groupName + ']'; 099 } 100 101 return toString; 102 } 103}