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

com.vladsch.flexmark.experimental.util.collection.iteration.MappingIterable Maven / Gradle / Ivy

Go to download

Contains experimental classes that may or may not work in all cases. Use at your own risk.

The newest version!
/*
 * Copyright (c) 2015-2019 Vladimir Schneider , all rights reserved.
 *
 * This code is private property of the copyright holder and cannot be used without
 * having obtained a license or prior written permission of the of the copyright holder.
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 *
 */

package com.vladsch.flexmark.experimental.util.collection.iteration;

import org.jetbrains.annotations.NotNull;

import java.util.Iterator;
import java.util.function.Function;

public class MappingIterable implements Iterable {
    final private @NotNull Iterable myIterable;
    final private @NotNull Function myFunction;

    public MappingIterable(@NotNull Iterable iterable, @NotNull Function function) {
        myIterable = iterable;
        myFunction = function;
    }

    @NotNull
    @Override
    public Iterator iterator() {
        return new MyIterator<>(myIterable.iterator(), myFunction);
    }

    private static class MyIterator implements Iterator {
        final private @NotNull Iterator myIterator;
        final private @NotNull Function myFunction;

        public MyIterator(@NotNull Iterator iterator, @NotNull Function function) {
            myIterator = iterator;
            myFunction = function;
        }

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

        @Override
        public V next() {
            return myFunction.apply(myIterator.next());
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy