01: package org.enhydra.kelp.ant.swing;
02:
03: // Class for used for history buttons in help browser
04: // with max 100 URLs
05: // if 101st elem added => first go out
06:
07: import java.net.URL;
08:
09: public class LifoURL {
10: public int currElem;
11: public int maxElemsNum;
12: public URL[] urls;
13:
14: public LifoURL(int max) {
15: currElem = 0;
16: if (max > 100) {
17: maxElemsNum = 100;
18: urls = new URL[100];
19: } else {
20: maxElemsNum = max;
21: urls = new URL[max];
22: }
23: }
24:
25: public void add(URL 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 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: }
|