package cache;

import java.util.HashMap;

public class Cache {
	private HashMap<String,RequestedObject> hashmap;
	private int capacity;
	
	public Cache(HashMap<String,RequestedObject> hashmap,int capacity)
	{
		this.hashmap = hashmap;
		this.capacity = capacity;
	}

  public Cache(int capacity)
  {
    this.hashmap = new HashMap<String,RequestedObject>(capacity);
    this.capacity = capacity;
  }
	
	public void put(RequestedObject requestObject)
	{
		if(this.hashmap.size()>= capacity)
		{
			remove();
		}
    hashmap.put(requestObject.getName(),requestObject);
    this.capacity++;
	}
	
	private void remove() {
    RequestedObject current = null; 
    int min = Integer.MAX;
    for(RequestedObject request : this.hashmap.values())
    {
      if(request.getAccessCounter() < min)
      {
        min = request.getAccessCounter();
        current = request;  
      }
    }
    hashmap.remove(current.getName());
    this.capacity--;
	}

	public boolean get(RequestedObject requestObject)
	{
    boolean res = true;
		if(this.hashmap.get(requestObject.getName())==null)
		{
      put(requestObject); 	 	
      res = false;
		}
    return res;
	}

}

@@ -488,16 +488,70 @@
 ty)%0A%09%09%7B%0A
+      System.out.println(%22CACHE FULL REMOVING ELEM%22);%0A
 %09%09%09remov
@@ -1125,24 +1125,57 @@
 ==null)%0A%09%09%7B%0A
+      System.out.println(%22FAIL%22)%0A
       put(re

print debug