diff --git a/group17/785396327/3.5/array/ArrayUtils.java b/group17/785396327/3.5/array/ArrayUtils.java index 9334dbe5f2..c98aec55dd 100644 --- a/group17/785396327/3.5/array/ArrayUtils.java +++ b/group17/785396327/3.5/array/ArrayUtils.java @@ -4,6 +4,7 @@ import list.List; import java.util.Arrays; +import java.util.InputMismatchException; import java.util.NoSuchElementException; @@ -11,8 +12,6 @@ * Created by william on 2017/2/27. */ public class ArrayUtils { - private int[] fibonacciArray; - public static void reserveArray(int[] src) { int begin = 0; @@ -54,7 +53,17 @@ public static int[] grow(int[] oldArray, int size) { } public static int[] fibonacci(int max) { - return null; + if (max <= 1) + return new int[0]; + List fList = new ArrayList(); + fList.add(1); + fList.add(1); + int last = fList.size() - 1; + while (fList.get(last) < max) { + fList.add(fList.get(last) + fList.get(last - 1)); + last++; + } + return toIntArray(fList); } public static int[] getPrimes(int max) { diff --git a/group17/785396327/3.5/array/ArrayUtilsTest.java b/group17/785396327/3.5/array/ArrayUtilsTest.java index 5bafc329c8..276e840b44 100644 --- a/group17/785396327/3.5/array/ArrayUtilsTest.java +++ b/group17/785396327/3.5/array/ArrayUtilsTest.java @@ -78,4 +78,9 @@ public void joinTest() { System.out.println(value); } + @Test + public void fibonacciTest() { + System.out.println(Arrays.toString(ArrayUtils.fibonacci(34))); + } + } diff --git a/group17/785396327/3.5/struts/Struts.java b/group17/785396327/3.5/struts/Struts.java index c351b4473e..609c493852 100644 --- a/group17/785396327/3.5/struts/Struts.java +++ b/group17/785396327/3.5/struts/Struts.java @@ -14,20 +14,22 @@ public class Struts { public static View runAction(String actionName, Map parameters) { Element root = StrutsUtils.getRoot("struts/struts.xml"); - View view = null; + View view = new View(); if (root != null) { Element selectedEle = (Element) root.selectSingleNode("//action[@name='" + actionName + "']"); if (selectedEle != null) { + Class clazz = genClass(selectedEle.attributeValue("class")); Object target = setValue(parameters, clazz); + String result; try { result = (String) clazz.getMethod("execute").invoke(target); } catch (Exception e) { throw new RuntimeException("invoke execute have some error", e); } + Map response = getValue(clazz, target); - view = new View(); view.setParameters(response); Element selectedResult = (Element) root.selectSingleNode("//action[@name='" + actionName + "']//result[@name='" + result + "']"); view.setJsp(selectedResult == null ? null : selectedResult.getText()); @@ -54,7 +56,7 @@ private static Object setValue(Map parameters, Class clazz) { for (Map.Entry entry : parameters.entrySet()) { String key = entry.getKey(); if (!StrutsUtils.isEmpty(key)) { - String setterName = new StringBuilder("set").append(key.substring(0, 1).toUpperCase()).append(key.substring(1, key.length())).toString(); + String setterName = new StringBuilder("set").append(key.substring(0, 1).toUpperCase()).append(key.substring(1)).toString(); clazz.getMethod(setterName, String.class).invoke(target, entry.getValue()); } } @@ -73,7 +75,7 @@ private static Map getValue(Class clazz, Object target) { if (fieldName.startsWith("get") && !fieldName.equals("getClass")) { try { Object value = method.invoke(target); - resultsMap.put(new StringBuilder(fieldName.substring(3, 4)).append(fieldName.substring(4, fieldName.length())).toString(), value); + resultsMap.put(new StringBuilder(fieldName.substring(3, 4)).append(fieldName.substring(4)).toString(), value); } catch (Exception e) { e.printStackTrace(); }