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 * Description of the Class
027 */
028public class GroupAttrName<T>
029    implements Serializable
030{
031    /** Don't change */
032    private static final long serialVersionUID = 1586079686300744198L;
033
034    /** Description of the Field */
035    public final GroupId groupId;
036
037    /** the name of the attribute */
038    public final T attrName;
039
040    /**
041     * Constructor for the GroupAttrName object
042     * @param groupId
043     * @param attrName
044     */
045    public GroupAttrName( final GroupId groupId, final T attrName )
046    {
047        this.groupId = groupId;
048        this.attrName = attrName;
049
050        if ( groupId == null )
051        {
052            throw new IllegalArgumentException( "groupId must not be null." );
053        }
054    }
055
056    /**
057     * Tests object equality.
058     * @param obj The <code>GroupAttrName</code> instance to test.
059     * @return Whether equal.
060     */
061    @Override
062    public boolean equals( final Object obj )
063    {
064        if (!(obj instanceof GroupAttrName))
065        {
066            return false;
067        }
068        final GroupAttrName<?> to = (GroupAttrName<?>) obj;
069
070        if (groupId.equals( to.groupId ))
071        {
072            return Objects.equals(attrName, to.attrName);
073        }
074
075        return false;
076    }
077
078    /**
079     * @return A hash code based on the hash code of @ #groupid} and {@link #attrName}.
080     */
081    @Override
082    public int hashCode()
083    {
084        return Objects.hash(groupId, attrName);
085    }
086
087    /**
088     * @return the cached value.
089     */
090    @Override
091    public String toString()
092    {
093        return String.format("GAN:%s:%s", groupId, Objects.toString(attrName, ""));
094    }
095
096}