2012-04-12 10:39:01 +02:00
|
|
|
package io.netty.util;
|
|
|
|
|
|
|
|
import java.io.Serializable;
|
|
|
|
import java.util.concurrent.ConcurrentHashMap;
|
|
|
|
import java.util.concurrent.ConcurrentMap;
|
|
|
|
|
|
|
|
public final class AttributeKey<T> implements Serializable, Comparable<AttributeKey<T>> {
|
|
|
|
|
|
|
|
private static final long serialVersionUID = 2783354860083517323L;
|
|
|
|
|
|
|
|
private static final ConcurrentMap<String, Boolean> names = new ConcurrentHashMap<String, Boolean>();
|
|
|
|
|
|
|
|
private final String name;
|
|
|
|
private final Class<T> valueType;
|
2012-05-12 17:40:52 +02:00
|
|
|
private final String strVal;
|
2012-04-12 10:39:01 +02:00
|
|
|
|
|
|
|
public AttributeKey(String name, Class<T> valueType) {
|
|
|
|
if (name == null) {
|
|
|
|
throw new NullPointerException("name");
|
|
|
|
}
|
|
|
|
if (valueType == null) {
|
|
|
|
throw new NullPointerException("valueType");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (names.putIfAbsent(name, Boolean.TRUE) != null) {
|
|
|
|
throw new IllegalArgumentException("key name already in use: " + name);
|
|
|
|
}
|
|
|
|
|
|
|
|
this.name = name;
|
|
|
|
this.valueType = valueType;
|
2012-05-12 17:40:52 +02:00
|
|
|
strVal = name + '[' + valueType.getSimpleName() + ']';
|
2012-04-12 10:39:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public String name() {
|
|
|
|
return name;
|
|
|
|
}
|
|
|
|
|
|
|
|
public Class<T> valueType() {
|
|
|
|
return valueType;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int compareTo(AttributeKey<T> o) {
|
|
|
|
return name().compareTo(o.name());
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String toString() {
|
2012-05-12 17:40:52 +02:00
|
|
|
return strVal;
|
2012-04-12 10:39:01 +02:00
|
|
|
}
|
|
|
|
}
|