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

com.hn.im.easemob.comm.wrapper.QueryWrapper Maven / Gradle / Ivy

There is a newer version: 1.0.18
Show newest version
package com.hn.im.easemob.comm.wrapper;

import cn.hutool.core.util.StrUtil;
import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;

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

public class QueryWrapper {
	
	private static final String LIMIT = "limit";
	
	private static final String CURSOR = "cursor";

	private static final String QUERY = "ql";
	
	private List queries = new ArrayList();
	
	public static QueryWrapper newInstance() {
		return new QueryWrapper();
	}
	
	public QueryWrapper addQuery(String key, String value) {
		if( StrUtil.isBlank(key) || StrUtil.isBlank(value) ){
			return this;
		}
		
		queries.add(new BasicNameValuePair(key, value));
		return this;
	}
	
	public QueryWrapper addLimit(Long limit) {
		limit = null == limit ? 10L : limit;

		return addQuery(LIMIT, limit.toString());
	}
	
	public QueryWrapper addCursor(String cursor) {
		return addQuery(CURSOR, cursor);
	}

	public QueryWrapper addQueryLang(String ql) {
		return addQuery(QUERY, ql);
	}

	public List getQueries() {
		return queries;
	}

	@Override
	public String toString() {
		StringBuffer sb = new StringBuffer();
		for( NameValuePair query : queries ) {
			sb.append("[").append(query.getName()).append(":").append(query.getValue()).append("] ");
		}
		
		return sb.toString();
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy