1/* 2 * Copyright (C) 2012 The Guava Authors 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17package com.google.common.collect; 18 19import static com.google.common.base.Preconditions.checkNotNull; 20 21import com.google.common.annotations.GwtCompatible; 22 23import java.util.Iterator; 24 25/** 26 * An iterator that transforms a backing iterator; for internal use. This avoids 27 * the object overhead of constructing a {@link Function} for internal methods. 28 * 29 * @author Louis Wasserman 30 */ 31@GwtCompatible 32abstract class TransformedIterator<F, T> implements Iterator<T> { 33 final Iterator<? extends F> backingIterator; 34 35 TransformedIterator(Iterator<? extends F> backingIterator) { 36 this.backingIterator = checkNotNull(backingIterator); 37 } 38 39 abstract T transform(F from); 40 41 @Override 42 public final boolean hasNext() { 43 return backingIterator.hasNext(); 44 } 45 46 @Override 47 public final T next() { 48 return transform(backingIterator.next()); 49 } 50 51 @Override 52 public final void remove() { 53 backingIterator.remove(); 54 } 55} 56