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

Alachisoft.NCache.Common.JSON.JsonDocumentUtil Maven / Gradle / Ivy

package Alachisoft.NCache.Common.JSON;

import com.alachisoft.ncache.runtime.JSON.JsonValue;
import com.alachisoft.ncache.runtime.JSON.JsonValueBase;

public class JsonDocumentUtil
{
    public static java.util.ArrayList ToJsonValueList(Iterable arrayList)
    {
        java.util.ArrayList jsonList = new java.util.ArrayList();
        for (Object value : arrayList)
        {
            JsonValueBase jsonValue = ToJsonValueBase(value); //, 0, 0
            jsonList.add(jsonValue);
        }
        return jsonList;
    }

    public static JsonValueBase ToJsonValueBase(Object value) //, int binarySize, int binaryInMemorySize
    {
        JsonValueBase jsonValue = null;
        if (IsNumber(value))
            jsonValue = new JsonValue((Double)value);
        else if (value.getClass().equals(boolean.class))
            jsonValue = new JsonValue((Boolean)value);
        else if (value instanceof String || value instanceof Character)
            jsonValue = new JsonValue(value.toString());
        else if (value instanceof java.util.Date)
            jsonValue = new JsonValue(((java.util.Date)value).toString());
        else
            throw new RuntimeException("Json type not supported.");
        return jsonValue;
    }

    public static ExtendedJsonValueBase ToExtendedJsonValueBase(Object value, int binarySize, int binaryInMemorySize)
    {
        JsonValueBase jsonValue = (JsonValueBase)((value instanceof JsonValueBase) ? value : null);
        if (jsonValue == null)
            jsonValue = ToJsonValueBase(value); //, binarySize, binaryInMemorySize
        return new ExtendedJsonValue(jsonValue, binarySize, binaryInMemorySize);
    }

    public static boolean IsNumber(Object value)
    {
        if (value == null)
            return false;

        if (byte.class.equals(value.getClass()) || short.class.equals(value.getClass()) || int.class.equals(value.getClass()) || long.class.equals(value.getClass()) || double.class.equals(value.getClass())) {
            return true;
        }
        return false;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy