| 22 | |
| 23 | |
| 24 | public class Keyword implements IFn, Comparable, Named, Serializable, IHashEq { |
| 25 | |
| 26 | private static final long serialVersionUID = -2105088845257724163L; |
| 27 | |
| 28 | private static ConcurrentHashMap<Symbol, Reference<Keyword>> table = new ConcurrentHashMap(); |
| 29 | static final ReferenceQueue rq = new ReferenceQueue(); |
| 30 | public final Symbol sym; |
| 31 | final int hasheq; |
| 32 | transient String _str; |
| 33 | |
| 34 | public 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 | |
| 55 | public static Keyword intern(String ns, String name){ |
| 56 | return intern(Symbol.intern(ns, name)); |
| 57 | } |
| 58 | |
| 59 | public static Keyword intern(String nsname){ |
| 60 | return intern(Symbol.intern(nsname)); |
| 61 | } |
| 62 | |
| 63 | private Keyword(Symbol sym){ |
| 64 | this.sym = sym; |
| 65 | hasheq = sym.hasheq() + 0x9e3779b9; |
| 66 | } |
| 67 | |
| 68 | public 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 | |
| 76 | public static Keyword find(String ns, String name){ |
| 77 | return find(Symbol.intern(ns, name)); |
| 78 | } |
| 79 | |
| 80 | public static Keyword find(String nsname){ |
| 81 | return find(Symbol.intern(nsname)); |
nothing calls this directly
no outgoing calls
no test coverage detected