2 package org
.de
.metux
.util
;
4 import java
.util
.Hashtable
;
5 import java
.util
.Enumeration
;
7 public class VersionStack
9 Hashtable index
= new Hashtable();
15 public VersionStack(String
[] v
)
17 for (int x
=0; x
<v
.length
; x
++)
19 add(new Version(v
[x
]));
22 public VersionStack(Version
[] v
)
24 for (int x
=0; x
<v
.length
; x
++)
29 public Version
[] getVersions()
34 Version list
[] = new Version
[index
.size()];
36 for (Enumeration e
=index
.keys(); e
.hasMoreElements();)
37 list
[x
++] = (Version
)index
.get((Version
)e
.nextElement());
41 public String
toString()
47 for (Enumeration e
=index
.keys(); e
.hasMoreElements();)
49 Version v
= (Version
)index
.get((Version
)e
.nextElement());
50 s
= ((s
==null)?
"":s
+" ")+v
;
56 public boolean containsVersion(Version v
)
58 Version v2
= (Version
)index
.get(v
);
65 throw new RuntimeException("ugh: index mismatch: "+v2
+" - "+v
);
68 public boolean add(Version nv
)
74 public Version
[] getLowers(Version delim
)
76 VersionStack st
= new VersionStack();
77 divide(delim
,st
,null);
78 return st
.getVersions();
81 public Version
[] getHighers(Version delim
)
83 VersionStack st
= new VersionStack();
84 divide(delim
,null,st
);
85 return st
.getVersions();
93 public void divide(Version delim
, VersionStack lowers
, VersionStack highers
)
95 for (Enumeration e
=index
.keys(); e
.hasMoreElements(); )
97 Version v
= (Version
)index
.get((Version
)e
.nextElement());
98 switch (v
.compareTo(delim
))
102 if (lowers
!=null) lowers
.add(v
); break;
104 if (highers
!=null) highers
.add(v
); break;