// 
// Decompiled by Procyon v0.6.0
// 

package it.unimi.dsi.fastutil.shorts;

import it.unimi.dsi.fastutil.SafeMath;
import java.util.function.IntConsumer;
import java.util.function.Consumer;
import java.util.NoSuchElementException;
import java.io.Serializable;
import it.unimi.dsi.fastutil.bytes.ByteIterator;
import java.util.Objects;
import java.util.function.IntPredicate;
import java.util.ListIterator;
import it.unimi.dsi.fastutil.ints.IntIterators;
import it.unimi.dsi.fastutil.ints.IntIterator;
import java.util.PrimitiveIterator;
import java.util.Iterator;
import it.unimi.dsi.fastutil.BigArrays;

public final class ShortIterators
{
    public static final EmptyIterator EMPTY_ITERATOR;
    
    private ShortIterators() {
    }
    
    public static ShortListIterator singleton(final short element) {
        return new SingletonIterator(element);
    }
    
    public static ShortListIterator wrap(final short[] array, final int offset, final int length) {
        ShortArrays.ensureOffsetLength(array, offset, length);
        return new ArrayIterator(array, offset, length);
    }
    
    public static ShortListIterator wrap(final short[] array) {
        return new ArrayIterator(array, 0, array.length);
    }
    
    public static int unwrap(final ShortIterator i, final short[] array, int offset, final int max) {
        if (max < 0) {
            throw new IllegalArgumentException("The maximum number of elements (" + max + ") is negative");
        }
        if (offset < 0 || offset + max > array.length) {
            throw new IllegalArgumentException();
        }
        int j = max;
        while (j-- != 0 && i.hasNext()) {
            array[offset++] = i.nextShort();
        }
        return max - j - 1;
    }
    
    public static int unwrap(final ShortIterator i, final short[] array) {
        return unwrap(i, array, 0, array.length);
    }
    
    public static short[] unwrap(final ShortIterator i, int max) {
        if (max < 0) {
            throw new IllegalArgumentException("The maximum number of elements (" + max + ") is negative");
        }
        short[] array = new short[16];
        int j = 0;
        while (max-- != 0 && i.hasNext()) {
            if (j == array.length) {
                array = ShortArrays.grow(array, j + 1);
            }
            array[j++] = i.nextShort();
        }
        return ShortArrays.trim(array, j);
    }
    
    public static short[] unwrap(final ShortIterator i) {
        return unwrap(i, Integer.MAX_VALUE);
    }
    
    public static long unwrap(final ShortIterator i, final short[][] array, long offset, final long max) {
        if (max < 0L) {
            throw new IllegalArgumentException("The maximum number of elements (" + max + ") is negative");
        }
        if (offset < 0L || offset + max > BigArrays.length(array)) {
            throw new IllegalArgumentException();
        }
        long j = max;
        while (j-- != 0L && i.hasNext()) {
            BigArrays.set(array, offset++, i.nextShort());
        }
        return max - j - 1L;
    }
    
    public static long unwrap(final ShortIterator i, final short[][] array) {
        return unwrap(i, array, 0L, BigArrays.length(array));
    }
    
    public static int unwrap(final ShortIterator i, final ShortCollection c, final int max) {
        if (max < 0) {
            throw new IllegalArgumentException("The maximum number of elements (" + max + ") is negative");
        }
        int j = max;
        while (j-- != 0 && i.hasNext()) {
            c.add(i.nextShort());
        }
        return max - j - 1;
    }
    
    public static short[][] unwrapBig(final ShortIterator i, long max) {
        if (max < 0L) {
            throw new IllegalArgumentException("The maximum number of elements (" + max + ") is negative");
        }
        short[][] array = ShortBigArrays.newBigArray(16L);
        long j = 0L;
        while (max-- != 0L && i.hasNext()) {
            if (j == BigArrays.length(array)) {
                array = BigArrays.grow(array, j + 1L);
            }
            BigArrays.set(array, j++, i.nextShort());
        }
        return BigArrays.trim(array, j);
    }
    
    public static short[][] unwrapBig(final ShortIterator i) {
        return unwrapBig(i, Long.MAX_VALUE);
    }
    
    public static long unwrap(final ShortIterator i, final ShortCollection c) {
        long n = 0L;
        while (i.hasNext()) {
            c.add(i.nextShort());
            ++n;
        }
        return n;
    }
    
    public static int pour(final ShortIterator i, final ShortCollection s, final int max) {
        if (max < 0) {
            throw new IllegalArgumentException("The maximum number of elements (" + max + ") is negative");
        }
        int j = max;
        while (j-- != 0 && i.hasNext()) {
            s.add(i.nextShort());
        }
        return max - j - 1;
    }
    
    public static int pour(final ShortIterator i, final ShortCollection s) {
        return pour(i, s, Integer.MAX_VALUE);
    }
    
    public static ShortList pour(final ShortIterator i, final int max) {
        final ShortArrayList l = new ShortArrayList();
        pour(i, l, max);
        l.trim();
        return l;
    }
    
    public static ShortList pour(final ShortIterator i) {
        return pour(i, Integer.MAX_VALUE);
    }
    
    public static ShortIterator asShortIterator(final Iterator i) {
        if (i instanceof ShortIterator) {
            return (ShortIterator)i;
        }
        return new IteratorWrapper(i);
    }
    
    public static ShortIterator narrow(final PrimitiveIterator.OfInt i) {
        return new CheckedPrimitiveIteratorWrapper(i);
    }
    
    public static ShortIterator uncheckedNarrow(final PrimitiveIterator.OfInt i) {
        return new PrimitiveIteratorWrapper(i);
    }
    
    public static IntIterator widen(final ShortIterator i) {
        return IntIterators.wrap(i);
    }
    
    public static ShortListIterator asShortIterator(final ListIterator i) {
        if (i instanceof ShortListIterator) {
            return (ShortListIterator)i;
        }
        return new ListIteratorWrapper(i);
    }
    
    public static boolean any(final ShortIterator iterator, final ShortPredicate predicate) {
        return indexOf(iterator, predicate) != -1;
    }
    
    public static boolean any(final ShortIterator iterator, final IntPredicate predicate) {
        ShortPredicate predicate2;
        if (predicate instanceof ShortPredicate) {
            predicate2 = (ShortPredicate)predicate;
        }
        else {
            Objects.requireNonNull(predicate);
            predicate2 = predicate::test;
        }
        return any(iterator, predicate2);
    }
    
    public static boolean all(final ShortIterator iterator, final ShortPredicate predicate) {
        Objects.requireNonNull(predicate);
        while (iterator.hasNext()) {
            if (!predicate.test(iterator.nextShort())) {
                return false;
            }
        }
        return true;
    }
    
    public static boolean all(final ShortIterator iterator, final IntPredicate predicate) {
        ShortPredicate predicate2;
        if (predicate instanceof ShortPredicate) {
            predicate2 = (ShortPredicate)predicate;
        }
        else {
            Objects.requireNonNull(predicate);
            predicate2 = predicate::test;
        }
        return all(iterator, predicate2);
    }
    
    public static int indexOf(final ShortIterator iterator, final ShortPredicate predicate) {
        Objects.requireNonNull(predicate);
        int i = 0;
        while (iterator.hasNext()) {
            if (predicate.test(iterator.nextShort())) {
                return i;
            }
            ++i;
        }
        return -1;
    }
    
    public static int indexOf(final ShortIterator iterator, final IntPredicate predicate) {
        ShortPredicate predicate2;
        if (predicate instanceof ShortPredicate) {
            predicate2 = (ShortPredicate)predicate;
        }
        else {
            Objects.requireNonNull(predicate);
            predicate2 = predicate::test;
        }
        return indexOf(iterator, predicate2);
    }
    
    public static ShortListIterator fromTo(final short from, final short to) {
        return new IntervalIterator(from, to);
    }
    
    public static ShortIterator concat(final ShortIterator... a) {
        return concat(a, 0, a.length);
    }
    
    public static ShortIterator concat(final ShortIterator[] a, final int offset, final int length) {
        return new IteratorConcatenator(a, offset, length);
    }
    
    public static ShortIterator unmodifiable(final ShortIterator i) {
        return new UnmodifiableIterator(i);
    }
    
    public static ShortBidirectionalIterator unmodifiable(final ShortBidirectionalIterator i) {
        return new UnmodifiableBidirectionalIterator(i);
    }
    
    public static ShortListIterator unmodifiable(final ShortListIterator i) {
        return new UnmodifiableListIterator(i);
    }
    
    public static ShortIterator wrap(final ByteIterator iterator) {
        return new ByteIteratorWrapper(iterator);
    }
    
    static {
        EMPTY_ITERATOR = new EmptyIterator();
    }
    
    public static class EmptyIterator implements ShortListIterator, Serializable, Cloneable
    {
        private static final long serialVersionUID = -7046029254386353129L;
        
        protected EmptyIterator() {
        }
        
        @Override
        public boolean hasNext() {
            return false;
        }
        
        @Override
        public boolean hasPrevious() {
            return false;
        }
        
        @Override
        public short nextShort() {
            throw new NoSuchElementException();
        }
        
        @Override
        public short previousShort() {
            throw new NoSuchElementException();
        }
        
        @Override
        public int nextIndex() {
            return 0;
        }
        
        @Override
        public int previousIndex() {
            return -1;
        }
        
        @Override
        public int skip(final int n) {
            return 0;
        }
        
        @Override
        public int back(final int n) {
            return 0;
        }
        
        @Override
        public void forEachRemaining(final ShortConsumer action) {
        }
        
        @Deprecated
        @Override
        public void forEachRemaining(final Consumer<? super Short> action) {
        }
        
        public Object clone() {
            return ShortIterators.EMPTY_ITERATOR;
        }
        
        private Object readResolve() {
            return ShortIterators.EMPTY_ITERATOR;
        }
    }
    
    private static class SingletonIterator implements ShortListIterator
    {
        private final short element;
        private byte curr;
        
        public SingletonIterator(final short element) {
            this.element = element;
        }
        
        @Override
        public boolean hasNext() {
            return this.curr == 0;
        }
        
        @Override
        public boolean hasPrevious() {
            return this.curr == 1;
        }
        
        @Override
        public short nextShort() {
            if (!this.hasNext()) {
                throw new NoSuchElementException();
            }
            this.curr = 1;
            return this.element;
        }
        
        @Override
        public short previousShort() {
            if (!this.hasPrevious()) {
                throw new NoSuchElementException();
            }
            this.curr = 0;
            return this.element;
        }
        
        @Override
        public void forEachRemaining(final ShortConsumer action) {
            Objects.requireNonNull(action);
            if (this.curr == 0) {
                action.accept(this.element);
                this.curr = 1;
            }
        }
        
        @Override
        public int nextIndex() {
            return this.curr;
        }
        
        @Override
        public int previousIndex() {
            return this.curr - 1;
        }
        
        @Override
        public int back(final int n) {
            if (n < 0) {
                throw new IllegalArgumentException("Argument must be nonnegative: " + n);
            }
            if (n == 0 || this.curr < 1) {
                return 0;
            }
            this.curr = 1;
            return 1;
        }
        
        @Override
        public int skip(final int n) {
            if (n < 0) {
                throw new IllegalArgumentException("Argument must be nonnegative: " + n);
            }
            if (n == 0 || this.curr > 0) {
                return 0;
            }
            this.curr = 0;
            return 1;
        }
    }
    
    private static class ArrayIterator implements ShortListIterator
    {
        private final short[] array;
        private final int offset;
        private final int length;
        private int curr;
        
        public ArrayIterator(final short[] array, final int offset, final int length) {
            this.array = array;
            this.offset = offset;
            this.length = length;
        }
        
        @Override
        public boolean hasNext() {
            return this.curr < this.length;
        }
        
        @Override
        public boolean hasPrevious() {
            return this.curr > 0;
        }
        
        @Override
        public short nextShort() {
            if (!this.hasNext()) {
                throw new NoSuchElementException();
            }
            return this.array[this.offset + this.curr++];
        }
        
        @Override
        public short previousShort() {
            if (!this.hasPrevious()) {
                throw new NoSuchElementException();
            }
            final short[] array = this.array;
            final int offset = this.offset;
            final int curr = this.curr - 1;
            this.curr = curr;
            return array[offset + curr];
        }
        
        @Override
        public void forEachRemaining(final ShortConsumer action) {
            Objects.requireNonNull(action);
            while (this.curr < this.length) {
                action.accept(this.array[this.offset + this.curr]);
                ++this.curr;
            }
        }
        
        @Override
        public int skip(int n) {
            if (n < 0) {
                throw new IllegalArgumentException("Argument must be nonnegative: " + n);
            }
            if (n <= this.length - this.curr) {
                this.curr += n;
                return n;
            }
            n = this.length - this.curr;
            this.curr = this.length;
            return n;
        }
        
        @Override
        public int back(int n) {
            if (n < 0) {
                throw new IllegalArgumentException("Argument must be nonnegative: " + n);
            }
            if (n <= this.curr) {
                this.curr -= n;
                return n;
            }
            n = this.curr;
            this.curr = 0;
            return n;
        }
        
        @Override
        public int nextIndex() {
            return this.curr;
        }
        
        @Override
        public int previousIndex() {
            return this.curr - 1;
        }
    }
    
    private static class IteratorWrapper implements ShortIterator
    {
        final Iterator<Short> i;
        
        public IteratorWrapper(final Iterator<Short> i) {
            this.i = i;
        }
        
        @Override
        public boolean hasNext() {
            return this.i.hasNext();
        }
        
        @Override
        public void remove() {
            this.i.remove();
        }
        
        @Override
        public short nextShort() {
            return this.i.next();
        }
        
        @Override
        public void forEachRemaining(final ShortConsumer action) {
            this.i.forEachRemaining(action);
        }
        
        @Deprecated
        @Override
        public void forEachRemaining(final Consumer<? super Short> action) {
            this.i.forEachRemaining(action);
        }
    }
    
    private static class PrimitiveIteratorWrapper implements ShortIterator
    {
        final PrimitiveIterator.OfInt i;
        
        public PrimitiveIteratorWrapper(final PrimitiveIterator.OfInt i) {
            this.i = i;
        }
        
        @Override
        public boolean hasNext() {
            return this.i.hasNext();
        }
        
        @Override
        public void remove() {
            this.i.remove();
        }
        
        @Override
        public short nextShort() {
            return (short)this.i.nextInt();
        }
        
        @Override
        public void forEachRemaining(final ShortConsumer action) {
            this.i.forEachRemaining((IntConsumer)action);
        }
    }
    
    private static class CheckedPrimitiveIteratorWrapper extends PrimitiveIteratorWrapper
    {
        public CheckedPrimitiveIteratorWrapper(final PrimitiveIterator.OfInt i) {
            super(i);
        }
        
        @Override
        public short nextShort() {
            return SafeMath.safeIntToShort(this.i.nextInt());
        }
        
        @Override
        public void forEachRemaining(final ShortConsumer action) {
            this.i.forEachRemaining(value -> action.accept(SafeMath.safeIntToShort(value)));
        }
    }
    
    private static class ListIteratorWrapper implements ShortListIterator
    {
        final ListIterator<Short> i;
        
        public ListIteratorWrapper(final ListIterator<Short> i) {
            this.i = i;
        }
        
        @Override
        public boolean hasNext() {
            return this.i.hasNext();
        }
        
        @Override
        public boolean hasPrevious() {
            return this.i.hasPrevious();
        }
        
        @Override
        public int nextIndex() {
            return this.i.nextIndex();
        }
        
        @Override
        public int previousIndex() {
            return this.i.previousIndex();
        }
        
        @Override
        public void set(final short k) {
            this.i.set(k);
        }
        
        @Override
        public void add(final short k) {
            this.i.add(k);
        }
        
        @Override
        public void remove() {
            this.i.remove();
        }
        
        @Override
        public short nextShort() {
            return this.i.next();
        }
        
        @Override
        public short previousShort() {
            return this.i.previous();
        }
        
        @Override
        public void forEachRemaining(final ShortConsumer action) {
            this.i.forEachRemaining(action);
        }
        
        @Deprecated
        @Override
        public void forEachRemaining(final Consumer<? super Short> action) {
            this.i.forEachRemaining(action);
        }
    }
    
    public abstract static class AbstractIndexBasedIterator extends AbstractShortIterator
    {
        protected final int minPos;
        protected int pos;
        protected int lastReturned;
        
        protected AbstractIndexBasedIterator(final int minPos, final int initialPos) {
            this.minPos = minPos;
            this.pos = initialPos;
        }
        
        protected abstract short get(final int p0);
        
        protected abstract void remove(final int p0);
        
        protected abstract int getMaxPos();
        
        @Override
        public boolean hasNext() {
            return this.pos < this.getMaxPos();
        }
        
        @Override
        public short nextShort() {
            if (!this.hasNext()) {
                throw new NoSuchElementException();
            }
            final int lastReturned = this.pos++;
            this.lastReturned = lastReturned;
            return this.get(lastReturned);
        }
        
        @Override
        public void remove() {
            if (this.lastReturned == -1) {
                throw new IllegalStateException();
            }
            this.remove(this.lastReturned);
            if (this.lastReturned < this.pos) {
                --this.pos;
            }
            this.lastReturned = -1;
        }
        
        @Override
        public void forEachRemaining(final ShortConsumer action) {
            while (this.pos < this.getMaxPos()) {
                final int lastReturned = this.pos++;
                this.lastReturned = lastReturned;
                action.accept(this.get(lastReturned));
            }
        }
        
        @Override
        public int skip(int n) {
            if (n < 0) {
                throw new IllegalArgumentException("Argument must be nonnegative: " + n);
            }
            final int max = this.getMaxPos();
            final int remaining = max - this.pos;
            if (n < remaining) {
                this.pos += n;
            }
            else {
                n = remaining;
                this.pos = max;
            }
            this.lastReturned = this.pos - 1;
            return n;
        }
    }
    
    public abstract static class AbstractIndexBasedListIterator extends AbstractIndexBasedIterator implements ShortListIterator
    {
        protected AbstractIndexBasedListIterator(final int minPos, final int initialPos) {
            super(minPos, initialPos);
        }
        
        protected abstract void add(final int p0, final short p1);
        
        protected abstract void set(final int p0, final short p1);
        
        @Override
        public boolean hasPrevious() {
            return this.pos > this.minPos;
        }
        
        @Override
        public short previousShort() {
            if (!this.hasPrevious()) {
                throw new NoSuchElementException();
            }
            final int n = this.pos - 1;
            this.pos = n;
            this.lastReturned = n;
            return this.get(n);
        }
        
        @Override
        public int nextIndex() {
            return this.pos;
        }
        
        @Override
        public int previousIndex() {
            return this.pos - 1;
        }
        
        @Override
        public void add(final short k) {
            this.add(this.pos++, k);
            this.lastReturned = -1;
        }
        
        @Override
        public void set(final short k) {
            if (this.lastReturned == -1) {
                throw new IllegalStateException();
            }
            this.set(this.lastReturned, k);
        }
        
        @Override
        public int back(int n) {
            if (n < 0) {
                throw new IllegalArgumentException("Argument must be nonnegative: " + n);
            }
            final int remaining = this.pos - this.minPos;
            if (n < remaining) {
                this.pos -= n;
            }
            else {
                n = remaining;
                this.pos = this.minPos;
            }
            this.lastReturned = this.pos;
            return n;
        }
    }
    
    private static class IntervalIterator implements ShortListIterator
    {
        private final short from;
        private final short to;
        short curr;
        
        public IntervalIterator(final short from, final short to) {
            this.curr = from;
            this.from = from;
            this.to = to;
        }
        
        @Override
        public boolean hasNext() {
            return this.curr < this.to;
        }
        
        @Override
        public boolean hasPrevious() {
            return this.curr > this.from;
        }
        
        @Override
        public short nextShort() {
            if (!this.hasNext()) {
                throw new NoSuchElementException();
            }
            final short curr = this.curr;
            this.curr = (short)(curr + 1);
            return curr;
        }
        
        @Override
        public short previousShort() {
            if (!this.hasPrevious()) {
                throw new NoSuchElementException();
            }
            return (short)(--this.curr);
        }
        
        @Override
        public void forEachRemaining(final ShortConsumer action) {
            Objects.requireNonNull(action);
            while (this.curr < this.to) {
                action.accept(this.curr);
                ++this.curr;
            }
        }
        
        @Override
        public int nextIndex() {
            return this.curr - this.from;
        }
        
        @Override
        public int previousIndex() {
            return this.curr - this.from - 1;
        }
        
        @Override
        public int skip(int n) {
            if (n < 0) {
                throw new IllegalArgumentException("Argument must be nonnegative: " + n);
            }
            if (this.curr + n <= this.to) {
                this.curr += (short)n;
                return n;
            }
            n = this.to - this.curr;
            this.curr = this.to;
            return n;
        }
        
        @Override
        public int back(int n) {
            if (this.curr - n >= this.from) {
                this.curr -= (short)n;
                return n;
            }
            n = this.curr - this.from;
            this.curr = this.from;
            return n;
        }
    }
    
    private static class IteratorConcatenator implements ShortIterator
    {
        final ShortIterator[] a;
        int offset;
        int length;
        int lastOffset;
        
        public IteratorConcatenator(final ShortIterator[] a, final int offset, final int length) {
            this.lastOffset = -1;
            this.a = a;
            this.offset = offset;
            this.length = length;
            this.advance();
        }
        
        private void advance() {
            while (this.length != 0 && !this.a[this.offset].hasNext()) {
                --this.length;
                ++this.offset;
            }
        }
        
        @Override
        public boolean hasNext() {
            return this.length > 0;
        }
        
        @Override
        public short nextShort() {
            if (!this.hasNext()) {
                throw new NoSuchElementException();
            }
            final ShortIterator[] a = this.a;
            final int offset = this.offset;
            this.lastOffset = offset;
            final short next = a[offset].nextShort();
            this.advance();
            return next;
        }
        
        @Override
        public void forEachRemaining(final ShortConsumer action) {
            while (this.length > 0) {
                final ShortIterator[] a = this.a;
                final int offset = this.offset;
                this.lastOffset = offset;
                a[offset].forEachRemaining(action);
                this.advance();
            }
        }
        
        @Deprecated
        @Override
        public void forEachRemaining(final Consumer<? super Short> action) {
            while (this.length > 0) {
                final ShortIterator[] a = this.a;
                final int offset = this.offset;
                this.lastOffset = offset;
                a[offset].forEachRemaining(action);
                this.advance();
            }
        }
        
        @Override
        public void remove() {
            if (this.lastOffset == -1) {
                throw new IllegalStateException();
            }
            this.a[this.lastOffset].remove();
        }
        
        @Override
        public int skip(final int n) {
            if (n < 0) {
                throw new IllegalArgumentException("Argument must be nonnegative: " + n);
            }
            this.lastOffset = -1;
            int skipped = 0;
            while (skipped < n && this.length != 0) {
                skipped += this.a[this.offset].skip(n - skipped);
                if (this.a[this.offset].hasNext()) {
                    break;
                }
                --this.length;
                ++this.offset;
            }
            return skipped;
        }
    }
    
    public static class UnmodifiableIterator implements ShortIterator
    {
        protected final ShortIterator i;
        
        public UnmodifiableIterator(final ShortIterator i) {
            this.i = i;
        }
        
        @Override
        public boolean hasNext() {
            return this.i.hasNext();
        }
        
        @Override
        public short nextShort() {
            return this.i.nextShort();
        }
        
        @Override
        public void forEachRemaining(final ShortConsumer action) {
            this.i.forEachRemaining(action);
        }
        
        @Deprecated
        @Override
        public void forEachRemaining(final Consumer<? super Short> action) {
            this.i.forEachRemaining(action);
        }
    }
    
    public static class UnmodifiableBidirectionalIterator implements ShortBidirectionalIterator
    {
        protected final ShortBidirectionalIterator i;
        
        public UnmodifiableBidirectionalIterator(final ShortBidirectionalIterator i) {
            this.i = i;
        }
        
        @Override
        public boolean hasNext() {
            return this.i.hasNext();
        }
        
        @Override
        public boolean hasPrevious() {
            return this.i.hasPrevious();
        }
        
        @Override
        public short nextShort() {
            return this.i.nextShort();
        }
        
        @Override
        public short previousShort() {
            return this.i.previousShort();
        }
        
        @Override
        public void forEachRemaining(final ShortConsumer action) {
            this.i.forEachRemaining(action);
        }
        
        @Deprecated
        @Override
        public void forEachRemaining(final Consumer<? super Short> action) {
            this.i.forEachRemaining(action);
        }
    }
    
    public static class UnmodifiableListIterator implements ShortListIterator
    {
        protected final ShortListIterator i;
        
        public UnmodifiableListIterator(final ShortListIterator i) {
            this.i = i;
        }
        
        @Override
        public boolean hasNext() {
            return this.i.hasNext();
        }
        
        @Override
        public boolean hasPrevious() {
            return this.i.hasPrevious();
        }
        
        @Override
        public short nextShort() {
            return this.i.nextShort();
        }
        
        @Override
        public short previousShort() {
            return this.i.previousShort();
        }
        
        @Override
        public int nextIndex() {
            return this.i.nextIndex();
        }
        
        @Override
        public int previousIndex() {
            return this.i.previousIndex();
        }
        
        @Override
        public void forEachRemaining(final ShortConsumer action) {
            this.i.forEachRemaining(action);
        }
        
        @Deprecated
        @Override
        public void forEachRemaining(final Consumer<? super Short> action) {
            this.i.forEachRemaining(action);
        }
    }
    
    private static final class ByteIteratorWrapper implements ShortIterator
    {
        final ByteIterator iterator;
        
        public ByteIteratorWrapper(final ByteIterator iterator) {
            this.iterator = iterator;
        }
        
        @Override
        public boolean hasNext() {
            return this.iterator.hasNext();
        }
        
        @Deprecated
        @Override
        public Short next() {
            return (short)this.iterator.nextByte();
        }
        
        @Override
        public short nextShort() {
            return this.iterator.nextByte();
        }
        
        @Override
        public void forEachRemaining(final ShortConsumer action) {
            Objects.requireNonNull(action);
            final ByteIterator iterator = this.iterator;
            Objects.requireNonNull(action);
            iterator.forEachRemaining(action::accept);
        }
        
        @Override
        public void remove() {
            this.iterator.remove();
        }
        
        @Override
        public int skip(final int n) {
            return this.iterator.skip(n);
        }
    }
}
