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

gu.sql2java.StringFieldSearcher Maven / Gradle / Ivy

There is a newer version: 5.2.0
Show newest version
package gu.sql2java;

import static com.google.common.base.Preconditions.checkNotNull;
import static gu.sql2java.Managers.baseManagerOf;

import com.google.common.base.Function;
import com.google.common.base.Predicate;
import com.google.common.base.Strings;
import com.google.common.collect.Multimap;

public class StringFieldSearcher extends BaseFieldSearcher {

	private Function funKeyGetter;
	public StringFieldSearcher(RowMetaData metaData, int... effectColumnIds) {
		super(metaData, effectColumnIds);
		setDefaultMatchFilter(StringMatchType.REGEX_MATCH);
	}

	public StringFieldSearcher(RowMetaData metaData, String... effectColumnNames) {
		this(metaData, checkNotNull(metaData,"metaData is null").columnIDsOf(effectColumnNames));
	}

	public > StringFieldSearcher(Class interfaceClass, int[] effectColumnId) {
		this(baseManagerOf(interfaceClass).metaData, effectColumnId);
	}

	public > StringFieldSearcher(Class interfaceClass, String... effectColumnNames) {
		this(baseManagerOf(interfaceClass).metaData, effectColumnNames);
	}

	@Override
	protected String keyOf(B bean) {
		// 返回空则视为null
		return Strings.emptyToNull(checkNotNull(funKeyGetter,"funKeyGetter is uninitialized").apply(bean));
	}
	
	public Function getFunKeyGetter() {
		return funKeyGetter;
	}

	public StringFieldSearcher setFunKeyGetter(Function funKeyGetter) {
		this.funKeyGetter = funKeyGetter;
		return this;
	}
	
	public StringFieldSearcher setDefaultMatchFilter(StringMatchType defaultMatchType){
		if(defaultMatchType != null){
			setDefaultMatchFilter(defaultMatchType.createMatchFilter());
		}
		return this;
	}
	public final  Multimap search(String key, int matchFlags, StringMatchType matchType, Predicate pkFilter){
		return search(key,matchFlags, matchType == null ? null : matchType.createMatchFilter(), pkFilter);
	}
}