@Test public void verify() throws Exception { String str = "a, ; bA"; int loopTime = 100000; System.out.println("originStr is: \"" + str + "\", loopTime is: " + loopTime); System.out.println("method1 execute res: " + PalindromeStr.verify(str, 1)); System.out.println("method2 execute res: " + PalindromeStr.verify(str, 2)); System.out.println("method3 execute res: " + PalindromeStr.verify(str, 3)); System.out.println("method4 execute res: " + PalindromeStr.verify(str, 4)); long curTime = System.currentTimeMillis(); for (int i = 0; i < loopTime; i++) { PalindromeStr.verify(str, 1); } System.out.println("method1 execute time is: " + (System.currentTimeMillis() - curTime)); curTime = System.currentTimeMillis(); for (int i = 0; i < loopTime; i++) { PalindromeStr.verify(str, 2); } System.out.println("method2 execute time is: " + (System.currentTimeMillis() - curTime)); curTime = System.currentTimeMillis(); for (int i = 0; i < loopTime; i++) { PalindromeStr.verify(str, 3); } System.out.println("method3 execute time is: " + (System.currentTimeMillis() - curTime)); curTime = System.currentTimeMillis(); for (int i = 0; i < loopTime; i++) { PalindromeStr.verify(str, 4); } System.out.println("method4 execute time is: " + (System.currentTimeMillis() - curTime)); }
public static boolean verify(String originStr, int methodFlag) throws NoSuchMethodException, InvocationTargetException, IllegalAccessException { if (methodFlag < 0 || methodFlag > methodNum) { System.out.println("ReverseEqualStr, verify Method, methodFlag param illegal, is: " + methodFlag); } if (originStr == null) { return false; } else if (originStr.length() <= 1) { return true; } return (boolean) PalindromeStr.class.getMethod("method" + methodFlag, String.class).invoke(PalindromeStr.class, originStr); }
PalindromeStr { public static boolean verify(String originStr, int methodFlag) throws NoSuchMethodException, InvocationTargetException, IllegalAccessException { if (methodFlag < 0 || methodFlag > methodNum) { System.out.println("ReverseEqualStr, verify Method, methodFlag param illegal, is: " + methodFlag); } if (originStr == null) { return false; } else if (originStr.length() <= 1) { return true; } return (boolean) PalindromeStr.class.getMethod("method" + methodFlag, String.class).invoke(PalindromeStr.class, originStr); } }
PalindromeStr { public static boolean verify(String originStr, int methodFlag) throws NoSuchMethodException, InvocationTargetException, IllegalAccessException { if (methodFlag < 0 || methodFlag > methodNum) { System.out.println("ReverseEqualStr, verify Method, methodFlag param illegal, is: " + methodFlag); } if (originStr == null) { return false; } else if (originStr.length() <= 1) { return true; } return (boolean) PalindromeStr.class.getMethod("method" + methodFlag, String.class).invoke(PalindromeStr.class, originStr); }  }
PalindromeStr { public static boolean verify(String originStr, int methodFlag) throws NoSuchMethodException, InvocationTargetException, IllegalAccessException { if (methodFlag < 0 || methodFlag > methodNum) { System.out.println("ReverseEqualStr, verify Method, methodFlag param illegal, is: " + methodFlag); } if (originStr == null) { return false; } else if (originStr.length() <= 1) { return true; } return (boolean) PalindromeStr.class.getMethod("method" + methodFlag, String.class).invoke(PalindromeStr.class, originStr); }  static boolean verify(String originStr, int methodFlag); static boolean method1(String originStr); static boolean method2(String originStr); static boolean method3(String originStr); static boolean method4(String originStr); }
PalindromeStr { public static boolean verify(String originStr, int methodFlag) throws NoSuchMethodException, InvocationTargetException, IllegalAccessException { if (methodFlag < 0 || methodFlag > methodNum) { System.out.println("ReverseEqualStr, verify Method, methodFlag param illegal, is: " + methodFlag); } if (originStr == null) { return false; } else if (originStr.length() <= 1) { return true; } return (boolean) PalindromeStr.class.getMethod("method" + methodFlag, String.class).invoke(PalindromeStr.class, originStr); }  static boolean verify(String originStr, int methodFlag); static boolean method1(String originStr); static boolean method2(String originStr); static boolean method3(String originStr); static boolean method4(String originStr);  }