MCPcopy Index your code
hub / github.com/clojure/clojure / Keyword

Class Keyword

src/jvm/clojure/lang/Keyword.java:24–267  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

22
23
24public class Keyword implements IFn, Comparable, Named, Serializable, IHashEq {
25
26private static final long serialVersionUID = -2105088845257724163L;
27
28private static ConcurrentHashMap<Symbol, Reference<Keyword>> table = new ConcurrentHashMap();
29static final ReferenceQueue rq = new ReferenceQueue();
30public final Symbol sym;
31final int hasheq;
32transient String _str;
33
34public static Keyword intern(Symbol sym){
35 Keyword k = null;
36 Reference<Keyword> existingRef = table.get(sym);
37 if(existingRef == null)
38 {
39 Util.clearCache(rq, table);
40 if(sym.meta() != null)
41 sym = (Symbol) sym.withMeta(null);
42 k = new Keyword(sym);
43 existingRef = table.putIfAbsent(sym, new WeakReference<Keyword>(k, rq));
44 }
45 if(existingRef == null)
46 return k;
47 Keyword existingk = existingRef.get();
48 if(existingk != null)
49 return existingk;
50 //entry died in the interim, do over
51 table.remove(sym, existingRef);
52 return intern(sym);
53}
54
55public static Keyword intern(String ns, String name){
56 return intern(Symbol.intern(ns, name));
57}
58
59public static Keyword intern(String nsname){
60 return intern(Symbol.intern(nsname));
61}
62
63private Keyword(Symbol sym){
64 this.sym = sym;
65 hasheq = sym.hasheq() + 0x9e3779b9;
66}
67
68public static Keyword find(Symbol sym){
69 Reference<Keyword> ref = table.get(sym);
70 if (ref != null)
71 return ref.get();
72 else
73 return null;
74}
75
76public static Keyword find(String ns, String name){
77 return find(Symbol.intern(ns, name));
78}
79
80public static Keyword find(String nsname){
81 return find(Symbol.intern(nsname));

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected