1 11 package org.eclipse.core.internal.indexing; 12 13 import java.util.HashMap ; 14 import java.util.Map ; 15 16 public class Reservation { 17 18 protected int freeSlots = 0; 19 protected int freeSpace = 0; 20 protected int reservedSpace = 0; 21 protected int initialEntry = 0; 22 protected Map reservedItems = new HashMap (); 23 24 public Reservation(int freeSpace, int freeSlots, int initialEntry) { 25 this.freeSlots = freeSlots; 26 this.freeSpace = freeSpace; 27 this.initialEntry = initialEntry; 28 } 29 30 public void add(int slot, int bytes) { 31 reservedSpace += bytes; 32 reservedItems.put(new Integer (slot), new Integer (bytes)); 33 } 34 35 public void remove(int slot) { 36 Integer bytes = (Integer ) reservedItems.remove(new Integer (slot)); 37 if (bytes == null) 38 return; 39 reservedSpace -= bytes.intValue(); 40 } 41 42 boolean contains(int slot) { 43 return reservedItems.containsKey(new Integer (slot)); 44 } 45 46 int getFreeSpace() { 47 if (reservedItems.size() >= freeSlots) 48 return 0; 49 return Math.max(0, freeSpace - reservedSpace); 50 } 51 52 public int getInitialEntry() { 53 return initialEntry; 54 } 55 56 public void setInitialEntry(int n) { 57 initialEntry = n; 58 } 59 60 } 61 | Popular Tags |