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

com.gitee.l0km.codegen.base.FullNameByImporList Maven / Gradle / Ivy

There is a newer version: 3.5.0
Show newest version
package com.gitee.l0km.codegen.base;

import java.util.Collections;
import java.util.Map;
import java.util.Objects;

import com.gitee.l0km.com4j.base.Assert;
import com.gitee.l0km.com4j.basex.TypeNameUtils.FullName;
import com.google.common.base.MoreObjects;

public class FullNameByImporList implements FullName{
	private final Map> importedList;
	/** output package */
	private String pkg;
	public FullNameByImporList(Map> importedList) {
		this(importedList, "");
	}
	public FullNameByImporList(Map> importedList,String pkg) {
		Assert.notNull(importedList, "importedList");
		this.importedList = Collections.unmodifiableMap(importedList);
		this.pkg = pkg;
	}
	@Override
	public boolean isFullName(Class type) {
		Class clazz = CodeGenUtils.getElementClass(type);
		Class importedClass;
		if (clazz.isPrimitive()) {
			return true;
		} else if (CodeGenUtils.isJavaLangClass(clazz)) {
			return null != (importedClass = importedList.get(clazz.getSimpleName())) && importedClass != clazz;
		} else if(pkg.equals(clazz.getPackage().getName())){
			return false;
		}else{
			return !importedList.containsValue(clazz);
		}
	}
	public void setPkg(String pkg) {
		this.pkg = MoreObjects.firstNonNull(pkg, "");
	}
	@Override
	public int hashCode() {
		return Objects.hash(importedList, pkg);
	}
	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		FullNameByImporList other = (FullNameByImporList) obj;
		return Objects.equals(importedList, other.importedList) && Objects.equals(pkg, other.pkg);
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy