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 * Used to avoid name conflict when group cache items are mixed with non-group cache items in the
27 * same cache.
28 */
29 public class GroupId
30 implements Serializable
31 {
32 /** Don't change. */
33 private static final long serialVersionUID = 4626368486444860133L;
34
35 /** Description of the Field */
36 public final String groupName;
37
38 /** the name of the region. */
39 public final String cacheName;
40
41 /**
42 * Constructor for the GroupId object
43 * <p>
44 * @param cacheName
45 * @param groupName
46 */
47 public GroupId( final String cacheName, final String groupName )
48 {
49 this.cacheName = cacheName;
50 this.groupName = groupName;
51
52 if ( cacheName == null )
53 {
54 throw new IllegalArgumentException( "cacheName must not be null." );
55 }
56 if ( groupName == null )
57 {
58 throw new IllegalArgumentException( "groupName must not be null." );
59 }
60 }
61
62 /**
63 * @param obj
64 * @return cacheName.equals( g.cacheName ) &&groupName.equals( g.groupName );
65 */
66 @Override
67 public boolean equals( final Object obj )
68 {
69 if (!(obj instanceof GroupId))
70 {
71 return false;
72 }
73 final GroupId g = (GroupId) obj;
74 return cacheName.equals( g.cacheName ) && groupName.equals( g.groupName );
75 }
76
77 /**
78 * @return Objects.hash(cacheName, groupName);
79 */
80 @Override
81 public int hashCode()
82 {
83 return Objects.hash(cacheName, groupName);
84 }
85
86 /**
87 * Convert to string
88 *
89 * @return the string representation of this ID.
90 */
91 @Override
92 public String toString()
93 {
94 return String.format("[groupId=%s, %s]", cacheName, groupName);
95 }
96 }