
com.github.sirikid.iterators.EmptyIterator Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of maybe Show documentation
Show all versions of maybe Show documentation
Implementation Maybe monad in Java
The newest version!
/*
* Copyright (c) 2016, Ivan Sokolov. All rights reserved.
* This code is licensed under MIT license (see LICENSE for details)
*/
package com.github.sirikid.iterators;
import java.util.ListIterator;
import java.util.NoSuchElementException;
/**
* Empty iterator. Use it when need return an iterator, but you have no elements.
*
* @author Ivan Sokolov
* @version 1.1.0
* @param type of elements
* @see EmptySpliterator
* @since 1.0.0
*/
public class EmptyIterator implements ListIterator {
@Override
public boolean hasNext() {
return false;
}
@Override
public E next() {
throw new NoSuchElementException();
}
@Override
public boolean hasPrevious() {
return false;
}
@Override
public E previous() {
throw new NoSuchElementException();
}
@Override
public int nextIndex() {
return 0;
}
@Override
public int previousIndex() {
return -1;
}
@Override
public void remove() {
throw new UnsupportedOperationException("remove");
}
@Override
public void set(final E unused) {
throw new UnsupportedOperationException("set");
}
@Override
public void add(final E unused) {
throw new UnsupportedOperationException("add");
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy