Refactoring-merging functions with reflection

Source: Internet
Author: User
Tags reflection

First look at the test cases before refactoring:

public class Testlogin extends testcase{private Buttonmanageribatis buttonmanageribatis;
      protected void SetUp () throws Exception {context = GetContext ();
      Buttonmanageribatis = (buttonmanageribatis) context.getbean ("Buttonmanageribatis");
    Super.setup ();
    } ApplicationContext context;
       Protected ApplicationContext GetContext () {string[] paths = {"/context/application_context.xml"};
       ApplicationContext CTX = new Classpathxmlapplicationcontext (paths);
    return CTX; /** *//** * Test: Read permission information after login, and encapsulated as tree structure * * public void Testlongin () {list<button> List = Buttonmanag
     Eribatis.getauth ("0000");
     
   Testall (list);
    } map<string,model> Modelmap = new hashmap<string,model> ();
    map<string,menu> Fmenumap = new hashmap<string,menu> ();
    
    map<string,menu> Smenumap = new hashmap<string,menu> (); public void Testall (list<button> buttonlist) {for(Button button:buttonlist)
      {test (Modelmap,button);
      For (Model model:modelmap.values ()) {test2 (Smenumap,model);
      For (Menu menu:smenumap.values ()) {test3 (fmenumap,menu);
        For (Menu fmenu:fmenumap.values ()) {System.out.println (Fmenu.getmenuname ());
          For (menu Smenu:fmenu.getMenus ()) {System.out.println ("" +smenu.getmenuname ());
            For (Model model:smenu.getModels ()) {System.out.println ("" +model.getname ());
            For (Button b:model.getbuttons ()) {System.out.println ("" + B.getbuttondesc ()); '}}} ' public void Test (map<string,model> modelmap, Button b) {Model m
      = B.getmodel ();
      if (!modelmap.containskey (M.getid ())) Modelmap.put (M.getid (), m);
    Modelmap.get (M.getid ()). Getbuttons (). Add (b); } public void Test2 (map<string,menu> menumap, Model m) {Menu Menu = M.getmenu ();
      if (!menumap.containskey (Menu.getid ())) Menumap.put (Menu.getid (), menu);
        
    Menumap.get (Menu.getid ()). Getmodels (). Add (m);
      public void Test3 (map<string,menu> menumap, Menu smenu) {Menu Fmenu = Smenu.getmenu ();
      if (!menumap.containskey (Fmenu.getid ())) Menumap.put (Fmenu.getid (), fmenu);
    Menumap.get (Fmenu.getid ()). Getmenus (). Add (Smenu); }      }

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.