package com.uas.report.crystal2jasper;

import com.uas.report.util.StringUtils;

/**
 * @author sunyj
 * @since 2017年5月24日 上午10:29:14
 */
public class Sort {

	private String field;

	private SortType sortType;

	public Sort(String field, SortType sortType) {
		super();
		this.field = field;
		this.sortType = sortType;
	}

	public String getField() {
		return field;
	}

	public void setField(String field) {
		this.field = field;
	}

	public SortType getSortType() {
		return sortType;
	}

	public void setSortType(SortType sortType) {
		this.sortType = sortType;
	}

	public String getExpression() {
		String sortTypeExpression = sortType.getExpresstion();
		return StringUtils.isEmpty(sortTypeExpression) ? field : field + " " + sortType.getExpresstion();
	}

	@Override
	public String toString() {
		return "Sort [field=" + field + ", sortType=" + sortType + "]";
	}

	public enum SortType {
		ASC(""), DESC("desc");

		private String expresstion;

		private SortType(String expresstion) {
			this.expresstion = expresstion;
		}

		public String getExpresstion() {
			return expresstion;
		}

		public void setExpresstion(String expresstion) {
			this.expresstion = expresstion;
		}

		public static SortType getSortType(String sortType) {
			return valueOf(sortType.toUpperCase());
		}
	}
}
