JSONArrayIterator.java [src/java/reports] Revision: default Date:
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package reports;
import java.util.Iterator;
import org.codehaus.jettison.json.JSONArray;
import org.codehaus.jettison.json.JSONException;
/**
* Used by JSONArrayIteratingUberspector to allow the "#foreach( $management in
* $managements )" notation in Apache Velocity to understand JSONArrays.
*/
public final class JSONArrayIterator implements Iterator<Object> {
private final JSONArray array;
private int nextIndex;
private final int length;
public JSONArrayIterator(JSONArray array) {
this.array = array;
nextIndex = 0;
length = array.length();
}
@Override
public boolean hasNext() {
return nextIndex < length;
}
@Override
public Object next() {
nextIndex++;
try {
return array.get(nextIndex - 1);
} catch (JSONException e) {
throw new IllegalStateException(e);
}
}
@Override
public void remove() {
throw new UnsupportedOperationException();
}
}