Added "Interator" and plugged in some quick usage. I'll add more soon.

git-svn-id: https://samskivert.googlecode.com/svn/trunk@1700 6335cc39-0255-0410-8fd6-9bcaacd3b74c
This commit is contained in:
ray
2005-08-25 17:49:32 +00:00
parent 16c5b7e727
commit 8e050fa4bb
3 changed files with 53 additions and 5 deletions
@@ -96,22 +96,26 @@ public class ArrayIntSet extends AbstractSet
return (binarySearch(value) >= 0);
}
// documentation inherited from interface
public Iterator iterator ()
// documentation inherited from interface IntSet
public Interator interator ()
{
return new Iterator() {
return new Interator() {
public boolean hasNext () {
return (_pos < _size);
}
public Object next () {
public int nextInt () {
if (_pos == _size) {
throw new NoSuchElementException();
} else {
return new Integer(_values[_pos++]);
return _values[_pos++];
}
}
public Object next () {
return new Integer(nextInt());
}
public void remove () {
throw new UnsupportedOperationException();
}
@@ -120,6 +124,12 @@ public class ArrayIntSet extends AbstractSet
};
}
// documentation inherited from interface
public Iterator iterator ()
{
return interator();
}
// documentation inherited from interface
public Object[] toArray ()
{
@@ -74,6 +74,11 @@ public interface IntSet extends Set
*/
public boolean remove (int value);
/**
* Return an Interator that iterates over the ints in this set.
*/
public Interator interator ();
/**
* Returns an array containing all of the elements in this set. Obeys
* the general contract of the <tt>Collection.toArray</tt> method.
@@ -0,0 +1,33 @@
//
// samskivert library - useful routines for java programs
// Copyright (C) 2001-2004 Michael Bayne
//
// This library is free software; you can redistribute it and/or modify it
// under the terms of the GNU Lesser General Public License as published
// by the Free Software Foundation; either version 2.1 of the License, or
// (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
package com.samskivert.util;
import java.util.Iterator;
/**
* Can be used as an Iterator, and all Objects returned should be Integer
* objects, but can also can avoid object creation by calling nextInt().
*/
public interface Interator extends Iterator
{
/**
* @return the next int value from this Iterator.
*/
public int nextInt ();
}