/*
 * Copyright © WebServices pour l'Éducation, 2014
 *
 * 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 fr.wseduc.webutils.collections;

import io.vertx.core.buffer.Buffer;
import io.vertx.core.json.Json;
import io.vertx.core.json.JsonObject;

import java.time.Instant;
import java.util.ArrayList;
import java.util.List;

public class JsonArray extends io.vertx.core.json.JsonArray {

	private final List<Object> list;

	public JsonArray(String json) {
		this(Json.decodeValue(json, List.class));
	}

	public JsonArray() {
		this(new ArrayList<>());
	}

	public JsonArray(List list) {
		super(list);
		this.list = list;
	}

	public JsonArray(Buffer buf) {
		this(Json.decodeValue(buf, List.class));
	}

	@Override
	public io.vertx.core.json.JsonArray add(Enum value) {
		list.add(value);
		return this;
	}

	@Override
	public io.vertx.core.json.JsonArray add(CharSequence value) {
		list.add(value);
		return this;
	}

	@Override
	public io.vertx.core.json.JsonArray add(String value) {
		list.add(value);
		return this;
	}

	@Override
	public io.vertx.core.json.JsonArray add(Integer value) {
		list.add(value);
		return this;
	}

	@Override
	public io.vertx.core.json.JsonArray add(Long value) {
		list.add(value);
		return this;
	}

	@Override
	public io.vertx.core.json.JsonArray add(Double value) {
		list.add(value);
		return this;
	}

	@Override
	public io.vertx.core.json.JsonArray add(Float value) {
		list.add(value);
		return this;
	}

	@Override
	public io.vertx.core.json.JsonArray add(Boolean value) {
		list.add(value);
		return this;
	}

	@Override
	public io.vertx.core.json.JsonArray add(JsonObject value) {
		list.add(value);
		return this;
	}

	@Override
	public io.vertx.core.json.JsonArray add(io.vertx.core.json.JsonArray value) {
		list.add(value);
		return this;
	}

	@Override
	public io.vertx.core.json.JsonArray add(byte[] value) {
		list.add(value);
		return this;
	}

	@Override
	public io.vertx.core.json.JsonArray add(Instant value) {
		list.add(value);
		return this;
	}

	@Override
	public io.vertx.core.json.JsonArray add(Object value) {
		list.add(value);
		return this;
	}

}

@@ -2624,10 +2624,770 @@
 is;%0A%09%7D%0A%0A
+%09public static io.vertx.core.json.JsonArray setInJsonArray(io.vertx.core.json.JsonArray a, int pos, String value)%0A%09%7B%0A%09%09// Vertx doesn't support set in 3.5.0 JsonArrays...%0A%09%09if(pos %3C 0 %7C%7C pos %3E a.size())%0A%09%09%09throw new ArrayIndexOutOfBoundsException();%0A%09%09else if(pos == a.size())%0A%09%09%09a.add(value);%0A%09%09else%0A%09%09%7B%0A%09%09%09List aList = a.getList();%0A%09%09%09aList.set(pos, value);%0A%09%09%7D%0A%09%09return a;%0A%09%7D%0A%0A%09public static io.vertx.core.json.JsonArray setInJsonArray(io.vertx.core.json.JsonArray a, int pos, Object value)%0A%09%7B%0A%09%09// Vertx doesn't support set in 3.5.0 JsonArrays...%0A%09%09if(pos %3C 0 %7C%7C pos %3E a.size())%0A%09%09%09throw new ArrayIndexOutOfBoundsException();%0A%09%09else if(pos == a.size())%0A%09%09%09a.add(value);%0A%09%09else%0A%09%09%7B%0A%09%09%09List aList = a.getList();%0A%09%09%09aList.set(pos, value);%0A%09%09%7D%0A%09%09return a;%0A%09%7D%0A%0A
 %7D%0A

Add functions to set elements in JsonArrays