Subversion Repositories distributed

Rev

Go to most recent revision | Blame | Last modification | View Log | RSS feed

  1. package de.viathinksoft.distributed.apps.immortal.iterator.sequential;
  2.  
  3. import java.math.BigInteger;
  4. import java.util.Iterator;
  5.  
  6. import de.viathinksoft.distributed.apps.immortal.iterator.QuickImmortableCheck;
  7.  
  8. //TODO: Iterable aufspalten?
  9.  
  10. public class SequentialIterator implements Iterator<BigInteger>, Iterable<BigInteger> {
  11.        
  12.         private BigInteger position = BigInteger.ZERO;
  13.        
  14.         public SequentialIterator(BigInteger start) {
  15.                 this.position = start;
  16.         }
  17.  
  18.         @Override
  19.         public boolean hasNext() {
  20.                 return true;
  21.         }
  22.  
  23.         @Override
  24.         public BigInteger next() {
  25.                 BigInteger chk = position;
  26.                
  27.                 do {
  28.                         chk = chk.add(BigInteger.ONE);
  29.                 } while (!QuickImmortableCheck.check(chk));
  30.                 position = chk;
  31.  
  32.                 return position;
  33.         }
  34.  
  35.         @Override
  36.         public void remove() {
  37.                 throw new UnsupportedOperationException();
  38.         }
  39.  
  40.         @Override
  41.         public Iterator<BigInteger> iterator() {
  42.                 return this;
  43.         }
  44. }
  45.