bobmarley12345

map last access cache

Oct 14th, 2021 (edited)
390
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.07 KB | None | 0 0
  1. package reghzy.carrottools.utils;
  2.  
  3. public abstract class KVObjEqualityCache<K, V> {
  4.     private K lastAccessedKey;
  5.     private V lastAccessedValue;
  6.  
  7.     public V get(K key) {
  8.         if (key == null) {
  9.             this.lastAccessedKey = null;
  10.             this.lastAccessedValue = getValue(null);
  11.         }
  12.         else if (this.lastAccessedKey == null) {
  13.             this.lastAccessedKey = key;
  14.             this.lastAccessedValue = getValue(key);
  15.         }
  16.         else if (this.lastAccessedKey == key) {
  17.             if (this.lastAccessedValue == null) {
  18.                 this.lastAccessedValue = getValue(key);
  19.             }
  20.         }
  21.         else if (this.lastAccessedKey.equals(key)) {
  22.             if (this.lastAccessedValue == null) {
  23.                 this.lastAccessedValue = getValue(key);
  24.             }
  25.  
  26.             this.lastAccessedKey = key;
  27.         }
  28.         else {
  29.             this.lastAccessedKey = key;
  30.             this.lastAccessedValue = getValue(key);
  31.         }
  32.  
  33.         return this.lastAccessedValue;
  34.     }
  35.  
  36.     public abstract V getValue(K key);
  37. }
Add Comment
Please, Sign In to add comment