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

com.softicar.platform.common.container.iterator.SkipIterator Maven / Gradle / Ivy

Go to download

The SoftiCAR Platform is a lightweight, Java-based library to create interactive business web applications.

There is a newer version: 50.0.0
Show newest version
package com.softicar.platform.common.container.iterator;

import com.softicar.platform.common.core.annotations.Nullable;
import java.util.Iterator;

/**
 * An iterator adapter that skips elements that are equal to a given skip
 * element.
 * 

* This supports null elements in the iterated sequence without problem. This * also supports null as skip element. * * @author Oliver Richers * @param * the element type */ public class SkipIterator<@Nullable T> extends AbstractIteratorAdapter { private Iterator iterator; private ISkipper skipper; // -------------------------------- constructors -------------------------------- // /** * Constructs a new skip iterator. * * @param iterator * the iterator to use as a base * @param skipper * the skipper instance to use */ public SkipIterator(Iterator iterator, ISkipper skipper) { this.iterator = iterator; this.skipper = skipper; } /** * Constructs a new skip iterator. * * @param iterator * the iterator to use as a base * @param toSkip * an object to compare the elements to (null is also supported) */ public SkipIterator(Iterator iterator, T toSkip) { this(iterator, new EqualitySkipper<>(toSkip)); } public SkipIterator(Iterable iterable, T toSkip) { this(iterable.iterator(), toSkip); } // -------------------------------- internal -------------------------------- // @Override protected T fetchNext() { if (iterator.hasNext()) { T next = iterator.next(); if (skipper.shallSkip(next)) { return fetchNext(); } else { return next; } } return setFinished(); } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy