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