com.liferay.portal.json.JSONArrayImpl Maven / Gradle / Ivy
/**
* Copyright (c) 2000-present Liferay, Inc. All rights reserved.
*
* This library is free software; you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by the Free
* Software Foundation; either version 2.1 of the License, or (at your option)
* any later version.
*
* This library is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
* details.
*/
package com.liferay.portal.json;
import com.liferay.petra.function.UnsafeSupplier;
import com.liferay.portal.kernel.json.JSONArray;
import com.liferay.portal.kernel.json.JSONException;
import com.liferay.portal.kernel.json.JSONObject;
import com.liferay.portal.kernel.log.Log;
import com.liferay.portal.kernel.log.LogFactoryUtil;
import com.liferay.portal.kernel.util.Validator;
import java.io.IOException;
import java.io.ObjectInput;
import java.io.ObjectOutput;
import java.io.Writer;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
/**
* @author Brian Wing Shun Chan
*/
public class JSONArrayImpl implements JSONArray {
public JSONArrayImpl() {
_jsonArray = new org.json.JSONArray();
}
public JSONArrayImpl(Collection> collection) {
_jsonArray = new org.json.JSONArray(collection);
}
public JSONArrayImpl(org.json.JSONArray jsonArray) {
_jsonArray = jsonArray;
}
public JSONArrayImpl(String json) throws JSONException {
try {
if (Validator.isNull(json)) {
json = _NULL_JSON;
}
_jsonArray = new org.json.JSONArray(json);
}
catch (Exception exception) {
throw new JSONException(exception);
}
}
@Override
public Object get(int index) {
Object value = _jsonArray.opt(index);
if (value instanceof org.json.JSONArray) {
return new JSONArrayImpl((org.json.JSONArray)value);
}
if (value instanceof org.json.JSONObject) {
return new JSONObjectImpl((org.json.JSONObject)value);
}
return value;
}
@Override
public boolean getBoolean(int index) {
return _jsonArray.optBoolean(index);
}
@Override
public double getDouble(int index) {
return _jsonArray.optDouble(index);
}
@Override
public int getInt(int index) {
return _jsonArray.optInt(index);
}
public org.json.JSONArray getJSONArray() {
return _jsonArray;
}
@Override
public JSONArray getJSONArray(int index) {
org.json.JSONArray jsonArray = _jsonArray.optJSONArray(index);
if (jsonArray == null) {
return null;
}
return new JSONArrayImpl(jsonArray);
}
@Override
public JSONObject getJSONObject(int index) {
org.json.JSONObject jsonObj = _jsonArray.optJSONObject(index);
if (jsonObj == null) {
return null;
}
return new JSONObjectImpl(jsonObj);
}
@Override
public long getLong(int index) {
return _jsonArray.optLong(index);
}
@Override
public String getString(int index) {
return _jsonArray.optString(index);
}
@Override
public boolean isNull(int index) {
return _jsonArray.isNull(index);
}
@Override
public Iterator © 2015 - 2025 Weber Informatics LLC | Privacy Policy