001/* 002 * Copyright (c) 2005 Peter Palotas, Fredrik Johansson, Einar Pehrson, 003 * Sebastian Kekkonen, Lars Magnus Lang, Malin Johansson and Sofia Nilsson 004 * 005 * This file is part of 006 * CleanSheets Extension for Assertions 007 * 008 * CleanSheets Extension for Assertions is free software; you can 009 * redistribute it and/or modify it under the terms of the GNU General Public 010 * License as published by the Free Software Foundation; either version 2 of 011 * the License, or (at your option) any later version. 012 * 013 * CleanSheets Extension for Assertions is distributed in the hope that 014 * it will be useful, but WITHOUT ANY WARRANTY; without even the implied 015 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 016 * See the GNU General Public License for more details. 017 * 018 * You should have received a copy of the GNU General Public License 019 * along with CleanSheets Extension for Assertions; if not, write to the 020 * Free Software Foundation, Inc., 59 Temple Place, Suite 330, 021 * Boston, MA 02111-1307 USA 022 */ 023package csheets.ext.assertion; 024 025import java.util.Iterator; 026import java.util.NoSuchElementException; 027 028/** An iterator wrapper used by MultiInterval to be able to expose 029 the intervals contained in the MultiInterval without 030 allowing the user to modify the underlying collection 031 directly. 032 @author Peter Palotas */ 033public class ConstMultiIntervalIterator implements Iterator<Interval> { 034 035 private Iterator<Interval> iter; 036 037 /** Creates a new "const"-iterator using the iterator specified 038 for all operations except remove. 039 @param iter the iterator to use for iteration. */ 040 protected ConstMultiIntervalIterator(Iterator<Interval> iter) { 041 this.iter = iter; 042 } 043 044 /** Returns <code>true</code> if the iteration has more elements. 045 (In other words, returns <code>true</code> if <code>next</code> would return 046 an element rather than throwing an exception.) 047 @return true if the iterator has more elements, <code>false</code> otherwise. */ 048 public boolean hasNext() { 049 return iter.hasNext(); 050 } 051 052 /** Returns the next element in the iteration. Calling this method repeatedly until the 053 <code>hasNext()</code> method returns <code>false</code> will return each element 054 in the underlying collection exactly once. 055 @return the next element in the iteration. 056 @exception NoSuchElementException iteration has no more elements. */ 057 public Interval next() { 058 return iter.next(); 059 } 060 061 /** Throws UnsupportedOperationException since this iterator does not allow modification 062 of the unerlying collection. 063 @exception UnsupportedOperationException whenever called. */ 064 public void remove() { 065 throw new UnsupportedOperationException("Cannot modify a MultiInterval through its iterator"); 066 } 067};