001 /** 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the 007 * "License"); you may not use this file except in compliance 008 * with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, software 013 * distributed under the License is distributed on an "AS IS" BASIS, 014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 015 * See the License for the specific language governing permissions and 016 * limitations under the License. 017 */ 018 019 package org.apache.hadoop.mapreduce; 020 021 import java.io.IOException; 022 import java.util.Iterator; 023 024 import org.apache.hadoop.classification.InterfaceAudience; 025 import org.apache.hadoop.classification.InterfaceStability; 026 027 /** 028 * <code>MarkableIterator</code> is a wrapper iterator class that 029 * implements the {@link MarkableIteratorInterface}. 030 * 031 */ 032 @InterfaceAudience.Public 033 @InterfaceStability.Evolving 034 public class MarkableIterator<VALUE> 035 implements MarkableIteratorInterface<VALUE> { 036 037 MarkableIteratorInterface<VALUE> baseIterator; 038 039 /** 040 * Create a new iterator layered on the input iterator 041 * @param itr underlying iterator that implements MarkableIteratorInterface 042 */ 043 public MarkableIterator(Iterator<VALUE> itr) { 044 if (!(itr instanceof MarkableIteratorInterface)) { 045 throw new IllegalArgumentException("Input Iterator not markable"); 046 } 047 baseIterator = (MarkableIteratorInterface<VALUE>) itr; 048 } 049 050 @Override 051 public void mark() throws IOException { 052 baseIterator.mark(); 053 } 054 055 @Override 056 public void reset() throws IOException { 057 baseIterator.reset(); 058 } 059 060 @Override 061 public void clearMark() throws IOException { 062 baseIterator.clearMark(); 063 } 064 065 @Override 066 public boolean hasNext() { 067 return baseIterator.hasNext(); 068 } 069 070 @Override 071 public VALUE next() { 072 return baseIterator.next(); 073 } 074 075 @Override 076 public void remove() { 077 throw new UnsupportedOperationException("Remove Not Implemented"); 078 } 079 }