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

com.maxifier.mxcache.clean.MappingIterable Maven / Gradle / Ivy

Go to download

Constains all classes necessary for launching a MxCache-instrumentated application

There is a newer version: 2.6.9
Show newest version
/*
 * Copyright (c) 2008-2014 Maxifier Ltd. All Rights Reserved.
 */
package com.maxifier.mxcache.clean;

import javax.annotation.Nonnull;

import java.util.Iterator;

/**
 * @author Alexander Kochurov ([email protected])
 */
public abstract class MappingIterable implements Iterable {
    private final Iterable iterable;

    protected MappingIterable(@Nonnull Iterable iterable) {
        this.iterable = iterable;
    }

    @Override
    public Iterator iterator() {
        return new MappingIterator(iterable.iterator());
    }

    public abstract T map(F f);

    private final class MappingIterator implements Iterator {
        private final Iterator iterator;

        private MappingIterator(Iterator iterator) {
            this.iterator = iterator;
        }

        @Override
        public boolean hasNext() {
            return iterator.hasNext();
        }

        @Override
        public T next() {
            return map(iterator.next());
        }

        @Override
        public void remove() {
            iterator.remove();
        }
    }

    @Override
    public String toString() {
        return iterable.toString();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy