001 package railo.runtime.type.it; 002 003 import java.util.Enumeration; 004 import java.util.Iterator; 005 import java.util.Map.Entry; 006 007 import railo.runtime.type.Collection; 008 import railo.runtime.type.Collection.Key; 009 010 public class EntryIterator implements Iterator<Entry<Key, Object>>, Enumeration<Entry<Key, Object>> { 011 012 013 014 private Collection coll; 015 protected Key[] keys; 016 protected int pos; 017 018 public EntryIterator(Collection coll, Collection.Key[] keys){ 019 this.coll=coll; 020 this.keys=keys; 021 } 022 023 @Override 024 public boolean hasNext() { 025 return (keys.length)>pos; 026 } 027 028 @Override 029 public Entry<Key, Object> next() { 030 Key key = keys[pos++]; 031 if(key==null) return null; 032 return new EntryImpl(coll,key); 033 } 034 035 @Override 036 public boolean hasMoreElements() { 037 return hasNext(); 038 } 039 040 @Override 041 public Entry<Key, Object> nextElement() { 042 return next(); 043 } 044 045 @Override 046 public void remove() { 047 throw new UnsupportedOperationException("this operation is not suppored"); 048 } 049 050 051 public class EntryImpl implements Entry<Key, Object> { 052 053 private Collection coll; 054 protected Key key; 055 056 public EntryImpl(Collection coll, Key key) { 057 this.coll=coll; 058 this.key=key; 059 } 060 061 @Override 062 public Key getKey() { 063 return key; 064 } 065 066 @Override 067 public Object getValue() { 068 return coll.get(key,null); 069 } 070 071 @Override 072 public Object setValue(Object value) { 073 return coll.setEL(key, value); 074 } 075 076 } 077 }