package com.cocoahero.android.geojson;

import java.io.IOException;
import java.io.InputStream;

import org.json.JSONException;
import org.json.JSONObject;

import com.cocoahero.android.geojson.util.JSONUtils;
import com.cocoahero.android.geojson.util.StreamUtils;

public class GeoJSON {

    // ------------------------------------------------------------------------
    // Public Constants
    // ------------------------------------------------------------------------

    public static final String TYPE_POINT = "Point";

    public static final String TYPE_MULTI_POINT = "MultiPoint";

    public static final String TYPE_LINE_STRING = "LineString";

    public static final String TYPE_MULTI_LINE_STRING = "MultiLineString";

    public static final String TYPE_POLYGON = "Polygon";

    public static final String TYPE_MULTI_POLYGON = "MultiPolygon";

    public static final String TYPE_GEOMETRY_COLLECTION = "GeometryCollection";

    public static final String TYPE_FEATURE = "Feature";

    public static final String TYPE_FEATURE_COLLECTION = "FeatureCollection";

    // ------------------------------------------------------------------------
    // Class Methods
    // ------------------------------------------------------------------------

    public static GeoJSONObject parse(JSONObject json) {
        String type = JSONUtils.optString(json, GeoJSONObject.JSON_TYPE);

        if (TYPE_POINT.equalsIgnoreCase(type)) {
            return new Point(json);
        }

        if (TYPE_MULTI_POINT.equalsIgnoreCase(type)) {
            return new MultiPoint(json);
        }

        if (TYPE_LINE_STRING.equalsIgnoreCase(type)) {
            return new LineString(json);
        }

        if (TYPE_MULTI_LINE_STRING.equalsIgnoreCase(type)) {
            return new MultiLineString(json);
        }

        if (TYPE_POLYGON.equalsIgnoreCase(type)) {
            return new Polygon(json);
        }

        if (TYPE_MULTI_POLYGON.equalsIgnoreCase(type)) {
            return new MultiPolygon(json);
        }

        if (TYPE_GEOMETRY_COLLECTION.equalsIgnoreCase(type)) {
            return new GeometryCollection(json);
        }

        if (TYPE_FEATURE.equalsIgnoreCase(type)) {
            return new Feature(json);
        }

        if (TYPE_FEATURE_COLLECTION.equalsIgnoreCase(type)) {
            return new FeatureCollection(json);
        }

        throw new IllegalArgumentException("The type '" + type + "' is not a valid GeoJSON type.");
    }

    public static GeoJSONObject parse(String jsonString) throws JSONException {
        return parse(new JSONObject(jsonString));
    }

    public static GeoJSONObject parse(InputStream stream) throws IOException, JSONException {
        return parse(StreamUtils.toString(stream));
    }

}

@@ -44,55 +44,107 @@
 ort 
-java.io.IOException;%0Aimport java.io.Input
+com.cocoahero.android.geojson.util.JSONUtils;%0Aimport com.cocoahero.android.geojson.util.
 Stream
+Utils
 ;%0A%0Ai
@@ -213,107 +213,55 @@
 ort 
-com.cocoahero.android.geojson.util.JSONUtils;%0Aimport com.cocoahero.android.geojson.util.
+java.io.IOException;%0Aimport java.io.Input
 Stream
-Utils
 ;%0A%0Ap
@@ -1247,32 +1247,786 @@
 --------------%0A%0A
+    /**%0A     * Parses the given JSONObject as GeoJSON and returns a concrete subclass of %7B@link%0A     * GeoJSONObject%7D corresponding to the type of the root object.%0A     * %3Cp/%3E%0A     * Example:%0A     * %3Cp/%3E%0A     * %3Cpre%3E%0A     * %7B%0A     *     %22type%22: %22Feature%22,%0A     *     %22geometry%22: %7B%0A     *         %22type%22: %22Point%22,%0A     *         %22coordinates%22: %5B125.6, 10.1%5D%0A     *     %7D,%0A     * %7D%0A     * %3C/pre%3E%0A     * %3Cp/%3E%0A     * The above GeoJSON would return an instance of %7B@link Feature%7D.%0A     *%0A     * @param json%0A     *         A %7B@link JSONObject%7D to parse as GeoJSON%0A     *%0A     * @return A concrete subclass instance of %7B@link GeoJSONObject%7D.%0A     *%0A     * @throws IllegalArgumentException%0A     *         If the given object is not a valid GeoJSON type.%0A     */%0A
     public stati

Add JavaDoc: GeoJSON#parse(JSONObject)