com.googlecode.ecache.annotations.key.HashCodeCacheKey Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of ehcache-spring-annotations Show documentation
Show all versions of ehcache-spring-annotations Show documentation
Provides a simple model for integrating Ehcache in a Spring project via annotations.
/**
* Copyright 2010 Nicholas Blair, Eric Dalquist
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.googlecode.ecache.annotations.key;
import java.io.Serializable;
/**
*
* Cache key which value is based on a pre-calculated hash code.
*
*
* @author Alex Ruiz
*/
public final class HashCodeCacheKey implements Serializable {
private static final long serialVersionUID = 3904677167731454262L;
/**
* Number that helps keep the uniqueness of this key.
*/
private long checkSum;
/**
* Pre-calculated hash code.
*/
private int hashCode;
/**
* Construct a HashCodeCacheKey
.
*/
public HashCodeCacheKey() {
super();
}
/**
* Construct a HashCodeCacheKey
.
*
* @param newCheckSum
* the number that helps keep the uniqueness of this key
* @param newHashCode
* the pre-calculated hash code
*/
public HashCodeCacheKey(long newCheckSum, int newHashCode) {
this();
setCheckSum(newCheckSum);
setHashCode(newHashCode);
}
/**
* @see Object#equals(Object)
*/
@Override
public boolean equals(Object obj) {
if (this == obj) return true;
if (!(obj instanceof HashCodeCacheKey)) return false;
HashCodeCacheKey other = (HashCodeCacheKey) obj;
if (checkSum != other.checkSum) return false;
if (hashCode != other.hashCode) return false;
return true;
}
/**
* @return the number that helps keep the uniqueness of this key
*/
public long getCheckSum() {
return checkSum;
}
/**
* @return the pre-calculated hash code
*/
public int getHashCode() {
return hashCode;
}
/**
* @see Object#hashCode()
*/
@Override
public int hashCode() {
return getHashCode();
}
/**
* Sets the number that helps keep the uniqueness of this key.
*
* @param newCheckSum
* the new number
*/
public void setCheckSum(long newCheckSum) {
checkSum = newCheckSum;
}
/**
* Sets the pre-calculated hash code.
*
* @param newHashCode
* the new hash code
*/
public void setHashCode(int newHashCode) {
hashCode = newHashCode;
}
/**
* @see Object#toString()
*/
@Override
public String toString() {
return getHashCode() + "|" + getCheckSum();
}
}