package org.ehcache.management.providers;
import org.ehcache.Cache;
import org.terracotta.management.registry.Named;
import org.terracotta.management.registry.RequiredContext;
import java.util.Objects;
@RequiredContext({@Named("cacheManagerName"), @Named("cacheName")})
public final class CacheBinding {
private final String alias;
private final Cache<?, ?> cache;
public CacheBinding(String alias, Cache<?, ?> cache) {
this.alias = Objects.requireNonNull(alias);
this.cache = Objects.requireNonNull(cache);
}
public String getAlias() {
return alias;
}
@SuppressWarnings("unchecked")
public <K, V> Cache<K, V> getCache() {
return (Cache<K, V>) cache;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
CacheBinding that = (CacheBinding) o;
return alias.equals(that.alias) && cache.equals(that.cache);
}
@Override
public int hashCode() {
int result = alias.hashCode();
result = 31 * result + cache.hashCode();
return result;
}
@Override
public String toString() {
return alias;
}
}