Skip to content

Commit

Permalink
finish the homework
Browse files Browse the repository at this point in the history
  • Loading branch information
gongxun committed Mar 4, 2017
1 parent 7996ecb commit e0bbccb
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 7 deletions.
15 changes: 12 additions & 3 deletions group17/785396327/3.5/array/ArrayUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,14 @@
import list.List;

import java.util.Arrays;
import java.util.InputMismatchException;
import java.util.NoSuchElementException;


/**
* Created by william on 2017/2/27.
*/
public class ArrayUtils {
private int[] fibonacciArray;


public static void reserveArray(int[] src) {
int begin = 0;
Expand Down Expand Up @@ -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<Integer> fList = new ArrayList<Integer>();
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) {
Expand Down
5 changes: 5 additions & 0 deletions group17/785396327/3.5/array/ArrayUtilsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,9 @@ public void joinTest() {
System.out.println(value);
}

@Test
public void fibonacciTest() {
System.out.println(Arrays.toString(ArrayUtils.fibonacci(34)));
}

}
10 changes: 6 additions & 4 deletions group17/785396327/3.5/struts/Struts.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,22 @@ public class Struts {

public static View runAction(String actionName, Map<String, String> 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<String, Object> 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());
Expand All @@ -54,7 +56,7 @@ private static Object setValue(Map<String, String> parameters, Class clazz) {
for (Map.Entry<String, String> 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());
}
}
Expand All @@ -73,7 +75,7 @@ private static Map<String, Object> 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();
}
Expand Down

0 comments on commit e0bbccb

Please sign in to comment.