Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package reghzy.carrottools.utils;
- public abstract class KVObjEqualityCache<K, V> {
- private K lastAccessedKey;
- private V lastAccessedValue;
- public V get(K key) {
- if (key == null) {
- this.lastAccessedKey = null;
- this.lastAccessedValue = getValue(null);
- }
- else if (this.lastAccessedKey == null) {
- this.lastAccessedKey = key;
- this.lastAccessedValue = getValue(key);
- }
- else if (this.lastAccessedKey == key) {
- if (this.lastAccessedValue == null) {
- this.lastAccessedValue = getValue(key);
- }
- }
- else if (this.lastAccessedKey.equals(key)) {
- if (this.lastAccessedValue == null) {
- this.lastAccessedValue = getValue(key);
- }
- this.lastAccessedKey = key;
- }
- else {
- this.lastAccessedKey = key;
- this.lastAccessedValue = getValue(key);
- }
- return this.lastAccessedValue;
- }
- public abstract V getValue(K key);
- }
Add Comment
Please, Sign In to add comment