/*
 * Copyright (C) 2014 Kalin Maldzhanski
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.djodjo.json.wrapper;


import org.djodjo.json.JsonArray;
import org.djodjo.json.JsonElement;
import org.djodjo.json.exception.JsonException;

import java.io.IOException;
import java.util.ArrayList;

public class JsonObjectArrayWrapper<T extends JsonObjectWrapper> extends JsonElementWrapper {

    public ArrayList<T> getJsonWrappersList() {
        return jsonWrappersList;
    }

    private final ArrayList<T> jsonWrappersList = new ArrayList<T>() ;

    public JsonObjectArrayWrapper() {
        super();

    }

    public JsonObjectArrayWrapper wrap(JsonArray jsonArray, Class<T> cls) {
        super.wrap(jsonArray);
        jsonWrappersList.clear();

        for(JsonElement e : getJson()) {
            if(e.isJsonObject()) {
                try {
                    T el = cls.newInstance();
                    el.wrap(e);
                    jsonWrappersList.add(el);
                } catch (InstantiationException e1) {
                    e1.printStackTrace();
                } catch (IllegalAccessException e1) {
                    e1.printStackTrace();
                }
            }
        }


        return this;
    }

    @Override
    public JsonArray getJson() {
        if(super.getJson() == null) try {
            this.json  = JsonElement.readFrom("[ ]");
        } catch (JsonException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return super.getJson().asJsonArray();
    }


}

@@ -811,16 +811,98 @@
 yList;%0A%0A
+/**%0A * Json Array that contains Json Objects of a specific type%0A * @param %3CT%3E%0A */%0A
 public c
@@ -2181,11 +2181,264 @@
 %0A    %7D%0A%0A
+    public %3CO extends JsonObjectArrayWrapper%3E O addJsonObjectWrapperItem(T jsonObjectWrapperItem) %7B%0A        jsonWrappersList.add(jsonObjectWrapperItem);%0A        getJson().asJsonArray().put(jsonObjectWrapperItem.getJson());%0A        return (O)this;%0A    %7D%0A
 %0A%7D%0A

implement addJsonObjectWrapperItem