From: <the...@us...> - 2003-12-18 15:27:25
|
Update of /cvsroot/junk/junk/WEB-INF/classes/junk/util In directory sc8-pr-cvs1:/tmp/cvs-serv32213 Modified Files: HostMap.java Log Message: HostIteratorProvider related updates Index: HostMap.java =================================================================== RCS file: /cvsroot/junk/junk/WEB-INF/classes/junk/util/HostMap.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** HostMap.java 16 Dec 2003 10:53:31 -0000 1.2 --- HostMap.java 18 Dec 2003 15:27:22 -0000 1.3 *************** *** 33,46 **** * @author Marcus Proest (theevilflow at users dot sf dot net) */ ! public class HostMap extends HashMap implements OnlineIteratorProvider, Map { /** returns an Iterator over the online ip addresses * @return an Iterator over the online ip addresses */ ! public Iterator getOnlineIterator() { ! return new OnlineIterator(this); } /** implements an iterator over the online ip addresses */ ! class OnlineIterator implements Iterator { /** the HashMap containing the ip -> NameOnline values */ private HashMap h; --- 33,50 ---- * @author Marcus Proest (theevilflow at users dot sf dot net) */ ! public class HostMap extends HashMap implements HostIteratorProvider, Map { /** returns an Iterator over the online ip addresses * @return an Iterator over the online ip addresses */ ! public Iterator getOnlineIpStringIterator() { ! return new OnlineIpStringIterator(this); ! } ! ! public Iterator getOnlineComputerIterator() { ! return new OnlineComputerIterator(this); } /** implements an iterator over the online ip addresses */ ! class OnlineIpStringIterator implements Iterator { /** the HashMap containing the ip -> NameOnline values */ private HashMap h; *************** *** 55,59 **** * @param h the HashMap containing the ip -> NameOnline values */ ! private OnlineIterator(HashMap h) { this.h = h; this.keys = this.h.keySet().iterator(); --- 59,63 ---- * @param h the HashMap containing the ip -> NameOnline values */ ! private OnlineIpStringIterator(HashMap h) { this.h = h; this.keys = this.h.keySet().iterator(); *************** *** 94,97 **** --- 98,176 ---- return temp; //return value + } + + this.ip = (String) this.keys.next(); + } + + //if there is no next key, hasNext would return false + throw new java.util.NoSuchElementException(); + } + + /** not needed */ + public void remove() { + throw new UnsupportedOperationException("remove not implemented"); + } + } + + /** implements an Computer Object iterator over the online ip addresses */ + class OnlineComputerIterator implements Iterator { + /** the HashMap containing the ip -> NameOnline values */ + private HashMap h; + + /** iterator over the keys */ + private Iterator keys; + + /** the current ip string */ + private String ip = null; + + /** constructor + * @param h the HashMap containing the ip -> NameOnline values + */ + private OnlineComputerIterator(HashMap h) { + this.h = h; + this.keys = this.h.keySet().iterator(); + this.ip = (String) this.keys.next(); + } + + /** Returns true if the iteration has more elements. (In other words, + * returns true if next would return an element rather than throwing + * an exception.) + * @return true if the iterator has more elements. + * + */ + public boolean hasNext() { + while (this.keys.hasNext()) { + if (((NameOnline) this.h.get(ip)).getOnline() + .equals(Boolean.TRUE)) { + return true; //return true if we get an online ip + } + + + //if it was false (or null), try the next one + this.ip = (String) this.keys.next(); + } + + return false; // if there is no next key, return false + } + + /** Returns the next element in the iteration. + * @return the next element in the iteration. + * + */ + public Object next() { + while (this.keys.hasNext()) { + if (((NameOnline) this.h.get(ip)).getOnline() + .equals(Boolean.TRUE)) { + //assemble Computer + Computer c = new Computer(); + NameOnline no = (NameOnline) this.h.get(this.ip); + c.setIp(this.ip); + c.setName(no.getName()); + c.setNetFiles(null); + c.setOnline(no.getOnline()); + + this.ip = (String) keys.next(); //forward iterator + + return c; //return value } |