Range.java
Go to the documentation of this file.00001 /* 00002 * Main authors: 00003 * Mikael Lagerkvist <lagerkvist@gecode.org> 00004 * Guido Tack <tack@gecode.org> 00005 * 00006 * Copyright: 00007 * Mikael Lagerkvist, 2006 00008 * Guido Tack, 2006 00009 * 00010 * Last modified: 00011 * $Date: 2006-09-11 17:06:50 +0200 (Mon, 11 Sep 2006) $ by $Author: zayenz $ 00012 * $Revision: 3650 $ 00013 * 00014 * This file is part of Gecode, the generic constraint 00015 * development environment: 00016 * http://www.gecode.org 00017 * 00018 * See the file "LICENSE" for information on usage and 00019 * redistribution of this file, and for a 00020 * DISCLAIMER OF ALL WARRANTIES. 00021 * 00022 */ 00023 00024 package org.gecode; 00025 00026 import java.util.Iterator; 00027 import java.util.NoSuchElementException; 00028 00033 public class Range implements Iterable<Integer> { 00034 public int min; 00035 public int max; 00036 public Range(int min0, int max0) { min=min0; max=max0; } 00037 00038 public int min() { 00039 return min; 00040 } 00041 public int max() { 00042 return max; 00043 } 00044 00047 public Iterator<Integer> iterator() { 00048 return new JavaRangeContentIterator(min, max); 00049 } 00050 00053 class JavaRangeContentIterator implements Iterator<Integer> { 00054 int min, max, cur; 00055 public JavaRangeContentIterator(int min0, int max0) { 00056 min = min0; 00057 max = max0; 00058 cur = min - 1; 00059 } 00060 public boolean hasNext() { 00061 return cur != max; 00062 } 00063 public Integer next() { 00064 if (cur == max) 00065 throw new NoSuchElementException(); 00066 return ++cur; 00067 } 00068 public void remove() { 00069 throw new UnsupportedOperationException(); 00070 } 00071 } 00072 00073 }
