1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package io.netty.util;
17
18 import io.netty.util.internal.PlatformDependent;
19
20 import java.util.concurrent.ConcurrentMap;
21
22 import static io.netty.util.internal.ObjectUtil.checkNotNull;
23
24
25
26
27
28
29
30
31 @SuppressWarnings({ "UnusedDeclaration", "deprecation" })
32 public final class AttributeKey<T> extends UniqueName {
33
34 @SuppressWarnings("rawtypes")
35 private static final ConcurrentMap<String, AttributeKey> names = PlatformDependent.newConcurrentHashMap();
36
37
38
39
40
41 @SuppressWarnings("unchecked")
42 public static <T> AttributeKey<T> valueOf(String name) {
43 checkNotNull(name, "name");
44 AttributeKey<T> option = names.get(name);
45 if (option == null) {
46 option = new AttributeKey<T>(name);
47 AttributeKey<T> old = names.putIfAbsent(name, option);
48 if (old != null) {
49 option = old;
50 }
51 }
52 return option;
53 }
54
55
56
57
58 public static boolean exists(String name) {
59 checkNotNull(name, "name");
60 return names.containsKey(name);
61 }
62
63
64
65
66
67 @SuppressWarnings("unchecked")
68 public static <T> AttributeKey<T> newInstance(String name) {
69 checkNotNull(name, "name");
70 AttributeKey<T> option = new AttributeKey<T>(name);
71 AttributeKey<T> old = names.putIfAbsent(name, option);
72 if (old != null) {
73 throw new IllegalArgumentException(String.format("'%s' is already in use", name));
74 }
75 return option;
76 }
77
78
79
80
81 @Deprecated
82 public AttributeKey(String name) {
83 super(name);
84 }
85 }