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

com.loocme.sys.datastruct.WeekSimple Maven / Gradle / Ivy

package com.loocme.sys.datastruct;

import java.util.Date;
import java.util.List;
import java.util.Map;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;

import com.loocme.sys.constance.DateFormatConst;
import com.loocme.sys.util.DateUtil;

/**
 * @author liuchi
 */
class WeekSimple extends Var implements java.io.Serializable
{

    private static final long serialVersionUID = 1L;

    private transient Object priValue = null;

    public WeekSimple()
    {
        super();
    }

    public WeekSimple(Object value)
    {
        super();
        this.setValue(value);
    }

    @SuppressWarnings("unchecked")
    void setValue(Object value)
    {
        if (null == value)
        {
            return;
        }

        if (value instanceof List)
        {
            JSONArray arr = new JSONArray((List) value);
            this.priValue = arr.toString();
            return;
        }

        if (value instanceof Map)
        {
            JSONObject obj = new JSONObject((Map) value);
            this.priValue = obj.toString();
            return;
        }

        this.priValue = value;
    }

    Object getValue()
    {
        if (this.priValue instanceof Date)
        {
            return DateUtil.getFormat((Date) this.priValue,
                    DateFormatConst.YMDHMS_);
        }

        return this.priValue;
    }

    @Override
    public boolean isObject()
    {
        return false;
    }

    @Override
    public boolean isArray()
    {
        return false;
    }

    @Override
    public boolean isBasicType()
    {
        return true;
    }

    @Override
    public boolean isNull()
    {
        return false;
    }
    
    @Override
    public void foreach(IVarForeachHandler handler)
    {
        return;
    }

    @Override
    public void clear()
    {
        this.priValue = null;
    }

    @Override
    public Object getObject()
    {
        return this.priValue;
    }

    @Override
    public void addAll(Var var)
    {
    }

    @Override
    public String toString()
    {
        if (null == this.priValue)
        {
            return "";
        }
        return this.priValue.toString();
    }
    
    @Override
    public String toXml(boolean simple)
    {
        if (null == this.priValue)
        {
            return "";
        }
        return this.priValue.toString();
    }
}