⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 abstractenum.java

📁 老外的在线考试
💻 JAVA
字号:
/* * Core - Library of useful classes that are used in many CyberDemia projects. * Copyright (C) 2003 CyberDemia Research and Services * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU * Library General Public License for more details. * * You should have received a copy of the GNU Library General Public * License along with this library; if not, write to the * Free Software Foundation, Inc., 59 Temple Place - Suite 330, * Boston, MA  02111-1307, USA. * * See the COPYING file located in the top-level-directory of * the archive of this library for complete text of license. */package com.cyberdemia.generic;/*** Abstract base class from which all classes that represent enumerated* values (akin to C++ enum) can be extended.* <P>Provides all the functionality of a enumerated value class.* <P>The enumerated value contains an integer code for differentiation* between values, and an optional name, mainly for display purposes.* <p>I expect this class to be absolete when JDK 1.5 appears. * * @author Alexander Yap * @version $Revision: 1.4 $ at $Date: 2004/03/22 07:39:44 $ by $Author: alexycyap $*/public abstract class AbstractEnum implements java.io.Serializable, Comparable{	private Integer m_code=null;	private String m_name = null;	private String m_str = null;	private String m_classNCode = null;	// Ctors are protected to prevent user instantiation.	protected AbstractEnum()     {        // Not used.    }	/**	* Creates unamed enumerated value class.	*/	protected AbstractEnum(Integer code, String str)	{		this(code,str,"Unamed");	}	/**	* Creates named enumerated value class.	*/	protected AbstractEnum(Integer code, String str, String name)	{		m_code = code;		m_str = str;		m_name = name;		m_classNCode = this.getClass().getName()+code.toString();			}	/**	* Gets textual display name of the enumerated value.	* In multi-lingial application, this may be the message resource key.	*/	public String getName()	{		return m_name;	}	/**	* Gets textual representation of the programmatic string of this enum	* object. This is typically used as an abbreviated name.	*/	public String getStr()	{		return m_str;	}	/**	* Returns the integer code.	*/	public Integer getCode()	{		return m_code;	}	/**	* Gets textual representation of the integer code of the enumerated value.	* <P> This is similar to casting a C++ enum to a string stream.	*/	public String toString()	{		return m_code.toString();	}	/**	* Equality comparison.	* @return true if obj is a subclass of AbstractEnum with the same	* code and is of the same class as this enumerated value class.	*/	public boolean equals(Object obj)	{		if (obj == null)			return false;		if (! this.getClass().isInstance(obj))			return false;		return (((AbstractEnum)obj).m_code.equals(m_code));	}	/**	* Gets the hashCode which is derived from the integer code and the	* class name.	* <P>This makes it unique between different subclasses with the same code.	*/	public int hashCode()	{		return m_classNCode.hashCode();	}	public int compareTo(Object rhs)	{		if (rhs instanceof AbstractEnum)		{			return m_code.compareTo( ((AbstractEnum)rhs).getCode());		}		return -1;	}}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -