diff --git a/group16/1154151360/.classpath b/group16/1154151360/.classpath
index fb5011632c..9746a6c933 100644
--- a/group16/1154151360/.classpath
+++ b/group16/1154151360/.classpath
@@ -2,5 +2,8 @@
+
+
+
diff --git a/group16/1154151360/src/com/array/ArrayUtil.java b/group16/1154151360/src/com/array/ArrayUtil.java
new file mode 100644
index 0000000000..39f587c847
--- /dev/null
+++ b/group16/1154151360/src/com/array/ArrayUtil.java
@@ -0,0 +1,266 @@
+package com.array;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import com.sun.org.apache.xalan.internal.xsltc.compiler.sym;
+
+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 int[] reverseArray(int[] origin){
+
+ int [] temp = new int [origin.length];
+
+ for (int i = 0; i < temp.length; i++){
+ temp [i] = origin [temp.length - 1 - i];
+ }
+
+ origin = temp;
+
+ return origin;
+ }
+
+ /**
+ * 现在有如下的一个数组: 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 newLength = 0;
+
+ for (int i = 0; i < oldArray.length ; i++){
+ if (oldArray[i] == 0)
+ newLength ++;
+ }
+
+ int [] newArray = new int [oldArray.length - newLength];
+ int index = 0;
+ for (int j = 0; j < oldArray.length; j++){
+ if (oldArray[j] != 0)
+ newArray[index++] = oldArray[j];
+ }
+
+ newArray = sort(newArray, 0, newArray.length - 1);
+ 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){
+
+ int newLength = array1.length + array2.length;
+ int [] newArray = new int [newLength];
+ System.arraycopy(array1, 0, newArray, 0, array1.length);
+ System.arraycopy(array2, 0, newArray, array1.length, array2.length);
+ Set arraySet = new HashSet();
+ for (int i = 0; i < newArray.length; i++){
+ arraySet.add(newArray[i]);
+ }
+ int [] tempArray = new int[arraySet.size()];
+ Iterator iterator = arraySet.iterator();
+ int index = 0;
+ while (iterator.hasNext()){
+ tempArray[index++] = iterator.next();
+ }
+ newArray = sort(tempArray, 0, tempArray.length - 1);
+ return newArray;
+ }
+ /**
+ * 把一个已经存满数据的数组 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){
+ int [] newArray = new int[oldArray.length + size];
+ System.arraycopy(oldArray, 0, newArray, 0, size);
+ 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){
+ List array = new ArrayList();
+ array.add(1);
+ array.add(1);
+ for(int i = 2;;i++){
+ array.add(array.get(i - 1) + array.get(i - 2));
+ if (array.get(i) > max){
+ array.remove(i);
+ break;
+ }
+ }
+ int [] result = returnArray(array);
+ return result;
+ }else{
+ int [] b = new int[]{};
+ return b;
+ }
+
+ }
+
+ /**
+ * 返回小于给定最大值max的所有素数数组
+ * 例如max = 23, 返回的数组为[2,3,5,7,11,13,17,19]
+ * @param max
+ * @return
+ */
+ public int[] getPrimes(int max){
+ ArrayList list1 = new ArrayList();
+ ArrayList list2 = new ArrayList();
+ for (int i = 2; i < max; i++){
+ list1.add(i);
+ }
+
+ for (int m = 0; m < list1.size(); m++){
+ boolean flag = true;
+ for (int n = 2; n < list1.get(m); n++){
+ if (list1.get(m) % n == 0){
+ flag = false;
+ break;
+ }
+
+ }
+ if (flag)
+ list2.add(list1.get(m));
+ }
+
+ int [] result = returnArray(list2);
+
+ return result;
+ }
+
+ /**
+ * 所谓“完数”, 是指这个数恰好等于它的因子之和,例如6=1+2+3
+ * 给定一个最大值max, 返回一个数组, 数组中是小于max 的所有完数
+ * @param max
+ * @return
+ */
+ public int[] getPerfectNumbers(int max){
+ ArrayList array = new ArrayList();
+ Map> arrayMap = new HashMap>();
+ ArrayList array2 = new ArrayList();
+ for (int i = 2; i < max; i++){
+ array.add(i);
+ }
+ for(int m = 0; m < array.size(); m++){
+ ArrayList tempArray = new ArrayList();
+ for (int n = 2; n < array.get(m);n++){
+ if (array.get(m) % n == 0)
+ tempArray.add(n);
+ }
+ arrayMap.put(array.get(m), tempArray);
+ }
+ for(Map.Entry> entry: arrayMap.entrySet()){
+ Integer key = entry.getKey();
+ ArrayList tempArray = entry.getValue();
+ Integer tempInt = 0;
+ for (Integer i:tempArray){
+ tempInt += i;
+ }
+ if (key == tempInt){
+ array2.add(key);
+ }
+ }
+ int [] result = returnArray(array2);
+
+ return result;
+ }
+
+ /**
+ * 用seperator 把数组 array给连接起来
+ * 例如array= [3,8,9], seperator = "-"
+ * 则返回值为"3-8-9"
+ * @param array
+ * @param s
+ * @return
+ */
+ public String join(int[] array, String seperator){
+
+ StringBuilder builder = new StringBuilder();
+
+ for (int i = 0; i < array.length; i++){
+ builder.append(array[i]);
+ builder.append(seperator);
+ }
+ builder.deleteCharAt(builder.length() - 1);
+ return builder.toString();
+ }
+//***************************工具类*****************************************
+ public int [] returnArray( List list){
+ int [] result = new int[list.size()];
+ int index = 0;
+ Iterator iterator = list.iterator();
+ while(iterator.hasNext()){
+ result[index++] = iterator.next();
+ }
+ return result;
+ }
+
+ //快速排序算法
+ public int [] sort (int [] array, int low, int height ){
+
+ int start = low;
+ int end = height;
+ int key = array[low];
+
+ while (end > start){
+ //从后往前遍历
+ while (end > start && array[end] >= key)
+ end--;
+
+ if (array[end] <= key){
+ int temp = array[end];
+ array[end] = array[start];
+ array[start] = temp;
+ }
+
+ //从前往后遍历
+ while(end > start && array[start] <= key)
+ start++;
+
+ if (array[start] >= key){
+ int temp = array[start];
+ array[start] = array[end];
+ array[end] = temp;
+ }
+ }
+
+ if(start > low)sort(array, low, start - 1);
+ if (end < height)sort(array, end + 1, height);
+
+ return array;
+ }
+//******************************************************************8
+}
diff --git a/group16/1154151360/src/com/array/ArrayUtilTest.java b/group16/1154151360/src/com/array/ArrayUtilTest.java
new file mode 100644
index 0000000000..159d497b6d
--- /dev/null
+++ b/group16/1154151360/src/com/array/ArrayUtilTest.java
@@ -0,0 +1,102 @@
+package com.array;
+
+import static org.junit.Assert.*;
+import junit.framework.Assert;
+
+import org.junit.Before;
+import org.junit.Test;
+@SuppressWarnings("deprecation")
+public class ArrayUtilTest {
+
+ ArrayUtil util;
+
+ @Before
+ public void init(){
+ util = new ArrayUtil();
+ }
+
+ @Test
+ public void test_reverseArray() {
+ int [] a = {7, 9, 30, 3, 4};
+ a = util.reverseArray(a);
+ Assert.assertEquals("[4,3,30,9,7]", toString(a));
+ }
+
+ @Test
+ public void test_removeZero(){
+ int [] oldArr={1,3,4,5,0,0,6,6,0,5,4,7,6,7,0,5};
+
+ oldArr = util.removeZero(oldArr);
+
+ Assert.assertEquals("[1,3,4,5,6,6,5,4,7,6,7,5]", toString(oldArr));
+ }
+
+
+ @Test
+ public void test_merge(){
+ int [] a1 = {3, 5, 7,8};
+ int [] a2 = {4, 5, 6,7};
+ int [] a3 = util.merge(a1, a2);
+
+ Assert.assertEquals("[3,4,5,6,7,8]", toString(a3));
+
+ }
+
+ @Test
+ public void test_grow(){
+ int [] oldArray = {2,3,6};
+ int size = 3;
+ int [] newArray = util.grow(oldArray, size);
+
+ Assert.assertEquals("[2,3,6,0,0,0]", toString(newArray));
+ }
+
+
+ @Test
+ public void test_fibonacci(){
+
+ int [] array = util.fibonacci(15);
+
+ Assert.assertEquals("[1,1,2,3,5,8,13]", toString(array));
+
+ }
+
+
+ @Test
+ public void test_getPrimes(){
+
+ int [] array = util.getPrimes(23);
+ Assert.assertEquals("[2,3,5,7,11,13,17,19]", toString(array));
+
+ }
+
+ @Test
+ public void test_getPerfectNumbers(){
+ int [] array = util.getPerfectNumbers(10);
+
+ Assert.assertEquals("[6]", toString(array));
+
+ }
+
+ @Test
+ public void test_join(){
+
+ int [] array = {3,8,9};
+ String result = util.join(array, "-");
+ Assert.assertEquals("3-8-9", result);
+ }
+
+
+ public String toString(int [] array){
+ StringBuilder builder = new StringBuilder();
+ builder.append("[");
+ for(int item: array){
+ builder.append(item)
+ .append(",");
+ }
+ builder.replace(builder.length() - 1, builder.length(), "");
+ builder.append("]");
+ return builder.toString();
+
+ }
+}
diff --git a/group16/1154151360/src/com/litestruts/LoginAction.java b/group16/1154151360/src/com/litestruts/LoginAction.java
new file mode 100644
index 0000000000..24369135f9
--- /dev/null
+++ b/group16/1154151360/src/com/litestruts/LoginAction.java
@@ -0,0 +1,40 @@
+package com.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/group16/1154151360/src/com/litestruts/Struts.java b/group16/1154151360/src/com/litestruts/Struts.java
new file mode 100644
index 0000000000..49254d6a5f
--- /dev/null
+++ b/group16/1154151360/src/com/litestruts/Struts.java
@@ -0,0 +1,139 @@
+package com.litestruts;
+
+import java.io.File;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import org.dom4j.Attribute;
+import org.dom4j.Document;
+import org.dom4j.DocumentException;
+import org.dom4j.Element;
+import org.dom4j.io.SAXReader;
+
+
+
+public class Struts {
+
+ public static View runAction(String actionName, Map parameters) throws DocumentException, ClassNotFoundException, InstantiationException, IllegalAccessException, NoSuchMethodException, SecurityException, IllegalArgumentException, InvocationTargetException {
+
+ /*
+
+ 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字段中。
+ */
+
+
+ //创建SAXreader对象
+ SAXReader reader = new SAXReader();
+ //将读取的文件封装成document对象
+ Document document = reader.read(new File("src/com/litestruts/struts.xml"));
+ //获取文档的根节点
+ Element root = document.getRootElement();
+
+ List elist = listNode(root);
+
+ Map > actionMap = getAction(elist, actionName);
+
+ for(Map.Entry> entity: actionMap.entrySet()){
+ String className = entity.getKey();
+ Class clazz = Class.forName(className);
+ Method setName = clazz.getMethod("setName", String.class);
+ Method setPassword = clazz.getMethod("setPassword", String.class);
+ Method getMessage = clazz.getMethod("getMessage");
+ Method execute = clazz.getMethod("execute");
+ Object object = clazz.newInstance();
+ setName.invoke(object, parameters.get("name"));
+ setPassword.invoke(object, parameters.get("password"));
+ String status = (String) execute.invoke(object);
+ String message = (String) getMessage.invoke(object);
+
+ String jsp = entity.getValue().get(status);
+
+ Map parameter = new HashMap();
+
+ parameter.put("message", message);
+
+ View view = new View();
+
+ view.setJsp(jsp);
+ view.setParameters(parameter);
+
+ return view;
+ }
+
+ return null;
+ }
+
+ //获取节点的所有子节点
+ private static List listNode(Element node){
+
+ Iterator iterator = node.elementIterator();
+ List elist = new ArrayList();
+ while (iterator.hasNext()){
+ Element e = iterator.next();
+ elist.add(e);
+ }
+ if (elist.isEmpty())
+ return null;
+ else
+ return elist;
+ }
+
+ //获取对应的Action信息
+ private static Map > getAction(List elist,String actionName){
+
+ for (Element node:elist){
+ List attributes = node.attributes();
+ if (attributes.isEmpty())
+ getAction(listNode(node),actionName);
+ else{
+ Attribute attribute = node.attribute("name");
+ if (attribute.getValue().equals(actionName)){
+ String className = node.attribute("class").getValue();
+ List childElements = listNode(node);
+ Map resMap =install(childElements);
+ Map > actionMap = new HashMap>();
+ actionMap.put(className, resMap);
+ return actionMap;
+ }
+ }
+ }
+ return null;
+ }
+
+ //组装action的result
+ private static Map install(List elements){
+ Map resultMap = new HashMap();
+ for (Element node: elements){
+ Attribute attribute = node.attribute("name");
+ String value;
+ if (node.getTextTrim().isEmpty())
+ value = "";
+ else
+ value = node.getTextTrim();
+
+ resultMap.put(attribute.getValue(), value);
+
+ }
+ return resultMap;
+ }
+
+}
diff --git a/group16/1154151360/src/com/litestruts/StrutsTest.java b/group16/1154151360/src/com/litestruts/StrutsTest.java
new file mode 100644
index 0000000000..9317cc5e26
--- /dev/null
+++ b/group16/1154151360/src/com/litestruts/StrutsTest.java
@@ -0,0 +1,51 @@
+package com.litestruts;
+
+import static org.junit.Assert.*;
+
+import java.io.File;
+import java.lang.reflect.InvocationTargetException;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import junit.framework.Assert;
+
+import org.dom4j.Attribute;
+import org.dom4j.Document;
+import org.dom4j.DocumentException;
+import org.dom4j.Element;
+import org.dom4j.io.SAXReader;
+import org.junit.Test;
+
+public class StrutsTest {
+
+ @Test
+ public void testLoginActionSuccess() throws DocumentException, ClassNotFoundException, InstantiationException, IllegalAccessException, NoSuchMethodException, SecurityException, IllegalArgumentException, InvocationTargetException {
+
+ 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() throws DocumentException, ClassNotFoundException, InstantiationException, IllegalAccessException, NoSuchMethodException, SecurityException, IllegalArgumentException, InvocationTargetException {
+ 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/group16/1154151360/src/com/litestruts/View.java b/group16/1154151360/src/com/litestruts/View.java
new file mode 100644
index 0000000000..af63dce301
--- /dev/null
+++ b/group16/1154151360/src/com/litestruts/View.java
@@ -0,0 +1,23 @@
+package com.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/group16/1154151360/src/com/litestruts/struts.xml b/group16/1154151360/src/com/litestruts/struts.xml
new file mode 100644
index 0000000000..ddbcbc38da
--- /dev/null
+++ b/group16/1154151360/src/com/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/group16/1287642108/0226/src/com/coding/basic/ArrayList.java b/group16/1287642108/0226/src/com/coding/basic/ArrayList.java
index e287419dc0..f82d064e2a 100644
--- a/group16/1287642108/0226/src/com/coding/basic/ArrayList.java
+++ b/group16/1287642108/0226/src/com/coding/basic/ArrayList.java
@@ -1,63 +1,63 @@
-package com.coding.basic;
-
-public class ArrayList implements List {
-
- private int size = 0;
-
- private Object[] elementData = new Object[100];
-
- public void add(Object o) {
- IncrementsCapacity(size + 1);
- elementData[size++] = o;
-
- }
-
- public void add(int index, Object o) {
- checkIndex(index);
- IncrementsCapacity(size + 1);
- System.arraycopy(elementData, index, elementData, index + 1, size - index);
- elementData[index] = o;
- size++;
- }
-
- public Object get(int index) {
- checkIndex(index);
- return elementData[index];
- }
-
- public Object remove(int index) {
- checkIndex(index);
- Object o = elementData[index];
- System.arraycopy(elementData, index + 1, elementData, index, size - index - 1);
- elementData[--size] = null;
- return o;
- }
-
- public int size() {
- return size;
- }
-
- public int length() {
- return elementData.length;
- }
-
- //
- private void IncrementsCapacity(int num) {
- if (num > elementData.length) {
- int oldCapacity = elementData.length; // ǰ鳤
- int newCapacity = ((num + oldCapacity) * 3) >> 2; // ǰ鳤ȵ1.5
- if (newCapacity - num < 0) {
- newCapacity = num; // Dz,ֱΪֵ
- }
- Object[] oldelements = elementData;
- elementData = new Object[newCapacity];
- System.arraycopy(oldelements, 0, elementData, 0, size);
- }
- }
-
- // ±Խж
- private void checkIndex(int index) {
- if (index >= size || index < 0)
- throw new IndexOutOfBoundsException("±Խ");
- }
-}
+package com.coding.basic;
+
+public class ArrayList implements List {
+
+ private int size = 0;
+
+ private Object[] elementData = new Object[100];
+
+ public void add(Object o) {
+ IncrementsCapacity(size + 1);
+ elementData[size++] = o;
+
+ }
+
+ public void add(int index, Object o) {
+ checkIndex(index);
+ IncrementsCapacity(size + 1);
+ System.arraycopy(elementData, index, elementData, index + 1, size - index);
+ elementData[index] = o;
+ size++;
+ }
+
+ public Object get(int index) {
+ checkIndex(index);
+ return elementData[index];
+ }
+
+ public Object remove(int index) {
+ checkIndex(index);
+ Object o = elementData[index];
+ System.arraycopy(elementData, index + 1, elementData, index, size - index - 1);
+ elementData[--size] = null;
+ return o;
+ }
+
+ public int size() {
+ return size;
+ }
+
+ public int length() {
+ return elementData.length;
+ }
+
+ //
+ private void IncrementsCapacity(int num) {
+ if (num > elementData.length) {
+ int oldCapacity = elementData.length; // ǰ鳤
+ int newCapacity = ((num + oldCapacity) * 3) >> 2; // ǰ鳤ȵ1.5
+ if (newCapacity - num < 0) {
+ newCapacity = num; // Dz,ֱΪֵ
+ }
+ Object[] oldelements = elementData;
+ elementData = new Object[newCapacity];
+ System.arraycopy(oldelements, 0, elementData, 0, size);
+ }
+ }
+
+ // ±Խж
+ private void checkIndex(int index) {
+ if (index >= size || index < 0)
+ throw new IndexOutOfBoundsException("±Խ");
+ }
+}
diff --git a/group16/1287642108/0226/src/com/coding/basic/Iterator.java b/group16/1287642108/0226/src/com/coding/basic/Iterator.java
index e7cbd474ec..ff93e30377 100644
--- a/group16/1287642108/0226/src/com/coding/basic/Iterator.java
+++ b/group16/1287642108/0226/src/com/coding/basic/Iterator.java
@@ -1,6 +1,6 @@
-package com.coding.basic;
-
-public interface Iterator {
- public boolean hasNext();
- public Object next();
-}
+package com.coding.basic;
+
+public interface Iterator {
+ public boolean hasNext();
+ public Object next();
+}
diff --git a/group16/1287642108/0226/src/com/coding/basic/LinkedList.java b/group16/1287642108/0226/src/com/coding/basic/LinkedList.java
index 99c92fb9f1..fc206b4cec 100644
--- a/group16/1287642108/0226/src/com/coding/basic/LinkedList.java
+++ b/group16/1287642108/0226/src/com/coding/basic/LinkedList.java
@@ -1,101 +1,101 @@
-package com.coding.basic;
-
-public class LinkedList implements List {
-
- private Node head;
- private Node tail;
- private int size = 0 ;
-
- public void add(Object o){
- addLast(o);
- }
-
- public void add(int index, Object o) {
- if (index == 0) {
- addFirst(o);
- } else if (index >= size) {
- addLast(o);
- } else {
- Node node = new Node();
- node.data = o;
- node.next = getNode(index);
- getNode(index - 1).next = node;
- size++;
- }
- }
-
- public Object get(int index) {
- Node node = getNode(index);
- return node.data;
- }
-
- public Object remove(int index){
- Node currentNode = getNode(index);
- Node prevNode = getNode(index - 1);
- Node lastNode = getNode(index + 1);
- prevNode.next = lastNode;
- size--;
- return currentNode.data;
- }
-
- public int size(){
- return size;
- }
-
- public void addFirst(Object o){
- Node node=new Node();
- node.data = o;
- node.next = head;
- head = node;
- size++;
- }
- public void addLast(Object o){
- Node node=new Node();
- node.data = o;
- node.next = null;
- Node lastNode = getNode(size-1);
- lastNode.next = node;
- size++;
- }
- public Object removeFirst(){
- Object obj = getNode(0).data;
- Node node = getNode(1);
- node.next = head;
- size--;
- return obj;
- }
- public Object removeLast(){
- Object obj = getNode(size - 1).data;
- Node node = getNode(size - 2);
- node.next = null;
- size--;
- return obj;
- }
-
- //ȡڵ
- public Node getNode(int index){
- checkIndex(index);
- if(index == 0 ){
- return head;
- }else if(index == size -1 ){
- return tail;
- }else{
- Node node = head;
- for(int i=0;i= size || index < 0)
- throw new IndexOutOfBoundsException("±Խ");
- }
-
- private static class Node {
- Object data;
- Node next;
- }
-}
+package com.coding.basic;
+
+public class LinkedList implements List {
+
+ private Node head;
+ private Node tail;
+ private int size = 0 ;
+
+ public void add(Object o){
+ addLast(o);
+ }
+
+ public void add(int index, Object o) {
+ if (index == 0) {
+ addFirst(o);
+ } else if (index >= size) {
+ addLast(o);
+ } else {
+ Node node = new Node();
+ node.data = o;
+ node.next = getNode(index);
+ getNode(index - 1).next = node;
+ size++;
+ }
+ }
+
+ public Object get(int index) {
+ Node node = getNode(index);
+ return node.data;
+ }
+
+ public Object remove(int index){
+ Node currentNode = getNode(index);
+ Node prevNode = getNode(index - 1);
+ Node lastNode = getNode(index + 1);
+ prevNode.next = lastNode;
+ size--;
+ return currentNode.data;
+ }
+
+ public int size(){
+ return size;
+ }
+
+ public void addFirst(Object o){
+ Node node=new Node();
+ node.data = o;
+ node.next = head;
+ head = node;
+ size++;
+ }
+ public void addLast(Object o){
+ Node node=new Node();
+ node.data = o;
+ node.next = null;
+ Node lastNode = getNode(size-1);
+ lastNode.next = node;
+ size++;
+ }
+ public Object removeFirst(){
+ Object obj = getNode(0).data;
+ Node node = getNode(1);
+ node.next = head;
+ size--;
+ return obj;
+ }
+ public Object removeLast(){
+ Object obj = getNode(size - 1).data;
+ Node node = getNode(size - 2);
+ node.next = null;
+ size--;
+ return obj;
+ }
+
+ //ȡڵ
+ public Node getNode(int index){
+ checkIndex(index);
+ if(index == 0 ){
+ return head;
+ }else if(index == size -1 ){
+ return tail;
+ }else{
+ Node node = head;
+ for(int i=0;i= size || index < 0)
+ throw new IndexOutOfBoundsException("±Խ");
+ }
+
+ private static class Node {
+ Object data;
+ Node next;
+ }
+}
diff --git a/group16/1287642108/0226/src/com/coding/basic/List.java b/group16/1287642108/0226/src/com/coding/basic/List.java
index 10d13b5832..396b1f6416 100644
--- a/group16/1287642108/0226/src/com/coding/basic/List.java
+++ b/group16/1287642108/0226/src/com/coding/basic/List.java
@@ -1,9 +1,9 @@
-package com.coding.basic;
-
-public interface List {
- public void add(Object o);
- public void add(int index, Object o);
- public Object get(int index);
- public Object remove(int index);
- public int size();
-}
+package com.coding.basic;
+
+public interface List {
+ public void add(Object o);
+ public void add(int index, Object o);
+ public Object get(int index);
+ public Object remove(int index);
+ public int size();
+}
diff --git a/group16/1287642108/0226/src/com/coding/basic/Queue.java b/group16/1287642108/0226/src/com/coding/basic/Queue.java
index 95dee3d81b..418e42826e 100644
--- a/group16/1287642108/0226/src/com/coding/basic/Queue.java
+++ b/group16/1287642108/0226/src/com/coding/basic/Queue.java
@@ -1,28 +1,28 @@
-package com.coding.basic;
-
-public class Queue {
- private LinkedList elementData = new LinkedList();
-
- public void enQueue(Object o){
- elementData.addLast(o);
- }
-
- public Object deQueue(){
- if (isEmpty()) {
- return null;
- }else{
- return elementData.removeFirst();
- }
- }
-
- public boolean isEmpty(){
- if (elementData.size() == 0) {
- return true;
- }
- return false;
- }
-
- public int size(){
- return elementData.size();
- }
-}
+package com.coding.basic;
+
+public class Queue {
+ private LinkedList elementData = new LinkedList();
+
+ public void enQueue(Object o){
+ elementData.addLast(o);
+ }
+
+ public Object deQueue(){
+ if (isEmpty()) {
+ return null;
+ }else{
+ return elementData.removeFirst();
+ }
+ }
+
+ public boolean isEmpty(){
+ if (elementData.size() == 0) {
+ return true;
+ }
+ return false;
+ }
+
+ public int size(){
+ return elementData.size();
+ }
+}
diff --git a/group16/1287642108/0226/src/com/coding/basic/Stack.java b/group16/1287642108/0226/src/com/coding/basic/Stack.java
index c0b7da89f8..6138bc6973 100644
--- a/group16/1287642108/0226/src/com/coding/basic/Stack.java
+++ b/group16/1287642108/0226/src/com/coding/basic/Stack.java
@@ -1,38 +1,38 @@
-package com.coding.basic;
-
-public class Stack {
- private ArrayList elementData = new ArrayList();
-
- public void push(Object o) {
- if (isEmpty()) {
- elementData.add(elementData.length() - 1, o);
- }
- elementData.add(elementData.length() - elementData.size() - 1, o);
- }
-
- public Object pop() {
- if (isEmpty()) {
- return null;
- }
- return elementData.remove(elementData.length() - elementData.size() - 1);
- }
-
- public Object peek() {
- if (isEmpty()) {
- return null;
- }
- return elementData.get(elementData.length() - elementData.size() - 1);
- }
-
- public boolean isEmpty() {
- if (elementData.size() == 0) {
- return true;
- }
- return false;
- }
-
- public int size() {
- return elementData.size();
- }
-
-}
+package com.coding.basic;
+
+public class Stack {
+ private ArrayList elementData = new ArrayList();
+
+ public void push(Object o) {
+ if (isEmpty()) {
+ elementData.add(elementData.length() - 1, o);
+ }
+ elementData.add(elementData.length() - elementData.size() - 1, o);
+ }
+
+ public Object pop() {
+ if (isEmpty()) {
+ return null;
+ }
+ return elementData.remove(elementData.length() - elementData.size() - 1);
+ }
+
+ public Object peek() {
+ if (isEmpty()) {
+ return null;
+ }
+ return elementData.get(elementData.length() - elementData.size() - 1);
+ }
+
+ public boolean isEmpty() {
+ if (elementData.size() == 0) {
+ return true;
+ }
+ return false;
+ }
+
+ public int size() {
+ return elementData.size();
+ }
+
+}
diff --git a/group16/1287642108/0305/src/com/coderising/array/ArrayUtil.java b/group16/1287642108/0305/src/com/coderising/array/ArrayUtil.java
new file mode 100644
index 0000000000..8e0d8af87b
--- /dev/null
+++ b/group16/1287642108/0305/src/com/coderising/array/ArrayUtil.java
@@ -0,0 +1,205 @@
+package com.coderising.array;
+
+import java.util.ArrayList;
+
+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[] temp = new int[origin.length];
+ int index = 0;
+ for (int i = origin.length - 1; i >= 0; i--) {
+ temp[index++] = origin[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 static int[] removeZero(int[] oldArray) {
+ int countZero = 0;
+ for (int i = 0; i < oldArray.length; i++) {
+ if(oldArray[i] == 0){
+ countZero++;
+ }
+ }
+
+ int[] temp = new int[oldArray.length - countZero];
+ int index = 0;
+ for (int i = 0; i < oldArray.length; i++) {
+ if (oldArray[i] != 0) {
+ temp[index++] = oldArray[i];
+ }
+ }
+ return temp;
+ }
+
+ /**
+ * 给定两个已经排序好的整形数组, 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 Integer[] merge(int[] array1, int[] array2) {
+ Integer[] temp = new Integer[array1.length + array2.length];
+ int i = 0,j = 0;
+ int index = 0;
+
+ while(i < array1.length && j < array2.length){
+ if(array1[i] <= array2[j]){
+ temp[index++] = array1[i++];
+ }else{
+ temp[index++] = array2[j++];
+ }
+ }
+
+ while(i < array1.length){
+ temp[index++] = array1[i++];
+ }
+ while(j < array2.length){
+ temp[index++] = array2[j++];
+ }
+ return removeRepetition(temp);
+ }
+
+ /**
+ * 把一个已经存满数据的数组 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[] temp = new int[oldArray.length + size];
+ System.arraycopy(oldArray, 0, temp, 0, oldArray.length);
+ return temp;
+ }
+
+ /**
+ * 斐波那契数列为: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){
+ int[] temp = new int[max];
+ if(max == 1){
+ return null;
+ }
+ int index = 0;
+ for(int i = 0;i temp = new ArrayList<>();
+ for(int i=2; i < max; i++){
+ isPrime = true;
+ for (int j = 2; j < i; j++){
+ if ((i % j) == 0) {
+ isPrime = false;
+ break;
+ }
+ }
+ if(isPrime){
+ temp.add(i);
+ }
+ }
+ int[] array = new int[temp.size()];
+ int index = 0;
+ for(Integer te : temp){
+ array[index++] = te;
+ }
+ return array;
+ }
+
+ /**
+ * 所谓“完数”, 是指这个数恰好等于它的因子之和,例如6=1+2+3 给定一个最大值max, 返回一个数组, 数组中是小于max 的所有完数
+ *
+ * @param max
+ * @return
+ */
+ public static Integer[] getPerfectNumbers(int max) {
+ Integer[] temp = new Integer[max];
+ int index = 0;
+ for (int i = 2; i < max; i++) {
+ int sum = 0;
+ for (int j = 1; j < i; j++) {
+ if (i % j == 0) {
+ sum += j;
+ }
+ if (sum == i){
+ temp[index++] = i;
+ }
+ }
+ }
+ return removeRepetition(temp);
+ }
+
+ /**
+ * 用seperator 把数组 array给连接起来 例如array= {3,8,9}, seperator = "-" 则返回值为"3-8-9"
+ *
+ * @param array
+ * @param s
+ * @return
+ */
+ public String join(int[] array, String seperator) {
+ String temp = "";
+ for(int i = 0;i < array.length -1; i++){
+ temp += array[i] + seperator;
+ }
+ temp += array[array.length-1];
+ return temp;
+ }
+
+ public static Integer[] removeRepetition(Integer[] oldArray){
+ ArrayList temp = new ArrayList<>();
+ for(int i=0;i parameters) throws ClassNotFoundException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException {
+ //创建SAXReader读取器,专门用于读取xml
+ SAXReader saxReader = new SAXReader();
+ Document document = null;
+ try {
+ document = saxReader.read(new File("D:/DemoSpace/coding2017/group16/1287642108/0305/src/com/coderising/litestruts/struts.xml"));
+ Element root = document.getRootElement();
+ //根据节点名称找节点
+ Node node = root.selectSingleNode("action[@name='"+actionName+"']");
+ String classPath = ((Element) node).attributeValue("class");
+ //根据类名反射实例化
+ Class> onwClass = Class.forName(classPath);
+ Object o = onwClass.newInstance();
+ Method setName = onwClass.getMethod("setName",String.class);
+ Method setPassword = onwClass.getMethod("setPassword",String.class);
+ Method execute = onwClass.getMethod("execute");
+ Method getName = onwClass.getMethod("getName");
+ Method getPassword = onwClass.getMethod("getPassword");
+ Method getMessage = onwClass.getMethod("getMessage");
+ setName.invoke(o,parameters.get("name"));
+ setPassword.invoke(o,parameters.get("password"));
+ String result = (String) execute.invoke(o);
+ //组装params参数
+ HashMap map = new HashMap<>();
+ String name = (String) getName.invoke(o);
+ String password = (String) getPassword.invoke(o);
+ String message = (String) getMessage.invoke(o);
+ map.put("name", name);
+ map.put("password", password);
+ map.put("message", message);
+ //组装view数据
+ View view = new View();
+ view.setParameters(map);
+ //根据execute的返回值,找对应的jsp页面路径
+ String jspPath = node.valueOf("//result[@name='"+result+"']");
+ view.setJsp(jspPath);
+ return view;
+ } catch (DocumentException e) {
+ e.printStackTrace();
+ }
+ return null;
+ }
+}
diff --git a/group16/1287642108/0305/src/com/coderising/litestruts/StrutsTest.java b/group16/1287642108/0305/src/com/coderising/litestruts/StrutsTest.java
new file mode 100644
index 0000000000..2a8ed76022
--- /dev/null
+++ b/group16/1287642108/0305/src/com/coderising/litestruts/StrutsTest.java
@@ -0,0 +1,40 @@
+package com.coderising.litestruts;
+
+import java.lang.reflect.InvocationTargetException;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+public class StrutsTest {
+
+ @Test
+ public void testLoginActionSuccess() throws ClassNotFoundException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException {
+
+ 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() throws ClassNotFoundException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException {
+ 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/group16/1287642108/0305/src/com/coderising/litestruts/View.java b/group16/1287642108/0305/src/com/coderising/litestruts/View.java
new file mode 100644
index 0000000000..0194c681f6
--- /dev/null
+++ b/group16/1287642108/0305/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/group16/1287642108/0305/src/com/coderising/litestruts/struts.xml b/group16/1287642108/0305/src/com/coderising/litestruts/struts.xml
new file mode 100644
index 0000000000..e22003fc12
--- /dev/null
+++ b/group16/1287642108/0305/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/group16/1325756593/src/com/coderising/array/ArrayUtil.java b/group16/1325756593/src/com/coderising/array/ArrayUtil.java
new file mode 100644
index 0000000000..0f67e6b54f
--- /dev/null
+++ b/group16/1325756593/src/com/coderising/array/ArrayUtil.java
@@ -0,0 +1,273 @@
+package com.coderising.array;
+
+import static org.hamcrest.CoreMatchers.nullValue;
+
+import java.util.Arrays;
+
+import com.dong.week1.ArrayList;
+
+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==0){
+ return;
+ }
+ int len = origin.length;
+ for(int i=0;iarray2[index2]){
+ arrayList.add(array2[index2]);
+ index2++;
+ }else if(array1[index1]==array2[index2]){
+ arrayList.add(array2[index2]);
+ index1++;
+ index2++;
+ }
+ else{
+ arrayList.add(array1[index1]);
+ index1++;
+ }
+ }
+ if(index1==len1){
+ for(int i=index2;i=max){
+ break;
+ }
+ arrayList.add(third);
+ first = second;
+ second=third;
+
+
+ }
+ return ListToArray(arrayList);
+ }
+
+ /**
+ * 返回小于给定最大值max的所有素数数组
+ * 例如max = 23, 返回的数组为[2,3,5,7,11,13,17,19]
+ * @param max
+ * @return
+ */
+ public int[] getPrimes(int max){
+ ArrayList arrayList = new ArrayList();
+ for(int i=2;i resultAndViewMap;
+ public String getActioName() {
+ return actioName;
+ }
+ public void setActioName(String actioName) {
+ this.actioName = actioName;
+ }
+ @Override
+ public String toString() {
+ return "Action [actioName=" + actioName + ", className=" + className + ", resultAndViewMap=" + resultAndViewMap
+ + "]";
+ }
+ public String getClassName() {
+ return className;
+ }
+ public void setClassName(String className) {
+ this.className = className;
+ }
+ public Map getResultAndViewMap() {
+ return resultAndViewMap;
+ }
+ public void setResultAndViewMap(Map resultAndViewMap) {
+ this.resultAndViewMap = resultAndViewMap;
+ }
+
+
+
+
+}
diff --git a/group16/1325756593/src/com/coderising/litestruts/LoginAction.java b/group16/1325756593/src/com/coderising/litestruts/LoginAction.java
new file mode 100644
index 0000000000..dcdbe226ed
--- /dev/null
+++ b/group16/1325756593/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/group16/1325756593/src/com/coderising/litestruts/Struts.java b/group16/1325756593/src/com/coderising/litestruts/Struts.java
new file mode 100644
index 0000000000..ae6289d5f0
--- /dev/null
+++ b/group16/1325756593/src/com/coderising/litestruts/Struts.java
@@ -0,0 +1,246 @@
+package com.coderising.litestruts;
+
+import java.io.File;
+import java.io.IOException;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.NamedNodeMap;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+import org.xml.sax.SAXException;
+
+
+
+public class Struts {
+
+ public static String strutsPath;
+
+
+ public static String getStrutsPath() {
+ return strutsPath;
+ }
+
+ public static void setStrutsPath(String strutsPath) {
+ Struts.strutsPath = strutsPath;
+ }
+
+
+
+
+ public static View runAction(String actionName, Map parameters) throws ParserConfigurationException, SAXException, IOException, InstantiationException, IllegalAccessException, ClassNotFoundException, NoSuchMethodException, SecurityException, IllegalArgumentException, InvocationTargetException {
+
+ /*
+
+ 0. 读取配置文件struts.xml
+
+ 1. 根据actionName找到相对应的class , 例如LoginAction, 通过反射实例化(创建对象)
+ 据parameters中的数据,调用对象的setter方法, 例如parameters中的数据是
+ ("name"="test" , "password"="1234") ,
+ 那就应该调用 setName和setPassword方法
+
+ 2. 通过反射调用对象的exectue 方法, 并获得返回值,例如"success"
+
+
+
+ 4. 根据struts.xml中的 配置,以及execute的返回值, 确定哪一个jsp,
+ 放到View对象的jsp字段中。
+
+ */
+ if(strutsPath==null||strutsPath.equals("")){
+ strutsPath = initStrutsPath();
+ }
+ List actions = parseXml(strutsPath);
+ Action action = getAction(actions,actionName);
+ NotBeNull(action);
+
+
+ String actionClassName = action.getClassName();
+ Class actionClass = Class.forName(actionClassName);
+ Object actionClassObject = actionClass.newInstance();
+
+ doSetterMethod(parameters, actionClass, actionClassObject);
+
+ Method excuteMethod = actionClass.getMethod("execute", null);
+ String result = excuteMethod.invoke(actionClassObject, null).toString();
+ String viewPath = action.getResultAndViewMap().get(result);
+ View view = new View();
+ view.setJsp(viewPath);
+ Map parametersMap = doGetterMethod(actionClass, actionClassObject);
+ view.setParameters(parametersMap);
+
+ return view;
+ }
+
+
+ /**
+ * 3. 通过反射找到对象的所有getter方法(例如 getMessage),
+ 通过反射来调用, 把值和属性形成一个HashMap , 例如 {"message": "登录成功"} ,
+ 放到View对象的parameters
+ * @param actionClass
+ * @param actionClassObject
+ * @return
+ * @throws IllegalAccessException
+ * @throws InvocationTargetException
+ */
+ private static Map doGetterMethod(Class actionClass, Object actionClassObject)
+ throws IllegalAccessException, InvocationTargetException {
+ Map parametersMap = new HashMap<>();
+ for(Method method :actionClass.getMethods()){
+ if(method.getName().startsWith("get")){
+ String getValue = getMethodValue(method.getName());
+ parametersMap.put(getValue, method.invoke(actionClassObject, null));
+ }
+ }
+ return parametersMap;
+ }
+
+ /**
+ * 1. 根据actionName找到相对应的class , 例如LoginAction, 通过反射实例化(创建对象)
+ 据parameters中的数据,调用对象的setter方法, 例如parameters中的数据是
+ ("name"="test" , "password"="1234") ,
+ 那就应该调用 setName和setPassword方法
+ * @param parameters
+ * @param actionClass
+ * @param actionClassObject
+ * @throws NoSuchMethodException
+ * @throws IllegalAccessException
+ * @throws InvocationTargetException
+ */
+ private static void doSetterMethod(Map parameters, Class actionClass, Object actionClassObject)
+ throws NoSuchMethodException, IllegalAccessException, InvocationTargetException {
+ for( Map.Entry entry: parameters.entrySet()){
+ String param = entry.getKey();
+ Method methodKeySet = actionClass.getMethod(getMethodSet(param), String.class);
+ methodKeySet.invoke(actionClassObject, entry.getValue());
+ }
+ }
+
+ /**
+ * 初始化strutsPath
+ * @return
+ */
+ private static String initStrutsPath() {
+ String path = Struts.class.getClassLoader().getResource("").getPath();
+ String strutsXmlPath = path+"/com/coderising/litestruts/struts.xml";
+ return strutsXmlPath;
+ }
+
+
+ /**
+ * 通过name构造setName
+ * @param name
+ * @return
+ */
+ public static String getMethodSet(String name){
+ String firstChar = name.substring(0, 1).toUpperCase();
+ return "set"+firstChar+name.substring(1);
+ }
+
+ /**
+ * 获取getMessage对应的message
+ * @param name
+ * @return
+ */
+ public static String getMethodValue(String name){
+ if(name.length()>=3){
+ name = name.substring(3);
+ }
+ String firstChar = name.substring(0, 1).toLowerCase();
+ return firstChar+name.substring(1);
+ }
+
+
+
+ /**
+ * 将xml解析成为Action的List结构
+ * @param xmlPath
+ * @return
+ * @throws ParserConfigurationException
+ * @throws SAXException
+ * @throws IOException
+ */
+ public static List parseXml(String xmlPath) throws ParserConfigurationException, SAXException, IOException{
+ List retActionList = new ArrayList<>();
+ File xmlFile = new File(xmlPath);
+ DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
+ DocumentBuilder builder = factory.newDocumentBuilder();
+ Document doc = builder.parse(xmlFile);
+ NodeList actionLists = doc.getElementsByTagName("action");
+ for(int i=0;i resultAndViewMap=getResultAndViewNodeList(currentNode);
+ action.setResultAndViewMap(resultAndViewMap);
+ retActionList.add(action);
+ }
+ return retActionList;
+ }
+
+ /**
+ * 获取该Node对应的result和对应的jsppath
+ * @param currentNode
+ * @param resultAndViewMap
+ */
+ private static HashMap getResultAndViewNodeList(Node currentNode) {
+ Map resultAndViewMap = new HashMap<>();
+ NodeList resultAndViewNodeList = currentNode.getChildNodes();
+
+ for(int j=0;j) resultAndViewMap;
+ }
+
+
+ private static void NotBeNull(Object result) {
+ if(result==null){
+ throw new IllegalArgumentException();
+ }
+ }
+
+
+
+ public static String getAttribute(Node node ,String name){
+ NamedNodeMap nameNodeMap = node.getAttributes();
+ NotBeNull(nameNodeMap);
+ Node nameNode = nameNodeMap.getNamedItem(name);
+ NotBeNull(nameNode);
+ String actionName =nameNode.getNodeValue();
+ return actionName;
+ }
+
+ public static Action getAction(List actions ,String actionName){
+ for(Action action:actions){
+ if(action.getActioName().equals(actionName)){
+ return action;
+ }
+ }
+ return null;
+
+ }
+
+
+
+}
diff --git a/group16/1325756593/src/com/coderising/litestruts/StrutsTest.java b/group16/1325756593/src/com/coderising/litestruts/StrutsTest.java
new file mode 100644
index 0000000000..487f05542c
--- /dev/null
+++ b/group16/1325756593/src/com/coderising/litestruts/StrutsTest.java
@@ -0,0 +1,48 @@
+package com.coderising.litestruts;
+
+import java.io.IOException;
+import java.lang.reflect.InvocationTargetException;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.xml.parsers.ParserConfigurationException;
+
+import org.junit.Assert;
+import org.junit.Test;
+import org.xml.sax.SAXException;
+
+
+
+
+
+public class StrutsTest {
+
+ @Test
+ public void testLoginActionSuccess() throws InstantiationException, IllegalAccessException, ClassNotFoundException, NoSuchMethodException, SecurityException, IllegalArgumentException, InvocationTargetException, ParserConfigurationException, SAXException, IOException {
+
+ 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() throws InstantiationException, IllegalAccessException, ClassNotFoundException, NoSuchMethodException, SecurityException, IllegalArgumentException, InvocationTargetException, ParserConfigurationException, SAXException, IOException {
+ 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/group16/1325756593/src/com/coderising/litestruts/View.java b/group16/1325756593/src/com/coderising/litestruts/View.java
new file mode 100644
index 0000000000..07df2a5dab
--- /dev/null
+++ b/group16/1325756593/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/group16/1325756593/src/com/coderising/litestruts/struts.xml b/group16/1325756593/src/com/coderising/litestruts/struts.xml
new file mode 100644
index 0000000000..07f80b6476
--- /dev/null
+++ b/group16/1325756593/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/group16/214074094/src/com/coding/basic/BinaryTreeNode.java b/group16/214074094/src/com/coding/basic/BinaryTreeNode.java
deleted file mode 100644
index b40066ebe1..0000000000
--- a/group16/214074094/src/com/coding/basic/BinaryTreeNode.java
+++ /dev/null
@@ -1,39 +0,0 @@
-package coding.basic;
-
-public class BinaryTreeNode {
-
- private Object data;
-
- private BinaryTreeNode left;
-
- private BinaryTreeNode right;
-
- public Object getData() {
- return data;
- }
-
- public void setData(Object data) {
- this.data = data;
- }
-
- public BinaryTreeNode getLeft() {
- return left;
- }
-
- public void setLeft(BinaryTreeNode left) {
- this.left = left;
- }
-
- public BinaryTreeNode getRight() {
- return right;
- }
-
- public void setRight(BinaryTreeNode right) {
- this.right = right;
- }
-
- public BinaryTreeNode insert(Object o) {
- return null;
- }
-
-}
diff --git a/group16/214074094/src/com/coding/basic/List.java b/group16/214074094/src/com/coding/basic/List.java
deleted file mode 100644
index 5da9b0d4c6..0000000000
--- a/group16/214074094/src/com/coding/basic/List.java
+++ /dev/null
@@ -1,15 +0,0 @@
-package coding.basic;
-
-public interface List {
-
- void add(Object o);
-
- void add(int index, Object o);
-
- Object get(int index);
-
- Object remove(int index);
-
- int size();
-
-}
diff --git a/group16/214074094/src/com/reading/blog_test.txt b/group16/214074094/src/com/reading/blog_test.txt
deleted file mode 100644
index b7e5cbfe14..0000000000
--- a/group16/214074094/src/com/reading/blog_test.txt
+++ /dev/null
@@ -1 +0,0 @@
-just test new fork
\ No newline at end of file
diff --git a/group16/214074094/src/main/java/study/coderising/array/ArrayUtil.java b/group16/214074094/src/main/java/study/coderising/array/ArrayUtil.java
new file mode 100644
index 0000000000..c2b0c62a79
--- /dev/null
+++ b/group16/214074094/src/main/java/study/coderising/array/ArrayUtil.java
@@ -0,0 +1,213 @@
+package study.coderising.array;
+
+
+import study.coding.basic.ArrayList;
+
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Set;
+
+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 static void reverseArray(int[] origin) {
+ int tmp;
+ for (int i = 0; i < origin.length / 2; i++) {
+ tmp = origin[i];
+ origin[i] = origin[origin.length - i - 1];
+ origin[origin.length - i - 1] = tmp;
+ }
+ }
+
+ /**
+ * 现在有如下的一个数组: 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 = new int[oldArray.length];
+ int k = 0;
+ for (int i = 0; i < oldArray.length; i++) {
+ if (0 != oldArray[i]) {
+ newArray[k++] = oldArray[i];
+ }
+ }
+ return Arrays.copyOf(newArray, k);
+ }
+
+ /**
+ * 给定两个已经排序好的整形数组,a1和a2,创建一个新的数组a3,使得a3包含a1和a2的所有元素,并且仍然是有序的
+ * 例如 a1 = {3, 5, 7, 8},a2 = {4, 5, 6, 7},则 a3 为[3,4,5,6,7,8],注意:已经消除了重复
+ *
+ * @param a1
+ * @param a2
+ * @return
+ */
+
+ public static int[] merge(int[] a1, int[] a2) {
+ Set set = new HashSet();
+
+ for (int i = 0; i < a1.length + a2.length; i++) {
+ if (i < a1.length) {
+ set.add(a1[i]);
+ } else {
+ set.add(a2[i - a1.length]);
+ }
+ }
+
+ int[] a3 = new int[set.size()];
+
+ Iterator it = set.iterator();
+ int i = 0;
+ while (it.hasNext()) {
+ a3[i++] = (Integer) it.next();
+ }
+ return a3;
+ }
+
+ /**
+ * 把一个已经存满数据的数组 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) {
+ return Arrays.copyOf(oldArray, 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 static int[] fibonacci(int max) {
+ if (max == 1) {
+ return new int[0];
+ }
+ ArrayList list = new ArrayList();
+ list.add(1);
+ list.add(1);
+ for (int i = 0; ; i++) {
+ int tmp = list.get(i) + list.get(i + 1);
+ if (tmp >= max) {
+ break;
+ }
+ list.add(i + 2, tmp);
+ }
+
+ return convertIntegerArray2Int(list);
+ }
+
+ /**
+ * 返回小于给定最大值max的所有素数数组
+ * 例如max = 23, 返回的数组为[2,3,5,7,11,13,17,19]
+ *
+ * @param max
+ * @return
+ */
+ public static int[] getPrimes(int max) {
+ if (max < 2) {
+ return null;
+ }
+ ArrayList list = new ArrayList<>();
+ for (int i = 2; i < max; i++) {
+ if (isPrime(i)) {
+ list.add(i);
+ }
+ }
+ return convertIntegerArray2Int(list);
+ }
+
+ /**
+ * 所谓“完数”, 是指这个数恰好等于它的因子之和,例如6=1+2+3
+ * 给定一个最大值max, 返回一个数组, 数组中是小于max 的所有完数
+ *
+ * @param max
+ * @return
+ */
+ public static int[] getPerfectNumbers(int max) {
+ if (max < 2) {
+ return null;
+ }
+ ArrayList list = new ArrayList<>();
+
+ int count = 0;
+ //如果p是质数,且2^p-1也是质数,那么(2^p-1)X2^(p-1)便是一个完全数
+ for (int i = 2; i <= max / 2; i++) {
+ count++;
+ if (isPrime(i) && isPrime((int) Math.pow(2, i) - 1)) {
+ System.out.println("count " + i + ":" + (int) (Math.pow(2, i) - 1) + " * " + (int) Math.pow(2, (i - 1)));
+ int perfectNum = (int) ((Math.pow(2, i) - 1) * Math.pow(2, (i - 1)));
+ if (perfectNum > max) {
+ break;
+ }
+ if (perfectNum < max) {
+ list.add(perfectNum);
+ }
+ }
+ }
+ System.out.println("total count : " + count);
+ return convertIntegerArray2Int(list);
+ }
+
+ /**
+ * 用seperator 把数组 array给连接起来
+ * 例如array= [3,8,9], seperator = "-"
+ * 则返回值为"3-8-9"
+ *
+ * @param array
+ * @param seperator
+ * @return
+ */
+ public static String join(int[] array, String seperator) {
+ if (null == array || array.length < 1) {
+ return null;
+ }
+ StringBuffer sb = new StringBuffer();
+ for (int i = 0; i < array.length; i++) {
+ sb.append(array[i]).append(seperator);
+ }
+ return sb.substring(0, sb.length() - 1);
+ }
+
+ private static boolean isPrime(int n) {
+ if (n == 2) {
+ return true;
+ }
+ for (int j = 2; j <= Math.sqrt(n); j++) {
+ if (n % j == 0) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ private static int[] convertIntegerArray2Int(ArrayList list) {
+ int[] arr = new int[list.size()];
+ for (int i = 0; i < list.size(); i++) {
+ arr[i] = list.get(i).intValue();
+ }
+ return arr;
+ }
+
+
+}
diff --git a/group16/214074094/src/main/java/study/coderising/litestruts/LoginAction.java b/group16/214074094/src/main/java/study/coderising/litestruts/LoginAction.java
new file mode 100644
index 0000000000..043df200d8
--- /dev/null
+++ b/group16/214074094/src/main/java/study/coderising/litestruts/LoginAction.java
@@ -0,0 +1,42 @@
+package study.coderising.litestruts;
+
+/**
+ * 这是一个用来展示登录的业务类, 其中的用户名和密码都是硬编码的。
+ *
+ * @author liuxin
+ */
+public class LoginAction {
+
+ private String name;
+ private String password;
+ private String message;
+
+ 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 String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public String getPassword() {
+ return password;
+ }
+
+ public void setPassword(String password) {
+ this.password = password;
+ }
+
+ public String getMessage() {
+ return this.message;
+ }
+}
diff --git a/group16/214074094/src/main/java/study/coderising/litestruts/LogoutAction.java b/group16/214074094/src/main/java/study/coderising/litestruts/LogoutAction.java
new file mode 100644
index 0000000000..e3a10a6726
--- /dev/null
+++ b/group16/214074094/src/main/java/study/coderising/litestruts/LogoutAction.java
@@ -0,0 +1,39 @@
+package study.coderising.litestruts;
+
+/**
+ * @Author shane
+ * @Time 2017/3/4 12:13
+ * @Email stevenchenguang@gmail.com
+ * @Desc ...
+ */
+public class LogoutAction {
+
+ private String name;
+
+ private String message;
+
+ public String execute() {
+ if ("test".equalsIgnoreCase(name)) {
+ message = name + " logout success";
+ return "success";
+ }
+ message = name + " logout fail";
+ return "error";
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public String getMessage() {
+ return message;
+ }
+
+ public void setMessage(String message) {
+ this.message = message;
+ }
+}
diff --git a/group16/214074094/src/main/java/study/coderising/litestruts/Struts.java b/group16/214074094/src/main/java/study/coderising/litestruts/Struts.java
new file mode 100644
index 0000000000..9a70e7a525
--- /dev/null
+++ b/group16/214074094/src/main/java/study/coderising/litestruts/Struts.java
@@ -0,0 +1,147 @@
+package study.coderising.litestruts;
+
+import org.dom4j.Attribute;
+import org.dom4j.Document;
+import org.dom4j.DocumentException;
+import org.dom4j.Element;
+import org.dom4j.io.SAXReader;
+import study.coderising.litestruts.bean.Action;
+import study.coderising.litestruts.bean.Result;
+
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.util.*;
+
+
+public class Struts {
+
+ private static final String EXECUTE = "execute";
+
+ public static View runAction(String actionName, Map parameters)
+ throws DocumentException, ClassNotFoundException, NoSuchMethodException,
+ InvocationTargetException, IllegalAccessException, InstantiationException {
+
+ //0. 读取配置文件struts.xml
+ SAXReader reader = new SAXReader();
+ Document doc = reader.read("./src/main/resources/struts.xml");
+ Element root = doc.getRootElement();
+ Action action = getAction(actionName, root);
+
+ //1. 根据actionName找到相对应的class
+ Class clz = Class.forName(action.getClassPath());
+ //获取一个实例,方便接下来对同一个对象赋值
+ Object obj = clz.newInstance();
+
+ //1.1 据parameters中的数据,调用对象的setter方法
+ for (Map.Entry entry : parameters.entrySet()) {
+ String setFunctionName = getFunctionName("set", entry.getKey());
+ Method set = clz.getDeclaredMethod(setFunctionName, String.class);
+ set.invoke(obj, entry.getValue());
+ }
+
+ //2. 通过反射调用对象的exectue方法, 并获得返回值
+ Method execute = clz.getDeclaredMethod(EXECUTE);
+ String response = execute.invoke(obj).toString();
+
+ //3. 通过反射找到对象的所有getter方法并调用, 把值和属性形成一个HashMap
+ Method[] methods = clz.getDeclaredMethods();
+ Map map = new HashMap<>();
+ for (Method m : methods) {
+ if (m.getName().startsWith("get")) {
+ String paramName = m.getName().replaceFirst("get", "");
+ map.put(paramName.toLowerCase(), m.invoke(obj));
+ }
+ }
+
+ //3.1 放到View对象的parameters
+ View view = new View();
+ view.setParameters(map);
+
+ //4. 根据struts.xml中的配置,以及execute的返回值,确定jsp,放到View对象的jsp字段中。
+ for (Result result : action.getResults()) {
+ if (response.equalsIgnoreCase(result.getResult())) {
+ view.setJsp(result.getJumpPath());
+ break;
+ }
+ }
+
+ return view;
+ }
+
+ /**
+ * @Author: shane
+ * @Time: 2017/3/4 23:53
+ * @Email: stevenchenguang@gmail.com
+ * @param: begin, key
+ * @Return: String
+ * @Throw:
+ * @Desc: 根据开始名称和key获取方法名
+ * e.g.: begin: get, key: name, return getName
+ */
+ private static String getFunctionName(String begin, String key) {
+ if (key == null || "".equals(key)) {
+ return null;
+ }
+ StringBuffer sb = new StringBuffer(begin);
+ if (key.length() < 2) {
+ sb.append(key.toUpperCase());
+ } else {
+ String first = String.valueOf(key.charAt(0));
+ sb.append(first.toUpperCase());
+ sb.append(key.substring(1, key.length()));
+ }
+ return sb.toString();
+ }
+
+ /**
+ * @Author: shane
+ * @Time: 2017/3/4 23:55
+ * @Email: stevenchenguang@gmail.com
+ * @param: actionName, node
+ * @Return: Action
+ * @Throw:
+ * @Desc: 根据actionName和xml节点获取Action
+ */
+ private static Action getAction(String actionName, Element node) {
+ Action action = new Action();
+
+ Iterator iterator = node.elementIterator();
+ boolean flag = false;
+ while (iterator.hasNext()) {
+ Element e = iterator.next();
+ List list = e.attributes();
+
+ //遍历属性节点
+ for (Attribute attr : list) {
+ if ("name".equalsIgnoreCase(attr.getName())) {
+ if (!actionName.equalsIgnoreCase(attr.getValue())) {
+ continue;
+ } else {
+ flag = true;
+ }
+ action.setName(attr.getValue());
+ }
+ if ("class".equalsIgnoreCase(attr.getName())) {
+ action.setClassPath(attr.getValue());
+ }
+
+ List results = new ArrayList<>();
+
+ Iterator it = e.elementIterator();
+ while (it.hasNext()) {
+ Result result = new Result();
+ Element el = it.next();
+ result.setResult(el.attribute(0).getValue());
+ result.setJumpPath(el.getText());
+ results.add(result);
+ }
+ action.setResults(results);
+ }
+ if (flag) {
+ break;
+ }
+ }
+ return action;
+ }
+
+}
diff --git a/group16/214074094/src/main/java/study/coderising/litestruts/StrutsTest.java b/group16/214074094/src/main/java/study/coderising/litestruts/StrutsTest.java
new file mode 100644
index 0000000000..db1b37de1b
--- /dev/null
+++ b/group16/214074094/src/main/java/study/coderising/litestruts/StrutsTest.java
@@ -0,0 +1,109 @@
+package study.coderising.litestruts;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.dom4j.DocumentException;
+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 = null;
+ try {
+ view = Struts.runAction(actionName, params);
+ } catch (DocumentException e) {
+ e.printStackTrace();
+ } catch (ClassNotFoundException e) {
+ e.printStackTrace();
+ } catch (NoSuchMethodException e) {
+ e.printStackTrace();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ 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 = null;
+ try {
+ view = Struts.runAction(actionName, params);
+ } catch (DocumentException e) {
+ e.printStackTrace();
+ } catch (ClassNotFoundException e) {
+ e.printStackTrace();
+ } catch (NoSuchMethodException e) {
+ e.printStackTrace();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ Assert.assertEquals("/jsp/showLogin.jsp", view.getJsp());
+ Assert.assertEquals("login failed,please check your user/pwd", view.getParameters().get("message"));
+ }
+
+ @Test
+ public void testLogoutSuccess() {
+ String actionName = "logout";
+
+ Map params = new HashMap();
+ params.put("name", "test");
+
+ View view = null;
+ try {
+ view = Struts.runAction(actionName, params);
+ } catch (DocumentException e) {
+ e.printStackTrace();
+ } catch (ClassNotFoundException e) {
+ e.printStackTrace();
+ } catch (NoSuchMethodException e) {
+ e.printStackTrace();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ Assert.assertEquals("/jsp/welcome.jsp", view.getJsp());
+ Assert.assertEquals("test logout success", view.getParameters().get("message"));
+ }
+
+ @Test
+ public void testLogoutFail() {
+ String actionName = "logout";
+
+ Map params = new HashMap();
+ params.put("name", "unknownUser");
+
+ View view = null;
+ try {
+ view = Struts.runAction(actionName, params);
+ } catch (DocumentException e) {
+ e.printStackTrace();
+ } catch (ClassNotFoundException e) {
+ e.printStackTrace();
+ } catch (NoSuchMethodException e) {
+ e.printStackTrace();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ Assert.assertEquals("/jsp/error.jsp", view.getJsp());
+ Assert.assertEquals("unknownUser logout fail", view.getParameters().get("message"));
+ }
+}
diff --git a/group16/214074094/src/main/java/study/coderising/litestruts/View.java b/group16/214074094/src/main/java/study/coderising/litestruts/View.java
new file mode 100644
index 0000000000..af3df5b9e9
--- /dev/null
+++ b/group16/214074094/src/main/java/study/coderising/litestruts/View.java
@@ -0,0 +1,27 @@
+package study.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/group16/214074094/src/main/java/study/coderising/litestruts/bean/Action.java b/group16/214074094/src/main/java/study/coderising/litestruts/bean/Action.java
new file mode 100644
index 0000000000..12aa461cfc
--- /dev/null
+++ b/group16/214074094/src/main/java/study/coderising/litestruts/bean/Action.java
@@ -0,0 +1,43 @@
+package study.coderising.litestruts.bean;
+
+
+import java.util.List;
+
+/**
+ * @Author shane
+ * @Time 2017/3/4 21:49
+ * @Email shanbaohua@lxfintech.com
+ * @Desc ...
+ */
+public class Action {
+
+ private String name;
+
+ private String classPath;
+
+ private List results;
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public String getClassPath() {
+ return classPath;
+ }
+
+ public void setClassPath(String classPath) {
+ this.classPath = classPath;
+ }
+
+ public List getResults() {
+ return results;
+ }
+
+ public void setResults(List results) {
+ this.results = results;
+ }
+}
diff --git a/group16/214074094/src/main/java/study/coderising/litestruts/bean/Result.java b/group16/214074094/src/main/java/study/coderising/litestruts/bean/Result.java
new file mode 100644
index 0000000000..649844ff31
--- /dev/null
+++ b/group16/214074094/src/main/java/study/coderising/litestruts/bean/Result.java
@@ -0,0 +1,30 @@
+package study.coderising.litestruts.bean;
+
+/**
+ * @Author shane
+ * @Time 2017/3/4 21:50
+ * @Email shanbaohua@lxfintech.com
+ * @Desc ...
+ */
+public class Result {
+
+ private String result;
+
+ private String jumpPath;
+
+ public String getResult() {
+ return result;
+ }
+
+ public void setResult(String result) {
+ this.result = result;
+ }
+
+ public String getJumpPath() {
+ return jumpPath;
+ }
+
+ public void setJumpPath(String jumpPath) {
+ this.jumpPath = jumpPath;
+ }
+}
diff --git a/group16/214074094/src/com/coding/basic/ArrayList.java b/group16/214074094/src/main/java/study/coding/basic/ArrayList.java
similarity index 84%
rename from group16/214074094/src/com/coding/basic/ArrayList.java
rename to group16/214074094/src/main/java/study/coding/basic/ArrayList.java
index 158c866d45..ebe04dd177 100644
--- a/group16/214074094/src/com/coding/basic/ArrayList.java
+++ b/group16/214074094/src/main/java/study/coding/basic/ArrayList.java
@@ -1,4 +1,4 @@
-package coding.basic;
+package study.coding.basic;
import java.util.Arrays;
@@ -10,7 +10,7 @@
* @Email stevenchenguang@gmail.com
* @Desc OwnArrayList
*/
-public class ArrayList implements List {
+public class ArrayList implements List {
private int size = 0;
@@ -28,22 +28,22 @@ public ArrayList() {
}
@Override
- public void add(Object o) {
+ public void add(E e) {
if (elementData == EMPTY_ELEMENTDATA) {
elementData = Arrays.copyOf(elementData, DEFAULT_CAPACITY);
- elementData[0] = o;
+ elementData[0] = e;
} else if (size < elementData.length) {
- elementData[size] = o;
+ elementData[size] = e;
} else {
_grow();
- elementData[size] = o;
+ elementData[size] = e;
}
size++;
_analyze();
}
@Override
- public void add(int index, Object o) {
+ public void add(int index, E e) {
if (index < 0) {
throw new IndexOutOfBoundsException("Index:" + index + ", Size:" + size);
}
@@ -52,40 +52,40 @@ public void add(int index, Object o) {
throw new IndexOutOfBoundsException("Index:" + index + ", Size:" + size);
} else {
elementData = new Object[DEFAULT_CAPACITY];
- elementData[0] = o;
+ elementData[0] = e;
}
} else if (index > size) {
throw new IndexOutOfBoundsException("Index:" + index + ", Size:" + size);
} else if (index == size) {
_grow();
- elementData[size] = o;
+ elementData[size] = e;
size++;
} else {
if (elementData.length == size) {
_grow();
}
System.arraycopy(elementData, index, elementData, index + 1, size - index);
- elementData[index] = o;
+ elementData[index] = e;
size++;
}
_analyze();
}
@Override
- public Object get(int index) {
- if (index < 0 || index > size) {
+ public E get(int index) {
+ if (index < 0 || index >= size) {
throw new IndexOutOfBoundsException("Index:" + index + ", Size:" + size);
}
- return elementData[index];
+ return (E) elementData[index];
}
@Override
- public Object remove(int index) {
+ public E remove(int index) {
- if (index < 0 || index > size) {
+ if (index < 0 || index >= size) {
throw new IndexOutOfBoundsException("Index:" + index + ", Size:" + size);
}
- Object oldValue = elementData[index];
+ E oldValue = (E) elementData[index];
//需要复制的长度
int needMoveLength = size - index - 1;
//如果该长度小于0, 说明只有一个元素, 直接置空即可
@@ -102,6 +102,11 @@ public int size() {
return size;
}
+ @Override
+ public E[] toArray() {
+ return (E[]) elementData;
+ }
+
public Iterator iterator() {
return new ArrayListItrator();
}
diff --git a/group16/214074094/src/main/java/study/coding/basic/BinaryTreeNode.java b/group16/214074094/src/main/java/study/coding/basic/BinaryTreeNode.java
new file mode 100644
index 0000000000..4eae81c97a
--- /dev/null
+++ b/group16/214074094/src/main/java/study/coding/basic/BinaryTreeNode.java
@@ -0,0 +1,95 @@
+package study.coding.basic;
+
+/**
+ * @Author shane
+ * @Time 2017/2/26 19:30
+ * @Email stevenchenguang@gmail.com
+ * @Desc Own BinaryTreeNode
+ */
+public class BinaryTreeNode {
+
+ private Object data;
+
+ private BinaryTreeNode left;
+
+ private BinaryTreeNode right;
+
+ public BinaryTreeNode insert(Object o) {
+ if (null == data) {
+ data = o;
+ return this;
+ }
+ if (bigger(data, o)) {
+ if (null == left) {
+ left = new BinaryTreeNode();
+ left.data = o;
+ } else {
+ left.insert(o);
+ }
+ } else if (smaller(data, o)) {
+ if (null == right) {
+ right = new BinaryTreeNode();
+ right.data = o;
+ } else {
+ right.insert(o);
+ }
+ } else {
+ throw new RuntimeException("The value has exists");
+ }
+ return this;
+ }
+
+ public Object getData() {
+ return data;
+ }
+
+ public void setData(Object data) {
+ this.data = data;
+ }
+
+ public BinaryTreeNode getLeft() {
+ return left;
+ }
+
+ public void setLeft(BinaryTreeNode left) {
+ this.left = left;
+ }
+
+ public BinaryTreeNode getRight() {
+ return right;
+ }
+
+ public void setRight(BinaryTreeNode right) {
+ this.right = right;
+ }
+
+ private boolean bigger(Object data1, Object data2) {
+ return data1.toString().compareTo(data2.toString()) > 0;
+ }
+
+ private boolean smaller(Object data1, Object data2) {
+ return data1.toString().compareTo(data2.toString()) < 0;
+ }
+
+ private ArrayList list = new ArrayList();
+
+ /**
+ * 对二叉树进行遍历 结果存储到list中
+ */
+ private void sort(BinaryTreeNode node) {
+
+ list.add(node.data);
+ if(null != node.left){
+ sort(node.left);
+ }
+ if(null != node.right){
+ sort(node.right);
+ }
+ }
+
+ @Override
+ public String toString() {
+ sort(this);
+ return list.toString();
+ }
+}
diff --git a/group16/214074094/src/com/coding/basic/Iterator.java b/group16/214074094/src/main/java/study/coding/basic/Iterator.java
similarity index 73%
rename from group16/214074094/src/com/coding/basic/Iterator.java
rename to group16/214074094/src/main/java/study/coding/basic/Iterator.java
index 1acc5349a4..0befe6a209 100644
--- a/group16/214074094/src/com/coding/basic/Iterator.java
+++ b/group16/214074094/src/main/java/study/coding/basic/Iterator.java
@@ -1,4 +1,4 @@
-package coding.basic;
+package study.coding.basic;
public interface Iterator {
diff --git a/group16/214074094/src/com/coding/basic/LinkedList.java b/group16/214074094/src/main/java/study/coding/basic/LinkedList.java
similarity index 97%
rename from group16/214074094/src/com/coding/basic/LinkedList.java
rename to group16/214074094/src/main/java/study/coding/basic/LinkedList.java
index 9108c2b6fe..b6fede6824 100644
--- a/group16/214074094/src/com/coding/basic/LinkedList.java
+++ b/group16/214074094/src/main/java/study/coding/basic/LinkedList.java
@@ -1,4 +1,4 @@
-package coding.basic;
+package study.coding.basic;
/**
* @Author shane
@@ -50,6 +50,7 @@ public Object remove(int index) {
} else if (index == size - 1) {
return removeLast();
}
+
Node curr = _node(index);
Object data = curr.data;
final Node prev = curr.prev;
@@ -120,6 +121,11 @@ public int size() {
return size;
}
+ @Override
+ public Object[] toArray() {
+ return new Object[0];
+ }
+
public Iterator iterator() {
return null;
}
diff --git a/group16/214074094/src/main/java/study/coding/basic/List.java b/group16/214074094/src/main/java/study/coding/basic/List.java
new file mode 100644
index 0000000000..e62dd86d52
--- /dev/null
+++ b/group16/214074094/src/main/java/study/coding/basic/List.java
@@ -0,0 +1,16 @@
+package study.coding.basic;
+
+public interface List {
+
+ void add(E e);
+
+ void add(int index, E e);
+
+ E get(int index);
+
+ E remove(int index);
+
+ int size();
+
+ E[] toArray();
+}
diff --git a/group16/214074094/src/com/coding/basic/Queue.java b/group16/214074094/src/main/java/study/coding/basic/Queue.java
similarity index 95%
rename from group16/214074094/src/com/coding/basic/Queue.java
rename to group16/214074094/src/main/java/study/coding/basic/Queue.java
index 869d0f7333..b15950ac36 100644
--- a/group16/214074094/src/com/coding/basic/Queue.java
+++ b/group16/214074094/src/main/java/study/coding/basic/Queue.java
@@ -1,4 +1,4 @@
-package coding.basic;
+package study.coding.basic;
/**
* @Author shane
diff --git a/group16/214074094/src/com/coding/basic/Stack.java b/group16/214074094/src/main/java/study/coding/basic/Stack.java
similarity index 95%
rename from group16/214074094/src/com/coding/basic/Stack.java
rename to group16/214074094/src/main/java/study/coding/basic/Stack.java
index 7ef1c9ad06..188de74ee9 100644
--- a/group16/214074094/src/com/coding/basic/Stack.java
+++ b/group16/214074094/src/main/java/study/coding/basic/Stack.java
@@ -1,4 +1,4 @@
-package coding.basic;
+package study.coding.basic;
/**
* @Author shane
diff --git a/group16/214074094/src/main/java/study/reading/blog.txt b/group16/214074094/src/main/java/study/reading/blog.txt
new file mode 100644
index 0000000000..f112f8ea6a
--- /dev/null
+++ b/group16/214074094/src/main/java/study/reading/blog.txt
@@ -0,0 +1 @@
+学习-CPU、内存、硬盘、指令及它们之间的关系: https://stevenshane.github.io/study/2017/02/27/coding2017-reading.html
\ No newline at end of file
diff --git a/group16/214074094/src/main/resources/struts.xml b/group16/214074094/src/main/resources/struts.xml
new file mode 100644
index 0000000000..f93213e241
--- /dev/null
+++ b/group16/214074094/src/main/resources/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/group16/214074094/src/test/coding/basic/AbstractTest.java b/group16/214074094/src/test/java/study/AbstractTest.java
similarity index 71%
rename from group16/214074094/src/test/coding/basic/AbstractTest.java
rename to group16/214074094/src/test/java/study/AbstractTest.java
index 80eaaa6fe5..42737e270f 100644
--- a/group16/214074094/src/test/coding/basic/AbstractTest.java
+++ b/group16/214074094/src/test/java/study/AbstractTest.java
@@ -1,4 +1,6 @@
-package coding.basic;
+package study;
+
+import com.alibaba.fastjson.JSON;
/**
* @Author shane
@@ -16,4 +18,7 @@ protected void printHyphen() {
System.out.println("--------------------------------------------");
}
+ protected void printJson(Object obj) {
+ System.out.println(JSON.toJSONString(obj));
+ }
}
diff --git a/group16/214074094/src/test/java/study/coderising/ArrayUtilTest.java b/group16/214074094/src/test/java/study/coderising/ArrayUtilTest.java
new file mode 100644
index 0000000000..24cdeadb64
--- /dev/null
+++ b/group16/214074094/src/test/java/study/coderising/ArrayUtilTest.java
@@ -0,0 +1,82 @@
+package study.coderising;
+
+import org.junit.Assert;
+import org.junit.Test;
+import study.AbstractTest;
+import study.coderising.array.ArrayUtil;
+
+/**
+ * @Author shane
+ * @Time 2017/3/1 20:29
+ * @Email shanbaohua@lxfintech.com
+ * @Desc ...
+ */
+public class ArrayUtilTest extends AbstractTest {
+
+ @Test
+ public void testReverseArray(){
+ int[] a = {7, 9 , 30, 3};
+ printJson(a);
+ ArrayUtil.reverseArray(a);
+ printJson(a);
+ }
+
+ @Test
+ public void testremoveZero(){
+ int oldArr[] = {1,3,4,5,0,0,6,6,0,5,4,7,6,7,0,5};
+ int newArr[] = ArrayUtil.removeZero(oldArr);
+ printJson(oldArr);
+ printJson(newArr);
+ }
+
+ @Test
+ public void testMerge(){
+ int[] a1 = {3, 5, 7, 8};
+ int[] a2 = {4, 5, 6, 7};
+
+ int[] a3 = ArrayUtil.merge(a1, a2);
+ printJson(a1);
+ printJson(a2);
+ printJson(a3);
+ }
+
+ @Test
+ public void testGrow(){
+ int[] oldArray = {2,3,6};
+ printJson(oldArray);
+ int[] newArray = ArrayUtil.grow(oldArray, 3);
+ printJson(newArray);
+ }
+
+ @Test
+ public void testFibonacci(){
+ int[] onlyOne = {};
+ int[] before15 = {1, 1, 2, 3, 5, 8, 13};
+ int[] before21 = {1, 1, 2, 3, 5, 8, 13};
+ Assert.assertArrayEquals(onlyOne, ArrayUtil.fibonacci(1));
+ Assert.assertArrayEquals(before15, ArrayUtil.fibonacci(15));
+ Assert.assertArrayEquals(before21, ArrayUtil.fibonacci(21));
+ }
+
+ @Test
+ public void testGetPrimes(){
+ int[] _19 = {2,3,5,7,11,13,17,19};
+ Assert.assertArrayEquals(_19, ArrayUtil.getPrimes(23));
+ int[] _32 = {2,3,5,7,11,13,17,19,23,29,31};
+ Assert.assertArrayEquals(_32, ArrayUtil.getPrimes(32));
+ }
+
+ @Test
+ public void testGetPerfectNumbers(){
+ int[] arr = {6,28,496,8128,33550336};
+ Assert.assertArrayEquals(arr, ArrayUtil.getPerfectNumbers(33550337));
+ }
+
+ @Test
+ public void testJoin(){
+ int[] arr = {3,8,9};
+ String seperator = "-";
+ Assert.assertEquals("3-8-9", ArrayUtil.join(arr, seperator));
+ }
+
+}
diff --git a/group16/214074094/src/test/coding/basic/ArrayListTest.java b/group16/214074094/src/test/java/study/coding/basic/ArrayListTest.java
similarity index 96%
rename from group16/214074094/src/test/coding/basic/ArrayListTest.java
rename to group16/214074094/src/test/java/study/coding/basic/ArrayListTest.java
index 2f03342d61..6ffe2e5715 100644
--- a/group16/214074094/src/test/coding/basic/ArrayListTest.java
+++ b/group16/214074094/src/test/java/study/coding/basic/ArrayListTest.java
@@ -1,9 +1,10 @@
-package coding.basic;
+package study.coding.basic;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
+import study.AbstractTest;
/**
* @Author shane
diff --git a/group16/214074094/src/test/java/study/coding/basic/BinaryTreeNodeTest.java b/group16/214074094/src/test/java/study/coding/basic/BinaryTreeNodeTest.java
new file mode 100644
index 0000000000..370b339434
--- /dev/null
+++ b/group16/214074094/src/test/java/study/coding/basic/BinaryTreeNodeTest.java
@@ -0,0 +1,33 @@
+package study.coding.basic;
+
+import org.junit.Test;
+import study.AbstractTest;
+
+/**
+ * @Author shane
+ * @Time 2017/2/26 19:57
+ * @Email shanbaohua@lxfintech.com
+ * @Desc ...
+ */
+public class BinaryTreeNodeTest extends AbstractTest {
+
+ @Test
+ public void test(){
+ BinaryTreeNode node = new BinaryTreeNode();
+ node.insert(8);
+ node.insert(5);
+ node.insert(9);
+ node.insert(1);
+ node.insert(6);
+ node.insert(11);
+ node.insert(10);
+ node.insert(15);
+ node.insert(13);
+ node.insert(19);
+
+ printStar();
+ System.out.println(node.getData());
+ System.out.println(node);
+ printStar();
+ }
+}
diff --git a/group16/214074094/src/test/coding/basic/LinkedListTest.java b/group16/214074094/src/test/java/study/coding/basic/LinkedListTest.java
similarity index 96%
rename from group16/214074094/src/test/coding/basic/LinkedListTest.java
rename to group16/214074094/src/test/java/study/coding/basic/LinkedListTest.java
index bc78728a25..f22d1cc611 100644
--- a/group16/214074094/src/test/coding/basic/LinkedListTest.java
+++ b/group16/214074094/src/test/java/study/coding/basic/LinkedListTest.java
@@ -1,9 +1,10 @@
-package coding.basic;
+package study.coding.basic;
import junit.framework.Assert;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
+import study.AbstractTest;
/**
* @Author shane
diff --git a/group16/214074094/src/test/coding/basic/QueueTest.java b/group16/214074094/src/test/java/study/coding/basic/QueueTest.java
similarity index 95%
rename from group16/214074094/src/test/coding/basic/QueueTest.java
rename to group16/214074094/src/test/java/study/coding/basic/QueueTest.java
index 12302783b3..cdfe5c95ab 100644
--- a/group16/214074094/src/test/coding/basic/QueueTest.java
+++ b/group16/214074094/src/test/java/study/coding/basic/QueueTest.java
@@ -1,9 +1,10 @@
-package coding.basic;
+package study.coding.basic;
import junit.framework.Assert;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
+import study.AbstractTest;
/**
* @Author shane
diff --git a/group16/214074094/src/test/coding/basic/StackTest.java b/group16/214074094/src/test/java/study/coding/basic/StackTest.java
similarity index 95%
rename from group16/214074094/src/test/coding/basic/StackTest.java
rename to group16/214074094/src/test/java/study/coding/basic/StackTest.java
index f289744a67..8269967dff 100644
--- a/group16/214074094/src/test/coding/basic/StackTest.java
+++ b/group16/214074094/src/test/java/study/coding/basic/StackTest.java
@@ -1,9 +1,10 @@
-package coding.basic;
+package study.coding.basic;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
+import study.AbstractTest;
/**
* @Author shane
diff --git a/group16/2816977791/.gitignore b/group16/2816977791/.gitignore
new file mode 100644
index 0000000000..4ede1404d2
--- /dev/null
+++ b/group16/2816977791/.gitignore
@@ -0,0 +1,181 @@
+# Created by https://www.gitignore.io/api/java,intellij,eclipse,emacs,svn,maven
+
+### Java ###
+*.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*
+
+
+### Intellij ###
+# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm
+# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
+
+# User-specific stuff:
+.idea/workspace.xml
+.idea/tasks.xml
+.idea/dictionaries
+.idea/vcs.xml
+.idea/jsLibraryMappings.xml
+*.idea
+
+# Sensitive or high-churn files:
+.idea/dataSources.ids
+.idea/dataSources.xml
+.idea/dataSources.local.xml
+.idea/sqlDataSources.xml
+.idea/dynamic.xml
+.idea/uiDesigner.xml
+
+# Gradle:
+.idea/gradle.xml
+.idea/libraries
+
+# Mongo Explorer plugin:
+.idea/mongoSettings.xml
+
+## File-based project format:
+*.iws
+
+## Plugin-specific files:
+
+# IntelliJ
+/out/
+
+# mpeltonen/sbt-idea plugin
+.idea_modules/
+
+# JIRA plugin
+atlassian-ide-plugin.xml
+
+# Crashlytics plugin (for Android Studio and IntelliJ)
+com_crashlytics_export_strings.xml
+crashlytics.properties
+crashlytics-build.properties
+fabric.properties
+
+### Intellij Patch ###
+*.iml
+
+
+### Eclipse ###
+
+.metadata
+bin/
+tmp/
+*.tmp
+*.bak
+*.swp
+*~.nib
+local.properties
+.settings/
+.loadpath
+.recommenders
+
+# Eclipse Core
+.project
+
+# External tool builders
+.externalToolBuilders/
+
+# Locally stored "Eclipse launch configurations"
+*.launch
+
+# PyDev specific (Python IDE for Eclipse)
+*.pydevproject
+
+# CDT-specific (C/C++ Development Tooling)
+.cproject
+
+# JDT-specific (Eclipse Java Development Tools)
+.classpath
+
+# Java annotation processor (APT)
+.factorypath
+
+# PDT-specific (PHP Development Tools)
+.buildpath
+
+# sbteclipse plugin
+.target
+
+# Tern plugin
+.tern-project
+
+# TeXlipse plugin
+.texlipse
+
+# STS (Spring Tool Suite)
+.springBeans
+
+# Code Recommenders
+.recommenders/
+
+
+### Emacs ###
+# -*- mode: gitignore; -*-
+*~
+\#*\#
+/.emacs.desktop
+/.emacs.desktop.lock
+*.elc
+auto-save-list
+tramp
+.\#*
+
+# Org-mode
+.org-id-locations
+*_archive
+
+# flymake-mode
+*_flymake.*
+
+# eshell files
+/eshell/history
+/eshell/lastdir
+
+# elpa packages
+/elpa/
+
+# reftex files
+*.rel
+
+# AUCTeX auto folder
+/auto/
+
+# cask packages
+.cask/
+
+# Flycheck
+flycheck_*.el
+
+# server auth directory
+/server/
+
+# projectiles files
+.projectile
+
+### SVN ###
+.svn/
+
+
+### Maven ###
+target/
+pom.xml.tag
+pom.xml.releaseBackup
+pom.xml.versionsBackup
+pom.xml.next
+release.properties
+dependency-reduced-pom.xml
+buildNumber.properties
+.mvn/timing.properties
+
+Servers/
diff --git a/group16/2816977791/firstExercise/src/com/coding/basic/ArrayList.java b/group16/2816977791/firstExercise/src/com/coding/basic/ArrayList.java
new file mode 100644
index 0000000000..7ac196b700
--- /dev/null
+++ b/group16/2816977791/firstExercise/src/com/coding/basic/ArrayList.java
@@ -0,0 +1,94 @@
+package com.coding.basic;
+
+public class ArrayList implements List {
+
+ private int size = 0;
+
+ private Object[] elementData = new Object[10];
+
+ public void add(Object o) {
+ ensureCapacity(size + 1);
+ elementData[size++] = o;
+ }
+
+ public void add(int index, Object o) {
+ checkForLength(index);
+
+ ensureCapacity(size + 1);
+ System.arraycopy(elementData, index, elementData, index + 1, size - index);
+ elementData[index] = o;
+ size++;
+ }
+
+ public Object get(int index) {
+ checkForLength(index);
+ return elementData[index];
+ }
+
+ public Object remove(int index) {
+ checkForLength(index);
+ Object oldValue = elementData[index];
+ System.arraycopy(elementData, index + 1, elementData, index, size - index - 1);
+ size--;
+ return oldValue;
+ }
+
+ public int size() {
+ return size;
+ }
+
+ public Iterator iterator() {
+ return null;
+ }
+
+ private void checkForLength(int index) {
+ if (index < 0 || index >= size) {
+ throw new RuntimeException("out of memory");
+ }
+ }
+
+ private void ensureCapacity(int minCapacity) {
+ if (minCapacity - elementData.length > 0) {
+ grow(minCapacity);
+ }
+ }
+
+ private void grow(int minCapacity) {
+ int oldCapacity = elementData.length;
+ int newCapacity = oldCapacity + (oldCapacity >> 1);//增大容量
+ if (newCapacity - minCapacity < 0) {
+ newCapacity = minCapacity;
+ }
+ elementData = copyOf(elementData, newCapacity);
+ }
+
+ private Object[] copyOf(Object[] src, int newCapacity) {
+ Object[] target = new Object[newCapacity];
+ System.arraycopy(src, 0, target, 0, src.length);
+ return target;
+ }
+
+ public static void main(String[] args) {
+ ArrayList list = new ArrayList();
+ String num = "num";
+ for (int i = 0; i < 100; i++) {
+ list.add(num + String.valueOf(i));
+ System.out.println(String.valueOf(i) + ":size:" + list.size());
+ System.out.println(String.valueOf(i) + ":length:" + list.elementData.length);
+ }
+ System.out.println(list.size());
+
+ for (int i = 0; i < 100; i++) {
+ list.add(i, num + String.valueOf(i));
+ System.out.println(String.valueOf(i) + ":size:" + list.size());
+ System.out.println(String.valueOf(i) + ":length:" + list.elementData.length);
+ }
+ System.out.println(list.size());
+
+ for (int i = 0; i < 200; i++) {
+ System.out.println(list.remove(0));
+ }
+
+ System.out.println(list.size());
+ }
+}
diff --git a/group16/2816977791/firstExercise/src/com/coding/basic/BinaryTreeNode.java b/group16/2816977791/firstExercise/src/com/coding/basic/BinaryTreeNode.java
new file mode 100644
index 0000000000..e34a68b3c2
--- /dev/null
+++ b/group16/2816977791/firstExercise/src/com/coding/basic/BinaryTreeNode.java
@@ -0,0 +1,67 @@
+package com.coding.basic;
+
+public class BinaryTreeNode {
+
+ private Object data;
+ private BinaryTreeNode left;
+ private BinaryTreeNode right;
+ private BinaryTreeNode root;
+
+ public BinaryTreeNode(Object data, BinaryTreeNode left, BinaryTreeNode right) {
+ this.data = data;
+ this.left = left;
+ this.right = right;
+ }
+
+ public Object getData() {
+ return data;
+ }
+
+ public void setData(Object data) {
+ this.data = data;
+ }
+
+ public BinaryTreeNode getLeft() {
+ return left;
+ }
+
+ public void setLeft(BinaryTreeNode left) {
+ this.left = left;
+ }
+
+ public BinaryTreeNode getRight() {
+ return right;
+ }
+
+ public void setRight(BinaryTreeNode right) {
+ this.right = right;
+ }
+
+ public BinaryTreeNode insert(Object o) {
+ BinaryTreeNode binaryTreeNode = new BinaryTreeNode(o, null, null);
+ if (root == null) {
+ root = binaryTreeNode;
+ } else {
+ add(o, root);
+ }
+ return binaryTreeNode;
+ }
+
+ private BinaryTreeNode add(Object o, BinaryTreeNode target) {
+ if (target == null) {
+ target = new BinaryTreeNode(o, null, null);
+ } else {
+ if (compare(o, target.data) > 0) {
+ target.right = add(o, target.right);
+ } else if (compare(o, target.data) < 0) {
+ target.left = add(o, target.left);
+ }
+ }
+ return target;
+ }
+
+ private int compare(Object src, Object target) {
+ return ((String) src).compareTo((String) target);
+ }
+
+}
diff --git a/group16/542087872/src/com/coding/basic/Iterator.java b/group16/2816977791/firstExercise/src/com/coding/basic/Iterator.java
similarity index 100%
rename from group16/542087872/src/com/coding/basic/Iterator.java
rename to group16/2816977791/firstExercise/src/com/coding/basic/Iterator.java
diff --git a/group16/2816977791/firstExercise/src/com/coding/basic/LinkedList.java b/group16/2816977791/firstExercise/src/com/coding/basic/LinkedList.java
new file mode 100644
index 0000000000..be5b236700
--- /dev/null
+++ b/group16/2816977791/firstExercise/src/com/coding/basic/LinkedList.java
@@ -0,0 +1,140 @@
+package com.coding.basic;
+
+public class LinkedList implements List {
+
+ private Node head;
+ private Node last;
+
+ private int size = 0;
+
+ public void add(Object o) {
+ addLast(o);
+ }
+
+ public void add(int index, Object o) {
+ checkPosition(index);
+ if (index == size) {
+ addLast(o);
+ } else {
+ addIndex(index, o);
+ }
+ }
+
+ public Object get(int index) {
+ return node(index).data;
+ }
+
+ public Object remove(int index) {
+ checkPosition(index);
+ Object old = get(index);
+ if (index == 0) {
+ removeFirst();
+ } else if (index == size - 1) {
+ removeLast();
+ } else {
+ node(index - 1).next = node(index + 1);
+ size--;
+ }
+ return old;
+ }
+
+ public int size() {
+ return size;
+ }
+
+ public void addFirst(Object o) {
+ Node h = head;
+ Node newNode = new Node(o, h);
+ head = newNode;
+ if (h == null) {
+ last = newNode;
+ }
+ size++;
+ }
+
+ public void addLast(Object o) {
+ Node l = last;
+ Node newNode = new Node(o, null);
+ last = newNode;
+ if (l == null) {
+ head = newNode;
+ } else {
+ l.next = newNode;
+ }
+ size++;
+ }
+
+ public Object removeFirst() {
+ Node old = head;
+ head = old.next;
+ size--;
+ return old.data;
+ }
+
+ public Object removeLast() {
+ Node old = last;
+ Node prev = node(size - 2);
+ last = prev;
+ size--;
+ return old.data;
+ }
+
+ public Iterator iterator() {
+ return null;
+ }
+
+ private void checkPosition(int index) {
+ if (index < 0 || index >= size) {
+ throw new RuntimeException("out of memory");
+ }
+ }
+
+ private void addIndex(int index, Object o) {
+ checkPosition(index);
+ Node newNode = new Node(o, node(index));
+ if (index != 0) {
+ node(index - 1).next = newNode;
+ } else {
+ head = newNode;
+ }
+ size++;
+ }
+
+ private Node node(int index) {
+ Node x = head;
+ for (int i = 0; i < index; i++) {
+ x = x.next;
+ }
+ return x;
+ }
+
+ private static class Node {
+ Object data;
+ Node next;
+
+ public Node(Object data, Node next) {
+ this.data = data;
+ this.next = next;
+ }
+ }
+
+ public static void main(String[] args) {
+ LinkedList list = new LinkedList();
+ list.addLast("last");
+ System.out.println(list.size());
+ list.addFirst("head");
+ System.out.println(list.size());
+ list.add(0, "0Object");
+ System.out.println(list.size());
+ list.add(2, "2Object");
+ System.out.println(list.size());
+ list.removeLast();
+ System.out.println(list.size());
+ list.removeFirst();
+ System.out.println(list.size());
+ list.removeLast();
+ System.out.println(list.size());
+ list.get(0);
+ System.out.println(list.size());
+ }
+}
diff --git a/group16/2816977791/firstExercise/src/com/coding/basic/List.java b/group16/2816977791/firstExercise/src/com/coding/basic/List.java
new file mode 100644
index 0000000000..01398944e6
--- /dev/null
+++ b/group16/2816977791/firstExercise/src/com/coding/basic/List.java
@@ -0,0 +1,13 @@
+package com.coding.basic;
+
+public interface List {
+ public void add(Object o);
+
+ public void add(int index, Object o);
+
+ public Object get(int index);
+
+ public Object remove(int index);
+
+ public int size();
+}
diff --git a/group16/2816977791/firstExercise/src/com/coding/basic/Queue.java b/group16/2816977791/firstExercise/src/com/coding/basic/Queue.java
new file mode 100644
index 0000000000..f2475fcfd6
--- /dev/null
+++ b/group16/2816977791/firstExercise/src/com/coding/basic/Queue.java
@@ -0,0 +1,21 @@
+package com.coding.basic;
+
+public class Queue {
+ private ArrayList elementData = new ArrayList();
+
+ public void enQueue(Object o) {
+ elementData.add(o);
+ }
+
+ public Object deQueue() {
+ return elementData.get(0);
+ }
+
+ public boolean isEmpty() {
+ return elementData.size() == 0 ? true : false;
+ }
+
+ public int size() {
+ return elementData.size();
+ }
+}
diff --git a/group16/2816977791/firstExercise/src/com/coding/basic/Stack.java b/group16/2816977791/firstExercise/src/com/coding/basic/Stack.java
new file mode 100644
index 0000000000..12a89eb613
--- /dev/null
+++ b/group16/2816977791/firstExercise/src/com/coding/basic/Stack.java
@@ -0,0 +1,25 @@
+package com.coding.basic;
+
+public class Stack {
+ private ArrayList elementData = new ArrayList();
+
+ public void push(Object o) {
+ elementData.add(0, o);
+ }
+
+ public Object pop() {
+ return elementData.remove(0);
+ }
+
+ public Object peek() {
+ return elementData.get(0);
+ }
+
+ public boolean isEmpty() {
+ return elementData.size() == 0 ? true : false;
+ }
+
+ public int size() {
+ return elementData.size();
+ }
+}
diff --git a/group16/2816977791/secondExercise/src/com/coderising/array/ArrayUtil.java b/group16/2816977791/secondExercise/src/com/coderising/array/ArrayUtil.java
new file mode 100644
index 0000000000..3572229739
--- /dev/null
+++ b/group16/2816977791/secondExercise/src/com/coderising/array/ArrayUtil.java
@@ -0,0 +1,258 @@
+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) {
+ int i = 0;
+ while (i < origin.length - 1 - i) {
+ int temp = origin[origin.length - 1 - i];
+ origin[origin.length - 1 - i] = origin[i];
+ origin[i] = temp;
+ 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) {
+ int point = 0;
+ for (int i : oldArray) {
+ if (i != 0) {
+ oldArray[point++] = i;
+ }
+ }
+ int[] newArray = new int[point];
+ System.arraycopy(oldArray, 0, newArray, 0, point);
+ 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) {
+ //两个指针
+ int pos1 = 0;
+ int pos2 = 0;
+ int point = 0;
+ int[] newArray = new int[array1.length + array2.length];
+ while (pos1 < array1.length && pos2 < array2.length) {
+ if (array1[pos1] > array2[pos2]) {
+ newArray[point++] = array2[pos2++];
+ } else if (array1[pos1] < array2[pos2]) {
+ newArray[point++] = array1[pos1++];
+ } else {
+ newArray[point++] = array1[pos1++];
+ pos2++;
+ }
+ }
+ while (pos1 < array1.length) {
+ newArray[point++] = array1[pos1++];
+ }
+ while (pos1 < array2.length) {
+ newArray[point++] = array1[pos2++];
+ }
+ int[] array = new int[point];
+ System.arraycopy(newArray, 0, array, 0, point);
+ return array;
+ }
+
+ /**
+ * 把一个已经存满数据的数组 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) {
+ int[] newArray = new int[oldArray.length + size];
+ System.arraycopy(oldArray, 0, newArray, 0, oldArray.length);
+ 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) {
+ int a = 0;
+ int b = 1;
+ int[] array = new int[max];
+ int i = 0;
+ if (max >= 2) {
+ array[i++] = 1;
+ }
+ while (a + b < max) {
+ int temp = b;
+ b = a + b;
+ a = temp;
+ array[i++] = b;
+ }
+ int[] newArray = new int[i];
+ System.arraycopy(array, 0, newArray, 0, i);
+ return newArray;
+ }
+
+ /**
+ * 返回小于给定最大值max的所有素数数组
+ * 例如max = 23, 返回的数组为[2,3,5,7,11,13,17,19]
+ *
+ * @param max
+ * @return
+ */
+ public int[] getPrimes(int max) {
+ int[] array = new int[max / 2 + 1];
+ int pos = 0;
+ for (int i = 1; i < max; i++) {
+ if (prime(i)) {
+ array[pos++] = i;
+ }
+ }
+ int[] newArray = new int[pos];
+ System.arraycopy(array, 0, newArray, 0, pos);
+ return newArray;
+ }
+
+ private boolean prime(int value) {
+ if (value < 2) {
+ return false;
+ } else if (value == 2) {
+ return true;
+ } else {
+ for (int i = 2; i < value / 2 + 1; i++) {
+ if (value % 2 == 0) {
+ return false;
+ }
+ }
+ return true;
+ }
+ }
+
+ /**
+ * 所谓“完数”, 是指这个数恰好等于它的因子之和,例如6=1+2+3
+ * 给定一个最大值max, 返回一个数组, 数组中是小于max 的所有完数
+ *
+ * @param max
+ * @return
+ */
+ public int[] getPerfectNumbers(int max) {
+ int pos = 0;
+ int[] array = new int[max];
+ for (int i = 1; i < max; i++) {
+ if (perfectNumber(i)) {
+ array[pos++] = i;
+ }
+ }
+ int[] newArray = new int[pos];
+ System.arraycopy(array, 0, newArray, 0, pos);
+ return newArray;
+ }
+
+ private boolean perfectNumber(int value) {
+ if (value == 1 || prime(value)) {
+ return false;
+ } else {
+ int sum = 0;
+ for (int i = 1; i <= value / 2; i++) {
+ if (value % i == 0) {
+ sum += i;
+ }
+ }
+ if (sum == value) {
+ return true;
+ }
+ return false;
+ }
+ }
+
+ /**
+ * 用seperator 把数组 array给连接起来
+ * 例如array= [3,8,9], seperator = "-"
+ * 则返回值为"3-8-9"
+ *
+ * @param array
+ * @param seperator
+ * @return
+ */
+ public String join(int[] array, String seperator) {
+ String out = "";
+ for (int i = 0; i < array.length; i++) {
+ if (i == 0) {
+ out += String.valueOf(i);
+ } else {
+ out += seperator + String.valueOf(i);
+ }
+ }
+ return out;
+ }
+
+
+ public static void main(String[] args) {
+ ArrayUtil arrayUtil = new ArrayUtil();
+ //reverse
+ int[] a = {7, 9, 30, 3};
+ arrayUtil.reverseArray(a);
+ System.out.println(a);
+
+ //remove zero
+ int[] zero = {1, 3, 4, 5, 0, 0, 6, 6, 0, 5, 4, 7, 6, 7, 0, 5};
+ int[] afterZero = arrayUtil.removeZero(zero);
+ System.out.println(afterZero);
+
+ //merge
+ int[] a1 = {3, 5, 7, 8};
+ int[] a2 = {4, 5, 6, 7};
+ int[] merge = arrayUtil.merge(a1, a2);
+ System.out.println(merge);
+
+ //grow
+ int[] oldArray = {2, 3, 6};
+ int[] grow = arrayUtil.grow(oldArray, 3);
+ System.out.println(grow);
+
+ //fibonacci
+ int[] fibonacci = arrayUtil.fibonacci(2);
+ System.out.println(fibonacci);
+
+ //primes
+ int[] primes = arrayUtil.getPrimes(15);
+ System.out.println(primes);
+
+ //perfect
+ int[] perfect = arrayUtil.getPerfectNumbers(500);
+ System.out.println(perfect);
+
+ //join
+ int[] joinArray = {2};
+ String join = arrayUtil.join(joinArray, "-");
+ System.out.println(join);
+
+ }
+}
diff --git a/group16/2816977791/secondExercise/src/com/coderising/litestruts/ActionXml.java b/group16/2816977791/secondExercise/src/com/coderising/litestruts/ActionXml.java
new file mode 100644
index 0000000000..55988befbe
--- /dev/null
+++ b/group16/2816977791/secondExercise/src/com/coderising/litestruts/ActionXml.java
@@ -0,0 +1,37 @@
+package com.coderising.litestruts;
+
+import java.util.Map;
+
+/**
+ * @author nvarchar
+ * date 2017/3/1
+ */
+public class ActionXml {
+ private String name;
+ private String className;
+ private Map map;
+
+ public String getClassName() {
+ return className;
+ }
+
+ public void setClassName(String className) {
+ this.className = className;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public Map getMap() {
+ return map;
+ }
+
+ public void setMap(Map map) {
+ this.map = map;
+ }
+}
diff --git a/group16/2816977791/secondExercise/src/com/coderising/litestruts/LoginAction.java b/group16/2816977791/secondExercise/src/com/coderising/litestruts/LoginAction.java
new file mode 100644
index 0000000000..1005f35a29
--- /dev/null
+++ b/group16/2816977791/secondExercise/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/group16/2816977791/secondExercise/src/com/coderising/litestruts/Struts.java b/group16/2816977791/secondExercise/src/com/coderising/litestruts/Struts.java
new file mode 100644
index 0000000000..f169cb1cbb
--- /dev/null
+++ b/group16/2816977791/secondExercise/src/com/coderising/litestruts/Struts.java
@@ -0,0 +1,150 @@
+package com.coderising.litestruts;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import java.lang.reflect.Field;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.util.HashMap;
+import java.util.Map;
+
+
+public class Struts {
+
+ private static Map actionXmlMap;
+
+ static {
+ //0. 读取配置文件struts.xml
+ actionXmlMap = parserXml("src/com/coderising/litestruts/struts.xml");
+ System.out.println("parse end");
+ }
+
+ public static View runAction(String actionName, Map parameters) {
+
+ try {
+ ActionXml actionXml = actionXmlMap.get(actionName);
+ if (actionName == null) {
+ return null;
+ } else {
+ String className = actionXml.getClassName();
+ Class cls = Class.forName(className);
+ Object obj = cls.newInstance();
+ /**
+ 根据actionName找到相对应的class , 例如LoginAction, 通过反射实例化(创建对象)
+ 据parameters中的数据,调用对象的setter方法, 例如parameters中的数据是
+ ("name"="test" , "password"="1234") ,
+ 那就应该调用 setName和setPassword方法
+ */
+ Method[] methods = cls.getMethods();
+ for (String field : parameters.keySet()) {
+ for (Method method : methods) {
+ if (method.getName().startsWith("set") && method.getName().toLowerCase().endsWith(field.toLowerCase())) {
+ method.invoke(obj, parameters.get(field));
+ break;
+ }
+ }
+ }
+ Method action = cls.getMethod("execute");
+ //通过反射调用对象的exectue 方法, 并获得返回值,例如"success"
+ String result = (String) action.invoke(obj);
+ /**
+ 通过反射找到对象的所有getter方法(例如 getMessage),
+ 通过反射来调用, 把值和属性形成一个HashMap , 例如 {"message": "登录成功"} ,
+ 放到View对象的parameters
+ */
+ Field[] fields = cls.getDeclaredFields();
+ Map params = new HashMap<>();
+ for (Field field : fields) {
+ for (Method method : methods) {
+ if (method.getName().startsWith("get") && method.getName().toLowerCase().endsWith(field.getName().toLowerCase())) {
+ String viewResult = (String) method.invoke(obj);
+ params.put(field.getName(), viewResult);
+ break;
+ }
+ }
+ }
+ /**
+ 根据struts.xml中的 配置,以及execute的返回值, 确定哪一个jsp,
+ 放到View对象的jsp字段中。
+ */
+ View view = new View();
+ view.setParameters(params);
+ view.setJsp(actionXmlMap.get(actionName).getMap().get(result));
+ return view;
+ }
+ } catch (ClassNotFoundException e) {
+ e.printStackTrace();
+ return null;
+ } catch (InstantiationException e) {
+ e.printStackTrace();
+ return null;
+ } catch (IllegalAccessException e) {
+ e.printStackTrace();
+ return null;
+ } catch (NoSuchMethodException e) {
+ e.printStackTrace();
+ return null;
+ } catch (InvocationTargetException e) {
+ e.printStackTrace();
+ return null;
+ }
+ }
+
+ //解析xml文件
+ private static Map parserXml(String fileName) {
+ try {
+ Map map = new HashMap<>();
+ //create documentBuilder
+ DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
+ DocumentBuilder db = dbf.newDocumentBuilder();
+ //create document
+ Document document = db.parse(fileName);
+ //extract root element
+ Element root = document.getDocumentElement();
+ System.out.println("Root element :" + document.getDocumentElement().getNodeName());
+ NodeList nodeList = document.getElementsByTagName("action");
+ System.out.println("----------------------------");
+ for (int temp = 0; temp < nodeList.getLength(); temp++) {
+ Node nNode = nodeList.item(temp);
+ System.out.println("\nCurrent Element :"
+ + nNode.getNodeName());
+ if (nNode.getNodeType() == Node.ELEMENT_NODE) {
+ ActionXml actionXml = new ActionXml();
+ Element eElement = (Element) nNode;
+ System.out.println("action name : "
+ + eElement.getAttribute("name"));
+ System.out.println("class name : "
+ + eElement.getAttribute("class"));
+ actionXml.setName(eElement.getAttribute("name"));
+ actionXml.setClassName(eElement.getAttribute("class"));
+ NodeList result = eElement.getElementsByTagName("result");
+ Map results = new HashMap<>();
+ for (int i = 0; i < result.getLength(); i++) {
+ Node resultNode = result.item(i);
+ if (resultNode.getNodeType() == Node.ELEMENT_NODE) {
+ Element resultElement = (Element) resultNode;
+ System.out.println("result name:" + resultElement.getAttribute("name"));
+ System.out.println("result context:" + resultElement.getTextContent());
+ results.put(resultElement.getAttribute("name"), resultElement.getTextContent());
+ }
+ actionXml.setMap(results);
+ }
+ map.put(actionXml.getName(), actionXml);
+ }
+ }
+ return map;
+ } catch (Exception e) {
+ e.printStackTrace();
+ return null;
+ }
+ }
+
+ public static void main(String[] args) {
+// parserXml("src/com/coderising/litestruts/struts.xml");
+ }
+}
diff --git a/group16/2816977791/secondExercise/src/com/coderising/litestruts/StrutsTest.java b/group16/2816977791/secondExercise/src/com/coderising/litestruts/StrutsTest.java
new file mode 100644
index 0000000000..a44c1878ac
--- /dev/null
+++ b/group16/2816977791/secondExercise/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/group16/2816977791/secondExercise/src/com/coderising/litestruts/View.java b/group16/2816977791/secondExercise/src/com/coderising/litestruts/View.java
new file mode 100644
index 0000000000..0194c681f6
--- /dev/null
+++ b/group16/2816977791/secondExercise/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/group16/2816977791/secondExercise/src/com/coderising/litestruts/struts.xml b/group16/2816977791/secondExercise/src/com/coderising/litestruts/struts.xml
new file mode 100644
index 0000000000..246b3595ad
--- /dev/null
+++ b/group16/2816977791/secondExercise/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/group16/313001956/src/com/coding/basic/ArrayList.java b/group16/313001956/src/com/coding/basic/ArrayList.java
index eaaa690fa6..3bec144013 100644
Binary files a/group16/313001956/src/com/coding/basic/ArrayList.java and b/group16/313001956/src/com/coding/basic/ArrayList.java differ
diff --git a/group16/313001956/src/com/coding/basic/LinkedList.java b/group16/313001956/src/com/coding/basic/LinkedList.java
new file mode 100644
index 0000000000..de886c9084
--- /dev/null
+++ b/group16/313001956/src/com/coding/basic/LinkedList.java
@@ -0,0 +1,140 @@
+package com.coding.basic;
+
+public class LinkedList implements List {
+
+ private Node head;
+ private int size;
+
+ public LinkedList() {
+
+ }
+
+ public void add(Object o) {
+ addLast(o);
+ }
+
+ public void add(int index, Object o) {
+ if (index < 0 || index > size) {
+ throw new IndexOutOfBoundsException("Խ磡");
+ }
+ if (head == null) {
+ head = new Node();
+ head.data = o;
+ } else {
+
+ Node n = getNodebyIndex(index);
+
+ Node newnode = new Node();
+ newnode.data = o;
+ newnode.next = n.next;
+ n.next = newnode;
+ }
+ size++;
+ }
+
+ public Object get(int index) {
+ if (index < 0 || index > size) {
+ throw new IndexOutOfBoundsException("Խ磡");
+ }
+ if (head == null)
+ return null;
+ Node n = getNodebyIndex(index);
+ return n.data;
+ }
+
+ public Object remove(int index) {
+ if (index < 0 || index > size) {
+ throw new IndexOutOfBoundsException("Խ磡");
+ }
+ Node n = getNodebyIndex(index - 1);
+ Object o = n.next.data;
+ n.next = n.next.next;
+ size--;
+ return o;
+ }
+
+ public int size() {
+ return size;
+ }
+
+ public void addFirst(Object o) {
+ if (head == null) {
+ head = new Node();
+ head.data = o;
+ } else {
+ Node newnode = new Node();
+ newnode.data = o;
+ newnode.next = head;
+ head = newnode;
+ }
+ size++;
+ }
+
+ public void addLast(Object o) {
+ if (head == null) {
+ head = new Node();
+ head.data = o;
+ } else {
+ Node n = getNodebyIndex(size);
+ Node newnode = new Node();
+ newnode.data = o;
+ n.next = newnode;
+ }
+ size++;
+ }
+
+ public Object removeFirst() {
+ if (head == null)
+ return null;
+
+ head = head.next;
+ size--;
+ return head.data;
+ }
+
+ public Object removeLast() {
+ if (head == null)
+ return null;
+ Node n = getNodebyIndex(size - 1);
+ Object o = n.next.data;
+ n.next = null;
+ size--;
+ return o;
+ }
+
+ public Iterator iterator() {
+ return null;
+ }
+
+ private Node getNodebyIndex(int index) {
+ int i = 0;
+ Node n = head;
+ while (i < index) {
+ n = n.next;
+ i++;
+ }
+ return n;
+ }
+
+ private static class Node {
+ Object data;
+ Node next;
+
+ Object Getdata() {
+ return data;
+ }
+
+ void Setdata(Object o) {
+ data = o;
+ }
+
+ Node Getnext() {
+ return next;
+ }
+
+ void Setnext(Node n) {
+ next = n;
+ }
+ }
+}
+
diff --git a/group16/313001956/src/com/coding/basic/Queue.java b/group16/313001956/src/com/coding/basic/Queue.java
new file mode 100644
index 0000000000..4b9f311f99
--- /dev/null
+++ b/group16/313001956/src/com/coding/basic/Queue.java
@@ -0,0 +1,24 @@
+package com.coding.basic;
+
+public class Queue {
+
+ private LinkedList elementData = new LinkedList();
+ public void enQueue(Object o){
+ elementData.addLast(o);
+ }
+
+ public Object deQueue(){
+ Object o= elementData.get(0);
+ elementData.removeFirst();
+ return o;
+ }
+
+
+ public boolean isEmpty(){
+ return elementData.size()==0;
+ }
+
+ public int size(){
+ return elementData.size();
+ }
+}
diff --git a/group16/313001956/src/com/coding/basic/Stack.java b/group16/313001956/src/com/coding/basic/Stack.java
new file mode 100644
index 0000000000..6ec157201e
--- /dev/null
+++ b/group16/313001956/src/com/coding/basic/Stack.java
@@ -0,0 +1,37 @@
+package com.coding.basic;
+
+public class Stack {
+ private ArrayList elementData = new ArrayList();
+
+ public Stack() {
+ // TODO Auto-generated constructor stub
+ }
+
+ public void push(Object o) {
+ elementData.add(o);
+ }
+
+ public Object pop() {
+ int size = elementData.size();
+ Object o = elementData.get(size - 1);
+ elementData.remove(size - 1);
+ return o;
+ }
+
+ public Object peek() {
+ int size = elementData.size();
+ Object o = elementData.get(size - 1);
+
+ return o;
+ }
+
+ public boolean isEmpty() {
+ if (elementData.size() == 0)
+ return true;
+ return false;
+ }
+
+ public int size() {
+ return elementData.size();
+ }
+}
diff --git a/group16/420355244/Homework1/.classpath b/group16/420355244/Homework1/.classpath
new file mode 100644
index 0000000000..373dce4005
--- /dev/null
+++ b/group16/420355244/Homework1/.classpath
@@ -0,0 +1,7 @@
+
+
+
+
+
+
+
diff --git a/group16/420355244/Homework1/.gitignore b/group16/420355244/Homework1/.gitignore
new file mode 100644
index 0000000000..ae3c172604
--- /dev/null
+++ b/group16/420355244/Homework1/.gitignore
@@ -0,0 +1 @@
+/bin/
diff --git a/group16/420355244/Homework1/.project b/group16/420355244/Homework1/.project
new file mode 100644
index 0000000000..ec1134f33a
--- /dev/null
+++ b/group16/420355244/Homework1/.project
@@ -0,0 +1,17 @@
+
+
+ Homework1
+
+
+
+
+
+ org.eclipse.jdt.core.javabuilder
+
+
+
+
+
+ org.eclipse.jdt.core.javanature
+
+
diff --git a/group16/420355244/Homework1/.settings/org.eclipse.jdt.core.prefs b/group16/420355244/Homework1/.settings/org.eclipse.jdt.core.prefs
new file mode 100644
index 0000000000..3a21537071
--- /dev/null
+++ b/group16/420355244/Homework1/.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.8
+org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
+org.eclipse.jdt.core.compiler.compliance=1.8
+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.8
diff --git a/group16/420355244/Homework1/src/com/coding/basic/ArrayList.java b/group16/420355244/Homework1/src/com/coding/basic/ArrayList.java
new file mode 100644
index 0000000000..6534c3c029
--- /dev/null
+++ b/group16/420355244/Homework1/src/com/coding/basic/ArrayList.java
@@ -0,0 +1,91 @@
+package com.coding.basic;
+
+import java.util.Arrays;
+
+public class ArrayList implements List {
+
+ private int size = 0;
+
+ private Object[] elementData = new Object[100];
+
+ public void add(Object o){
+ if(size < elementData.length){
+ elementData[size] = o;
+ }else{
+ Object[] newElementData = new Object[elementData.length + elementData.length/2];
+ System.arraycopy(elementData, 0, newElementData, 0, size);
+ newElementData[size] = o;
+ this.elementData = newElementData;
+ }
+ size++;
+
+ }
+ public void add(int index, Object o){
+ if(index >= 0 && index <= size){
+ //1.不扩容
+ if(index == size - 1){
+ //1.1 加在最后
+ elementData[index] = o;
+ }else{
+ //1.2 加在前面
+ //index的位置的数值变为改对象,index以后位置的都往后挪一位
+ Object[] newElementData = new Object[elementData.length];
+ System.arraycopy(elementData, 0, newElementData, 0, index);
+ newElementData[index] = o ;
+ System.arraycopy(elementData, index, newElementData, index + 1, size - index);
+ this.elementData = newElementData;
+ }
+ size++;
+ }else{
+ throw new IndexOutOfBoundsException();
+ }
+ }
+
+ public Object get(int index){
+ if(index < size){
+ return elementData[index];
+ }else{
+ throw new IndexOutOfBoundsException();
+ }
+ }
+
+ public Object remove(int index){
+ if(index < size){
+ Object obj = elementData[index];
+ Object[] newElementData = new Object[elementData.length];
+ if(size != 1){
+ //1.若集合长度为1
+ if(0 == index){
+ //1.1.如果remove的是0索引的
+ System.arraycopy(elementData, 1, newElementData, 0, size - 1);
+ }else if(index == size -1){
+ //1.2.如果remove的是最后索引的
+ System.arraycopy(elementData, 0, newElementData, 0, size - 1);
+ }else{
+ //1.3.在中间
+ System.arraycopy(elementData, 0, newElementData, 0, index);
+ System.arraycopy(elementData, index + 1, newElementData, index, size - index - 1);
+ }
+ }
+ this.elementData = newElementData;
+ size--;
+ return obj;
+ }else{
+ throw new IndexOutOfBoundsException();
+ }
+ }
+
+ public int size(){
+ return size;
+ }
+
+ public Iterator iterator(){
+ return null;
+ }
+ @Override
+ public String toString() {
+ return "ArrayList [size=" + size + ", elementData=" + Arrays.toString(elementData) + "]";
+ }
+
+
+}
diff --git a/group16/420355244/Homework1/src/com/coding/basic/ArrayListTest.java b/group16/420355244/Homework1/src/com/coding/basic/ArrayListTest.java
new file mode 100644
index 0000000000..420c412a7b
--- /dev/null
+++ b/group16/420355244/Homework1/src/com/coding/basic/ArrayListTest.java
@@ -0,0 +1,62 @@
+package com.coding.basic;
+
+import org.junit.Before;
+import org.junit.Test;
+
+public class ArrayListTest {
+
+ private static ArrayList arrayList = new ArrayList();
+
+ @Before
+ public void setUp() throws Exception {
+ }
+
+ @Test
+ public void testAddObject() {
+ for(int i = 0 ;i < 150; i++){
+ arrayList.add("aaa");
+ }
+ System.out.println(arrayList);
+ System.out.println(arrayList.size());
+ }
+
+ @Test
+ public void testAddIntObject() {
+ arrayList.add("aaa");
+ arrayList.add("bbb");
+ arrayList.add("ccc");
+ arrayList.add("ddd");
+ arrayList.add(1,"eee");
+ System.out.println(arrayList);
+ }
+
+ @Test
+ public void testGet() {
+ arrayList.add("aaa");
+ arrayList.add("bbb");
+ arrayList.add("ccc");
+ arrayList.add("ddd");
+ Object object = arrayList.get(0);
+ System.out.println(object);
+ }
+
+ @Test
+ public void testRemove() {
+ arrayList.add("aaa");
+ arrayList.add("bbb");
+ arrayList.add("ccc");
+ arrayList.add("ddd");
+ arrayList.remove(0);
+ System.out.println(arrayList);
+ }
+
+ @Test
+ public void testSize() {
+ arrayList.add("aaa");
+ arrayList.add("bbb");
+ arrayList.add("ccc");
+ arrayList.add("ddd");
+ System.out.println(arrayList.size());
+ }
+
+}
diff --git a/group16/420355244/Homework1/src/com/coding/basic/BinaryTreeNode.java b/group16/420355244/Homework1/src/com/coding/basic/BinaryTreeNode.java
new file mode 100644
index 0000000000..d7ac820192
--- /dev/null
+++ b/group16/420355244/Homework1/src/com/coding/basic/BinaryTreeNode.java
@@ -0,0 +1,32 @@
+package com.coding.basic;
+
+public class BinaryTreeNode {
+
+ private Object data;
+ private BinaryTreeNode left;
+ private BinaryTreeNode right;
+
+ public Object getData() {
+ return data;
+ }
+ public void setData(Object data) {
+ this.data = data;
+ }
+ public BinaryTreeNode getLeft() {
+ return left;
+ }
+ public void setLeft(BinaryTreeNode left) {
+ this.left = left;
+ }
+ public BinaryTreeNode getRight() {
+ return right;
+ }
+ public void setRight(BinaryTreeNode right) {
+ this.right = right;
+ }
+
+ public BinaryTreeNode insert(Object o){
+ return null;
+ }
+
+}
diff --git a/group16/420355244/Homework1/src/com/coding/basic/Iterator.java b/group16/420355244/Homework1/src/com/coding/basic/Iterator.java
new file mode 100644
index 0000000000..06ef6311b2
--- /dev/null
+++ b/group16/420355244/Homework1/src/com/coding/basic/Iterator.java
@@ -0,0 +1,7 @@
+package com.coding.basic;
+
+public interface Iterator {
+ public boolean hasNext();
+ public Object next();
+
+}
diff --git a/group16/420355244/Homework1/src/com/coding/basic/LinkedList.java b/group16/420355244/Homework1/src/com/coding/basic/LinkedList.java
new file mode 100644
index 0000000000..9af35a399d
--- /dev/null
+++ b/group16/420355244/Homework1/src/com/coding/basic/LinkedList.java
@@ -0,0 +1,224 @@
+package com.coding.basic;
+
+import java.util.NoSuchElementException;
+
+public class LinkedList implements List {
+
+
+ private Node first;
+
+ private Node last;
+
+ private int size = 0;
+
+ public void add(Object o){
+ if(null == first){
+ //当链表元素为空时,新建一个Node
+ Node node = new Node();
+ node.data = o;
+ node.next = null;
+ first = node;
+ last = node;
+ size ++;
+ }else{
+ addLast(o);
+ }
+ }
+ public void add(int index , Object o){
+ if(index < 0 || index >= size){
+ //数组越界异常
+ throw new IndexOutOfBoundsException();
+ }else{
+ if(0 == index){
+ //1.如果加在头上
+ addFirst(o);
+ }else{
+ //2.加在中间位置
+ Node node = first.next;
+ int nodeIndex = 1;
+ if(nodeIndex == index){
+ //如果是第二个位置的话
+ Node nodeAdd = new Node();
+ nodeAdd.data = o;
+ first.next = nodeAdd;
+ nodeAdd.next = node;
+ last = node;
+ size ++;
+ }
+ //第三个位置及以后、开始遍历所有的索引
+ while(null != node.next){
+ //保留遍历中node之前的结点
+ Node nodeLast = node;
+ node = node.next;
+ nodeIndex++;
+ if(nodeIndex == index){
+ Node nodeAdd = new Node();
+ nodeAdd.data = o;
+ nodeLast.next = nodeAdd;
+ nodeAdd.next = node;
+ size ++;
+ break;
+ }
+ }
+ }
+ }
+
+ }
+ public Object get(int index){
+ if(index < 0 || index >= size){
+ //数组越界异常
+ throw new IndexOutOfBoundsException();
+ }else{
+ if(0 == index){
+ //1.如果加在头上
+ return first.data;
+ }
+ Node node = first.next;
+ int nodeIndex = 1;
+ if(nodeIndex == index){
+ //如果是第二个位置的话
+ return node.data;
+ }
+ //第三个位置及以后、开始遍历所有的索引
+ while(null != node.next){
+ //保留遍历中node之前的结点
+ node = node.next;
+ nodeIndex++;
+ if(nodeIndex == index){
+ return node.data;
+ }
+ }
+ }
+ throw new IndexOutOfBoundsException();
+ }
+ public Object remove(int index){
+ if(index < 0 || index >= size){
+ //数组越界异常
+ throw new IndexOutOfBoundsException();
+ }else{
+ if(0 == index){
+ //1.如果移除头
+ removeFirst();
+ }else if(index == (size - 1)){
+ //2.移除尾
+ removeLast();
+ }else{
+ //3.移除中间位置
+ Node node = first.next;
+ //从first的零号索引开始
+ int nodeIndex = 1;
+
+ //开始遍历所有的索引,记住要移除的索引位数据的前后结点
+ Node lastNode = first;
+ if(index == nodeIndex){
+ //第一次不匹配则后续的循环执行
+ Object o = node.data;
+ lastNode.next = node.next;
+ size--;
+ return o;
+ }else{
+ while(null != node.next){
+ lastNode = node;
+ node = node.next;
+ nodeIndex++;
+ if(index == nodeIndex){
+ Object o = node.data;
+ lastNode.next = node.next;
+ size--;
+ return o;
+ }
+ }
+ }
+ }
+ }
+ throw new IndexOutOfBoundsException();
+ }
+
+ public int size(){
+ return size;
+ }
+
+ public void addFirst(Object o){
+ Node node = new Node();
+ node.data = o ;
+ node.next = first;
+ first = node;
+ size++;
+ }
+ public void addLast(Object o){
+ Node node = new Node();
+ node.data = o ;
+ node.next = null;
+ last.next = node;
+ last = node;
+ size++;
+ }
+ public Object removeFirst(){
+ Object o = first.data;
+ Node node = first.next;
+ first = node;
+ size--;
+ return o;
+ }
+ public Object removeLast(){
+ if(0 == size){
+ throw new NoSuchElementException();
+
+ }else if(1 == size){
+ //只有一个元素
+ removeFirst();
+ }else{
+ //第二个元素
+ Node node = first.next;
+ if(null == node.next){
+ Object o = node.data;
+ last = first;
+ first.next = null;
+ return o;
+ }else{
+ while(null != node.next){
+ //若不止只有2个 ,记录最后一个结点的前一个。
+ Node lastNode = node;
+ node = node.next;
+ if(null == node.next){
+ Object o = node.data;
+ lastNode.next = null;
+ last = lastNode;
+ size--;
+ return o;
+ }
+ }
+ }
+ }
+ throw new NoSuchElementException();
+ }
+ public Iterator iterator(){
+ return null;
+ }
+
+
+ private static class Node{
+ Object data;
+ Node next;
+
+ }
+
+
+ @Override
+ public String toString() {
+ StringBuilder sb = new StringBuilder();
+ if(null != first){
+ sb.append(first.data.toString() + ",");
+ Node node = first.next;
+ sb.append(node.data.toString() + ",");
+ while(null != node.next){
+ node = node.next;
+ sb.append(node.data.toString() + ",");
+ }
+ }
+ return sb.toString();
+ }
+
+
+
+}
diff --git a/group16/420355244/Homework1/src/com/coding/basic/LinkedListTest.java b/group16/420355244/Homework1/src/com/coding/basic/LinkedListTest.java
new file mode 100644
index 0000000000..2caea9679b
--- /dev/null
+++ b/group16/420355244/Homework1/src/com/coding/basic/LinkedListTest.java
@@ -0,0 +1,112 @@
+package com.coding.basic;
+
+import static org.junit.Assert.*;
+
+import org.junit.Before;
+import org.junit.Test;
+
+public class LinkedListTest {
+ private static LinkedList linkedList = new LinkedList();
+ @Before
+ public void setUp() throws Exception {
+ }
+
+ @Test
+ public void testAddObject() {
+ linkedList.add("aaa");
+ linkedList.add("bbb");
+ System.out.println(linkedList);
+ }
+
+ @Test
+ public void testAddIntObject() {
+ linkedList.add("aaa");
+ linkedList.add("bbb");
+ linkedList.add("ccc");
+ linkedList.add(2,"ddd");
+ System.out.println(linkedList);
+ System.out.println(linkedList.size());
+ }
+
+ @Test
+ public void testGet() {
+ linkedList.add("aaa");
+ linkedList.add("bbb");
+ linkedList.add("ccc");
+ linkedList.add("eee");
+ linkedList.add("fff");
+ linkedList.add("ddd");
+// System.out.println(linkedList.size());
+ System.out.println(linkedList.get(3));
+ }
+
+ @Test
+ public void testRemove() {
+ linkedList.add("aaa");
+ linkedList.add("bbb");
+ linkedList.add("ccc");
+ linkedList.add("eee");
+ linkedList.add("fff");
+ linkedList.add("ddd");
+ linkedList.remove(5);
+ linkedList.remove(1);
+ linkedList.remove(2);
+ System.out.println(linkedList);
+ System.out.println(linkedList.size());
+ }
+
+ @Test
+ public void testSize() {
+ linkedList.add("aaa");
+ linkedList.add("bbb");
+ linkedList.add("ccc");
+ linkedList.add("eee");
+ linkedList.add("fff");
+ linkedList.add("ddd");
+ System.out.println(linkedList.size());
+ }
+
+ @Test
+ public void testAddFirst() {
+ linkedList.add("aaa");
+ linkedList.add("bbb");
+ linkedList.addFirst("sss");
+ System.out.println(linkedList);
+ }
+
+ @Test
+ public void testAddLast() {
+ linkedList.add("aaa");
+ linkedList.add("bbb");
+ linkedList.add("ccc");
+ System.out.println(linkedList);
+ }
+
+ @Test
+ public void testRemoveFirst() {
+ linkedList.add("aaa");
+ linkedList.add("bbb");
+ linkedList.add("ccc");
+ linkedList.removeFirst();
+ linkedList.addFirst("eee");
+ linkedList.removeFirst();
+ System.out.println(linkedList);
+ }
+
+ @Test
+ public void testRemoveLast() {
+ linkedList.add("aaa");
+ linkedList.add("bbb");
+ linkedList.add("ccc");
+ linkedList.removeLast();
+ linkedList.add("eee");
+ linkedList.addFirst("xxx");
+ System.out.println(linkedList);
+ }
+
+ @Test
+ public void testIterator() {
+ fail("Not yet implemented");
+ }
+
+}
diff --git a/group16/542087872/src/com/coding/basic/List.java b/group16/420355244/Homework1/src/com/coding/basic/List.java
similarity index 100%
rename from group16/542087872/src/com/coding/basic/List.java
rename to group16/420355244/Homework1/src/com/coding/basic/List.java
diff --git a/group16/420355244/Homework1/src/com/coding/basic/Queue.java b/group16/420355244/Homework1/src/com/coding/basic/Queue.java
new file mode 100644
index 0000000000..a2f9577b7b
--- /dev/null
+++ b/group16/420355244/Homework1/src/com/coding/basic/Queue.java
@@ -0,0 +1,66 @@
+package com.coding.basic;
+
+public class Queue {
+ private Node first;
+ private Node last;
+ private int size = 0;
+ public void enQueue(Object o){
+ if(null == first){
+ Node node = new Node();
+ node.data = o;
+ node.next = null;
+ first = node;
+ last = node;
+ }else{
+ Node node = new Node();
+ node.data = o;
+ node.next = null;
+ last.next = node;
+ last = node;
+ }
+ size++;
+ }
+
+ public Object deQueue(){
+ Node second = first.next;
+ Object o = first.data;
+ if(null != second){
+ first = second;
+ return o;
+ }else{
+ first = null;
+ size = 0;
+ return o;
+ }
+ }
+
+ public boolean isEmpty(){
+ if(size > 0){
+ return false;
+ }else{
+ return true;
+ }
+ }
+
+ public int size(){
+ return size;
+ }
+ static class Node{
+ Node next;
+ Object data;
+ }
+ @Override
+ public String toString() {
+ StringBuilder sb = new StringBuilder();
+ if(null != first){
+ sb.append(first.data.toString() + ",");
+ Node node = first.next;
+ sb.append(node.data.toString() + ",");
+ while(null != node.next){
+ node = node.next;
+ sb.append(node.data.toString() + ",");
+ }
+ }
+ return sb.toString();
+ }
+}
diff --git a/group16/420355244/Homework1/src/com/coding/basic/QueueTest.java b/group16/420355244/Homework1/src/com/coding/basic/QueueTest.java
new file mode 100644
index 0000000000..50d7fc0903
--- /dev/null
+++ b/group16/420355244/Homework1/src/com/coding/basic/QueueTest.java
@@ -0,0 +1,56 @@
+package com.coding.basic;
+
+import static org.junit.Assert.*;
+
+import org.junit.Before;
+import org.junit.Test;
+
+public class QueueTest {
+
+ public static Queue queue = new Queue();
+ @Before
+ public void setUp() throws Exception {
+ }
+
+ @Test
+ public void testEnQueue() {
+ queue.enQueue("aaa");
+ queue.enQueue("bbb");
+ queue.enQueue("ccc");
+ queue.enQueue("aaa");
+ System.out.println(queue);
+ }
+
+ @Test
+ public void testDeQueue() {
+ queue.enQueue("aaa");
+ queue.enQueue("bbb");
+ queue.enQueue("ccc");
+ queue.enQueue("ddd");
+ queue.enQueue("eee");
+ queue.deQueue();
+ System.out.println(queue);
+ }
+
+ @Test
+ public void testIsEmpty() {
+ System.out.println(queue.isEmpty());
+
+ }
+
+ @Test
+ public void testSize() {
+ queue.enQueue("aaa");
+ queue.enQueue("bbb");
+ queue.enQueue("ccc");
+ queue.enQueue("ddd");
+ queue.enQueue("eee");
+ System.out.println(queue.size());
+ }
+
+ @Test
+ public void testToString() {
+ fail("Not yet implemented");
+ }
+
+}
diff --git a/group16/420355244/Homework1/src/com/coding/basic/Stack.java b/group16/420355244/Homework1/src/com/coding/basic/Stack.java
new file mode 100644
index 0000000000..5c59bf34fc
--- /dev/null
+++ b/group16/420355244/Homework1/src/com/coding/basic/Stack.java
@@ -0,0 +1,39 @@
+package com.coding.basic;
+
+public class Stack {
+ private ArrayList elementData = new ArrayList();
+ private int size = 0;
+ public void push(Object o){
+ //入栈在栈顶进入最后压入
+ elementData.add(o);
+ size ++;
+ }
+
+ public Object pop(){
+ Object object = elementData.get(size -1);
+ elementData.remove(size -1);
+ size --;
+ return object;
+ }
+
+ public Object peek(){
+ Object object = elementData.get(size -1);
+ return object;
+ }
+ public boolean isEmpty(){
+ if(size <= 0){
+ return true;
+ }else{
+ return false;
+ }
+ }
+ public int size(){
+ return size;
+ }
+
+ @Override
+ public String toString() {
+ return elementData.toString();
+ }
+
+}
diff --git a/group16/420355244/Homework1/src/com/coding/basic/StackTest.java b/group16/420355244/Homework1/src/com/coding/basic/StackTest.java
new file mode 100644
index 0000000000..b436785574
--- /dev/null
+++ b/group16/420355244/Homework1/src/com/coding/basic/StackTest.java
@@ -0,0 +1,62 @@
+package com.coding.basic;
+
+import org.junit.Before;
+import org.junit.Test;
+
+public class StackTest {
+ private static Stack stack = new Stack();
+ @Before
+ public void setUp() throws Exception {
+ }
+
+ @Test
+ public void testPush() {
+ stack.push("aaa");
+ stack.push("bbb");
+ stack.push("ccc");
+ System.out.println(stack);
+ }
+
+ @Test
+ public void testPop() {
+ stack.push("aaa");
+ stack.push("bbb");
+ stack.push("ccc");
+ Object pop = stack.pop();
+ System.out.println(pop);
+ System.out.println(stack);
+ }
+
+ @Test
+ public void testPeek() {
+ stack.push("aaa");
+ stack.push("bbb");
+ stack.push("ccc");
+ Object peek = stack.peek();
+ System.out.println(peek);
+ }
+
+ @Test
+ public void testIsEmpty() {
+ System.out.println(stack.isEmpty());
+ stack.push("aaa");
+ stack.push("bbb");
+ stack.push("ccc");
+ System.out.println(stack.isEmpty());
+ stack.pop();
+ stack.pop();
+ stack.pop();
+ System.out.println(stack.isEmpty());
+ }
+
+ @Test
+ public void testSize() {
+ stack.push("aaa");
+ stack.push("bbb");
+ stack.push("ccc");
+ stack.pop();
+ stack.pop();
+ System.out.println(stack.size());
+ }
+
+}
diff --git a/group16/420355244/Homework2/.classpath b/group16/420355244/Homework2/.classpath
new file mode 100644
index 0000000000..f5d4a033ec
--- /dev/null
+++ b/group16/420355244/Homework2/.classpath
@@ -0,0 +1,8 @@
+
+
+
+
+
+
+
+
diff --git a/group16/420355244/Homework2/.gitignore b/group16/420355244/Homework2/.gitignore
new file mode 100644
index 0000000000..ae3c172604
--- /dev/null
+++ b/group16/420355244/Homework2/.gitignore
@@ -0,0 +1 @@
+/bin/
diff --git a/group16/420355244/Homework2/.project b/group16/420355244/Homework2/.project
new file mode 100644
index 0000000000..1a13fc592d
--- /dev/null
+++ b/group16/420355244/Homework2/.project
@@ -0,0 +1,17 @@
+
+
+ Homework2
+
+
+
+
+
+ org.eclipse.jdt.core.javabuilder
+
+
+
+
+
+ org.eclipse.jdt.core.javanature
+
+
diff --git a/group16/420355244/Homework2/src/com/coderising/action/LoginAction.java b/group16/420355244/Homework2/src/com/coderising/action/LoginAction.java
new file mode 100644
index 0000000000..5496d8084d
--- /dev/null
+++ b/group16/420355244/Homework2/src/com/coderising/action/LoginAction.java
@@ -0,0 +1,39 @@
+package com.coderising.action;
+
+/**
+ * 这是一个用来展示登录的业务类, 其中的用户名和密码都是硬编码的。
+ * @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/group16/420355244/Homework2/src/com/coderising/array/ArrayUtil.java b/group16/420355244/Homework2/src/com/coderising/array/ArrayUtil.java
new file mode 100644
index 0000000000..5fd5f1efba
--- /dev/null
+++ b/group16/420355244/Homework2/src/com/coderising/array/ArrayUtil.java
@@ -0,0 +1,120 @@
+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 static void reverseArray(int[] origin){
+ for(int i = 0;i < origin.length/2; i++){
+ int x = origin[i];
+ origin[i] = origin[origin.length - i -1];
+ origin[origin.length - i -1] = x;
+ }
+ }
+
+ /**
+ * 现在有如下的一个数组: 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){
+ for(int i = 0;i < oldArray.length ;i++){
+ if(oldArray[i] == 0){
+ int[] a = {};
+ System.arraycopy(oldArray, 0, a, 0, i);
+ System.arraycopy(oldArray, 0, a, i, oldArray.length);
+ oldArray = a;
+ removeZero(oldArray);
+ }
+ }
+ return oldArray;
+ }
+
+ /**
+ * 给定两个已经排序好的整形数组, 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){
+ return null;
+ }
+ /**
+ * 把一个已经存满数据的数组 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){
+ return null;
+ }
+
+ /**
+ * 斐波那契数列为: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){
+ return null;
+ }
+
+ /**
+ * 返回小于给定最大值max的所有素数数组
+ * 例如max = 23, 返回的数组为[2,3,5,7,11,13,17,19]
+ * @param max
+ * @return
+ */
+ public static int[] getPrimes(int max){
+ return null;
+ }
+
+ /**
+ * 所谓“完数”, 是指这个数恰好等于它的因子之和,例如6=1+2+3
+ * 给定一个最大值max, 返回一个数组, 数组中是小于max 的所有完数
+ * @param max
+ * @return
+ */
+ public static int[] getPerfectNumbers(int max){
+ return null;
+ }
+
+ /**
+ * 用seperator 把数组 array给连接起来
+ * 例如array= [3,8,9], seperator = "-"
+ * 则返回值为"3-8-9"
+ * @param array
+ * @param s
+ * @return
+ */
+ public static String join(int[] array, String seperator){
+ return null;
+ }
+
+ public static void main(String[] args) {
+ /*int[] a = {7, 9 , 30, 3};
+ reverseArray(a);
+ for (int i : a) {
+ System.out.print(i+",");
+ }*/
+ int oldArr[]={1,3,4,5,0,0,6,6,0,5,4,7,6,7,0,5} ;
+ removeZero(oldArr);
+ for (int i : oldArr) {
+ System.out.print(i+",");
+ }
+ }
+}
diff --git a/group16/420355244/Homework2/src/com/coderising/litestruts/Struts.java b/group16/420355244/Homework2/src/com/coderising/litestruts/Struts.java
new file mode 100644
index 0000000000..40af955dfa
--- /dev/null
+++ b/group16/420355244/Homework2/src/com/coderising/litestruts/Struts.java
@@ -0,0 +1,133 @@
+package com.coderising.litestruts;
+
+import java.io.File;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Map.Entry;
+
+import org.dom4j.Document;
+import org.dom4j.DocumentException;
+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字段中。
+
+ */
+ //0. 读取配置文件struts.xml
+ SAXReader reader = new SAXReader();
+ try {
+ //0.2 读取文件
+ Document doc = reader.read(new File("./src/com/coderising/litestruts/struts.xml"));
+ //0.3 得到根标签
+ Element rootElement = doc.getRootElement();
+ //0.4 得到根标签下的所有action标签
+ Iterator elementIterator = rootElement.elementIterator("action");
+ while(elementIterator.hasNext()){
+ Element element = elementIterator.next();
+ String nameValue = element.attributeValue("name");
+ try {
+ if(null != actionName && actionName.trim() != ""){
+ if(actionName.equals(nameValue)){
+ View view = new View();
+ //进入该action标签内,结束后停止循环
+ String classValue = element.attributeValue("class");
+ //1.1 根据actionName找到相对应的class , 例如LoginAction, 通过反射实例化(创建对象)据parameters中的数据
+ Class clazz =Class.forName(classValue);
+ Object instance = clazz.newInstance();
+ Method[] methods = clazz.getMethods();
+ for (Entry entry : parameters.entrySet()) {
+ String methodName = "set" + entry.getKey().substring(0, 1).toUpperCase() + entry.getKey().substring(1);
+ //1.2调用对象的setter方法, 例如parameters中的数据是 ("name"="test" , "password"="1234") ,那就应该调用 setName和setPassword方法
+ for (Method setterMethod : methods) {
+ if(methodName.equals(setterMethod.getName())){
+ setterMethod.invoke(instance,entry.getValue());
+ break;
+ }
+ }
+ }
+ //2. 通过反射调用对象的exectue 方法, 并获得返回值,例如"success"
+ Method method = clazz.getMethod("execute", null);
+ Object exectueResult = method.invoke(instance, null);
+ Iterator resultElement = element.elementIterator("result");
+ while(resultElement.hasNext()){
+ Element result = resultElement.next();
+ if(exectueResult.equals(result.attributeValue("name"))){
+ String jsp = result.getText();
+ view.setJsp(jsp);
+ break;
+ }
+ }
+ /*3. 通过反射找到对象的所有getter方法(例如 getMessage),
+ 通过反射来调用, 把值和属性形成一个HashMap , 例如 {"message": "登录成功"} ,
+ 放到View对象的parameters*/
+ HashMap