001package org.clafer.collection; 002 003import gnu.trove.iterator.TIntIterator; 004 005/** 006 * An iterator over an interval in decreasing order. 007 * 008 * @author jimmy 009 */ 010public class ReverseBoundIntIterator implements TIntIterator { 011 012 private int index; 013 private final int low; 014 015 /** 016 * Iterate in decreasing order starting from high (inclusive) and ending in 017 * low (inclusive). 018 * 019 * @param low the lowest value 020 * @param high the highest value 021 */ 022 public ReverseBoundIntIterator(int low, int high) { 023 this.index = high; 024 this.low = low; 025 } 026 027 /** 028 * {@inheritDoc} 029 */ 030 @Override 031 public boolean hasNext() { 032 return index >= low; 033 } 034 035 /** 036 * {@inheritDoc} 037 */ 038 @Override 039 public int next() { 040 return index--; 041 } 042 043 /** 044 * Not supported. 045 * 046 * @throws UnsupportedOperationException if invoked 047 */ 048 @Override 049 public void remove() { 050 throw new UnsupportedOperationException(); 051 } 052}