001/**
002 *
003 * Copyright (c) 2014, the Railo Company Ltd. All rights reserved.
004 *
005 * This library is free software; you can redistribute it and/or
006 * modify it under the terms of the GNU Lesser General Public
007 * License as published by the Free Software Foundation; either 
008 * version 2.1 of the License, or (at your option) any later version.
009 * 
010 * This library is distributed in the hope that it will be useful,
011 * but WITHOUT ANY WARRANTY; without even the implied warranty of
012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
013 * Lesser General Public License for more details.
014 * 
015 * You should have received a copy of the GNU Lesser General Public 
016 * License along with this library.  If not, see <http://www.gnu.org/licenses/>.
017 * 
018 **/
019package lucee.runtime.type.it;
020
021import java.util.Enumeration;
022import java.util.Iterator;
023import java.util.Map.Entry;
024
025import lucee.runtime.type.Collection;
026import lucee.runtime.type.Collection.Key;
027
028public class EntryIterator implements Iterator<Entry<Key, Object>>, Enumeration<Entry<Key, Object>> {
029        
030        
031
032        private Collection coll;
033        protected Key[] keys;
034        protected int pos;
035
036        public EntryIterator(Collection coll, Collection.Key[] keys){
037                this.coll=coll;
038                this.keys=keys;
039        }
040        
041        @Override
042        public boolean hasNext() {
043                return (keys.length)>pos;
044        }
045
046        @Override
047        public Entry<Key, Object> next() {
048                Key key = keys[pos++];
049                if(key==null) return null;
050                return new EntryImpl(coll,key);
051        }
052
053        @Override
054        public boolean hasMoreElements() {
055                return hasNext();
056        }
057
058        @Override
059        public Entry<Key, Object> nextElement() {
060                return next();
061        }
062
063        @Override
064        public void remove() {
065                throw new UnsupportedOperationException("this operation is not suppored");
066        }
067
068        
069        public class EntryImpl implements Entry<Key, Object> {
070
071                private Collection coll;
072                protected Key key;
073
074                public EntryImpl(Collection coll, Key key) {
075                        this.coll=coll;
076                        this.key=key;
077                }
078
079                @Override
080                public Key getKey() {
081                        return key;
082                }
083
084                @Override
085                public Object getValue() {
086                        return coll.get(key,null);
087                }
088
089                @Override
090                public Object setValue(Object value) {
091                        return coll.setEL(key, value);
092                }
093
094        }
095}