package com.takensoft.pohangTp.data.vo;



import java.io.Serializable;

import com.takensoft.pohangTp.common.connection.db.vo.DataType;
import com.takensoft.pohangTp.common.util.CommonUtil;
import com.takensoft.pohangTp.common.util.StringUtil;


/**
 * @author 최정우
 * @since 2019.11.13
 * 
 * 열(Column) 데이터(데이터목록)를 담는 Class 입니다.
 */
public class ColumnValue implements Serializable , Comparable<ColumnValue> {
	
	/**
	 * 시리얼 버전
	 */
	private static final long serialVersionUID = 1L;
	
	/**
	 * 컬럼의 값
	 */
	private Object value;
	
	/**
	 * 해당 열 데이터의 데이터 타입
	 */
	private DataType dataType;
	
	/**
	 * 중복제거 시, 중복되는 갯수
	 */
	private int count;
	
	public ColumnValue() {
		
	}
	
	/**
	 * 초기화
	 */
	public ColumnValue(Object value,DataType dataType) {
		this.value = value;
		this.dataType = dataType;	
	}
	
	
	public ColumnValue(Object value,DataType dataType, int count ) {
		this.value = value;
		this.dataType = dataType;
		this.count = count;
	}
	
	public Object getValue() {
		return value;
	}

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

	public DataType getDataType() {
		return dataType;
	}

	public void setDataType(DataType dataType) {
		this.dataType = dataType;
	}

	public int getCount() {
		return count;
	}

	public void setCount(int count) {
		this.count = count;
	}

	@Override
	public int compareTo(ColumnValue columnValue) {
		
		int result = 0;
		if (this.value == null && columnValue.getValue() != null) {
			result = -1;
		} else if (this.value != null && columnValue.getValue() == null) {
			result = 1;
		} else if (this.value != null && columnValue.getValue() != null) {
			if(this.dataType.equals(DataType.STRING)) {
				result = StringUtil.toString(this.value).compareTo(StringUtil.toString(columnValue.getValue()));
			} else if(this.dataType.equals(DataType.DOUBLE)) {
				result = Double.compare(CommonUtil.parseDouble(this.value), CommonUtil.parseDouble(columnValue.getValue()));
			}else if(this.dataType.equals(DataType.LONG)) {
				result = Double.compare(CommonUtil.parseDouble(this.value), CommonUtil.parseDouble(columnValue.getValue()));
				//result = Long.compare(Long.parseLong(this.value.toString()), Long.parseLong(columnValue.getValue().toString()));
			}
		} else {//둘다 null
			result = 0;
		}
	
		return result;
	}

}
