fuliqi
2024-08-28 9f5b9db2c8cdbcf74bd2eecefc3557d4048b8d4c
ycl-server/src/main/java/com/ycl/api/DH/common/CaseMenu.java
@@ -1,4 +1,4 @@
package com.netsdk.common;
package com.ycl.api.DH.common;
import java.lang.reflect.Method;
import java.util.NoSuchElementException;
@@ -6,12 +6,12 @@
import java.util.Vector;
public class CaseMenu {
   public static class Item {
      private Object object;
      private String itemName;
      private String methodName;
      public Item(Object object, String itemName, String methodName) {
         super();
         this.object = object;
@@ -31,33 +31,33 @@
         return methodName;
      }
   }
   private Vector<Item> items;
   public CaseMenu() {
      super();
      items = new Vector<Item>();
   }
   public void addItem(Item item) {
      items.add(item);
   }
   private void showItem() {
      final String format = "%2d\t%-20s\n";
      int index = 0;
      int index = 0;
      System.out.printf(format, index++, "exit App");
      for (Item item : items) {
         System.out.printf(format, index++, item.getItemName());
      }
      System.out.println("Please input a item index to invoke the method:");
   }
   public void run() {
      Scanner scanner = new Scanner(System.in);
      while(true) {
         showItem();
         try {
      while(true) {
         showItem();
         try {
            int input = Integer.parseInt(scanner.nextLine());
            if (input <= 0 ) {
@@ -66,12 +66,12 @@
//               System.exit(0);
               break;
            }
            if (input < 0 || input > items.size()) {
               System.err.println("Input Error Item Index.");
               continue;
            }
            Item item = items.get(input - 1);
            Class<?> itemClass = item.getObject().getClass();
            Method method = itemClass.getMethod(item.getMethodName());
@@ -85,9 +85,9 @@
            continue;
         } catch (Exception e) {
            e.printStackTrace();
         }
         }
      }
      scanner.close();
   }
}