GeoJSON.java [src/m/utils] 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 m.utils;

import csip.api.server.ServiceException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;
import org.codehaus.jettison.json.JSONArray;
import org.codehaus.jettison.json.JSONObject;

/**
 * Represents a list of GeoJSON objects.  Can be of type Feature or FeatureCollection.
 * @author ktraff
 */
public class GeoJSON implements List<Layer> {
    
    JSONArray geojson;
    ArrayList<Layer> layers;
    IGISDatabase db;
    GeoJSONParser parser;

    public GeoJSON(JSONArray geojson, IGISDatabase db) throws ServiceException {
        this(geojson, db, "upload");
    }
    
    public GeoJSON(JSONArray geojson, IGISDatabase db, String prefix) throws ServiceException {
        this.db = db;
        this.geojson = geojson;
        this.parser = new GeoJSONParser(geojson, db, prefix);
        layers = parser.parse();
    }

    public GeoJSON(JSONObject geojson, IGISDatabase db) throws ServiceException {
        this(new JSONArray().put(geojson), db);
    }
    
    public GeoJSON(JSONObject geojson, IGISDatabase db, String prefix) throws ServiceException {
        this(new JSONArray().put(geojson), db, prefix);
    }

    @Override
    public int size() {
        return layers.size();
    }

    @Override
    public boolean isEmpty() {
        return layers.isEmpty();
    }

    @Override
    public boolean contains(Object o) {
        return layers.contains(o);
    }

    @Override
    public Iterator<Layer> iterator() {
        return layers.iterator();
    }

    @Override
    public Object[] toArray() {
        return layers.toArray();
    }

    @Override
    public <T> T[] toArray(T[] a) {
        return layers.toArray(a);
    }

    @Override
    public boolean add(Layer e) {
        return layers.add(e);
    }

    @Override
    public boolean remove(Object o) {
        return layers.remove(o);
    }

    @Override
    public boolean containsAll(Collection<?> c) {
        return layers.containsAll(c);
    }

    @Override
    public boolean addAll(Collection<? extends Layer> c) {
        return layers.addAll(c);
    }

    @Override
    public boolean addAll(int index, Collection<? extends Layer> c) {
        return layers.addAll(index, c);
    }

    @Override
    public boolean removeAll(Collection<?> c) {
        return layers.removeAll(c);
    }

    @Override
    public boolean retainAll(Collection<?> c) {
        return layers.retainAll(c);
    }

    @Override
    public void clear() {
        layers.clear();
    }

    @Override
    public Layer get(int index) {
        return layers.get(index);
    }

    @Override
    public Layer set(int index, Layer element) {
        return layers.set(index, element);
    }

    @Override
    public void add(int index, Layer element) {
        layers.add(index, element);
    }

    @Override
    public Layer remove(int index) {
        return layers.remove(index);
    }

    @Override
    public int indexOf(Object o) {
        return layers.indexOf(o);
    }

    @Override
    public int lastIndexOf(Object o) {
        return layers.lastIndexOf(o);
    }

    @Override
    public ListIterator<Layer> listIterator() {
        return layers.listIterator();
    }

    @Override
    public ListIterator<Layer> listIterator(int index) {
        return layers.listIterator(index);
    }

    @Override
    public List<Layer> subList(int fromIndex, int toIndex) {
        return layers.subList(fromIndex, toIndex);
    }
    
}