KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > core > internal > indexing > Reservation


1 /*******************************************************************************
2  * Copyright (c) 2000, 2005 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.core.internal.indexing;
12
13 import java.util.HashMap JavaDoc;
14 import java.util.Map JavaDoc;
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 JavaDoc reservedItems = new HashMap JavaDoc();
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 JavaDoc(slot), new Integer JavaDoc(bytes));
33     }
34
35     public void remove(int slot) {
36         Integer JavaDoc bytes = (Integer JavaDoc) reservedItems.remove(new Integer JavaDoc(slot));
37         if (bytes == null)
38             return;
39         reservedSpace -= bytes.intValue();
40     }
41
42     boolean contains(int slot) {
43         return reservedItems.containsKey(new Integer JavaDoc(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