All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.google.security.fences.util.CountingIterator Maven / Gradle / Ivy

There is a newer version: 1.9-beta
Show newest version
package com.google.security.fences.util;

import java.util.Iterator;

import com.google.common.base.Preconditions;

/**
 * A single enumeration over a {@link CountingIterator}.
 */
public final class CountingIterator implements Iterator {
  private int i;
  private final int rightExclusive;

  CountingIterator(int leftInclusive, int rightExclusive) {
    Preconditions.checkArgument(i <= rightExclusive);
    this.i = leftInclusive;
    this.rightExclusive = rightExclusive;
  }

  @Override
  public String toString() {
    return "[" + i + ".." + rightExclusive + ")";
  }

  public boolean hasNext() {
    return i < rightExclusive;
  }

  public synchronized Integer next() {
    if (i >= rightExclusive) {
      throw new IndexOutOfBoundsException(i + " >= " + rightExclusive);
    }
    return i++;
  }

  public void remove() {
    throw new UnsupportedOperationException();
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy