[JAVA100 example]005, hash table (Hashtable), and enumerator

Source: Internet
Author: User

public class Roleright


{


private static Hashtable rightlist = new Hashtable ();


/**


*<br> Method Description: Initializing Data


*<br> input Parameters:


*<br> return type:


*/


public void init ()


{


string[] accrolelist = {"Admin", "satrap", "manager", "User", "Guest"};


string[] rightcodelist = {"10001", "10011", "10021", "20011", "24011"};


for (int i=0;i<accrolelist.length;i++)


   {


rightlist.put (Accrolelist[i],rightcodelist[i]);


   }


}


/**


*<br> Method Description: Get the role permission code


*<br> input parameter: String accrole role name


*<br> return type: String permission code


*/


public String GetRight (string accrole)


{


if (Rightlist.containskey (accrole))


Return (String) rightlist.get (accrole);


Else


return null;


}


/**


*<br> Method Description: Add roles and code information


*<br> input parameter: String accrole role name


*<br> input parameter: String rightcode role Permission Code


*<br> return type: void (none)


*/


public void Insert (String accrole,string rightcode)


{


Rightlist.put (Accrole,rightcode);


}


/**


*<br> Method Description: Remove role Permissions


*<br> input parameter: String accrole role name


*<br> return type: void (none)


*/


public void Delete (String accrole)


{


if (Rightlist.containskey (accrole))


Rightlist.remove (Accrole);


}


/**


*<br> Method Description: Modify the role permission code


*<br> input parameter: String accrole role name


*<br> input parameter: String rightcode role Permission Code


*<br> return type: void (none)


*/


public void Update (String accrole,string rightcode)


{


//this.delete (Accrole);


This.insert (Accrole,rightcode);


}


/**


*<br> Method Description: Print the roles and code corresponding tables in the hash table


*<br> Input parameters: no


*<br> return type: No


*/


public void print ()


{


Enumeration Rlkey = Rightlist.keys ();


while (rlkey.hasmoreelements ())


  {


String accrole = Rlkey.nextelement (). toString ();


print (accrole+ "=" +this.getright (accrole));


  }


}


/**


*<br> Method Description: Print information (overload)


*<br> Input parameters: Object Opara printed information content


*<br> return type: No


*/


public void print (Object Opara)


{


System.out.println (Opara);


}


/**


*<br> Method Description: Main method,


*<br> input Parameters:


*<br> return type:


*/


public static void Main (string[] args)


{


roleright RR = new Roleright ();


Rr.init ();


Rr.print ();


rr.print ("___________________________");


Rr.insert ("Presider", "10110");


Rr.print ();


rr.print ("___________________________");


rr.update ("Presider", "10100");


Rr.print ();


rr.print ("___________________________");


rr.delete ("Presider");


Rr.print ();


}


}//end:) ~

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.