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

com.tmsps.ne4spring.orm.param.NeParamList Maven / Gradle / Ivy

There is a newer version: 999.0.0.0
Show newest version
package com.tmsps.ne4spring.orm.param;

import java.util.ArrayList;
import java.util.List;

import org.springframework.util.ObjectUtils;

import com.tmsps.ne4spring.utils.ChkUtil;

public class NeParamList {

	private List paramList = new ArrayList();
	// 最终值列表
	private List paramValueList = new ArrayList();

	public NeParamList add(Object value) {
		NeParam p = new NeParam();
		p.setValue(value);
		paramList.add(p);

		// 非空,加入[值] list
		if (!p.getIsNull()) {
			paramValueList.add(value);
		}

		return this;
	}
	
	/**
	 * 	@Description: 多参数加入
	 *	@author: zhangwei(Mr.z)[email protected]
	 *	@date: 2023/02/23
	 */
	public NeParamList add(Object[] values) {
		if (!ObjectUtils.isEmpty(values)) {
			NeParam p = new NeParam();
			for (Object value : values) {
				p.setValue(value);
				paramList.add(p);
				// 非空,加入[值] list
				if (!p.getIsNull()) {
					paramValueList.add(value);
				}
			}
		}
		return this;
	}

	public NeParamList addLikeL(String paramValue) {
		if (ChkUtil.isNotNull(paramValue)) {
			paramValue = "%" + paramValue;
		}
		return add(paramValue);
	}

	public NeParamList addLikeR(String paramValue) {
		if (ChkUtil.isNotNull(paramValue)) {
			paramValue = paramValue + "%";
		}
		return add(paramValue);
	}

	public NeParamList addLike(String paramValue) {
		if (ChkUtil.isNotNull(paramValue)) {
			paramValue = "%" + paramValue + "%";
		}
		return add(paramValue);
	}

	// 获取最终值的参数
	public Object[] getParamValues() {
		return paramValueList.toArray();
	}// #getParamValues

	public List getParamList() {
		return paramList;
	}

	public static NeParamList makeParams() {
		NeParamList params = new NeParamList();
		return params;
	}

	@Override
	public String toString() {
		StringBuilder sb = new StringBuilder();
		sb.append("[ ");
		for (Object value : paramValueList) {
			sb.append(value).append(" ");
		}
		sb.append("]");
		return sb.toString();
	}
}