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