Advertisement
Deerenaros

Simple memory manager in java

Jan 6th, 2016
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.50 KB | None | 0 0
  1. public class MemoryManager {
  2.     private HashMap<String, Object> heap = new HashMap<String, Object>();
  3.     private Integer maxSize = 0;
  4.  
  5.     public class LimitIsExceeded extends Exception {
  6.     }
  7.  
  8.     public MemoryManager(int maxSize) {
  9.         this.maxSize = maxSize;
  10.     }
  11.  
  12.     public void let(string name, object value) throws LimitIsExceeded {
  13.         if(heap.size() >= maxSize && !heap.containsKey(name)) {
  14.             throw new LimitIsExceeded();
  15.         } heap.put(name, value);
  16.     }
  17.  
  18.     public void get(string name) {
  19.         heap.get(name);
  20.     }
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement