MCPcopy Index your code
hub / github.com/wyouflf/xUtils3 / get

Method get

xutils/src/main/java/org/xutils/cache/LruCache.java:80–126  ·  view source on GitHub ↗

Returns the value for key if it exists in the cache or can be created by #create. If a value was returned, it is moved to the head of the queue. This returns null if a value is not cached and cannot be created.

(K key)

Source from the content-addressed store, hash-verified

78 * be created.
79 */
80 public final V get(K key) {
81 if (key == null) {
82 throw new NullPointerException("key == null");
83 }
84
85 V mapValue;
86 synchronized (this) {
87 mapValue = map.get(key);
88 if (mapValue != null) {
89 hitCount++;
90 return mapValue;
91 }
92 missCount++;
93 }
94
95 /*
96 * Attempt to create a value. This may take a long time, and the map
97 * may be different when create() returns. If a conflicting value was
98 * added to the map while create() was working, we leave that value in
99 * the map and release the created value.
100 */
101
102 V createdValue = create(key);
103 if (createdValue == null) {
104 return null;
105 }
106
107 synchronized (this) {
108 createCount++;
109 mapValue = map.put(key, createdValue);
110
111 if (mapValue != null) {
112 // There was a conflict so undo that last put
113 map.put(key, mapValue);
114 } else {
115 size += safeSizeOf(key, createdValue);
116 }
117 }
118
119 if (mapValue != null) {
120 entryRemoved(false, key, createdValue, mapValue);
121 return mapValue;
122 } else {
123 trimToSize(maxSize);
124 return createdValue;
125 }
126 }
127
128 /**
129 * Caches {@code value} for {@code key}. The value is moved to the head of

Callers

nothing calls this directly

Calls 6

createMethod · 0.95
safeSizeOfMethod · 0.95
entryRemovedMethod · 0.95
trimToSizeMethod · 0.95
getMethod · 0.65
putMethod · 0.45

Tested by

no test coverage detected