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

📄 roleright.java

📁 java课程的资料以及实验的代码
💻 JAVA
字号:
import java.util.*;
public class RoleRight {
private static Hashtable rightList=new Hashtable();
	/**Define a Hashtable for save the role and right
	 * @param args
	 */
	
		public void init()
		{
			String[] accRoleList={"admin","satrap","manage","user","guest"};
			String[] rightCodeList={"10001","10011","10021","20011","24011"};
			for(int i=0;i<accRoleList.length;i++)
			{rightList.put(accRoleList,rightCodeList);
			}//put the role and right in the Hashtable 
		}
			//the code for get the right for role
			public String getRight(String accRole)
			{if(rightList.containsKey(accRole))
				return (String)rightList.get(accRole);
			else
				return null;
			}
		

	//The code for insert role
public void insert(String accRole,String rightCode)
{
	rightList.put(accRole,rightCode);
}
//Delete the role and right
public void delete(String accRole)
{if(rightList.containsKey(accRole))
	rightList.remove(accRole);
}
//update role and right
public void update(String accRole,String rightCode)
{
	this.delete(accRole);
	this.insert(accRole,rightCode);
	}
//print the list
public void print()
{
	Enumeration RLKey=rightList.keys();
	while(RLKey.hasMoreElements())
		{
		String accRole=RLKey.nextElement().toString();
		print(accRole+"="+this.getRight(accRole));
		}
	}
public void print(Object para)
{
	System.out.println(para);
	}
public static void main(String[] args) {
	// TODO Auto-generated method stub
	//try
	//{
	RoleRight rr=new RoleRight();
	rr.init();
	rr.print();
	rr.print("__________________________");
	rr.insert("Jonner","10110");
	rr.print();
	rr.print("___________________________");
	rr.update("Jonner","10110");
	rr.print();
	rr.print("___________________________");
	rr.delete("Jonner");
	rr.print();
	//}
	//catch(UnsupportedOperationException ee)
	//{}
}
}
	

⌨️ 快捷键说明

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