Index: hbase-common/src/main/java/org/apache/hadoop/hbase/CompositeIterator.java =================================================================== --- hbase-common/src/main/java/org/apache/hadoop/hbase/CompositeIterator.java (revision 0) +++ hbase-common/src/main/java/org/apache/hadoop/hbase/CompositeIterator.java (revision 0) @@ -0,0 +1,68 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.hadoop.hbase; + +import java.util.Collections; +import java.util.Iterator; +import java.util.LinkedList; +import java.util.List; + +/** + * A composite iterator that aggregates a series of iterators + */ +public class CompositeIterator implements Iterator { + + private final LinkedList> iterators; + private Iterator current; + + /* + * reverses the order of the Iterators in iterators parameter + */ + public CompositeIterator(final List> iterators) { + this.iterators = new LinkedList>(); + for (final Iterator iterator : iterators) { + this.iterators.push(iterator); + } + current = Collections.emptyList().iterator(); + } + + public boolean hasNext() { + final boolean curHasNext = current.hasNext(); + if (!curHasNext && !iterators.isEmpty()) { + current = iterators.pop(); + return current.hasNext(); + } else { + return curHasNext; + } + } + + public T next() { + if (current.hasNext()) { + return current.next(); + } + if (!iterators.isEmpty()) { + current = iterators.pop(); + } + return current.next(); + } + + public void remove() { + throw new UnsupportedOperationException("remove() not supported"); + } +} \ No newline at end of file Index: hbase-common/src/main/java/org/apache/hadoop/hbase/CompoundConfiguration.java =================================================================== --- hbase-common/src/main/java/org/apache/hadoop/hbase/CompoundConfiguration.java (revision 1463790) +++ hbase-common/src/main/java/org/apache/hadoop/hbase/CompoundConfiguration.java (working copy) @@ -25,6 +25,7 @@ import java.io.OutputStream; import java.util.ArrayList; import java.util.Collection; +import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Map; @@ -57,11 +58,11 @@ // Devs: these APIs are the same contract as their counterparts in // Configuration.java - private static interface ImmutableConfigMap { + private static interface ImmutableConfigMap extends Iterable> { String get(String key); String getRaw(String key); Class getClassByName(String name) throws ClassNotFoundException; - int size(); + int size(); } protected List configs @@ -83,6 +84,11 @@ Configuration c = conf; @Override + public Iterator> iterator() { + return c.iterator(); + } + + @Override public String get(String key) { return c.get(key); } @@ -128,6 +134,15 @@ Map m = map; @Override + public Iterator> iterator() { + Map ret = new HashMap(); + for (Map.Entry entry : map.entrySet()) { + ret.put(entry.getKey().toString(), entry.getValue().toString()); + } + return ret.entrySet().iterator(); + } + + @Override public String get(String key) { ImmutableBytesWritable ibw = new ImmutableBytesWritable(Bytes .toBytes(key)); @@ -176,6 +191,11 @@ Map m = map; @Override + public Iterator> iterator() { + return map.entrySet().iterator(); + } + + @Override public String get(String key) { return m.get(key); } @@ -434,7 +454,14 @@ @Override public Iterator> iterator() { - throw new UnsupportedOperationException("Immutable Configuration"); + List>> iterators = + new ArrayList>>(); + if (!configs.isEmpty()) { + for (ImmutableConfigMap map : configs) { + iterators.add(map.iterator()); + } + } + return new CompositeIterator(iterators); } @Override