/** * Keeps track of timed objects */ private class TimedEntry<K, V> extends BasicEntry<K, V> { private long mTimestamp; TimedEntry(K pKey, V pValue) { super(pKey, pValue); mTimestamp = System.currentTimeMillis(); } public V setValue(V pValue) { mTimestamp = System.currentTimeMillis(); return super.setValue(pValue); } final boolean isExpired() { return isExpiredBy(System.currentTimeMillis()); } final boolean isExpiredBy(final long pTime) { return pTime > expires(); } final long expires() { return mTimestamp + expiryTime; } } }
/** * Returns the value to which this map maps the specified pKey. Returns * {@code null} if the map contains no mapping for this pKey. A return * value of {@code null} does not <i>necessarily</i> indicate that the * map contains no mapping for the pKey; it's also possible that the map * explicitly maps the pKey to {@code null}. The {@code containsKey} * operation may be used to distinguish these two cases. * * @param pKey pKey whose associated value is to be returned. * @return the value to which this map maps the specified pKey, or * {@code null} if the map contains no mapping for this pKey. * @see #containsKey(java.lang.Object) */ public V get(Object pKey) { TimedEntry<K, V> entry = (TimedEntry<K, V>) entries.get(pKey); if (entry == null) { return null; } else if (entry.isExpired()) { //noinspection SuspiciousMethodCalls entries.remove(pKey); processRemoved(entry); return null; } return entry.getValue(); }
/** * Keeps track of timed objects */ private class TimedEntry<K, V> extends BasicEntry<K, V> { private long mTimestamp; TimedEntry(K pKey, V pValue) { super(pKey, pValue); mTimestamp = System.currentTimeMillis(); } public V setValue(V pValue) { mTimestamp = System.currentTimeMillis(); return super.setValue(pValue); } final boolean isExpired() { return isExpiredBy(System.currentTimeMillis()); } final boolean isExpiredBy(final long pTime) { return pTime > expires(); } final long expires() { return mTimestamp + expiryTime; } } }
/** * Keeps track of timed objects */ private class TimedEntry<K, V> extends BasicEntry<K, V> { private long mTimestamp; TimedEntry(K pKey, V pValue) { super(pKey, pValue); mTimestamp = System.currentTimeMillis(); } public V setValue(V pValue) { mTimestamp = System.currentTimeMillis(); return super.setValue(pValue); } final boolean isExpired() { return isExpiredBy(System.currentTimeMillis()); } final boolean isExpiredBy(final long pTime) { return pTime > expires(); } final long expires() { return mTimestamp + mExpiryTime; } } }
/** * Keeps track of timed objects */ private class TimedEntry<K, V> extends BasicEntry<K, V> { private long mTimestamp; TimedEntry(K pKey, V pValue) { super(pKey, pValue); mTimestamp = System.currentTimeMillis(); } public V setValue(V pValue) { mTimestamp = System.currentTimeMillis(); return super.setValue(pValue); } final boolean isExpired() { return isExpiredBy(System.currentTimeMillis()); } final boolean isExpiredBy(final long pTime) { return pTime > expires(); } final long expires() { return mTimestamp + expiryTime; } } }
/** * Returns the value to which this map maps the specified pKey. Returns * {@code null} if the map contains no mapping for this pKey. A return * value of {@code null} does not <i>necessarily</i> indicate that the * map contains no mapping for the pKey; it's also possible that the map * explicitly maps the pKey to {@code null}. The {@code containsKey} * operation may be used to distinguish these two cases. * * @param pKey pKey whose associated value is to be returned. * @return the value to which this map maps the specified pKey, or * {@code null} if the map contains no mapping for this pKey. * @see #containsKey(java.lang.Object) */ public V get(Object pKey) { TimedEntry<K, V> entry = (TimedEntry<K, V>) entries.get(pKey); if (entry == null) { return null; } else if (entry.isExpired()) { //noinspection SuspiciousMethodCalls entries.remove(pKey); processRemoved(entry); return null; } return entry.getValue(); }
/** * Returns the value to which this map maps the specified pKey. Returns * {@code null} if the map contains no mapping for this pKey. A return * value of {@code null} does not <i>necessarily</i> indicate that the * map contains no mapping for the pKey; it's also possible that the map * explicitly maps the pKey to {@code null}. The {@code containsKey} * operation may be used to distinguish these two cases. * * @param pKey pKey whose associated value is to be returned. * @return the value to which this map maps the specified pKey, or * {@code null} if the map contains no mapping for this pKey. * @see #containsKey(java.lang.Object) */ public V get(Object pKey) { TimedEntry<K, V> entry = (TimedEntry<K, V>) entries.get(pKey); if (entry == null) { return null; } else if (entry.isExpired()) { //noinspection SuspiciousMethodCalls entries.remove(pKey); processRemoved(entry); return null; } return entry.getValue(); }
/** * Returns the value to which this map maps the specified pKey. Returns * {@code null} if the map contains no mapping for this pKey. A return * value of {@code null} does not <i>necessarily</i> indicate that the * map contains no mapping for the pKey; it's also possible that the map * explicitly maps the pKey to {@code null}. The {@code containsKey} * operation may be used to distinguish these two cases. * * @param pKey pKey whose associated value is to be returned. * @return the value to which this map maps the specified pKey, or * {@code null} if the map contains no mapping for this pKey. * @see #containsKey(java.lang.Object) */ public V get(Object pKey) { TimedEntry<K, V> entry = (TimedEntry<K, V>) mEntries.get(pKey); if (entry == null) { return null; } else if (entry.isExpired()) { //noinspection SuspiciousMethodCalls mEntries.remove(pKey); processRemoved(entry); return null; } return entry.getValue(); }