001/**
002 * Copyright The Apache Software Foundation
003 *
004 * Licensed to the Apache Software Foundation (ASF) under one
005 * or more contributor license agreements.  See the NOTICE file
006 * distributed with this work for additional information
007 * regarding copyright ownership.  The ASF licenses this file
008 * to you under the Apache License, Version 2.0 (the
009 * "License"); you may not use this file except in compliance
010 * with the License.  You may obtain a copy of the License at
011 *
012 *     http://www.apache.org/licenses/LICENSE-2.0
013 *
014 * Unless required by applicable law or agreed to in writing, software
015 * distributed under the License is distributed on an "AS IS" BASIS,
016 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
017 * See the License for the specific language governing permissions and
018 * limitations under the License.
019 */
020package org.apache.hadoop.hbase.io.hfile;
021
022import java.util.Iterator;
023
024import org.apache.yetus.audience.InterfaceAudience;
025
026/**
027 * Iterator over an array of BlockCache CachedBlocks.
028 */
029@InterfaceAudience.Private
030class BlockCachesIterator implements Iterator<CachedBlock> {
031  int index = 0;
032  final BlockCache [] bcs;
033  Iterator<CachedBlock> current;
034
035  BlockCachesIterator(final BlockCache [] blockCaches) {
036    this.bcs = blockCaches;
037    this.current = this.bcs[this.index].iterator();
038  }
039
040  @Override
041  public boolean hasNext() {
042    if (current.hasNext()) return true;
043    this.index++;
044    if (this.index >= this.bcs.length) return false;
045    this.current = this.bcs[this.index].iterator();
046    return hasNext();
047  }
048
049  @Override
050  public CachedBlock next() {
051    return this.current.next();
052  }
053
054  @Override
055  public void remove() {
056    throw new UnsupportedOperationException();
057  }
058}