diff --git a/.gitignore b/.gitignore
index 8b13789179..d749cfbd62 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1 +1,21 @@
-
+*.class
+# Mobile Tools for Java (J2ME)
+.mtj.tmp/
+
+# Package Files #
+*.jar
+*.war
+*.ear
+
+# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
+hs_err_pid*
+
+#ide config
+.metadata
+.recommenders
+.idea/
+*.iml
+rebel.*
+.rebel.*
+
+target
diff --git a/.project b/.project
new file mode 100644
index 0000000000..6b4d50ed9a
--- /dev/null
+++ b/.project
@@ -0,0 +1,11 @@
+
+
+ coding2017
+
+
+
+
+
+
+
+
diff --git a/.settings/org.eclipse.core.resources.prefs b/.settings/org.eclipse.core.resources.prefs
new file mode 100644
index 0000000000..4824b80263
--- /dev/null
+++ b/.settings/org.eclipse.core.resources.prefs
@@ -0,0 +1,2 @@
+eclipse.preferences.version=1
+encoding/=UTF-8
diff --git a/group01/1298552064/.classpath b/group01/1298552064/.classpath
new file mode 100644
index 0000000000..05cf0dba9e
--- /dev/null
+++ b/group01/1298552064/.classpath
@@ -0,0 +1,8 @@
+
+
+
+
+
+
+
+
diff --git a/group04/564451732/.gitignore b/group01/1298552064/.gitignore
similarity index 100%
rename from group04/564451732/.gitignore
rename to group01/1298552064/.gitignore
diff --git a/group01/1298552064/.project b/group01/1298552064/.project
new file mode 100644
index 0000000000..ddbb7719d0
--- /dev/null
+++ b/group01/1298552064/.project
@@ -0,0 +1,17 @@
+
+
+ 1298552064Learning
+
+
+
+
+
+ org.eclipse.jdt.core.javabuilder
+
+
+
+
+
+ org.eclipse.jdt.core.javanature
+
+
diff --git a/group01/1298552064/src/week01/basic/MyLinkedList.java b/group01/1298552064/src/week01/basic/MyLinkedList.java
index 4894c5ff6c..88db213864 100644
--- a/group01/1298552064/src/week01/basic/MyLinkedList.java
+++ b/group01/1298552064/src/week01/basic/MyLinkedList.java
@@ -124,7 +124,7 @@ public Object removeLast() {
Node p = head;
for (int i = 0; i < size; i++) {
if (p.next.next == null) {
- removeObject = p.next;
+ removeObject = p.next.data;
p.next = null;
break;
} else {
diff --git a/group01/1298552064/src/week02/array/ArrayUtil.java b/group01/1298552064/src/week02/array/ArrayUtil.java
new file mode 100644
index 0000000000..9b6c0bebaf
--- /dev/null
+++ b/group01/1298552064/src/week02/array/ArrayUtil.java
@@ -0,0 +1,245 @@
+package week02.array;
+
+import java.util.Arrays;
+
+public class ArrayUtil {
+
+ // 工具类,不予许创建实例
+ private ArrayUtil() {
+ }
+
+ /**
+ * 给定一个整形数组a , 对该数组的值进行置换 例如: a = [7, 9 , 30, 3] , 置换后为 [3, 30, 9,7] 如果 a =
+ * [7, 9, 30, 3, 4] , 置换后为 [4,3, 30 , 9,7]
+ *
+ * @param origin
+ * @return
+ */
+ public static void reverseArray(int[] origin) {
+ if (origin != null && origin.length > 0) {
+ int temp = 0;
+
+ // 数组首尾元素置换
+ for (int i = 0; i < origin.length / 2; i++) {
+ temp = origin[i];
+ origin[i] = origin[origin.length - i - 1];
+ origin[origin.length - i - 1] = temp;
+ }
+ }
+ }
+
+ /**
+ * 现在有如下的一个数组: int oldArr[]={1,3,4,5,0,0,6,6,0,5,4,7,6,7,0,5}
+ * 要求将以上数组中值为0的项去掉,将不为0的值存入一个新的数组,生成的新数组为: {1,3,4,5,6,6,5,4,7,6,7,5}
+ *
+ * @param oldArray
+ * @return
+ */
+
+ public static int[] removeZero(int[] oldArray) {
+ int[] newArray = null;
+ if (oldArray != null) {
+ newArray = new int[oldArray.length];
+ int size = 0;
+ for (int i = 0; i < oldArray.length; i++) {
+ if (oldArray[i] != 0) {
+ newArray[size] = oldArray[i];
+ size++;
+ }
+ }
+ newArray = Arrays.copyOf(newArray, size);
+ }
+ return newArray;
+ }
+
+ /**
+ * 给定两个已经排序好的整形数组, a1和a2 , 创建一个新的数组a3, 使得a3 包含a1和a2 的所有元素, 并且仍然是有序的 例如 a1 =
+ * [3, 5, 7,8] a2 = [4, 5, 6,7] 则 a3 为[3,4,5,6,7,8] , 注意: 已经消除了重复
+ *
+ * @param array1
+ * @param array2
+ * @return
+ */
+
+ public static int[] merge(int[] array1, int[] array2) {
+ int[] newArray = null;
+ if (array1 != null && array2 != null) {
+ int size = 0;
+
+ // index1、index2表示array1和array2数组的比较索引
+ int index1 = 0, index2 = 0;
+ newArray = new int[array1.length + array2.length];
+
+ while (index1 < array1.length && index2 < array2.length) {
+ if (array1[index1] == array2[index2]) {
+ newArray[size++] = array1[index1];
+ index1++;
+ index2++;
+ } else if (array1[index1] < array2[index2]) {
+ // 数组array1去重
+ if (size > 0 && array1[index1] == newArray[size - 1]) {
+ size--;
+ }
+ newArray[size++] = array1[index1];
+ index1++;
+ } else {
+ // 数组array2去重
+ if (size > 0 && array2[index2] == newArray[size - 1]) {
+ size--;
+ }
+ newArray[size++] = array2[index2];
+ index2++;
+ }
+ }
+
+ // 将数组array1剩下的元素放入
+ while (index1 < array1.length) {
+ newArray[size++] = array1[index1++];
+ }
+
+ // 将数组array2剩下的元素放入
+ while (index2 < array2.length) {
+ newArray[size++] = array2[index2++];
+ }
+
+ // 合并后有序数组
+ newArray = Arrays.copyOf(newArray, size);
+ }
+ return newArray;
+ }
+
+ /**
+ * 把一个已经存满数据的数组 oldArray的容量进行扩展, 扩展后的新数据大小为oldArray.length + size
+ * 注意,老数组的元素在新数组中需要保持 例如 oldArray = [2,3,6] , size = 3,则返回的新数组为
+ * [2,3,6,0,0,0]
+ *
+ * @param oldArray
+ * @param size
+ * @return
+ */
+ public static int[] grow(int[] oldArray, int size) {
+ int[] newArray = null;
+ if (oldArray != null) {
+ newArray = new int[oldArray.length + size];
+ for (int i = 0; i < oldArray.length; i++) {
+ newArray[i] = oldArray[i];
+ }
+ }
+ return newArray;
+ }
+
+ /**
+ * 斐波那契数列为:1,1,2,3,5,8,13,21...... ,给定一个最大值, 返回小于该值的数列 例如, max = 15 ,
+ * 则返回的数组应该为 [1,1,2,3,5,8,13] max = 1, 则返回空数组 []
+ *
+ * @param max
+ * @return
+ */
+ public static int[] fibonacci(int max) {
+
+ // 计算方法:f(n) = f(n-1) + f(n-2) 采用数组计算
+ int[] result = null;
+ if (max <= 1) {
+ result = new int[] {};
+ } else {
+ int i = 2;
+ result = new int[max];
+ result[0] = result[1] = 1;
+ for (; i < max; i++) {
+ if (result[i - 1] + result[i - 2] < max) {
+ result[i] = result[i - 1] + result[i - 2];
+ } else {
+ break;
+ }
+ }
+ result = Arrays.copyOf(result, i);
+ }
+ return result;
+ }
+
+ /**
+ * 返回小于给定最大值max的所有素数数组 例如max = 23, 返回的数组为[2,3,5,7,11,13,17,19]
+ *
+ * @param max
+ * @return
+ */
+ public static int[] getPrimes(int max) {
+ int[] newArray = new int[] {};
+ if (max > 2) {
+ newArray = new int[max];
+ int size = 0, j = 0;
+ for (int i = 2; i < max; i++) {
+ for (j = 2; j < i / 2 + 1; j++) {
+ if (i % j == 0) {
+ break;
+ }
+ }
+
+ if (j == i / 2 + 1) {
+ newArray[size++] = i;
+ }
+ }
+ newArray = Arrays.copyOf(newArray, size);
+ }
+ return newArray;
+ }
+
+ /**
+ * 所谓“完数”, 是指这个数恰好等于它的因子之和,例如6=1+2+3 给定一个最大值max, 返回一个数组, 数组中是小于max 的所有完数
+ *
+ * @param max
+ * @return
+ */
+ public static int[] getPerfectNumbers(int max) {
+ int[] newArray = new int[] {};
+ if (max > 0) {
+ newArray = new int[max];
+ int size = 0, sum = 0;
+ for (int i = 1; i < max; i++) {
+ sum = 0;
+ for (int j = 1; j < i / 2 + 1; j++) {
+ if (i % j == 0) {
+ sum += j;
+ }
+ }
+ if (i == sum) {
+ newArray[size++] = i;
+ }
+ }
+ newArray = Arrays.copyOf(newArray, size);
+ }
+ return newArray;
+ }
+
+ /**
+ * 用seperator 把数组 array给连接起来 例如array= [3,8,9], seperator = "-" 则返回值为"3-8-9"
+ *
+ * @param array
+ * @param seperator
+ * @return
+ */
+ public static String join(int[] array, String seperator) {
+ String joinResult = null;
+ if (array != null) {
+ joinResult = "";
+ for (int i = 0; i < array.length; i++) {
+ joinResult += array[i] + seperator;
+ }
+ joinResult = joinResult.equals("") ? "" : joinResult.substring(0, joinResult.length() - 1);
+ }
+ return joinResult;
+ }
+
+ public static void main(String[] args) {
+ int[] a = new ArrayUtil().getPerfectNumbers(1000);
+ for (int i = 0; i < a.length; i++) {
+ System.out.println(a[i]);
+ }
+
+ // [2,3,5,7,11,13,17,19]
+ a = new ArrayUtil().getPrimes(20);
+ for (int i = 0; i < a.length; i++) {
+ System.out.println(a[i]);
+ }
+ }
+}
diff --git a/group01/1298552064/src/week02/litestruts/LoginAction.java b/group01/1298552064/src/week02/litestruts/LoginAction.java
new file mode 100644
index 0000000000..aec243dd1b
--- /dev/null
+++ b/group01/1298552064/src/week02/litestruts/LoginAction.java
@@ -0,0 +1,42 @@
+package week02.litestruts;
+
+/**
+ * 这是一个用来展示登录的业务类, 其中的用户名和密码都是硬编码的。
+ *
+ * @author liuxin
+ *
+ */
+public class LoginAction {
+ private String name;
+ private String password;
+ private String message;
+
+ public String getName() {
+ return name;
+ }
+
+ public String getPassword() {
+ return password;
+ }
+
+ public String execute() {
+ if ("test".equals(name) && "1234".equals(password)) {
+ this.message = "login successful";
+ return "success";
+ }
+ this.message = "login failed,please check your user/pwd";
+ return "fail";
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public void setPassword(String password) {
+ this.password = password;
+ }
+
+ public String getMessage() {
+ return this.message;
+ }
+}
diff --git a/group01/1298552064/src/week02/litestruts/Struts.java b/group01/1298552064/src/week02/litestruts/Struts.java
new file mode 100644
index 0000000000..3cef26c396
--- /dev/null
+++ b/group01/1298552064/src/week02/litestruts/Struts.java
@@ -0,0 +1,106 @@
+package week02.litestruts;
+
+import java.io.InputStream;
+import java.lang.reflect.Method;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+
+import org.dom4j.Document;
+import org.dom4j.Element;
+import org.dom4j.io.SAXReader;
+
+public class Struts {
+
+ public static View runAction(String actionName, Map parameters) {
+
+ /*
+ *
+ * 0. 读取配置文件struts.xml
+ *
+ * 1. 根据actionName找到相对应的class , 例如LoginAction, 通过反射实例化(创建对象)
+ * 据parameters中的数据,调用对象的setter方法, 例如parameters中的数据是 ("name"="test" ,
+ * "password"="1234") , 那就应该调用 setName和setPassword方法
+ *
+ * 2. 通过反射调用对象的exectue 方法, 并获得返回值,例如"success"
+ *
+ * 3. 通过反射找到对象的所有getter方法(例如 getMessage), 通过反射来调用, 把值和属性形成一个HashMap , 例如
+ * {"message": "登录成功"} , 放到View对象的parameters
+ *
+ * 4. 根据struts.xml中的 配置,以及execute的返回值, 确定哪一个jsp,
+ * 放到View对象的jsp字段中。
+ *
+ */
+
+ try {
+
+ // 0. 读取配置文件struts.xml
+ SAXReader reader = new SAXReader();
+ InputStream in = Struts.class.getResourceAsStream("struts.xml");
+ Document document = reader.read(in);
+ Element root = document.getRootElement();
+
+ // 与actionName匹配的Element
+ Element actionElement = null;
+ String className = null;
+
+ for (Iterator iterator = root.elementIterator("action"); iterator.hasNext();) {
+ Element e = iterator.next();
+ if (e.attributeValue("name").equals(actionName)) {
+ actionElement = e;
+ className = e.attributeValue("class");
+ break;
+ }
+ }
+
+ Class> clazz = Class.forName(className);
+ Object action = clazz.newInstance();
+
+ // 1. 反射设置属性
+ if (parameters != null) {
+ for (Map.Entry entry : parameters.entrySet()) {
+ String fieldName = entry.getKey();
+ String methodName = "set" + fieldName.substring(0, 1).toUpperCase() + fieldName.substring(1);
+ Class> fieldType = clazz.getDeclaredField(fieldName).getType();
+ Method method = clazz.getDeclaredMethod(methodName, fieldType);
+ method.invoke(action, entry.getValue());
+ }
+ }
+
+ // 2. 通过反射调用对象的exectue 方法, 并获得返回值,例如"success"
+ Method execute = clazz.getDeclaredMethod("execute");
+ String result = (String) execute.invoke(action);
+
+ // 3. 通过反射找到对象的所有getter方法(例如 getMessage), 通过反射来调用, 把值和属性形成一个HashMap
+ Method[] methods = clazz.getDeclaredMethods();
+ Map param = new HashMap();
+ for (Method method : methods) {
+ String methodName = method.getName();
+ if (method.getName().startsWith("get")) {
+ String fieldName = methodName.substring(3, 4).toLowerCase() + methodName.substring(4);
+ Object fieldValue = method.invoke(action);
+ param.put(fieldName, fieldValue);
+ }
+ }
+
+ View view = new View();
+ view.setParameters(param);
+
+ // 4. 根据struts.xml中的 配置,以及execute的返回值, 确定哪一个jsp,
+ // 放到View对象的jsp字段中。
+ for (Iterator iterator = actionElement.elementIterator("result"); iterator.hasNext();) {
+ Element resultElement = iterator.next();
+ if (resultElement.attributeValue("name").equals(result)) {
+ view.setJsp(resultElement.getText());
+ break;
+ }
+ }
+
+ return view;
+ } catch (Exception e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ return null;
+ }
+}
diff --git a/group01/1298552064/src/week02/litestruts/View.java b/group01/1298552064/src/week02/litestruts/View.java
new file mode 100644
index 0000000000..a286412f0e
--- /dev/null
+++ b/group01/1298552064/src/week02/litestruts/View.java
@@ -0,0 +1,26 @@
+package week02.litestruts;
+
+import java.util.Map;
+
+public class View {
+ private String jsp;
+ private Map parameters;
+
+ public String getJsp() {
+ return jsp;
+ }
+
+ public View setJsp(String jsp) {
+ this.jsp = jsp;
+ return this;
+ }
+
+ public Map getParameters() {
+ return parameters;
+ }
+
+ public View setParameters(Map parameters) {
+ this.parameters = parameters;
+ return this;
+ }
+}
diff --git a/group01/1298552064/src/week02/litestruts/struts.xml b/group01/1298552064/src/week02/litestruts/struts.xml
new file mode 100644
index 0000000000..01398e9c3d
--- /dev/null
+++ b/group01/1298552064/src/week02/litestruts/struts.xml
@@ -0,0 +1,11 @@
+
+
+
+ /jsp/homepage.jsp
+ /jsp/showLogin.jsp
+
+
+ /jsp/welcome.jsp
+ /jsp/error.jsp
+
+
\ No newline at end of file
diff --git a/group01/1298552064/src/week02/test/ArrayUtilTest.java b/group01/1298552064/src/week02/test/ArrayUtilTest.java
new file mode 100644
index 0000000000..e796b5f845
--- /dev/null
+++ b/group01/1298552064/src/week02/test/ArrayUtilTest.java
@@ -0,0 +1,75 @@
+package week02.test;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import week02.array.ArrayUtil;
+
+public class ArrayUtilTest {
+
+ @Test
+ public void testReverseArray() {
+ int[] a = new int[] { 7, 9, 30, 3 };
+ int[] b = new int[] { 7, 9, 30, 3, 4 };
+
+ ArrayUtil.reverseArray(a);
+ ArrayUtil.reverseArray(b);
+
+ Assert.assertArrayEquals(new int[] { 3, 30, 9, 7 }, a);
+ Assert.assertArrayEquals(new int[] { 4, 3, 30, 9, 7 }, b);
+ }
+
+ @Test
+ public void testRemoveZero() {
+ int[] oldArr = new int[] { 1, 3, 4, 5, 0, 0, 6, 6, 0, 5, 4, 7, 6, 7, 0, 5 };
+ int[] newArray = ArrayUtil.removeZero(oldArr);
+ Assert.assertArrayEquals(new int[] { 1, 3, 4, 5, 6, 6, 5, 4, 7, 6, 7, 5 }, newArray);
+ }
+
+ @Test
+ public void testMerge() {
+ int[] a1 = new int[] { 3, 5, 7, 8 };
+ int[] a2 = new int[] { 4, 5, 6, 6, 7, 7 };
+ int[] a3 = ArrayUtil.merge(a1, a2);
+ Assert.assertArrayEquals(new int[] { 3, 4, 5, 6, 7, 8 }, a3);
+ }
+
+ @Test
+ public void testGrow() {
+ int[] oldArray = new int[] { 2, 3, 6 };
+ int size = 3;
+ int[] newArray = ArrayUtil.grow(oldArray, size);
+ Assert.assertArrayEquals(new int[] { 2, 3, 6, 0, 0, 0 }, newArray);
+ }
+
+ @Test
+ public void testFibonacci() {
+ int max = 15;
+ int max2 = 1;
+ int[] newArray = ArrayUtil.fibonacci(max);
+ int[] newArray2 = ArrayUtil.fibonacci(max2);
+ Assert.assertArrayEquals(new int[] { 1, 1, 2, 3, 5, 8, 13 }, newArray);
+ Assert.assertArrayEquals(new int[] {}, newArray2);
+ }
+
+ @Test
+ public void testGetPrimes() {
+ int[] newArray = ArrayUtil.getPrimes(23);
+ Assert.assertArrayEquals(new int[] { 2, 3, 5, 7, 11, 13, 17, 19 }, newArray);
+ }
+
+ @Test
+ public void testGetPerfectNumbers() {
+ int[] newArray = ArrayUtil.getPerfectNumbers(1000);
+ Assert.assertArrayEquals(new int[] { 6, 28, 496 }, newArray);
+ }
+
+ @Test
+ public void testJoin() {
+ int[] array = new int[] { 3, 8, 9 };
+ String seperator = "-";
+ String result = ArrayUtil.join(array, seperator);
+ Assert.assertEquals("3-8-9", result);
+ }
+
+}
diff --git a/group01/1298552064/src/week02/test/StrutsTest.java b/group01/1298552064/src/week02/test/StrutsTest.java
new file mode 100644
index 0000000000..3eb6d01fd0
--- /dev/null
+++ b/group01/1298552064/src/week02/test/StrutsTest.java
@@ -0,0 +1,41 @@
+package week02.test;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import week02.litestruts.Struts;
+import week02.litestruts.View;
+
+public class StrutsTest {
+
+ @Test
+ public void testLoginActionSuccess() {
+
+ String actionName = "login";
+
+ Map params = new HashMap();
+ params.put("name", "test");
+ params.put("password", "1234");
+
+ View view = Struts.runAction(actionName, params);
+
+ Assert.assertEquals("/jsp/homepage.jsp", view.getJsp());
+ Assert.assertEquals("login successful", view.getParameters().get("message"));
+ }
+
+ @Test
+ public void testLoginActionFailed() {
+ String actionName = "login";
+ Map params = new HashMap();
+ params.put("name", "test");
+ params.put("password", "123456"); // 密码和预设的不一致
+
+ View view = Struts.runAction(actionName, params);
+
+ Assert.assertEquals("/jsp/showLogin.jsp", view.getJsp());
+ Assert.assertEquals("login failed,please check your user/pwd", view.getParameters().get("message"));
+ }
+}
diff --git a/group01/1664823950/src/com/coderising/array/ArrayUtil.java b/group01/1664823950/src/com/coderising/array/ArrayUtil.java
new file mode 100644
index 0000000000..afb557277f
--- /dev/null
+++ b/group01/1664823950/src/com/coderising/array/ArrayUtil.java
@@ -0,0 +1,209 @@
+package com.coderising.array;
+import java.util.*;
+
+import com.sun.org.apache.bcel.internal.generic.NEWARRAY;
+
+public class ArrayUtil {
+
+ /**
+ * 给定一个整形数组a , 对该数组的值进行置换
+ 例如: a = [7, 9 , 30, 3] , 置换后为 [3, 30, 9,7]
+ 如果 a = [7, 9, 30, 3, 4] , 置换后为 [4,3, 30 , 9,7]
+ * @param origin
+ * @return
+ */
+ public void reverseArray(int[] origin)
+ {
+ int[] a = origin;
+ for (int i = 0; i < a.length; i++)
+ {
+ origin[i] = a[a.length-i];
+ }
+ }
+
+ /**
+ * 现在有如下的一个数组: int oldArr[]={1,3,4,5,0,0,6,6,0,5,4,7,6,7,0,5}
+ * 要求将以上数组中值为0的项去掉,将不为0的值存入一个新的数组,生成的新数组为:
+ * {1,3,4,5,6,6,5,4,7,6,7,5}
+ * @param oldArray
+ * @return
+ */
+
+ public int[] removeZero(int[] oldArray)
+ {
+ ArrayList a= new ArrayList();
+
+ for (int i : oldArray)
+ {
+ if (i != 0)
+ {
+ a.add(i);
+ }
+ }
+
+ int[] newArray = new int[a.size()];
+ for (int i = 0; i < a.size(); i++)
+ {
+ newArray[i] = a.get(i);
+ }
+ return null;
+ }
+
+ /**
+ * 给定两个已经排序好的整形数组, a1和a2 , 创建一个新的数组a3, 使得a3 包含a1和a2 的所有元素, 并且仍然是有序的
+ * 例如 a1 = [3, 5, 7,8] a2 = [4, 5, 6,7] 则 a3 为[3,4,5,6,7,8] , 注意: 已经消除了重复
+ * @param array1
+ * @param array2
+ * @return
+ */
+
+ public int[] merge(int[] array1, int[] array2)
+ {
+ for (int i = 0; i < array1.length; i++)
+ {
+ for (int j = 0; j < array2.length; j++)
+ {
+ if(array1[i] == array2[j])
+ {
+ array2[j] = 0;
+ }
+ }
+ }
+
+ removeZero(array2);
+
+ int[] array3 = new int[array1.length + array2.length];
+
+ for (int i = 0; i < array1.length; i++)
+ {
+ array3[i] = array1[i];
+ }
+
+ for (int i = 0; i < array2.length; i++)
+ {
+ array3[array1.length + i] = array2[i];
+ }
+
+ Arrays.sort(array3);
+ return array3;
+ }
+ /**
+ * 把一个已经存满数据的数组 oldArray的容量进行扩展, 扩展后的新数据大小为oldArray.length + size
+ * 注意,老数组的元素在新数组中需要保持
+ * 例如 oldArray = [2,3,6] , size = 3,则返回的新数组为
+ * [2,3,6,0,0,0]
+ * @param oldArray
+ * @param size
+ * @return
+ */
+ public int[] grow(int [] oldArray, int size)
+ {
+ return new int[oldArray.length + size];
+ }
+
+ /**
+ * 斐波那契数列为:1,1,2,3,5,8,13,21...... ,给定一个最大值, 返回小于该值的数列
+ * 例如, max = 15 , 则返回的数组应该为 [1,1,2,3,5,8,13]
+ * max = 1, 则返回空数组 []
+ * @param max
+ * @return
+ */
+ public int[] fibonacci(int max)
+ {
+ int top = 1;
+ int sec = 1;
+ ArrayList tem = new ArrayList();
+ while (top < max)
+ {
+ tem.add(top);
+ int a = top;
+ top += sec;
+ sec = a;
+ }
+
+
+ return toArray(tem);
+ }
+
+ /**
+ * 返回小于给定最大值max的所有素数数组
+ * 例如max = 23, 返回的数组为[2,3,5,7,11,13,17,19]
+ * @param max
+ * @return
+ */
+ public int[] getPrimes(int max)
+ {
+ ArrayList tem = new ArrayList();
+ for (int i = 0; i < max; i++)
+ {
+ if (isPrimes(i))
+ {
+ tem.add(i);
+ }
+ }
+
+ return toArray(tem);
+ }
+
+ private boolean isPrimes(int i)
+ {
+ return true;
+ }
+
+ private int[] toArray(ArrayList tem)
+ {
+ int[] newArr = new int[tem.size()];
+ for (int i = 0; i < newArr.length; i++)
+ {
+ newArr[i] = tem.get(i);
+ }
+ return newArr;
+ }
+ /**
+ * 所谓“完数”, 是指这个数恰好等于它的因子之和,例如6=1+2+3
+ * 给定一个最大值max, 返回一个数组, 数组中是小于max 的所有完数
+ * @param max
+ * @return
+ */
+ public int[] getPerfectNumbers(int max)
+ {
+ ArrayList tem = new ArrayList();
+ for (int i = 0; i < max; i++)
+ {
+ if (isPerfectNumbers(i))
+ {
+ tem.add(i);
+ }
+ }
+
+ return toArray(tem);
+ }
+
+
+ private boolean isPerfectNumbers(int i)
+ {
+ return true;
+ }
+ /**
+ * 用seperator 把数组 array给连接起来
+ * 例如array= [3,8,9], seperator = "-"
+ * 则返回值为"3-8-9"
+ * @param array
+ * @param s
+ * @return
+ */
+ public String join(int[] array, String seperator)
+ {
+ String newStr = "";
+ for (int i = 0; i < array.length; i++)
+ {
+ if(i == array.length-1)
+ {
+ seperator = "";
+ }
+ newStr += array[i] + seperator;
+ }
+ return newStr;
+ }
+
+}
diff --git a/group01/1664823950/src/com/coderising/litestruts/LoginAction.java b/group01/1664823950/src/com/coderising/litestruts/LoginAction.java
new file mode 100644
index 0000000000..1005f35a29
--- /dev/null
+++ b/group01/1664823950/src/com/coderising/litestruts/LoginAction.java
@@ -0,0 +1,39 @@
+package com.coderising.litestruts;
+
+/**
+ * 这是一个用来展示登录的业务类, 其中的用户名和密码都是硬编码的。
+ * @author liuxin
+ *
+ */
+public class LoginAction{
+ private String name ;
+ private String password;
+ private String message;
+
+ public String getName() {
+ return name;
+ }
+
+ public String getPassword() {
+ return password;
+ }
+
+ public String execute(){
+ if("test".equals(name) && "1234".equals(password)){
+ this.message = "login successful";
+ return "success";
+ }
+ this.message = "login failed,please check your user/pwd";
+ return "fail";
+ }
+
+ public void setName(String name){
+ this.name = name;
+ }
+ public void setPassword(String password){
+ this.password = password;
+ }
+ public String getMessage(){
+ return this.message;
+ }
+}
diff --git a/group01/1664823950/src/com/coderising/litestruts/Struts.java b/group01/1664823950/src/com/coderising/litestruts/Struts.java
new file mode 100644
index 0000000000..44cc35bf01
--- /dev/null
+++ b/group01/1664823950/src/com/coderising/litestruts/Struts.java
@@ -0,0 +1,34 @@
+package com.coderising.litestruts;
+
+import java.util.Map;
+
+
+
+public class Struts {
+
+ public static View runAction(String actionName, Map parameters) {
+
+ /*
+
+ 0. 读取配置文件struts.xml
+
+ 1. 根据actionName找到相对应的class , 例如LoginAction, 通过反射实例化(创建对象)
+ 据parameters中的数据,调用对象的setter方法, 例如parameters中的数据是
+ ("name"="test" , "password"="1234") ,
+ 那就应该调用 setName和setPassword方法
+
+ 2. 通过反射调用对象的exectue 方法, 并获得返回值,例如"success"
+
+ 3. 通过反射找到对象的所有getter方法(例如 getMessage),
+ 通过反射来调用, 把值和属性形成一个HashMap , 例如 {"message": "登录成功"} ,
+ 放到View对象的parameters
+
+ 4. 根据struts.xml中的 配置,以及execute的返回值, 确定哪一个jsp,
+ 放到View对象的jsp字段中。
+
+ */
+
+ return null;
+ }
+
+}
diff --git a/group01/1664823950/src/com/coderising/litestruts/StrutsTest.java b/group01/1664823950/src/com/coderising/litestruts/StrutsTest.java
new file mode 100644
index 0000000000..a44c1878ac
--- /dev/null
+++ b/group01/1664823950/src/com/coderising/litestruts/StrutsTest.java
@@ -0,0 +1,43 @@
+package com.coderising.litestruts;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+
+
+
+
+public class StrutsTest {
+
+ @Test
+ public void testLoginActionSuccess() {
+
+ String actionName = "login";
+
+ Map params = new HashMap();
+ params.put("name","test");
+ params.put("password","1234");
+
+
+ View view = Struts.runAction(actionName,params);
+
+ Assert.assertEquals("/jsp/homepage.jsp", view.getJsp());
+ Assert.assertEquals("login successful", view.getParameters().get("message"));
+ }
+
+ @Test
+ public void testLoginActionFailed() {
+ String actionName = "login";
+ Map params = new HashMap();
+ params.put("name","test");
+ params.put("password","123456"); //密码和预设的不一致
+
+ View view = Struts.runAction(actionName,params);
+
+ Assert.assertEquals("/jsp/showLogin.jsp", view.getJsp());
+ Assert.assertEquals("login failed,please check your user/pwd", view.getParameters().get("message"));
+ }
+}
diff --git a/group01/1664823950/src/com/coderising/litestruts/View.java b/group01/1664823950/src/com/coderising/litestruts/View.java
new file mode 100644
index 0000000000..0194c681f6
--- /dev/null
+++ b/group01/1664823950/src/com/coderising/litestruts/View.java
@@ -0,0 +1,23 @@
+package com.coderising.litestruts;
+
+import java.util.Map;
+
+public class View {
+ private String jsp;
+ private Map parameters;
+
+ public String getJsp() {
+ return jsp;
+ }
+ public View setJsp(String jsp) {
+ this.jsp = jsp;
+ return this;
+ }
+ public Map getParameters() {
+ return parameters;
+ }
+ public View setParameters(Map parameters) {
+ this.parameters = parameters;
+ return this;
+ }
+}
diff --git a/group01/1664823950/src/com/coderising/litestruts/struts.xml b/group01/1664823950/src/com/coderising/litestruts/struts.xml
new file mode 100644
index 0000000000..99063bcb0c
--- /dev/null
+++ b/group01/1664823950/src/com/coderising/litestruts/struts.xml
@@ -0,0 +1,11 @@
+
+
+
+ /jsp/homepage.jsp
+ /jsp/showLogin.jsp
+
+
+ /jsp/welcome.jsp
+ /jsp/error.jsp
+
+
\ No newline at end of file
diff --git a/group01/1814014897/zhouhui/src/.project b/group01/1814014897/zhouhui/src/.project
new file mode 100644
index 0000000000..f7d6de6781
--- /dev/null
+++ b/group01/1814014897/zhouhui/src/.project
@@ -0,0 +1,11 @@
+
+
+ src
+
+
+
+
+
+
+
+
diff --git a/group01/1814014897/zhouhui/src/week02/array/ArrayUtil.java b/group01/1814014897/zhouhui/src/week02/array/ArrayUtil.java
new file mode 100644
index 0000000000..dd939e7d2c
--- /dev/null
+++ b/group01/1814014897/zhouhui/src/week02/array/ArrayUtil.java
@@ -0,0 +1,222 @@
+package week02.array;
+
+/**
+ *
+ * @author Hui Zhou
+ * @version 1.0 2017-02-28
+ *
+ */
+
+public class ArrayUtil {
+
+ /**
+ * 给定一个整形数组a , 对该数组的值进行置换
+ 例如: a = [7, 9 , 30, 3] , 置换后为 [3, 30, 9,7]
+ 如果 a = [7, 9, 30, 3, 4] , 置换后为 [4,3, 30 , 9,7]
+ * @param origin
+ * @return
+ */
+ public void reverseArray(int[] origin){
+ if(origin == null) return;
+
+ int mid = origin.length/2;
+ for(int i=0;iarray4[j+1]){
+ int sto = array4[j];
+ array4[j] = array4[j+1];
+ array4[j+1] = sto;
+ }
+ }
+ }
+ return array4;
+ }
+ /**
+ * 把一个已经存满数据的数组 oldArray的容量进行扩展, 扩展后的新数据大小为oldArray.length + size
+ * 注意,老数组的元素在新数组中需要保持
+ * 例如 oldArray = [2,3,6] , size = 3,则返回的新数组为
+ * [2,3,6,0,0,0]
+ * @param oldArray
+ * @param size
+ * @return
+ */
+ public int[] grow(int [] oldArray, int size){
+ if(size<0 || oldArray==null) return null;
+
+ int[] newArray = new int[oldArray.length + size];
+ for(int i=0;i parameters) {
+
+ /*
+
+ 0. 读取配置文件struts.xml
+
+ 1. 根据actionName找到相对应的class , 例如LoginAction, 通过反射实例化(创建对象)
+ 据parameters中的数据,调用对象的setter方法, 例如parameters中的数据是
+ ("name"="test" , "password"="1234") ,
+ 那就应该调用 setName和setPassword方法
+
+ 2. 通过反射调用对象的exectue 方法, 并获得返回值,例如"success"
+
+ 3. 通过反射找到对象的所有getter方法(例如 getMessage),
+ 通过反射来调用, 把值和属性形成一个HashMap , 例如 {"message": "登录成功"} ,
+ 放到View对象的parameters
+
+ 4. 根据struts.xml中的 配置,以及execute的返回值, 确定哪一个jsp,
+ 放到View对象的jsp字段中。
+
+ */
+
+ //读取配置文件struts.xml
+ DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
+ DocumentBuilder builder;
+ Document doc = null;
+ View view = new View(); //实例化View(后面调用view,存储parameters以及jsp,最后return view)
+ try {
+ builder = factory.newDocumentBuilder();
+ File f = new File("src/week02/litestruts/struts.xml");
+ doc = builder.parse(f);
+ } catch (ParserConfigurationException|SAXException|IOException e) {
+ e.printStackTrace();
+ }
+
+ //根据actionName找到相对应的action
+ Element root = doc.getDocumentElement();
+ NodeList actionNode = root.getElementsByTagName("action");
+ Element action = null;
+ for(int i=0;i cls = Class.forName(actionClass);
+ Object obj = cls.newInstance();
+ Method setName = cls.getMethod("setName", String.class);
+ Method setPassword = cls.getMethod("setPassword", String.class);
+ setName.invoke(obj, parameters.get("name"));
+ setPassword.invoke(obj, parameters.get("password"));
+
+ //通过反射调用对象的exectue 方法,并获得返回值
+ Method execute = cls.getMethod("execute");
+ String exe_val = (String) execute.invoke(obj);
+
+ //通过反射找到对象的所有getter方法,通过反射来调用
+ Method[] met = cls.getDeclaredMethods();
+ List list = new LinkedList();
+ for(int i=0;i param = new HashMap<>();
+ for(int i=0;i 配置,以及execute的返回值,确定哪一个jsp,放到View对象的jsp字段中
+ if(exe_val.equals("success"))
+ view.setJsp("/jsp/homepage.jsp");
+ else view.setJsp("/jsp/showLogin.jsp");
+
+ } catch (ClassNotFoundException|InstantiationException|IllegalAccessException
+ |NoSuchMethodException|SecurityException|IllegalArgumentException|InvocationTargetException e) {
+ e.printStackTrace();
+ }
+
+ return view;
+ }
+}
diff --git a/group01/1814014897/zhouhui/src/week02/litestruts/StrutsTest.java b/group01/1814014897/zhouhui/src/week02/litestruts/StrutsTest.java
new file mode 100644
index 0000000000..e65f6525bd
--- /dev/null
+++ b/group01/1814014897/zhouhui/src/week02/litestruts/StrutsTest.java
@@ -0,0 +1,41 @@
+package week02.litestruts;
+
+import java.util.*;
+import org.junit.*;
+
+/**
+ * @author Hui Zhou
+ * @version 1.0 2017-02-28
+ */
+
+public class StrutsTest {
+
+ @Test
+ public void testLoginActionSuccess() {
+
+ String actionName = "login";
+
+ Map params = new HashMap();
+ params.put("name","test");
+ params.put("password","1234");
+
+
+ View view = Struts.runAction(actionName,params);
+
+ Assert.assertEquals("/jsp/homepage.jsp", view.getJsp());
+ Assert.assertEquals("login successful", view.getParameters().get("message"));
+ }
+
+ @Test
+ public void testLoginActionFailed() {
+ String actionName = "login";
+ Map params = new HashMap();
+ params.put("name","test");
+ params.put("password","123456"); //密码和预设的不一致
+
+ View view = Struts.runAction(actionName,params);
+
+ Assert.assertEquals("/jsp/showLogin.jsp", view.getJsp());
+ Assert.assertEquals("login failed,please check your user/pwd", view.getParameters().get("message"));
+ }
+}
diff --git a/group01/1814014897/zhouhui/src/week02/litestruts/View.java b/group01/1814014897/zhouhui/src/week02/litestruts/View.java
new file mode 100644
index 0000000000..3043fb5d5a
--- /dev/null
+++ b/group01/1814014897/zhouhui/src/week02/litestruts/View.java
@@ -0,0 +1,28 @@
+package week02.litestruts;
+
+import java.util.Map;
+
+/**
+ * @author Hui Zhou
+ * @version 1.0 2017-02-28
+ */
+
+public class View {
+ private String jsp;
+ private Map parameters;
+
+ public String getJsp() {
+ return jsp;
+ }
+ public View setJsp(String jsp) {
+ this.jsp = jsp;
+ return this;
+ }
+ public Map getParameters() {
+ return parameters;
+ }
+ public View setParameters(Map parameters) {
+ this.parameters = parameters;
+ return this;
+ }
+}
diff --git a/group01/1814014897/zhouhui/src/week02/litestruts/struts.xml b/group01/1814014897/zhouhui/src/week02/litestruts/struts.xml
new file mode 100644
index 0000000000..f449db14dd
--- /dev/null
+++ b/group01/1814014897/zhouhui/src/week02/litestruts/struts.xml
@@ -0,0 +1,11 @@
+
+
+
+ /jsp/homepage.jsp
+ /jsp/showLogin.jsp
+
+
+ /jsp/welcome.jsp
+ /jsp/error.jsp
+
+
\ No newline at end of file
diff --git a/group01/2137642225/work01/README.md b/group01/2137642225/work01/README.md
new file mode 100644
index 0000000000..46aae880a3
--- /dev/null
+++ b/group01/2137642225/work01/README.md
@@ -0,0 +1,6 @@
+- 实现基本的数据结构
+# ArrayList
+# LinkedList
+# Stack
+# Queue
+# BinaryTree
\ No newline at end of file
diff --git a/group01/2137642225/work02/.classpath b/group01/2137642225/work02/.classpath
new file mode 100644
index 0000000000..f832756744
--- /dev/null
+++ b/group01/2137642225/work02/.classpath
@@ -0,0 +1,8 @@
+
+
+
+
+
+
+
+
diff --git a/liuxin/.gitignore b/group01/2137642225/work02/.gitignore
similarity index 100%
rename from liuxin/.gitignore
rename to group01/2137642225/work02/.gitignore
diff --git a/group01/2137642225/work02/.project b/group01/2137642225/work02/.project
new file mode 100644
index 0000000000..e340a1dc5b
--- /dev/null
+++ b/group01/2137642225/work02/.project
@@ -0,0 +1,17 @@
+
+
+ work02
+
+
+
+
+
+ org.eclipse.jdt.core.javabuilder
+
+
+
+
+
+ org.eclipse.jdt.core.javanature
+
+
diff --git a/group01/2137642225/work02/.settings/org.eclipse.jdt.core.prefs b/group01/2137642225/work02/.settings/org.eclipse.jdt.core.prefs
new file mode 100644
index 0000000000..838bd9d694
--- /dev/null
+++ b/group01/2137642225/work02/.settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,11 @@
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
+org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
+org.eclipse.jdt.core.compiler.compliance=1.7
+org.eclipse.jdt.core.compiler.debug.lineNumber=generate
+org.eclipse.jdt.core.compiler.debug.localVariable=generate
+org.eclipse.jdt.core.compiler.debug.sourceFile=generate
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.source=1.7
diff --git a/group01/2137642225/work02/README.md b/group01/2137642225/work02/README.md
new file mode 100644
index 0000000000..ce9e536748
--- /dev/null
+++ b/group01/2137642225/work02/README.md
@@ -0,0 +1 @@
+-- 实现数组工具类和读取xml
\ No newline at end of file
diff --git a/group01/2137642225/work02/src/com/coderising/array/ArrayUtil.java b/group01/2137642225/work02/src/com/coderising/array/ArrayUtil.java
new file mode 100644
index 0000000000..f760a015f9
--- /dev/null
+++ b/group01/2137642225/work02/src/com/coderising/array/ArrayUtil.java
@@ -0,0 +1,236 @@
+package com.coderising.array;
+
+public class ArrayUtil {
+
+ /**
+ * 给定一个整形数组a , 对该数组的值进行置换
+ 例如: a = [7, 9 , 30, 3] , 置换后为 [3, 30, 9,7]
+ 如果 a = [7, 9, 30, 3, 4] , 置换后为 [4,3, 30 , 9,7]
+ * @param origin
+ * @return
+ */
+ public void reverseArray(int[] origin){
+ if (origin != null && origin.length > 1) {
+ int len = origin.length;
+ int temp;
+ for(int left = 0,right = len - 1; left < right; left++,right = len - left - 1){
+ temp = origin[left];
+ origin[left] = origin[right];
+ origin[right] = temp;
+ }
+ }
+ }
+
+ /**
+ * 现在有如下的一个数组: int oldArr[]={1,3,4,5,0,0,6,6,0,5,4,7,6,7,0,5}
+ * 要求将以上数组中值为0的项去掉,将不为0的值存入一个新的数组,生成的新数组为:
+ * {1,3,4,5,6,6,5,4,7,6,7,5}
+ * @param oldArray
+ * @return
+ */
+ public int[] removeZero(int[] oldArray){
+ int[] newArray = null;
+ if (oldArray != null && oldArray.length > 0) {
+ int[] indexArray = new int[oldArray.length];
+ int j = 0;
+ for (int i = 0; i < oldArray.length; i++) {
+ if(oldArray[i] != 0){
+ indexArray[j++] = i;
+ }
+ }
+ newArray = new int[j];
+ for (int i = 0; i < j; i++) {
+ newArray[i] = oldArray[indexArray[i]];
+ }
+ indexArray = null;
+ }
+ return newArray;
+ }
+
+ /**
+ * 给定两个已经排序好的整形数组, a1和a2 , 创建一个新的数组a3, 使得a3 包含a1和a2 的所有元素, 并且仍然是有序的
+ * 例如 a1 = [3, 5, 7,8] a2 = [4, 5, 6,7] 则 a3 为[3,4,5,6,7,8] , 注意: 已经消除了重复
+ * @param array1
+ * @param array2
+ * @return
+ */
+
+ public int[] merge(int[] array1, int[] array2){
+ if(array1 == null || array1.length <= 0){
+ return array2;
+ }
+ if(array2 == null || array2.length <= 0){
+ return array1;
+ }
+ int[] tempArray = new int[array1.length + array2.length];
+ int i = 0,j = 0,k = 0;
+ for (; i < array1.length && j < array2.length; ) {
+ if (array1[i] > array2[j]) {
+ tempArray[k++] = array2[j++];
+ }
+ else if(array1[i] < array2[j]){
+ tempArray[k++] = array1[i++];
+ }
+ else {
+ tempArray[k++] = array1[i++];
+ j++;
+ }
+ }
+ // 以array1为结束点
+ if(array1[array1.length - 1] > array2[array2.length - 1]){
+ for (; i < array1.length;) {
+ tempArray[k++] = array1[i++];
+ }
+ } else { // 以array2为结束点
+ for (; j < array2.length;) {
+ tempArray[k++] = array1[j++];
+ }
+ }
+ int[] mergeArray = new int[k];
+ for (int l = 0; l < mergeArray.length; l++) {
+ mergeArray[l] = tempArray[l];
+ }
+ tempArray = null;
+ return mergeArray;
+ }
+ /**
+ * 把一个已经存满数据的数组 oldArray的容量进行扩展, 扩展后的新数据大小为oldArray.length + size
+ * 注意,老数组的元素在新数组中需要保持
+ * 例如 oldArray = [2,3,6] , size = 3,则返回的新数组为
+ * [2,3,6,0,0,0]
+ * @param oldArray
+ * @param size
+ * @return
+ */
+ public int[] grow(int [] oldArray, int size){
+ if(size <= 0){
+ throw new RuntimeException("size大于0");
+ }
+ int[] newArray = null;
+ if(oldArray != null && oldArray.length > 0){
+ newArray = new int[oldArray.length + size];
+ for (int i = 0; i < oldArray.length; i++) {
+ newArray[i] = oldArray[i];
+ }
+ }
+ return newArray;
+ }
+
+ /**
+ * 斐波那契数列为:1,1,2,3,5,8,13,21...... ,给定一个最大值, 返回小于该值的数列
+ * 例如, max = 15 , 则返回的数组应该为 [1,1,2,3,5,8,13]
+ * max = 1, 则返回空数组 []
+ * @param max
+ * @return
+ */
+ public int[] fibonacci(int max){
+ if(max <= 1){
+ return new int[0];
+ }
+ int[] tempArray = new int[max];
+ int i = 0;
+ tempArray[i++] = 1;
+ tempArray[i] = 1;
+ while(tempArray[i] < max){
+ i++;
+ tempArray[i] = tempArray[i - 1] + tempArray[i - 2];
+ }
+ int[] array = new int[i];
+ for (int j = 0; j < array.length; j++) {
+ array[j] = tempArray[j];
+ }
+ tempArray = null;
+ return array;
+ }
+
+ /**
+ * 返回小于给定最大值max的所有素数数组
+ * 例如max = 23, 返回的数组为[2,3,5,7,11,13,17,19]
+ * @param max
+ * @return
+ */
+ public int[] getPrimes(int max){
+ if(max <= 2){
+ return new int[0];
+ }
+ int[] tempArray = new int[max];
+ int j = 0;
+ for (int i = 2; i < max; i++) {
+ if(isPrime(i)){
+ tempArray[j++] = i;
+ }
+ }
+ int[] array = new int[j];
+ for (int i = 0; i < j; i++) {
+ array[i] = tempArray[i];
+ }
+ tempArray = null;
+ return array;
+ }
+
+ private boolean isPrime(int i) {
+ for (int j = 2; j < i; j++) {
+ if(i % j == 0){
+ return false;
+ }
+ }
+ return true;
+ }
+
+ /**
+ * 所谓“完数”, 是指这个数恰好等于它的因子之和,例如6=1+2+3
+ * 给定一个最大值max, 返回一个数组, 数组中是小于max 的所有完数
+ * @param max
+ * @return
+ */
+ public int[] getPerfectNumbers(int max){
+ if(max <= 2){
+ return new int[0];
+ }
+ int[] tempArray = new int[max];
+ int j = 0;
+ for (int i = 3; i < max; i++) {
+ if(isPerfectNumber(i)){
+ tempArray[j++] = i;
+ }
+ }
+ int[] array = new int[j];
+ for (int i = 0; i < j; i++) {
+ array[i] = tempArray[i];
+ }
+ tempArray = null;
+ return array;
+ }
+
+ private boolean isPerfectNumber(int num) {
+ int sum = 1;
+ for(int i = 2; i < num; i++){
+ if(num % i == 0){
+ sum += i;
+ }
+ }
+ if(sum == num){
+ return true;
+ }
+ return false;
+ }
+
+ /**
+ * 用seperator 把数组 array给连接起来
+ * 例如array= [3,8,9], seperator = "-"
+ * 则返回值为"3-8-9"
+ * @param array
+ * @param s
+ * @return
+ */
+ public String join(int[] array, String seperator){
+ char[] chars = new char[array.length<<1];
+ for (int i = 0,j = 1; i < chars.length; i+=2,j+=2) {
+ chars[i] = (char) (array[i>>1] + 48);
+ chars[j] = seperator.charAt(0);
+ }
+ return new String(chars, 0, chars.length - 1);
+ }
+
+
+}
diff --git a/group01/2137642225/work02/src/com/coderising/litestruts/LoginAction.java b/group01/2137642225/work02/src/com/coderising/litestruts/LoginAction.java
new file mode 100644
index 0000000000..1005f35a29
--- /dev/null
+++ b/group01/2137642225/work02/src/com/coderising/litestruts/LoginAction.java
@@ -0,0 +1,39 @@
+package com.coderising.litestruts;
+
+/**
+ * 这是一个用来展示登录的业务类, 其中的用户名和密码都是硬编码的。
+ * @author liuxin
+ *
+ */
+public class LoginAction{
+ private String name ;
+ private String password;
+ private String message;
+
+ public String getName() {
+ return name;
+ }
+
+ public String getPassword() {
+ return password;
+ }
+
+ public String execute(){
+ if("test".equals(name) && "1234".equals(password)){
+ this.message = "login successful";
+ return "success";
+ }
+ this.message = "login failed,please check your user/pwd";
+ return "fail";
+ }
+
+ public void setName(String name){
+ this.name = name;
+ }
+ public void setPassword(String password){
+ this.password = password;
+ }
+ public String getMessage(){
+ return this.message;
+ }
+}
diff --git a/group01/2137642225/work02/src/com/coderising/litestruts/Struts.java b/group01/2137642225/work02/src/com/coderising/litestruts/Struts.java
new file mode 100644
index 0000000000..ab57e27477
--- /dev/null
+++ b/group01/2137642225/work02/src/com/coderising/litestruts/Struts.java
@@ -0,0 +1,338 @@
+package com.coderising.litestruts;
+
+import java.io.File;
+import java.io.UnsupportedEncodingException;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.net.URL;
+import java.net.URLDecoder;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Set;
+
+import org.dom4j.Attribute;
+import org.dom4j.Document;
+import org.dom4j.DocumentException;
+import org.dom4j.Element;
+import org.dom4j.io.SAXReader;
+
+
+@SuppressWarnings("unchecked")
+public class Struts {
+
+ public static View runAction(String actionName, Map parameters) {
+
+ if(actionName == null || actionName.trim().equals("")){
+ throw new RuntimeException("传入的actionName不能为null或者空");
+ }
+
+ // 0. 读取配置文件struts.xml ok
+ URL resource = Struts.class.getResource("/com/coderising/litestruts");
+ String path = "";
+ try {
+ path = URLDecoder.decode(resource.getPath(), "UTF-8");
+ } catch (UnsupportedEncodingException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ Map> actionMap = xmlParse(path + File.separator + "struts.xml");
+
+ // 找到访问的action通过actionName
+ Map action = findAction(actionName,actionMap);
+
+ //1. 根据actionName找到相对应的class , 例如LoginAction, 通过反射实例化(创建对象)
+ //据parameters中的数据,调用对象的setter方法, 例如parameters中的数据是
+ //("name"="test" , "password"="1234") ,
+ //那就应该调用 setName和setPassword方法
+ // 实例化对象
+ String className = (String) action.get("class");
+ Class> clazz = getActionClassByClassName(className);
+ Object actionObject = buildActionObject(clazz,parameters);
+
+ //2. 通过反射调用对象的exectue 方法, 并获得返回值,例如"success"
+ // 执行访问的方法
+ String result = (String) executeAccessMethod(actionObject,clazz,"execute");
+
+ //3. 通过反射找到对象的所有getter方法(例如 getMessage),
+ //通过反射来调用, 把值和属性形成一个HashMap , 例如 {"message": "登录成功"} ,
+ //放到View对象的parameters
+ Map parameterMap = getActionObjectParameters(actionObject,clazz);
+
+ //4. 根据struts.xml中的 配置,以及execute的返回值, 确定哪一个jsp,
+ //放到View对象的jsp字段中。
+ String jsp = getViewPath(action,result);
+ View v = buildView(jsp,parameterMap);
+
+ return v;
+ }
+
+ private static Class> getActionClassByClassName(String className) {
+
+ if(className == null || className.trim().equals("")){
+ throw new RuntimeException("没有配置action的class属性");
+ }
+
+ try {
+ return Class.forName(className);
+ } catch (ClassNotFoundException e) {
+ e.printStackTrace();
+ }
+ return null;
+ }
+
+ /**
+ * 获取配置文件中视图的路径
+ * @param action
+ * @param result
+ * @return
+ */
+ private static String getViewPath(Map action, String result) {
+
+ if(result != null && !result.trim().equals("")){
+
+ List