package io.netty.util; import java.io.Serializable; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; public final class AttributeKey implements Serializable, Comparable> { private static final long serialVersionUID = 2783354860083517323L; private static final ConcurrentMap names = new ConcurrentHashMap(); private final String name; private final Class valueType; private final String strVal; public AttributeKey(String name, Class 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; strVal = name + '[' + valueType.getSimpleName() + ']'; } public String name() { return name; } public Class valueType() { return valueType; } @Override public int compareTo(AttributeKey o) { return name().compareTo(o.name()); } @Override public String toString() { return strVal; } }