All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.alogic.xscript.doc.json.JsonArray Maven / Gradle / Ivy

There is a newer version: 1.6.17
Show newest version
package com.alogic.xscript.doc.json;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.alogic.xscript.doc.XsArray;
import com.alogic.xscript.doc.XsObject;

/**
 * 基于Json的XsArray
 * @author yyduan
 * @since 1.6.8.14
 */
public class JsonArray implements XsArray {
	
	protected List content = null;
	
	public JsonArray(List content) {
		this.content = content;
	}

	public Object getContent() {
		return content;
	}

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

	@SuppressWarnings("unchecked")
	@Override
	public XsObject get(int index) {
		Object found = content.get(index);
		if (found instanceof Map){
			return new JsonObject("item" + index,(Map)found);
		}
		
		return null;
	}

	@Override
	public XsObject newObject() {
		return new JsonObject("item" + content.size(),new HashMap());
	}

	@Override
	public void add(XsObject data) {
		content.add(data.getContent());
	}

}