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

com.adobe.aemds.guide.utils.JSONArrayIterator Maven / Gradle / Ivy

package com.adobe.aemds.guide.utils;

import java.util.Iterator;
import java.util.NoSuchElementException;

import org.apache.sling.commons.json.JSONArray;
import org.apache.sling.commons.json.JSONException;
import org.apache.sling.commons.json.JSONObject;


/**
 * Expectation of this iterator from input JSONArray is that array should consist of only and only JSONObjects
 * @pad.exclude Exclude from Published API.
 */
public class JSONArrayIterator implements Iterator {
    private final JSONArray arr;
    private int current;

    public JSONArrayIterator(JSONArray arr){
        this.arr = arr;
        this.current = 0;
    }
    public boolean hasNext() {
        return current < arr.length();
    }
	public JSONObject next() {
        if (!hasNext()){
            throw new NoSuchElementException();
        }
        try {
            return (JSONObject)arr.get(current++);
		} catch (JSONException e) {
		    throw new IllegalStateException(e.getMessage(), e);
        }
    }
    public void remove() {
        throw new UnsupportedOperationException("remove");
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy