[Nice-commit] Nice/stdlib/nice/lang range.nice,NONE,1.1 ForInIters.nice,1.4,1.5
Brought to you by:
bonniot
From: <ar...@us...> - 2003-08-28 17:46:24
|
Update of /cvsroot/nice/Nice/stdlib/nice/lang In directory sc8-pr-cvs1:/tmp/cvs-serv14527/F:/nice/stdlib/nice/lang Modified Files: ForInIters.nice Added Files: range.nice Log Message: Added a simple range class. --- NEW FILE: range.nice --- /**************************************************************************/ /* N I C E */ /* A high-level object-oriented research language */ /* (c) Daniel Bonniot 2003 */ /* */ /* This program is free software; you can redistribute it and/or modify */ /* it under the terms of the GNU General Public License as published by */ /* the Free Software Foundation; either version 2 of the License, or */ /* (at your option) any later version. */ /* */ /**************************************************************************/ package nice.lang; public class Range<T | T <: int, int <: T> extends AbstractList<T> { private final int begin; private final int end; isEmpty() = false; size() = 1+end-begin; get(index) { if (index < 0 || index >= 1+end-begin) throw new IndexOutOfBoundsException(); return begin + index; } add(elem) = throw new UnsupportedOperationException(); contains(elem) = begin <= cast(elem) <= end; iterator() = new RangeIterator(range: this, pos: begin-1); listIterator() = new RangeIterator(range: this, pos: begin-1); listIterator(index) = new RangeIterator(range: this, pos: begin + index-1); } public class RangeIterator<T | T <: int, int <: T> implements ListIterator<T> { final Range<int> range; int pos; hasNext() = pos+1 <= range.end; next() = ++pos; hasPrevious() = pos-1 >= range.begin; previous() = --pos; nextIndex() = (pos-range.begin) + 1; previousIndex() = pos - range.begin; remove() = throw new UnsupportedOperationException(); set(elem) = throw new UnsupportedOperationException(); add(elem) = throw new UnsupportedOperationException(); } public Range<int> `..`(int begin, int end) requires begin <= end { return new Range(begin: begin, end: end); } Index: ForInIters.nice =================================================================== RCS file: /cvsroot/nice/Nice/stdlib/nice/lang/ForInIters.nice,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** ForInIters.nice 21 Jul 2003 17:24:14 -0000 1.4 --- ForInIters.nice 28 Aug 2003 17:46:15 -0000 1.5 *************** *** 20,23 **** --- 20,24 ---- Iterator<char> forIterator(String s) = new StringForIterator(str: s); Iterator<char> forIterator(StringBuffer sb) = new StringBufferForIterator(strb: sb); + Iterator<int> forIterator(Range<int> range) = range.iterator(); //The implementations of additional Iterators |