All Downloads are FREE. Search and download functionalities are using the official Maven repository.

ch.lambdaj.function.convert.ConverterIterator Maven / Gradle / Ivy

The newest version!
// Modified or written by Lambdascale SRL for inclusion with lambdaj.
// Copyright (c) 2009-2010 Mario Fusco.
// Licensed under the Apache License, Version 2.0 (the "License")

package ch.lambdaj.function.convert;

import java.util.*;

/**
 * An Iterator that converts its items using the given Converter while iterating on them.
 * @author Mario Fusco
 */
public class ConverterIterator implements Iterator {

    private final Converter converter;
    private final Iterator iterator;

    /**
     * Creates a ConverterIterator
     */
    public ConverterIterator(Converter converter, Iterator iterator) {
        this.converter = converter;
        this.iterator = iterator;
    }

    /**
     * {@inheritDoc}
     */
    public boolean hasNext() {
        return iterator.hasNext();
    }

    /**
     * {@inheritDoc}
     */
    public T next() {
        return converter.convert(iterator.next());
    }

    /**
     * {@inheritDoc}
     */
    public void remove() {
        iterator.remove();
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy