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

easy.sql.Col Maven / Gradle / Ivy

There is a newer version: 1.0.71
Show newest version
package easy.sql;


import net.sf.json.JSONObject;

import java.io.Serializable;

public class Col implements Comparable,Serializable
{
	public void setFieldname(String fieldname)
	{
		this.fieldname = fieldname;
	}

	/**
	 *
	 */
	private static final long serialVersionUID = 1L;

	private String fieldname;
	private Object value;

	public void setValue(Object value)
	{
		this.value = value;
	}

	public Col()
	{
	}

	public Col (String fieldname,Object value)
	{
		if (value == null)
		{
			this.value = "";
		}
		else
		{
			this.value = value;
		}
		this.fieldname = fieldname;
	}

	public Col (String fieldname,String value)
	{
		if (value == null)
		{
			this.value = "";
		}
		else
		{
			this.value = value;
		}
		this.fieldname = fieldname;
	}

	public Col (String fieldname,int value)
	{
		this.fieldname = fieldname;
		this.value = value;
	}

	public Col (String fieldname,float value)
	{
		this.fieldname = fieldname;
		this.value = value;
	}

	public Col (String fieldname,long value)
	{
		this.fieldname = fieldname;
		this.value = value;
	}

	public Col (String fieldname,double value)
	{
		this.fieldname = fieldname;
		this.value = value;
	}

	public int compareTo(Col o)
	{
//		Col c = (Col)o;

		if (value instanceof Integer)
		{
			return Integer.compare((Integer)value, (Integer)o.value);
		}
		else if (value instanceof Long)
		{
			return Long.compare((Long)value, (Long)o.value);
		}
		else if (value instanceof Float)
		{
			return Float.compare((Float)value, (Float)o.value);
		}
		else if (value instanceof Double)
		{
			return Double.compare((Double)value, (Double)o.value);
		}
		else if (value instanceof byte[])
		{
			return new String((byte[])value).compareTo(new String((byte[])o.value));
		}
		else
		{
			return value.toString().compareTo(o.value.toString());
		}
	}


	public String getFieldname()
	{
		return fieldname;
	}

	/**
	 * @return Returns the value.
	 */
	public Object getValue()
	{
		return value;
	}

	@Override
	public String toString()
	{
		JSONObject json = new JSONObject();
		json.put(fieldname,value);
		return json.toString();
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy