01: /*
02: * This file is part of PFIXCORE.
03: *
04: * PFIXCORE is free software; you can redistribute it and/or modify
05: * it under the terms of the GNU Lesser General Public License as published by
06: * the Free Software Foundation; either version 2 of the License, or
07: * (at your option) any later version.
08: *
09: * PFIXCORE is distributed in the hope that it will be useful,
10: * but WITHOUT ANY WARRANTY; without even the implied warranty of
11: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12: * GNU Lesser General Public License for more details.
13: *
14: * You should have received a copy of the GNU Lesser General Public License
15: * along with PFIXCORE; if not, write to the Free Software
16: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17: */
18:
19: package de.schlund.pfixxml.util;
20:
21: import java.util.Iterator;
22: import java.util.Map;
23:
24: /**
25: * Describe class RefCountingCollectionIterator here.
26: *
27: *
28: * Created: Wed Nov 16 00:18:45 2005
29: *
30: * @author <a href="mailto:jtl@schlund.de">Jens Lautenbacher</a>
31: * @version 1.0
32: */
33:
34: public class RefCountingCollectionIterator<E> implements Iterator<E> {
35: Iterator<E> colliter;
36: RefCountingCollection<E> coll;
37: E current;
38: Map<E, Integer> map;
39:
40: RefCountingCollectionIterator(RefCountingCollection<E> coll,
41: Map<E, Integer> map) {
42: this .map = map;
43: this .coll = coll;
44: colliter = (Iterator<E>) map.keySet().iterator();
45: }
46:
47: public boolean hasNext() {
48: return colliter.hasNext();
49: }
50:
51: public E next() {
52: current = colliter.next();
53: return current;
54: }
55:
56: public void remove() {
57: remove(map.get(current));
58: }
59:
60: public void remove(int count) {
61: int current_count = coll.getCardinality(current);
62: if (count < current_count) {
63: coll.remove(current, count);
64: } else {
65: colliter.remove();
66: coll.fullsize = coll.fullsize - current_count;
67: }
68: }
69: }
|