Alachisoft.NCache.Common.JSON.ExtendedJsonValue Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of nc-common Show documentation
Show all versions of nc-common Show documentation
Internal package of Alachisoft.
package Alachisoft.NCache.Common.JSON;
import Alachisoft.NCache.Common.Caching.UserBinaryObject;
import com.alachisoft.ncache.runtime.JSON.JsonValueBase;
import com.alachisoft.ncache.runtime.JSON.JsonValueType;
import java.io.Serializable;
import java.nio.charset.Charset;
public class ExtendedJsonValue extends ExtendedJsonValueBase implements Serializable
{
///#region ------------------------------ Fields ------------------------------
private JsonValueBase _jsonValue;
private int _serializedCounterpartSize;
private int _serializedCounterpartInMemorySize;
///#endregion
///#region ---------------------------- Properties ----------------------------
@Override
public JsonValueType getJsonType()
{
return JsonValueType.Json;
}
@Override
public Object getValue()
{
return _jsonValue;
}
@Override
public int getSize()
{
return _serializedCounterpartSize;
}
@Override
public int getInMemorySize()
{
return _serializedCounterpartInMemorySize;
}
///#endregion
///#region --------------------------- Constructors ---------------------------
public ExtendedJsonValue(JsonValueBase jsonValue, int serializedCounterpartSize, int serializedCounterpartInMemorySize)
{
super();
_jsonValue = jsonValue;
// Although the following sounds right but they
// result in cache size going in negative
//Size += jsonValue.Size;
//InMemorySize += jsonValue.InMemorySize;
_serializedCounterpartSize = serializedCounterpartSize;
_serializedCounterpartInMemorySize = serializedCounterpartInMemorySize;
}
///#endregion
///#region ----------------------------- Behavior -----------------------------
@Override
public UserBinaryObject toUserBinaryObject()
{
return UserBinaryObject.createUserBinaryObject(_jsonValue.toJson().getBytes(Charset.forName("UTF-8")));
}
@Override
public String toJson()
{
if(_jsonValue != null)
return _jsonValue.toString();
return null;
}
///#endregion
///#region ---------------------------- Overrides -----------------------------
@Override
public String toString()
{
return toJson();
}
@Override
public boolean equals(Object obj)
{
ExtendedJsonValue otherJsonValue = (ExtendedJsonValue)((obj instanceof ExtendedJsonValue) ? obj : null);
if (otherJsonValue == null)
return false;
return _jsonValue.equals(otherJsonValue._jsonValue);
}
@Override
public int hashCode()
{
return _jsonValue.hashCode();
}
///#endregion
}