KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > kelp > ant > swing > LifoURL


1 package org.enhydra.kelp.ant.swing;
2
3 // Class for used for history buttons in help browser
4
// with max 100 URLs
5
// if 101st elem added => first go out
6

7 import java.net.URL JavaDoc;
8
9 public class LifoURL {
10     public int currElem;
11     public int maxElemsNum;
12     public URL JavaDoc[] urls;
13
14     public LifoURL(int max) {
15         currElem = 0;
16         if (max > 100) {
17             maxElemsNum = 100;
18             urls = new URL JavaDoc[100];
19         } else {
20             maxElemsNum = max;
21             urls = new URL JavaDoc[max];
22         }
23     }
24
25     public void add(URL JavaDoc url) {
26         if (currElem == maxElemsNum) {
27             for (int i = 0; i < maxElemsNum-2; i++)
28                 urls[i] = urls[i+1];
29             currElem--;
30         }
31         urls[currElem++] = url;
32     }
33
34     public URL JavaDoc remove() {
35         if (currElem == 0)
36             return null;
37         return urls[--currElem];
38     }
39
40     public boolean isEmpty() {
41         if (currElem == 0)
42             return true;
43         return false;
44     }
45
46 }
47         
Popular Tags