首页>代码>深入浅出hibernate书籍的源代码下载>/深入浅出Hibernate源码/samples-dist/tools/ext-tools/src/java/net/sf/hibernate/tool/hbm2java/ClassName.java
//$Id: ClassName.java,v 1.3 2003/12/04 21:42:17 maxcsaucdk Exp $
package net.sf.hibernate.tool.hbm2java;

import java.util.HashSet;
import java.util.Set;

import net.sf.hibernate.util.StringHelper;

/*
 * Represents a type/classname - both primitive and Class types.
 *  
 * @author MAX
 *
 * To change the template for this generated type comment go to
 * Window - Preferences - Java - Code Generation - Code and Comments
 */
public class ClassName {
	
    static final Set PRIMITIVES = new HashSet();
    static {
		PRIMITIVES.add("byte");
		PRIMITIVES.add("short");
		PRIMITIVES.add("int");
		PRIMITIVES.add("long");		
		PRIMITIVES.add("float");
		PRIMITIVES.add("double");
		PRIMITIVES.add("char");
		PRIMITIVES.add("boolean");
	}
	
    public ClassName(String fqn) {
        initFullyQualifiedName(fqn);
    }
	    
	private String fullyQualifiedName = null;
	private String name = null;
	private String packageName = null;
    
    /** Two ClassName are equals if their fullyQualifiedName are the same/equals! */
	public boolean equals(Object other) {
		ClassName otherClassName = (ClassName) other;
		return otherClassName.fullyQualifiedName.equals(fullyQualifiedName);
	}

	public String getFullyQualifiedName() {
		return this.fullyQualifiedName;
	}

    /** returns the atomar name for a class. 
     * 
     *  java.util.Set -> "Set" */
	public String getName() {
		return this.name;
	}

    /** returns the package name for a class/type. 
     * 
     *  java.util.Set -> "java.util" and Foo -> ""
     * @return
     */
	public String getPackageName() {
		return this.packageName;
	}

	public boolean inJavaLang() {
		return "java.lang".equals(packageName);
	}

	public boolean inSamePackage(ClassName other) {
		return other.packageName == this.packageName
			|| (other.packageName != null && other.packageName.equals(this.packageName));
	}
	
    /** return true if this type is an array. Check is done by checking if the type ends with []. */
	public boolean isArray() {
		return fullyQualifiedName.endsWith("[]");
	}
		
	/**
	 * Type is primitive if the basename (fqn without []) is in the PRIMITIVE set.
	 * @return boolean
	 */
	public boolean isPrimitive() {
		String baseTypeName = StringHelper.replace(fullyQualifiedName, "[]", "");
		return PRIMITIVES.contains(baseTypeName);
	}

	
    /*
     * Initialize the class fields with info from a fully qualified name.
     */
	private void initFullyQualifiedName(String fqn) {
		this.fullyQualifiedName = fqn;
		if (!isPrimitive()) {
			if (fqn != null) {

				int lastDot = fqn.lastIndexOf(".");
				if (lastDot < 0) {
					name = fqn;
					packageName = null;
				} else {
					name = fqn.substring(lastDot + 1);
					packageName = fqn.substring(0, lastDot);
				}
			} else {
				name = fqn;
				packageName = null;
			}
		} else {
			name = fqn;
			packageName = null;
		}

	}

	public String toString() {
		return getFullyQualifiedName();
	}

}
最近下载更多
shancjb  LV1 2020年5月25日
oaggao  LV1 2020年2月7日
qq893051835  LV1 2019年9月13日
ytx012  LV1 2019年7月11日
Zionism  LV6 2019年5月5日
DevLegal  LV2 2018年10月15日
lianghao1  LV1 2018年10月13日
张兆生  LV26 2018年7月25日
adminsht  LV2 2017年9月6日
dagf113225  LV68 2017年3月24日
最近浏览更多
liang85  LV1 2023年6月30日
moomin709  LV24 2022年3月29日
无敌是都么寂寞 2021年11月15日
暂无贡献等级
blueskyroof  LV9 2021年1月12日
那一年你在哪  LV13 2020年12月26日
shancjb  LV1 2020年5月25日
zxmiii  LV3 2020年4月18日
pmj2510  LV10 2020年4月16日
陈小弟  LV2 2020年3月27日
张言昊  LV9 2020年3月12日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友