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

org.infinispan.objectfilter.impl.util.ArrayIterator Maven / Gradle / Ivy

There is a newer version: 9.1.7.Final
Show newest version
package org.infinispan.objectfilter.impl.util;

import java.lang.reflect.Array;
import java.util.Iterator;

/**
 * An immutable Iterator for arrays.
 *
 * @author [email protected]
 * @since 7.0
 */
public final class ArrayIterator implements Iterator {

   /**
    * An array of whatever type.
    */
   private final Object array;

   /**
    * Current position.
    */
   private int pos = 0;

   public ArrayIterator(Object array) {
      if (array == null) {
         throw new IllegalArgumentException("Argument cannot be null");
      }
      if (!array.getClass().isArray()) {
         throw new IllegalArgumentException("Argument is expected to be an array");
      }
      this.array = array;
   }

   public boolean hasNext() {
      return pos < Array.getLength(array);
   }

   public T next() {
      return (T) Array.get(array, pos++);
   }

   public void remove() {
      throw new UnsupportedOperationException("This iterator is immutable");
   }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy