From 795b2f7dd72da48d25eef9f2fb3070eeff97c820 Mon Sep 17 00:00:00 2001
From: SarahhLee <1059156023@qq.com>
Date: Sat, 25 Feb 2017 12:16:28 +0800
Subject: [PATCH 01/30] a test
---
group11/1059156023/.classpath | 6 ++++++
group11/1059156023/.gitignore | 1 +
group11/1059156023/.project | 17 +++++++++++++++++
3 files changed, 24 insertions(+)
create mode 100644 group11/1059156023/.classpath
create mode 100644 group11/1059156023/.gitignore
create mode 100644 group11/1059156023/.project
diff --git a/group11/1059156023/.classpath b/group11/1059156023/.classpath
new file mode 100644
index 0000000000..fb5011632c
--- /dev/null
+++ b/group11/1059156023/.classpath
@@ -0,0 +1,6 @@
+
+
+
+
+
+
diff --git a/group11/1059156023/.gitignore b/group11/1059156023/.gitignore
new file mode 100644
index 0000000000..ae3c172604
--- /dev/null
+++ b/group11/1059156023/.gitignore
@@ -0,0 +1 @@
+/bin/
diff --git a/group11/1059156023/.project b/group11/1059156023/.project
new file mode 100644
index 0000000000..6565014ef5
--- /dev/null
+++ b/group11/1059156023/.project
@@ -0,0 +1,17 @@
+
+
+ 1059156023Learning
+
+
+
+
+
+ org.eclipse.jdt.core.javabuilder
+
+
+
+
+
+ org.eclipse.jdt.core.javanature
+
+
From 8eb2b5c5de202ace3eadd12083ecd2ae728448b9 Mon Sep 17 00:00:00 2001
From: ddcv587
Date: Mon, 27 Feb 2017 21:58:54 +0800
Subject: [PATCH 02/30] 2.26
---
group11/171535320/ArrayUtil.java | 114 ++++++++++++++++++
.../171535320/{ => DataStruct}/ArrayList.java | 2 +
.../{ => DataStruct}/BinaryTreeNode.java | 2 +
group11/171535320/DataStruct/Iterator.java | 12 ++
.../{ => DataStruct}/LinkedList.java | 4 +-
group11/171535320/{ => DataStruct}/List.java | 2 +
group11/171535320/Iterator.java | 5 -
7 files changed, 135 insertions(+), 6 deletions(-)
create mode 100644 group11/171535320/ArrayUtil.java
rename group11/171535320/{ => DataStruct}/ArrayList.java (98%)
rename group11/171535320/{ => DataStruct}/BinaryTreeNode.java (97%)
create mode 100644 group11/171535320/DataStruct/Iterator.java
rename group11/171535320/{ => DataStruct}/LinkedList.java (98%)
rename group11/171535320/{ => DataStruct}/List.java (89%)
delete mode 100644 group11/171535320/Iterator.java
diff --git a/group11/171535320/ArrayUtil.java b/group11/171535320/ArrayUtil.java
new file mode 100644
index 0000000000..92f7e49ab4
--- /dev/null
+++ b/group11/171535320/ArrayUtil.java
@@ -0,0 +1,114 @@
+/**
+ * Created by dengdechao on 2017/2/27.
+ */
+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){
+ if(origin == null) {
+ return ;
+ }
+ int i = 0;
+ int j = origin.length - 1;
+ while(i != j) {
+ int temp = origin[i];
+ origin[i] = origin[j];
+ origin[j] = temp;
+ i++;
+ j--;
+ }
+ }
+
+ public static void main(String[] args) {
+ int[] a = {1,2,3,4,5,6,7,8,9};
+ reverseArray(a);
+ for(int i : a) {
+ System.out.print(a);
+ }
+ }
+
+ /**
+ * 现在有如下的一个数组: 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){
+ return null;
+ }
+
+ /**
+ * 给定两个已经排序好的整形数组, a1和a2 , 创建一个新的数组a3, 使得a3 包含a1和a2 的所有元素, 并且仍然是有序的
+ * 例如 a1 = [3, 5, 7,8] a2 = [4, 5, 6,7] 则 a3 为[3,4,5,6,7,8] , 注意: 已经消除了重复
+ * @param array1
+ * @param array2
+ * @return
+ */
+
+ public int[] merge(int[] array1, int[] array2){
+ return null;
+ }
+ /**
+ * 把一个已经存满数据的数组 oldArray的容量进行扩展, 扩展后的新数据大小为oldArray.length + size
+ * 注意,老数组的元素在新数组中需要保持
+ * 例如 oldArray = [2,3,6] , size = 3,则返回的新数组为
+ * [2,3,6,0,0,0]
+ * @param oldArray
+ * @param size
+ * @return
+ */
+ public int[] grow(int [] oldArray, int size){
+ return null;
+ }
+
+ /**
+ * 斐波那契数列为: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){
+ return null;
+ }
+
+ /**
+ * 返回小于给定最大值max的所有素数数组
+ * 例如max = 23, 返回的数组为[2,3,5,7,11,13,17,19]
+ * @param max
+ * @return
+ */
+ public int[] getPrimes(int max){
+ return null;
+ }
+
+ /**
+ * 所谓“完数”, 是指这个数恰好等于它的因子之和,例如6=1+2+3
+ * 给定一个最大值max, 返回一个数组, 数组中是小于max 的所有完数
+ * @param max
+ * @return
+ */
+ public int[] getPerfectNumbers(int max){
+ return null;
+ }
+
+ /**
+ * 用seperator 把数组 array给连接起来
+ * 例如array= [3,8,9], seperator = "-"
+ * 则返回值为"3-8-9"
+ * @param array
+ * @param s
+ * @return
+ */
+ public String join(int[] array, String seperator){
+ return null;
+ }
+}
diff --git a/group11/171535320/ArrayList.java b/group11/171535320/DataStruct/ArrayList.java
similarity index 98%
rename from group11/171535320/ArrayList.java
rename to group11/171535320/DataStruct/ArrayList.java
index e277814cc9..4340deecf4 100644
--- a/group11/171535320/ArrayList.java
+++ b/group11/171535320/DataStruct/ArrayList.java
@@ -1,3 +1,5 @@
+package DataStruct;
+
import java.util.Arrays;
import java.util.Objects;
diff --git a/group11/171535320/BinaryTreeNode.java b/group11/171535320/DataStruct/BinaryTreeNode.java
similarity index 97%
rename from group11/171535320/BinaryTreeNode.java
rename to group11/171535320/DataStruct/BinaryTreeNode.java
index 3c8d543355..e0cc417a43 100644
--- a/group11/171535320/BinaryTreeNode.java
+++ b/group11/171535320/DataStruct/BinaryTreeNode.java
@@ -1,3 +1,5 @@
+package DataStruct;
+
public class BinaryTreeNode {
private Node root = null;
diff --git a/group11/171535320/DataStruct/Iterator.java b/group11/171535320/DataStruct/Iterator.java
new file mode 100644
index 0000000000..012d28806a
--- /dev/null
+++ b/group11/171535320/DataStruct/Iterator.java
@@ -0,0 +1,12 @@
+package DataStruct;
+
+/**
+ * Created by dengdechao on 2017/2/27.
+ */
+
+ public interface Iterator {
+ public boolean hasNext();
+ public Object next();
+
+ }
+
diff --git a/group11/171535320/LinkedList.java b/group11/171535320/DataStruct/LinkedList.java
similarity index 98%
rename from group11/171535320/LinkedList.java
rename to group11/171535320/DataStruct/LinkedList.java
index 43bb74e516..24a99466ca 100644
--- a/group11/171535320/LinkedList.java
+++ b/group11/171535320/DataStruct/LinkedList.java
@@ -1,4 +1,6 @@
-import java.util.Objects;
+package DataStruct;
+
+import DataStruct.List;
public class LinkedList implements List {
diff --git a/group11/171535320/List.java b/group11/171535320/DataStruct/List.java
similarity index 89%
rename from group11/171535320/List.java
rename to group11/171535320/DataStruct/List.java
index 4f7bcc71a8..125407436c 100644
--- a/group11/171535320/List.java
+++ b/group11/171535320/DataStruct/List.java
@@ -1,3 +1,5 @@
+package DataStruct;
+
public interface List {
public void add(Object o);
public void add(int index, Object o);
diff --git a/group11/171535320/Iterator.java b/group11/171535320/Iterator.java
deleted file mode 100644
index 96a43dbe0a..0000000000
--- a/group11/171535320/Iterator.java
+++ /dev/null
@@ -1,5 +0,0 @@
-public interface Iterator {
- public boolean hasNext();
- public Object next();
-
-}
From 33f25ddae7789b243d4231a322b4fa07e28338b2 Mon Sep 17 00:00:00 2001
From: SarahhLee <1059156023@qq.com>
Date: Mon, 27 Feb 2017 22:10:40 +0800
Subject: [PATCH 03/30] datastructure
---
.../1059156023/{ => dataStructure}/.classpath | 0
.../1059156023/{ => dataStructure}/.gitignore | 0
.../1059156023/{ => dataStructure}/.project | 2 +-
.../src/com/coding/basic/ArrayList.java | 71 +++++++++++++++++++
.../src/main/java/com/coding/Main.java | 12 ++--
5 files changed, 78 insertions(+), 7 deletions(-)
rename group11/1059156023/{ => dataStructure}/.classpath (100%)
rename group11/1059156023/{ => dataStructure}/.gitignore (100%)
rename group11/1059156023/{ => dataStructure}/.project (91%)
create mode 100644 group11/1059156023/dataStructure/src/com/coding/basic/ArrayList.java
diff --git a/group11/1059156023/.classpath b/group11/1059156023/dataStructure/.classpath
similarity index 100%
rename from group11/1059156023/.classpath
rename to group11/1059156023/dataStructure/.classpath
diff --git a/group11/1059156023/.gitignore b/group11/1059156023/dataStructure/.gitignore
similarity index 100%
rename from group11/1059156023/.gitignore
rename to group11/1059156023/dataStructure/.gitignore
diff --git a/group11/1059156023/.project b/group11/1059156023/dataStructure/.project
similarity index 91%
rename from group11/1059156023/.project
rename to group11/1059156023/dataStructure/.project
index 6565014ef5..35bb23a0fc 100644
--- a/group11/1059156023/.project
+++ b/group11/1059156023/dataStructure/.project
@@ -1,6 +1,6 @@
- 1059156023Learning
+ dataStructure
diff --git a/group11/1059156023/dataStructure/src/com/coding/basic/ArrayList.java b/group11/1059156023/dataStructure/src/com/coding/basic/ArrayList.java
new file mode 100644
index 0000000000..c853dcaea3
--- /dev/null
+++ b/group11/1059156023/dataStructure/src/com/coding/basic/ArrayList.java
@@ -0,0 +1,71 @@
+package com.coding.basic;
+
+import java.util.List;
+
+public class ArrayList implements List{
+ private int size;
+
+ //设置一个默认容量,当调用默认构造函数实例化数组后,需要扩容时可用
+ private static final int DEFAULT_CAPACITY=10;
+
+ //Integer.MAX_VALUE:2147483647,MAX_ARRAY_SIZE:2147483639
+ private static final int MAX_ARRAY_SIZE=Integer.MAX_VALUE-8;
+
+ private Object[] elementData;
+
+ //定义一个默认为空的数组,供默认构造函数使用
+ private static final Object[] EMPTY_ELEMENTDATA={};
+
+ //定义默认构造函数,实例化为空数组
+ public ArrayList(){
+ this.elementData=EMPTY_ELEMENTDATA;
+ }
+
+ //定义一个有参的构造函数
+ public ArrayList(int initialCapacity){
+ if(initialCapacity<0)
+ throw new IllegalArgumentException("Illegal Capacity:"+initialCapacity);
+ this.elementData = new Object[initialCapacity];
+ }
+
+ //定义add(Object o)方法,默认在数组末尾添加
+ public boolean add(Object o){
+ //要添加一个数,所以用ensureCapacityInternal()判断size+1个的数,数组是否放得下
+ ensureCapacityInternal(size+1);
+ elementData[size++]=o;
+ return true;
+ }
+
+ private void ensureCapacityInternal(int minCapacity) {
+ if(elementData == EMPTY_ELEMENTDATA)
+ minCapacity = DEFAULT_CAPACITY;
+
+ //如果需要扩容,则调用grow()
+ if(minCapacity-elementData.length>0)
+ grow(minCapacity);
+ }
+
+ private void grow(int minCapacity) {
+ int oldCapacity = elementData.length;
+ int newCapacity = oldCapacity+(oldCapacity>>1);
+
+ //原始长度是0时,即原来是空数组时
+ if(newCapacity-minCapacity<0)
+ newCapacity = minCapacity;
+
+ //如果新的容量超过了数组最大容量,就调用hugeCapacity()把能给的最大容量给它
+ if(newCapacity-MAX_ARRAY_SIZE>0)
+ newCapacity = hugeCapacity(minCapacity);
+
+
+ }
+
+ private static int hugeCapacity(int minCapacity) {
+ if (minCapacity<0) {
+ throw new OutOfMemoryError(); //抛出内存溢出异常
+ }
+ //如果minCapacity比MAX_ARRAY_SIZE大,则返回int类型所能表示的最大值,否则返回MAX_ARRAY_SIZE
+ return (minCapacity>MAX_ARRAY_SIZE) ? Integer.MAX_VALUE : MAX_ARRAY_SIZE;
+ }
+
+}
diff --git a/group11/1178243325/DataStructure/src/main/java/com/coding/Main.java b/group11/1178243325/DataStructure/src/main/java/com/coding/Main.java
index 31d2f2f277..3260081ca1 100644
--- a/group11/1178243325/DataStructure/src/main/java/com/coding/Main.java
+++ b/group11/1178243325/DataStructure/src/main/java/com/coding/Main.java
@@ -1,9 +1,9 @@
-package com.coding;
+package com.coding;
import com.coding.basic.*;
public class Main {
public static void main(String[] args) {
- ArrayList list = new ArrayList();
+ ArrayList list = new ArrayList();
list.add(0, "2xxx");
list.add(1, "we");
@@ -17,7 +17,7 @@ public static void main(String[] args) {
}
System.out.println(list.size());
- LinkedList llist = new LinkedList();
+ LinkedList llist = new LinkedList();
llist.add("hu");
llist.add("zhao");
llist.add(2,"xing");
@@ -31,12 +31,12 @@ public static void main(String[] args) {
System.out.print(llist.get(i));
System.out.println(llist.size());
- Iterator literator = llist.iterator();
+ Iterator literator = llist.iterator();
while(literator.hasNext()) {
System.out.println(literator.next());
}
- Stack stack = new Stack();
+ Stack stack = new Stack();
stack.push(1);
stack.push(2);
stack.push(3);
@@ -45,7 +45,7 @@ public static void main(String[] args) {
while(!stack.isEmpty())
System.out.println(stack.pop());
- Queue queue = new Queue();
+ Queue queue = new Queue();
queue.enQueue(1);
queue.enQueue(2);
queue.enQueue(3);
From dbc25d6a42285eb3e11e3d5dbeb9116efc876676 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E9=BE=9A=E5=90=AF=E7=9B=BC?=
Date: Tue, 28 Feb 2017 09:34:23 +0800
Subject: [PATCH 04/30] =?UTF-8?q?=E6=9A=82=E5=AD=98=E4=BD=9C=E4=B8=9A?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../org/apn/coding2017/array/ArrayUtil.java | 162 ++++++++++++++++++
.../apn/coding2017/array/ArrayUtilTest.java | 80 +++++++++
2 files changed, 242 insertions(+)
create mode 100644 group11/252308879/dataStructure/src/main/java/org/apn/coding2017/array/ArrayUtil.java
create mode 100644 group11/252308879/dataStructure/src/test/java/org/apn/coding2017/array/ArrayUtilTest.java
diff --git a/group11/252308879/dataStructure/src/main/java/org/apn/coding2017/array/ArrayUtil.java b/group11/252308879/dataStructure/src/main/java/org/apn/coding2017/array/ArrayUtil.java
new file mode 100644
index 0000000000..919e7a78c1
--- /dev/null
+++ b/group11/252308879/dataStructure/src/main/java/org/apn/coding2017/array/ArrayUtil.java
@@ -0,0 +1,162 @@
+package org.apn.coding2017.array;
+
+import java.util.Arrays;
+
+/**
+ * Created by QiPan on 2017/2/27.
+ */
+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){
+
+ // 如果是null, 或者长度小于等于1, 直接返回
+ if (origin == null || origin.length <= 1){
+ return;
+ }
+ for (int i = 0; i < origin.length/2; i++) {
+ int tmp = origin[i];
+ origin[i] = origin[origin.length - 1 - i];
+ origin[origin.length - 1 - i] = 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){
+
+ if (oldArray == null){
+ return oldArray;
+ }
+ int[] newArray = null;
+ int count = 0; //统计被移出的数组的个数
+ for (int i = 0; i < oldArray.length; i++) {
+ int num = oldArray[i];
+ if (num == 0){
+ count++;
+ System.arraycopy(oldArray, i+1, oldArray, i, oldArray.length - i - 1);
+ i--;
+ }
+ }
+ if (count == 0){
+ newArray = oldArray;
+ }else {
+ newArray = new int [oldArray.length - count];
+ System.arraycopy(oldArray, 0, newArray, 0 , oldArray.length - count);
+ }
+ return newArray;
+ }
+
+ /**
+ * 不用JavaAPI来做
+ * @param oldArray
+ * @return
+ */
+ public static int[] removeZero_2(int[] oldArray){
+
+ if (oldArray == null){
+ return oldArray;
+ }
+ int count = 0;
+ for (int num : oldArray) {
+ if (num == 0){
+ count ++;
+ }
+ }
+ int[] newArray = new int[oldArray.length - count];
+ for (int i = 0, j = 0; i < oldArray.length; i++, j++) {
+ int num = oldArray[i];
+ if (num == 0){
+ j--;
+ }else {
+ newArray[j] = num;
+ }
+ }
+ return newArray;
+ }
+
+ /**
+ * 给定两个已经排序好的整形数组, a1和a2 , 创建一个新的数组a3, 使得a3 包含a1和a2 的所有元素, 并且仍然是有序的
+ * 例如 a1 = [3, 5, 7,8] a2 = [4, 5, 6,7] 则 a3 为[3,4,5,6,7,8] , 注意: 已经消除了重复
+ * @param array1
+ * @param array2
+ * @return
+ */
+ public static int[] merge(int[] array1, int[] array2){
+ 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){
+ if (oldArray == null){
+ oldArray = new int[size];
+ }
+ oldArray = Arrays.copyOf(oldArray, oldArray.length + size);
+ return oldArray;
+ }
+
+ /**
+ * 斐波那契数列为: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){
+ return null;
+ }
+
+ /**
+ * 返回小于给定最大值max的所有素数数组
+ * 例如max = 23, 返回的数组为[2,3,5,7,11,13,17,19]
+ * @param max
+ * @return
+ */
+ public int[] getPrimes(int max){
+ return null;
+ }
+
+ /**
+ * 所谓“完数”, 是指这个数恰好等于它的因子之和,例如6=1+2+3
+ * 给定一个最大值max, 返回一个数组, 数组中是小于max 的所有完数
+ * @param max
+ * @return
+ */
+ public int[] getPerfectNumbers(int max){
+ return null;
+ }
+
+ /**
+ * 用seperator 把数组 array给连接起来
+ * 例如array= [3,8,9], seperator = "-"
+ * 则返回值为"3-8-9"
+ * @param array
+ * @param seperator
+ * @return
+ */
+ public String join(int[] array, String seperator){
+ return null;
+ }
+
+}
diff --git a/group11/252308879/dataStructure/src/test/java/org/apn/coding2017/array/ArrayUtilTest.java b/group11/252308879/dataStructure/src/test/java/org/apn/coding2017/array/ArrayUtilTest.java
new file mode 100644
index 0000000000..03e2d503a2
--- /dev/null
+++ b/group11/252308879/dataStructure/src/test/java/org/apn/coding2017/array/ArrayUtilTest.java
@@ -0,0 +1,80 @@
+package org.apn.coding2017.array;
+
+import org.junit.Test;
+
+import java.util.Arrays;
+
+import static org.junit.Assert.*;
+
+/**
+ * Created by QiPan on 2017/2/27.
+ */
+public class ArrayUtilTest {
+
+ @Test
+ public void removeZero() throws Exception {
+ int oldArr[]={1,3,4,5,0,0,6,6,0,5,4,7,6,7,0,5};
+ System.out.println("removeZero 移除0之前: "+ Arrays.toString(oldArr));
+ int[] newArrays = ArrayUtil.removeZero(oldArr);
+ System.out.println("removeZero 移除0之后: "+ Arrays.toString(newArrays));
+ }
+
+ @Test
+ public void removeZero_2() throws Exception {
+ int oldArr[]={1,3,4,5,0,0,6,6,0,5,4,7,6,7,0,5};
+ System.out.println("removeZero_2 移除0之前: "+ Arrays.toString(oldArr));
+ int[] newArrays = ArrayUtil.removeZero_2(oldArr);
+ System.out.println("removeZero_2 移除0之后: "+ Arrays.toString(newArrays));
+ }
+
+ @Test
+ public void reverseArray() throws Exception {
+ int[] array = new int[]{7, 9 , 30, 3};
+ int[] array2 = new int[] {7, 9, 30, 3, 4};
+ System.out.println("置换前: " + Arrays.toString(array));
+ ArrayUtil.reverseArray(array);
+ System.out.println("置换后: "+ Arrays.toString(array));
+ System.out.println("置换前: " + Arrays.toString(array2));
+ ArrayUtil.reverseArray(array2);
+ System.out.println("置换后: "+ Arrays.toString(array2));
+ }
+
+ @Test
+ public void merge() throws Exception {
+
+ }
+
+ @Test
+ public void grow() throws Exception {
+ int[] oldArray = {2,3,6} ;
+ int size = 3;
+ System.out.println("grow 之前:"+ Arrays.toString(oldArray));
+ int[] newArrays = ArrayUtil.grow(oldArray, size);
+ System.out.println("grow 之后:"+ Arrays.toString(newArrays));
+
+ }
+
+ @Test
+ public void fibonacci() throws Exception {
+
+ }
+
+ @Test
+ public void getPrimes() throws Exception {
+
+ }
+
+ @Test
+ public void getPerfectNumbers() throws Exception {
+
+ }
+
+ @Test
+ public void join() throws Exception {
+
+ }
+
+
+
+
+}
\ No newline at end of file
From 72f97ceebc43364f27f547758bcdd3396ee3d226 Mon Sep 17 00:00:00 2001
From: x_zhaohu
Date: Tue, 28 Feb 2017 19:54:59 +0800
Subject: [PATCH 05/30] =?UTF-8?q?=E7=83=AD=E8=BA=AB=E9=A2=98?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../com/coderising/array/.ArrayUtil.java.swp | Bin 0 -> 16384 bytes
.../java/com/coderising/array/ArrayUtil.java | 229 ++++++++++++++++++
.../coderising/litestruts/LoginAction.java | 39 +++
.../com/coderising/litestruts/Struts.java | 34 +++
.../com/coderising/litestruts/StrutsTest.java | 43 ++++
.../java/com/coderising/litestruts/View.java | 23 ++
.../java/com/coderising/litestruts/struts.xml | 11 +
7 files changed, 379 insertions(+)
create mode 100644 group11/1178243325/DataStructure/src/main/java/com/coderising/array/.ArrayUtil.java.swp
create mode 100644 group11/1178243325/DataStructure/src/main/java/com/coderising/array/ArrayUtil.java
create mode 100644 group11/1178243325/DataStructure/src/main/java/com/coderising/litestruts/LoginAction.java
create mode 100644 group11/1178243325/DataStructure/src/main/java/com/coderising/litestruts/Struts.java
create mode 100644 group11/1178243325/DataStructure/src/main/java/com/coderising/litestruts/StrutsTest.java
create mode 100644 group11/1178243325/DataStructure/src/main/java/com/coderising/litestruts/View.java
create mode 100644 group11/1178243325/DataStructure/src/main/java/com/coderising/litestruts/struts.xml
diff --git a/group11/1178243325/DataStructure/src/main/java/com/coderising/array/.ArrayUtil.java.swp b/group11/1178243325/DataStructure/src/main/java/com/coderising/array/.ArrayUtil.java.swp
new file mode 100644
index 0000000000000000000000000000000000000000..562760a67f7d3e5b0175ec4f8b8c72c563fdb0e7
GIT binary patch
literal 16384
zcmeI3e{38_700&?&|V1vQKV9V)Jag%ICu7W@9a2f;;26&pdhLsl(wol(8gXn>z?n-
z-8ny-VyF2X|44)L+ew?BBn@_)Ha{FYX_Nw`LZB)LwLqmRgxj+tN`E0#6^h{d-t4UR
zoU`5X7gE;I$G+X2c{B6o&6_uGFN;bae(*b@qNGg2&lfc9QqAc{_ni-ERiD+gbYsd&
zWaz=zKOeW;ld@pA-dJLUtCKY*{jw5uky5=PT$f5VHR^g;*DGd4%A(Ood3e5&F}{~c
zHC1PtQf4@vstz|8Rzg*8U=b-R4GCc*l`@ux@1x%fGgiEWni#v&{!?EAH0s)z^Tp0bc{Y27C?p8t^sXYrxmQ4X=SrgP4>&)^mCGPnd*gZW?rcyE%X+29K31v^0-*a$WN3p@y>
zfl1&upVPEc;3PN!o&yWO>k~EYEI0^ufURH)_yL#?%0MXygFC@r@x6rKflJ^5SO@L_
zcL5E2aGR#R58eiEfIooOz-3SlUdCWgfdgPWcp7woM?e_d1#SYb+=_mIW#Az&4gBL4
zP5UkA0vS*X3=jj~2LinN8BKc?w1UULY)}SDK{2=uy!mNOdkOS_i*&}w;19kRQWX=m)}my>sIIoA
z<659>(Ml~KW`yaNxL1mkpBs&o(Lg2mlB8A&JtXW6yM``y+I#j59_!C->m3|eBdTIt
zB>UoK`^f5d&bLw}DqJqS#doif#qIvip%aI*ef^?JM`0oYqM#hi0(w+R%x&M2d*Q&f
z)d%gvPouKEVF#+cbAI>e^-wvYm++4exELJRW%umP_BChwp38ML+lPK?H=oCSA;)0%
zc4Yh8(H-0!J20rqHji@4mB5kcOV{-)eKy}VD
z`}A1MMU$hnG&q0uU}PnX4RP@$A~;8M04ue&HRn8%)*l$HSCP?s74h^+H6#}lX+?ELcRQnx>`cV%jH*tZ$yb&f
zP%uafdelxrbv!s|lgoJ&qEySzp=+fWStAmo)i%0djGih+#uq$KPNJ$18%M1pdrayY
z(bc&HB`#fT#Z70Pub)hz=DDzH*~>{ofYp_fuB6-JrlYv0oL-)(VLkD+nk7~;xhuz{
zASxt3!}6q9*J*qFqLfKfKzk*1RZ3NNMsb%7W~$C4e+hRfMNnhzRfJ}cJk6;4r)-6t
z(Y5W=9rRF(0qnV|~0MLVxBq5>`lWy?b4@Uu>7
zxKiaLcMIw2a%VPN+jS`0zwX-lHv3Q;H>WnkL)Z+RQteyq{to-_1@?xg>z7T^psNCV}?3
zGugh*>_FS#nlrhbC+Jy!2g;4R-_jys7Z#{jYf<^bs`>(ZFRy>)mf=EZrI*Szk-sg6
zL_OO~q1~BGq#m2LYUz5WG~Jmn;4&C68FBe40WkjWrMMq0#r@fErx2h{E4zp5;~@)xw}sOiA%Lr^+Avk+Oxf7B
z4ZBVQb?p=9aHbfJRh!StkWzL@nT4~^s^dmFEm#xuJ$MR28jb45jXG0QCmTxWOZV~{
z^Ci4<%+culAH>=71Ds3g{2zA?gzw^ve+9e*PJ``W6{rQ@0$&GrgAZ}Ge-r!({0jU6
z{2c57?VtrL230@@#UKbMFYq?b|IdSiU
z@2X&)5~~HHa&IY5YESn6{w6DqeH^*iloM&?-N*2#F9kw$mg+`RBcpREMARp(g!hmd
z63&C+K_jpq=x0)~wDv)YP!ZOp)>(VRW=&C63hj7OWYP3;
zfD_bWq&3qZVxrE>6f=p5~k-{nu)zHVeC
z^;xg-CMHfHY1~g3Uckttki>%U{sw3*n*VY6
zJyEO|1@o>Wd3%s_h2%MDUUZrb`Vjlu`RSX;2Bh!gg0w$4+lP=f
k=khyL)tqy)pg0=5d>IHKavgF5o<)es9Mf&mOcZJV1$= 0 && j < length; i--, j++)
+ origin[j] = 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 static int[] removeZero(int[] oldArray){
+ if (oldArray == null) {
+ return null;
+ }
+
+ int zeroCount = 0;
+ for (int i = 0; i < oldArray.length; i++) {
+ if (oldArray[i] == 0)
+ zeroCount++;
+ }
+ int[] newArray = new int[oldArray.length-zeroCount];
+ for (int i = 0, j = 0; i < oldArray.length && j < newArray.length; i++) {
+ if (oldArray[i] != 0) {
+ newArray[j] = oldArray[i];
+ j++;
+ }
+ }
+ return newArray;
+ }
+
+ /**
+ * 给定两个已经排序好的整形数组, a1和a2 , 创建一个新的数组a3, 使得a3 包含a1和a2 的所有元素, 并且仍然是有序的
+ * 例如 a1 = [3, 5, 7,8] a2 = [4, 5, 6,7] 则 a3 为[3,4,5,6,7,8] , 注意: 已经消除了重复
+ * @param array1
+ * @param array2
+ * @return
+ */
+
+ public static int[] merge(int[] array1, int[] array2){
+ if (array1 == null && array2 == null)
+ return null;
+ int index1 = 0, index2 = 0;
+ int[] array3 = new int[array1.length + array2.length];
+ int index = 0;
+ while (index1 != array1.length && index2 != array2.length) {
+ if (array1[index1] < array2[index2]) {
+ array3[index++] = array1[index1++];
+ } else if (array1[index1] > array2[index2]) {
+ array3[index++] = array2[index2++];
+ } else if (array1[index1] == array2[index2]){
+ array3[index++] = array1[index1++];
+ index2++;
+ }
+ }
+
+ if (index1 == array1.length && index2 != array2.length) {
+ for (int i = index2; i < array2.length; i++)
+ array3[index++] = array2[i];
+ } else if (index2 == array2.length && index1 != array1.length) {
+ for (int i = index1; i < array1.length; i++) {
+ array3[index++] = array1[i];
+ }
+ }
+
+ int[] newArray = new int[index];
+ for (int i = 0; i < newArray.length; i++)
+ newArray[i] = array3[i];
+ return newArray;
+ }
+ /**
+ * 把一个已经存满数据的数组 oldArray的容量进行扩展, 扩展后的新数据大小为oldArray.length + size
+ * 注意,老数组的元素在新数组中需要保持
+ * 例如 oldArray = [2,3,6] , size = 3,则返回的新数组为
+ * [2,3,6,0,0,0]
+ *
+ * @param oldArray
+ * @param size
+ * @return
+ */
+ public static int[] grow(int [] oldArray, int size){
+ if (size <= 0)
+ return null;
+ int[] newArray = new int[oldArray.length + size];
+ for (int i = 0; i < oldArray.length; i++) {
+ newArray[i] = oldArray[i];
+ }
+ return newArray;
+ }
+
+ /**
+ * 斐波那契数列为:1,1,2,3,5,8,13,21...... ,给定一个最大值, 返回小于该值的数列
+ * 例如, max = 15 , 则返回的数组应该为 [1,1,2,3,5,8,13]
+ * max = 1, 则返回空数组 []
+ * @param max
+ * @return
+ */
+ public static int[] fibonacci(int max){
+ if (max < 1)
+ return null;
+ if (max == 1)
+ return null;
+ int[] array = new int[max];
+ int i = 0;
+ int value = fibonaccis(i+1);
+ while ( value < max) {
+ array[i++] = value;
+ value = fibonaccis(i+1);
+ }
+ int[] newArray = new int[i];
+ for (int j = 0; j < newArray.length; j++) {
+ newArray[j] = array[j];
+ }
+ return newArray;
+ }
+
+ private static int fibonaccis(int n) {
+ if (n <=0)
+ return 0;
+ if (n == 1 || n ==2 )
+ return 1;
+ return fibonaccis(n-1)+fibonaccis(n-2);
+ }
+
+ /**
+ * 返回小于给定最大值max的所有素数数组
+ * 例如max = 23, 返回的数组为[2,3,5,7,11,13,17,19]
+ * @param max
+ * @return
+ */
+ public static int[] getPrimes(int max){
+ if (max <= 1) {
+ return null;
+ }
+ int[] array = new int[max];
+ int index = 0;
+ for (int i = 2; i < max; i++) {
+ if (i == 2 || i == 3 || i == 5 || i == 7)
+ array[index++] = i;
+ if (i%2 !=0 && i%3 != 0 && i%5 != 0 && i%7 != 0)
+ array[index++] = i;
+ }
+ int[] newArray = new int[index];
+ for (int i = 0; i < newArray.length; i++) {
+ newArray[i] = array[i];
+ }
+
+ return newArray;
+ }
+
+ /**
+ * 所谓“完数”, 是指这个数恰好等于它的因子之和,例如6=1+2+3
+ * 给定一个最大值max, 返回一个数组, 数组中是小于max 的所有完数
+ * @param max
+ * @return
+ */
+ public static int[] getPerfectNumbers(int max){
+ if (max <= 0)
+ return null;
+ int[] array = new int[max];
+ int index = 0;
+ for (int i = 1; i < max; i++) {
+ if (isPerfectNumber(i))
+ array[index++] = i;
+ }
+
+ int[] newArray = new int[index];
+ for (int i = 0; i < newArray.length; i++)
+ newArray[i] = array[i];
+
+ return newArray;
+ }
+
+ private static boolean isPerfectNumber(int n) {
+ int sum = 0;
+ int i = 1;
+ while (i < n) {
+ if (n%i == 0)
+ sum += i;
+ i++;
+ }
+ if (sum == n)
+ return true;
+ return false;
+ }
+ /**
+ * 用seperator 把数组 array给连接起来
+ * 例如array= [3,8,9], seperator = "-"
+ * 则返回值为"3-8-9"
+ * @param array
+ * @param s
+ * @return
+ */
+ public static String join(int[] array, String seperator){
+ if (array == null)
+ return null;
+ StringBuilder str = new StringBuilder();
+ for (int i = 0; i < array.length; i++) {
+ if (i == array.length-1)
+ str.append(array[i]);
+ else
+ str.append(array[i] + seperator);
+ }
+ return str.toString();
+ }
+
+
+}
diff --git a/group11/1178243325/DataStructure/src/main/java/com/coderising/litestruts/LoginAction.java b/group11/1178243325/DataStructure/src/main/java/com/coderising/litestruts/LoginAction.java
new file mode 100644
index 0000000000..1005f35a29
--- /dev/null
+++ b/group11/1178243325/DataStructure/src/main/java/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/group11/1178243325/DataStructure/src/main/java/com/coderising/litestruts/Struts.java b/group11/1178243325/DataStructure/src/main/java/com/coderising/litestruts/Struts.java
new file mode 100644
index 0000000000..44cc35bf01
--- /dev/null
+++ b/group11/1178243325/DataStructure/src/main/java/com/coderising/litestruts/Struts.java
@@ -0,0 +1,34 @@
+package com.coderising.litestruts;
+
+import java.util.Map;
+
+
+
+public class Struts {
+
+ public static View runAction(String actionName, Map parameters) {
+
+ /*
+
+ 0. 读取配置文件struts.xml
+
+ 1. 根据actionName找到相对应的class , 例如LoginAction, 通过反射实例化(创建对象)
+ 据parameters中的数据,调用对象的setter方法, 例如parameters中的数据是
+ ("name"="test" , "password"="1234") ,
+ 那就应该调用 setName和setPassword方法
+
+ 2. 通过反射调用对象的exectue 方法, 并获得返回值,例如"success"
+
+ 3. 通过反射找到对象的所有getter方法(例如 getMessage),
+ 通过反射来调用, 把值和属性形成一个HashMap , 例如 {"message": "登录成功"} ,
+ 放到View对象的parameters
+
+ 4. 根据struts.xml中的 配置,以及execute的返回值, 确定哪一个jsp,
+ 放到View对象的jsp字段中。
+
+ */
+
+ return null;
+ }
+
+}
diff --git a/group11/1178243325/DataStructure/src/main/java/com/coderising/litestruts/StrutsTest.java b/group11/1178243325/DataStructure/src/main/java/com/coderising/litestruts/StrutsTest.java
new file mode 100644
index 0000000000..a44c1878ac
--- /dev/null
+++ b/group11/1178243325/DataStructure/src/main/java/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/group11/1178243325/DataStructure/src/main/java/com/coderising/litestruts/View.java b/group11/1178243325/DataStructure/src/main/java/com/coderising/litestruts/View.java
new file mode 100644
index 0000000000..0194c681f6
--- /dev/null
+++ b/group11/1178243325/DataStructure/src/main/java/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/group11/1178243325/DataStructure/src/main/java/com/coderising/litestruts/struts.xml b/group11/1178243325/DataStructure/src/main/java/com/coderising/litestruts/struts.xml
new file mode 100644
index 0000000000..ae0ce37fd8
--- /dev/null
+++ b/group11/1178243325/DataStructure/src/main/java/com/coderising/litestruts/struts.xml
@@ -0,0 +1,11 @@
+
+
+
+ /jsp/homepage.jsp
+ /jsp/showLogin.jsp
+
+
+ /jsp/welcome.jsp
+ /jsp/error.jsp
+
+
From 03857fb81f1a9b1bd8a8481e48fdbce357271de8 Mon Sep 17 00:00:00 2001
From: x_zhaohu
Date: Tue, 28 Feb 2017 19:55:21 +0800
Subject: [PATCH 06/30] =?UTF-8?q?=E6=B5=8B=E8=AF=95?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../DataStructure/src/main/java/com/Main.java | 51 +++++++++++++++++++
1 file changed, 51 insertions(+)
create mode 100644 group11/1178243325/DataStructure/src/main/java/com/Main.java
diff --git a/group11/1178243325/DataStructure/src/main/java/com/Main.java b/group11/1178243325/DataStructure/src/main/java/com/Main.java
new file mode 100644
index 0000000000..7b27f11aec
--- /dev/null
+++ b/group11/1178243325/DataStructure/src/main/java/com/Main.java
@@ -0,0 +1,51 @@
+package com;
+
+import com.coderising.array.*;
+public class Main {
+ public static void main(String[] args) {
+ int[] array = {1, 2, 3, 4, 5};
+ System.out.print("reverseArray测试:");
+ ArrayUtil.reverseArray(array);
+ for (int i : array)
+ System.out.print(i + " ");
+ System.out.print("\nremoveZero测试:");
+
+ int[] oldArray = {1, 3, 4, 5, 0, 0, 8 , 0, 9};
+ oldArray = ArrayUtil.removeZero(oldArray);
+ for (int i : oldArray) {
+ System.out.print(i + " ");
+ }
+
+ System.out.print("\nmerge测试:");
+ int[] a1 = {3, 5,8};
+ int[] a2 = {4, 5, 6,7};
+ int[] arrays = ArrayUtil.merge(a1, a2);
+ for (int i : arrays)
+ System.out.print(i + " ");
+
+ System.out.print("\ngrow测试:");
+
+ int[] growArray = ArrayUtil.grow(a1, 5);
+ for (int i : growArray)
+ System.out.print(i + " ");
+
+ System.out.print("\nfibonacci测试");
+ int[] fArray = ArrayUtil.fibonacci(1);
+ System.out.print(fArray);
+ System.out.println();
+ fArray = ArrayUtil.fibonacci(15);
+ for (int i : fArray)
+ System.out.print(i + " ");
+ System.out.print("\ngetPrimes测试:");
+ int[] primesArray = ArrayUtil.getPrimes(23);
+ for (int i : primesArray)
+ System.out.print(i + " ");
+ System.out.print("\ngetPerfectNumbers测试:");
+ int[] pArray = ArrayUtil.getPerfectNumbers(100);
+ for (int i : pArray)
+ System.out.print(i + " ");
+ System.out.print("\njoin测试:");
+ int[] jArray = new int[]{2, 3, 8};
+ System.out.print(ArrayUtil.join(jArray, "-"));
+ }
+}
From 8758428e7223044d7f067e378d437334db3df096 Mon Sep 17 00:00:00 2001
From: DDCV587
Date: Tue, 28 Feb 2017 22:42:09 +0800
Subject: [PATCH 07/30] 2.28
---
group11/171535320/ArrayUtil.java | 23 ++++++++++++++++++++++-
1 file changed, 22 insertions(+), 1 deletion(-)
diff --git a/group11/171535320/ArrayUtil.java b/group11/171535320/ArrayUtil.java
index 92f7e49ab4..1904a89061 100644
--- a/group11/171535320/ArrayUtil.java
+++ b/group11/171535320/ArrayUtil.java
@@ -54,7 +54,28 @@ public int[] removeZero(int[] oldArray){
*/
public int[] merge(int[] array1, int[] array2){
- return null;
+ int[] result = new int[array1.length + array2.length];
+ int len1 = 0;
+ int len2 = 0;
+ int i = 0;
+ while(len1 != array1.length || len2 != array2.length) {
+ if(len1 < array1.length && len2 < array2.length) {
+ if(array1[len1] < array2[len2]) {
+ result[i++] = array1[len1++];
+ } else if(array1[len1] > array2[len2]) {
+ result[i++] = array2[len2++];
+ } else {
+ len1++;
+ len2++;
+ }
+ } else if(len1 < array1.length){
+ result[i++] = array1[len1++];
+ } else {
+ result[i++] = array2[len2++];
+ }
+
+ }
+ return result;
}
/**
* 把一个已经存满数据的数组 oldArray的容量进行扩展, 扩展后的新数据大小为oldArray.length + size
From ea0a4bf95f9c74344a3bcb598227229437d53ec9 Mon Sep 17 00:00:00 2001
From: DDCV587
Date: Tue, 28 Feb 2017 22:50:22 +0800
Subject: [PATCH 08/30] 2.28
---
group11/171535320/ArrayUtil.java | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/group11/171535320/ArrayUtil.java b/group11/171535320/ArrayUtil.java
index 1904a89061..6ade05ed29 100644
--- a/group11/171535320/ArrayUtil.java
+++ b/group11/171535320/ArrayUtil.java
@@ -87,7 +87,12 @@ public int[] merge(int[] array1, int[] array2){
* @return
*/
public int[] grow(int [] oldArray, int size){
- return null;
+ int len = oldArray.length + size;
+ int[] result = new int[len];
+ for(int i = 0; i < oldArray.length; ++i) {
+ result[i] = oldArray[i];
+ }
+ return result;
}
/**
From dd4e0a7d68cef5ca5a8f53fe498d6b90141d934b Mon Sep 17 00:00:00 2001
From: Fred Qin
Date: Tue, 28 Feb 2017 22:12:59 -0800
Subject: [PATCH 09/30] complete array util
---
.../395443277/{data_structure => }/.gitignore | 0
.../src/com/coderising/array/ArrayUtil.java | 254 ++++++++++++++++++
.../com/coderising/array/ArrayUtilTest.java | 98 +++++++
.../coderising/litestruts/LoginAction.java | 39 +++
.../src/com/coderising/litestruts/Struts.java | 34 +++
.../com/coderising/litestruts/StrutsTest.java | 43 +++
.../src/com/coderising/litestruts/View.java | 23 ++
.../src/com/coderising/litestruts/struts.xml | 11 +
.../src/com/coding/basic/ArrayList.java | 0
.../src/com/coding/basic/ArrayListTest.java | 0
.../src/com/coding/basic/BinaryTreeNode.java | 0
.../com/coding/basic/BinaryTreeNodeTest.java | 0
.../src/com/coding/basic/Iterator.java | 0
.../src/com/coding/basic/LinkedList.java | 0
.../src/com/coding/basic/LinkedListTest.java | 0
.../src/com/coding/basic/List.java | 0
.../src/com/coding/basic/Queue.java | 0
.../src/com/coding/basic/QueueTest.java | 0
.../src/com/coding/basic/Stack.java | 0
.../src/com/coding/basic/StackTest.java | 0
20 files changed, 502 insertions(+)
rename group11/395443277/{data_structure => }/.gitignore (100%)
create mode 100644 group11/395443277/src/com/coderising/array/ArrayUtil.java
create mode 100644 group11/395443277/src/com/coderising/array/ArrayUtilTest.java
create mode 100644 group11/395443277/src/com/coderising/litestruts/LoginAction.java
create mode 100644 group11/395443277/src/com/coderising/litestruts/Struts.java
create mode 100644 group11/395443277/src/com/coderising/litestruts/StrutsTest.java
create mode 100644 group11/395443277/src/com/coderising/litestruts/View.java
create mode 100644 group11/395443277/src/com/coderising/litestruts/struts.xml
rename group11/395443277/{data_structure => }/src/com/coding/basic/ArrayList.java (100%)
rename group11/395443277/{data_structure => }/src/com/coding/basic/ArrayListTest.java (100%)
rename group11/395443277/{data_structure => }/src/com/coding/basic/BinaryTreeNode.java (100%)
rename group11/395443277/{data_structure => }/src/com/coding/basic/BinaryTreeNodeTest.java (100%)
rename group11/395443277/{data_structure => }/src/com/coding/basic/Iterator.java (100%)
rename group11/395443277/{data_structure => }/src/com/coding/basic/LinkedList.java (100%)
rename group11/395443277/{data_structure => }/src/com/coding/basic/LinkedListTest.java (100%)
rename group11/395443277/{data_structure => }/src/com/coding/basic/List.java (100%)
rename group11/395443277/{data_structure => }/src/com/coding/basic/Queue.java (100%)
rename group11/395443277/{data_structure => }/src/com/coding/basic/QueueTest.java (100%)
rename group11/395443277/{data_structure => }/src/com/coding/basic/Stack.java (100%)
rename group11/395443277/{data_structure => }/src/com/coding/basic/StackTest.java (100%)
diff --git a/group11/395443277/data_structure/.gitignore b/group11/395443277/.gitignore
similarity index 100%
rename from group11/395443277/data_structure/.gitignore
rename to group11/395443277/.gitignore
diff --git a/group11/395443277/src/com/coderising/array/ArrayUtil.java b/group11/395443277/src/com/coderising/array/ArrayUtil.java
new file mode 100644
index 0000000000..d73df85b05
--- /dev/null
+++ b/group11/395443277/src/com/coderising/array/ArrayUtil.java
@@ -0,0 +1,254 @@
+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 first = 0;
+ int last = origin.length - 1;
+
+ while (first < last) {
+ int temp;
+ temp = origin[first];
+ origin[first] = origin[last];
+ origin[last] = temp;
+
+ first++;
+ last--;
+ }
+ }
+
+ /**
+ * 现在有如下的一个数组: 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){
+ // count how many zeros
+ int zeroCount = 0;
+ int len= oldArray.length;
+
+ if (len==0) {
+ return new int[]{};
+ }
+
+ for (int i=0; i parameters) {
+
+ /*
+
+ 0. 读取配置文件struts.xml
+
+ 1. 根据actionName找到相对应的class , 例如LoginAction, 通过反射实例化(创建对象)
+ 据parameters中的数据,调用对象的setter方法, 例如parameters中的数据是
+ ("name"="test" , "password"="1234") ,
+ 那就应该调用 setName和setPassword方法
+
+ 2. 通过反射调用对象的exectue 方法, 并获得返回值,例如"success"
+
+ 3. 通过反射找到对象的所有getter方法(例如 getMessage),
+ 通过反射来调用, 把值和属性形成一个HashMap , 例如 {"message": "登录成功"} ,
+ 放到View对象的parameters
+
+ 4. 根据struts.xml中的 配置,以及execute的返回值, 确定哪一个jsp,
+ 放到View对象的jsp字段中。
+
+ */
+
+ return null;
+ }
+
+}
diff --git a/group11/395443277/src/com/coderising/litestruts/StrutsTest.java b/group11/395443277/src/com/coderising/litestruts/StrutsTest.java
new file mode 100644
index 0000000000..b8c81faf3c
--- /dev/null
+++ b/group11/395443277/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/group11/395443277/src/com/coderising/litestruts/View.java b/group11/395443277/src/com/coderising/litestruts/View.java
new file mode 100644
index 0000000000..07df2a5dab
--- /dev/null
+++ b/group11/395443277/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/group11/395443277/src/com/coderising/litestruts/struts.xml b/group11/395443277/src/com/coderising/litestruts/struts.xml
new file mode 100644
index 0000000000..4c9967dbaf
--- /dev/null
+++ b/group11/395443277/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/group11/395443277/data_structure/src/com/coding/basic/ArrayList.java b/group11/395443277/src/com/coding/basic/ArrayList.java
similarity index 100%
rename from group11/395443277/data_structure/src/com/coding/basic/ArrayList.java
rename to group11/395443277/src/com/coding/basic/ArrayList.java
diff --git a/group11/395443277/data_structure/src/com/coding/basic/ArrayListTest.java b/group11/395443277/src/com/coding/basic/ArrayListTest.java
similarity index 100%
rename from group11/395443277/data_structure/src/com/coding/basic/ArrayListTest.java
rename to group11/395443277/src/com/coding/basic/ArrayListTest.java
diff --git a/group11/395443277/data_structure/src/com/coding/basic/BinaryTreeNode.java b/group11/395443277/src/com/coding/basic/BinaryTreeNode.java
similarity index 100%
rename from group11/395443277/data_structure/src/com/coding/basic/BinaryTreeNode.java
rename to group11/395443277/src/com/coding/basic/BinaryTreeNode.java
diff --git a/group11/395443277/data_structure/src/com/coding/basic/BinaryTreeNodeTest.java b/group11/395443277/src/com/coding/basic/BinaryTreeNodeTest.java
similarity index 100%
rename from group11/395443277/data_structure/src/com/coding/basic/BinaryTreeNodeTest.java
rename to group11/395443277/src/com/coding/basic/BinaryTreeNodeTest.java
diff --git a/group11/395443277/data_structure/src/com/coding/basic/Iterator.java b/group11/395443277/src/com/coding/basic/Iterator.java
similarity index 100%
rename from group11/395443277/data_structure/src/com/coding/basic/Iterator.java
rename to group11/395443277/src/com/coding/basic/Iterator.java
diff --git a/group11/395443277/data_structure/src/com/coding/basic/LinkedList.java b/group11/395443277/src/com/coding/basic/LinkedList.java
similarity index 100%
rename from group11/395443277/data_structure/src/com/coding/basic/LinkedList.java
rename to group11/395443277/src/com/coding/basic/LinkedList.java
diff --git a/group11/395443277/data_structure/src/com/coding/basic/LinkedListTest.java b/group11/395443277/src/com/coding/basic/LinkedListTest.java
similarity index 100%
rename from group11/395443277/data_structure/src/com/coding/basic/LinkedListTest.java
rename to group11/395443277/src/com/coding/basic/LinkedListTest.java
diff --git a/group11/395443277/data_structure/src/com/coding/basic/List.java b/group11/395443277/src/com/coding/basic/List.java
similarity index 100%
rename from group11/395443277/data_structure/src/com/coding/basic/List.java
rename to group11/395443277/src/com/coding/basic/List.java
diff --git a/group11/395443277/data_structure/src/com/coding/basic/Queue.java b/group11/395443277/src/com/coding/basic/Queue.java
similarity index 100%
rename from group11/395443277/data_structure/src/com/coding/basic/Queue.java
rename to group11/395443277/src/com/coding/basic/Queue.java
diff --git a/group11/395443277/data_structure/src/com/coding/basic/QueueTest.java b/group11/395443277/src/com/coding/basic/QueueTest.java
similarity index 100%
rename from group11/395443277/data_structure/src/com/coding/basic/QueueTest.java
rename to group11/395443277/src/com/coding/basic/QueueTest.java
diff --git a/group11/395443277/data_structure/src/com/coding/basic/Stack.java b/group11/395443277/src/com/coding/basic/Stack.java
similarity index 100%
rename from group11/395443277/data_structure/src/com/coding/basic/Stack.java
rename to group11/395443277/src/com/coding/basic/Stack.java
diff --git a/group11/395443277/data_structure/src/com/coding/basic/StackTest.java b/group11/395443277/src/com/coding/basic/StackTest.java
similarity index 100%
rename from group11/395443277/data_structure/src/com/coding/basic/StackTest.java
rename to group11/395443277/src/com/coding/basic/StackTest.java
From 5d4a20ac6ae8b62941181cb9ceecbd00563ed381 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E9=BE=9A=E5=90=AF=E7=9B=BC?=
Date: Wed, 1 Mar 2017 19:14:53 +0800
Subject: [PATCH 10/30] =?UTF-8?q?=E6=9A=82=E5=AD=98?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../{apn => pan}/coding2017/array/ArrayUtil.java | 13 +++++++++++--
.../{apn => pan}/coding2017/basic/ArrayList.java | 2 +-
.../coding2017/basic/BinaryTreeNode.java | 2 +-
.../org/{apn => pan}/coding2017/basic/Iterator.java | 2 +-
.../{apn => pan}/coding2017/basic/LinkedList.java | 2 +-
.../org/{apn => pan}/coding2017/basic/List.java | 2 +-
.../org/{apn => pan}/coding2017/basic/Queue.java | 2 +-
.../org/{apn => pan}/coding2017/basic/Stack.java | 2 +-
.../org/{apn => pan}/coding2017/basic/Stack2.java | 2 +-
.../coding2017/TestJavaUtilArrayList.java | 2 +-
.../coding2017/array/ArrayUtilTest.java | 4 +---
.../coding2017/basic/ArrayListTest.java | 4 +---
.../coding2017/basic/BinaryTreeNodeTest.java | 4 +---
.../coding2017/basic/LinkedListTest.java | 4 +---
.../{apn => pan}/coding2017/basic/QueueTest.java | 4 +---
.../{apn => pan}/coding2017/basic/StackTest.java | 4 +---
16 files changed, 26 insertions(+), 29 deletions(-)
rename group11/252308879/dataStructure/src/main/java/org/{apn => pan}/coding2017/array/ArrayUtil.java (94%)
rename group11/252308879/dataStructure/src/main/java/org/{apn => pan}/coding2017/basic/ArrayList.java (99%)
rename group11/252308879/dataStructure/src/main/java/org/{apn => pan}/coding2017/basic/BinaryTreeNode.java (98%)
rename group11/252308879/dataStructure/src/main/java/org/{apn => pan}/coding2017/basic/Iterator.java (80%)
rename group11/252308879/dataStructure/src/main/java/org/{apn => pan}/coding2017/basic/LinkedList.java (98%)
rename group11/252308879/dataStructure/src/main/java/org/{apn => pan}/coding2017/basic/List.java (90%)
rename group11/252308879/dataStructure/src/main/java/org/{apn => pan}/coding2017/basic/Queue.java (96%)
rename group11/252308879/dataStructure/src/main/java/org/{apn => pan}/coding2017/basic/Stack.java (97%)
rename group11/252308879/dataStructure/src/main/java/org/{apn => pan}/coding2017/basic/Stack2.java (95%)
rename group11/252308879/dataStructure/src/test/java/org/{apn => pan}/coding2017/TestJavaUtilArrayList.java (94%)
rename group11/252308879/dataStructure/src/test/java/org/{apn => pan}/coding2017/array/ArrayUtilTest.java (96%)
rename group11/252308879/dataStructure/src/test/java/org/{apn => pan}/coding2017/basic/ArrayListTest.java (95%)
rename group11/252308879/dataStructure/src/test/java/org/{apn => pan}/coding2017/basic/BinaryTreeNodeTest.java (91%)
rename group11/252308879/dataStructure/src/test/java/org/{apn => pan}/coding2017/basic/LinkedListTest.java (96%)
rename group11/252308879/dataStructure/src/test/java/org/{apn => pan}/coding2017/basic/QueueTest.java (91%)
rename group11/252308879/dataStructure/src/test/java/org/{apn => pan}/coding2017/basic/StackTest.java (91%)
diff --git a/group11/252308879/dataStructure/src/main/java/org/apn/coding2017/array/ArrayUtil.java b/group11/252308879/dataStructure/src/main/java/org/pan/coding2017/array/ArrayUtil.java
similarity index 94%
rename from group11/252308879/dataStructure/src/main/java/org/apn/coding2017/array/ArrayUtil.java
rename to group11/252308879/dataStructure/src/main/java/org/pan/coding2017/array/ArrayUtil.java
index 919e7a78c1..9fa21a8155 100644
--- a/group11/252308879/dataStructure/src/main/java/org/apn/coding2017/array/ArrayUtil.java
+++ b/group11/252308879/dataStructure/src/main/java/org/pan/coding2017/array/ArrayUtil.java
@@ -1,4 +1,4 @@
-package org.apn.coding2017.array;
+package org.pan.coding2017.array;
import java.util.Arrays;
@@ -156,7 +156,16 @@ public int[] getPerfectNumbers(int max){
* @return
*/
public String join(int[] array, String seperator){
- return null;
+ if (array == null){
+ return null;
+ }
+ StringBuilder str = new StringBuilder();
+ for (int i = 0; i < array.length; i++) {
+ if (i == array.length - 1){
+
+ }
+ }
+ return str.toString();
}
}
diff --git a/group11/252308879/dataStructure/src/main/java/org/apn/coding2017/basic/ArrayList.java b/group11/252308879/dataStructure/src/main/java/org/pan/coding2017/basic/ArrayList.java
similarity index 99%
rename from group11/252308879/dataStructure/src/main/java/org/apn/coding2017/basic/ArrayList.java
rename to group11/252308879/dataStructure/src/main/java/org/pan/coding2017/basic/ArrayList.java
index 3d2a685f35..73dd4b7a5f 100644
--- a/group11/252308879/dataStructure/src/main/java/org/apn/coding2017/basic/ArrayList.java
+++ b/group11/252308879/dataStructure/src/main/java/org/pan/coding2017/basic/ArrayList.java
@@ -1,4 +1,4 @@
-package org.apn.coding2017.basic;
+package org.pan.coding2017.basic;
import java.util.Arrays;
import java.util.NoSuchElementException;
diff --git a/group11/252308879/dataStructure/src/main/java/org/apn/coding2017/basic/BinaryTreeNode.java b/group11/252308879/dataStructure/src/main/java/org/pan/coding2017/basic/BinaryTreeNode.java
similarity index 98%
rename from group11/252308879/dataStructure/src/main/java/org/apn/coding2017/basic/BinaryTreeNode.java
rename to group11/252308879/dataStructure/src/main/java/org/pan/coding2017/basic/BinaryTreeNode.java
index 3725e5c71b..80f7f78751 100644
--- a/group11/252308879/dataStructure/src/main/java/org/apn/coding2017/basic/BinaryTreeNode.java
+++ b/group11/252308879/dataStructure/src/main/java/org/pan/coding2017/basic/BinaryTreeNode.java
@@ -1,4 +1,4 @@
-package org.apn.coding2017.basic;
+package org.pan.coding2017.basic;
/**
* Created by QiPan on 2017/2/23.
diff --git a/group11/252308879/dataStructure/src/main/java/org/apn/coding2017/basic/Iterator.java b/group11/252308879/dataStructure/src/main/java/org/pan/coding2017/basic/Iterator.java
similarity index 80%
rename from group11/252308879/dataStructure/src/main/java/org/apn/coding2017/basic/Iterator.java
rename to group11/252308879/dataStructure/src/main/java/org/pan/coding2017/basic/Iterator.java
index 94dc84dfdc..3d1849f1a0 100644
--- a/group11/252308879/dataStructure/src/main/java/org/apn/coding2017/basic/Iterator.java
+++ b/group11/252308879/dataStructure/src/main/java/org/pan/coding2017/basic/Iterator.java
@@ -1,4 +1,4 @@
-package org.apn.coding2017.basic;
+package org.pan.coding2017.basic;
/**
* Created by QiPan on 2017/2/23.
diff --git a/group11/252308879/dataStructure/src/main/java/org/apn/coding2017/basic/LinkedList.java b/group11/252308879/dataStructure/src/main/java/org/pan/coding2017/basic/LinkedList.java
similarity index 98%
rename from group11/252308879/dataStructure/src/main/java/org/apn/coding2017/basic/LinkedList.java
rename to group11/252308879/dataStructure/src/main/java/org/pan/coding2017/basic/LinkedList.java
index e83de27c11..015ac3d59d 100644
--- a/group11/252308879/dataStructure/src/main/java/org/apn/coding2017/basic/LinkedList.java
+++ b/group11/252308879/dataStructure/src/main/java/org/pan/coding2017/basic/LinkedList.java
@@ -1,4 +1,4 @@
-package org.apn.coding2017.basic;
+package org.pan.coding2017.basic;
/**
* Created by QiPan on 2017/2/23.
diff --git a/group11/252308879/dataStructure/src/main/java/org/apn/coding2017/basic/List.java b/group11/252308879/dataStructure/src/main/java/org/pan/coding2017/basic/List.java
similarity index 90%
rename from group11/252308879/dataStructure/src/main/java/org/apn/coding2017/basic/List.java
rename to group11/252308879/dataStructure/src/main/java/org/pan/coding2017/basic/List.java
index 15c9d9d3be..daa8253313 100644
--- a/group11/252308879/dataStructure/src/main/java/org/apn/coding2017/basic/List.java
+++ b/group11/252308879/dataStructure/src/main/java/org/pan/coding2017/basic/List.java
@@ -1,4 +1,4 @@
-package org.apn.coding2017.basic;
+package org.pan.coding2017.basic;
/**
diff --git a/group11/252308879/dataStructure/src/main/java/org/apn/coding2017/basic/Queue.java b/group11/252308879/dataStructure/src/main/java/org/pan/coding2017/basic/Queue.java
similarity index 96%
rename from group11/252308879/dataStructure/src/main/java/org/apn/coding2017/basic/Queue.java
rename to group11/252308879/dataStructure/src/main/java/org/pan/coding2017/basic/Queue.java
index d51695b148..af478b4288 100644
--- a/group11/252308879/dataStructure/src/main/java/org/apn/coding2017/basic/Queue.java
+++ b/group11/252308879/dataStructure/src/main/java/org/pan/coding2017/basic/Queue.java
@@ -1,4 +1,4 @@
-package org.apn.coding2017.basic;
+package org.pan.coding2017.basic;
/**
* Created by QiPan on 2017/2/23.
diff --git a/group11/252308879/dataStructure/src/main/java/org/apn/coding2017/basic/Stack.java b/group11/252308879/dataStructure/src/main/java/org/pan/coding2017/basic/Stack.java
similarity index 97%
rename from group11/252308879/dataStructure/src/main/java/org/apn/coding2017/basic/Stack.java
rename to group11/252308879/dataStructure/src/main/java/org/pan/coding2017/basic/Stack.java
index 3233954cf8..918db8f70d 100644
--- a/group11/252308879/dataStructure/src/main/java/org/apn/coding2017/basic/Stack.java
+++ b/group11/252308879/dataStructure/src/main/java/org/pan/coding2017/basic/Stack.java
@@ -1,4 +1,4 @@
-package org.apn.coding2017.basic;
+package org.pan.coding2017.basic;
/**
* Created by QiPan on 2017/2/23.
diff --git a/group11/252308879/dataStructure/src/main/java/org/apn/coding2017/basic/Stack2.java b/group11/252308879/dataStructure/src/main/java/org/pan/coding2017/basic/Stack2.java
similarity index 95%
rename from group11/252308879/dataStructure/src/main/java/org/apn/coding2017/basic/Stack2.java
rename to group11/252308879/dataStructure/src/main/java/org/pan/coding2017/basic/Stack2.java
index 2769c72485..2a056b8bbf 100644
--- a/group11/252308879/dataStructure/src/main/java/org/apn/coding2017/basic/Stack2.java
+++ b/group11/252308879/dataStructure/src/main/java/org/pan/coding2017/basic/Stack2.java
@@ -1,4 +1,4 @@
-package org.apn.coding2017.basic;
+package org.pan.coding2017.basic;
/**
* Created by Pan on 2017/2/25.
diff --git a/group11/252308879/dataStructure/src/test/java/org/apn/coding2017/TestJavaUtilArrayList.java b/group11/252308879/dataStructure/src/test/java/org/pan/coding2017/TestJavaUtilArrayList.java
similarity index 94%
rename from group11/252308879/dataStructure/src/test/java/org/apn/coding2017/TestJavaUtilArrayList.java
rename to group11/252308879/dataStructure/src/test/java/org/pan/coding2017/TestJavaUtilArrayList.java
index 1b38998253..281a5bf07b 100644
--- a/group11/252308879/dataStructure/src/test/java/org/apn/coding2017/TestJavaUtilArrayList.java
+++ b/group11/252308879/dataStructure/src/test/java/org/pan/coding2017/TestJavaUtilArrayList.java
@@ -1,4 +1,4 @@
-package org.apn.coding2017;
+package org.pan.coding2017;
import org.junit.Assert;
import org.junit.Test;
diff --git a/group11/252308879/dataStructure/src/test/java/org/apn/coding2017/array/ArrayUtilTest.java b/group11/252308879/dataStructure/src/test/java/org/pan/coding2017/array/ArrayUtilTest.java
similarity index 96%
rename from group11/252308879/dataStructure/src/test/java/org/apn/coding2017/array/ArrayUtilTest.java
rename to group11/252308879/dataStructure/src/test/java/org/pan/coding2017/array/ArrayUtilTest.java
index 03e2d503a2..52434a98ed 100644
--- a/group11/252308879/dataStructure/src/test/java/org/apn/coding2017/array/ArrayUtilTest.java
+++ b/group11/252308879/dataStructure/src/test/java/org/pan/coding2017/array/ArrayUtilTest.java
@@ -1,11 +1,9 @@
-package org.apn.coding2017.array;
+package org.pan.coding2017.array;
import org.junit.Test;
import java.util.Arrays;
-import static org.junit.Assert.*;
-
/**
* Created by QiPan on 2017/2/27.
*/
diff --git a/group11/252308879/dataStructure/src/test/java/org/apn/coding2017/basic/ArrayListTest.java b/group11/252308879/dataStructure/src/test/java/org/pan/coding2017/basic/ArrayListTest.java
similarity index 95%
rename from group11/252308879/dataStructure/src/test/java/org/apn/coding2017/basic/ArrayListTest.java
rename to group11/252308879/dataStructure/src/test/java/org/pan/coding2017/basic/ArrayListTest.java
index a52647b7df..f93876522a 100644
--- a/group11/252308879/dataStructure/src/test/java/org/apn/coding2017/basic/ArrayListTest.java
+++ b/group11/252308879/dataStructure/src/test/java/org/pan/coding2017/basic/ArrayListTest.java
@@ -1,10 +1,8 @@
-package org.apn.coding2017.basic;
+package org.pan.coding2017.basic;
import org.junit.Before;
import org.junit.Test;
-import static org.junit.Assert.*;
-
/**
* Created by Pan on 2017/2/26.
*/
diff --git a/group11/252308879/dataStructure/src/test/java/org/apn/coding2017/basic/BinaryTreeNodeTest.java b/group11/252308879/dataStructure/src/test/java/org/pan/coding2017/basic/BinaryTreeNodeTest.java
similarity index 91%
rename from group11/252308879/dataStructure/src/test/java/org/apn/coding2017/basic/BinaryTreeNodeTest.java
rename to group11/252308879/dataStructure/src/test/java/org/pan/coding2017/basic/BinaryTreeNodeTest.java
index 8b15597ed2..4c3c01cd73 100644
--- a/group11/252308879/dataStructure/src/test/java/org/apn/coding2017/basic/BinaryTreeNodeTest.java
+++ b/group11/252308879/dataStructure/src/test/java/org/pan/coding2017/basic/BinaryTreeNodeTest.java
@@ -1,10 +1,8 @@
-package org.apn.coding2017.basic;
+package org.pan.coding2017.basic;
import org.junit.Before;
import org.junit.Test;
-import static org.junit.Assert.*;
-
/**
* Created by Pan on 2017/2/26.
*/
diff --git a/group11/252308879/dataStructure/src/test/java/org/apn/coding2017/basic/LinkedListTest.java b/group11/252308879/dataStructure/src/test/java/org/pan/coding2017/basic/LinkedListTest.java
similarity index 96%
rename from group11/252308879/dataStructure/src/test/java/org/apn/coding2017/basic/LinkedListTest.java
rename to group11/252308879/dataStructure/src/test/java/org/pan/coding2017/basic/LinkedListTest.java
index f932e49cf0..d10e2a1d48 100644
--- a/group11/252308879/dataStructure/src/test/java/org/apn/coding2017/basic/LinkedListTest.java
+++ b/group11/252308879/dataStructure/src/test/java/org/pan/coding2017/basic/LinkedListTest.java
@@ -1,10 +1,8 @@
-package org.apn.coding2017.basic;
+package org.pan.coding2017.basic;
import org.junit.Before;
import org.junit.Test;
-import static org.junit.Assert.*;
-
/**
* Created by Pan on 2017/2/26.
*/
diff --git a/group11/252308879/dataStructure/src/test/java/org/apn/coding2017/basic/QueueTest.java b/group11/252308879/dataStructure/src/test/java/org/pan/coding2017/basic/QueueTest.java
similarity index 91%
rename from group11/252308879/dataStructure/src/test/java/org/apn/coding2017/basic/QueueTest.java
rename to group11/252308879/dataStructure/src/test/java/org/pan/coding2017/basic/QueueTest.java
index 0d52d8585f..c720e7d95e 100644
--- a/group11/252308879/dataStructure/src/test/java/org/apn/coding2017/basic/QueueTest.java
+++ b/group11/252308879/dataStructure/src/test/java/org/pan/coding2017/basic/QueueTest.java
@@ -1,10 +1,8 @@
-package org.apn.coding2017.basic;
+package org.pan.coding2017.basic;
import org.junit.Before;
import org.junit.Test;
-import static org.junit.Assert.*;
-
/**
* Created by Pan on 2017/2/26.
*/
diff --git a/group11/252308879/dataStructure/src/test/java/org/apn/coding2017/basic/StackTest.java b/group11/252308879/dataStructure/src/test/java/org/pan/coding2017/basic/StackTest.java
similarity index 91%
rename from group11/252308879/dataStructure/src/test/java/org/apn/coding2017/basic/StackTest.java
rename to group11/252308879/dataStructure/src/test/java/org/pan/coding2017/basic/StackTest.java
index f1798f8329..df85b797d4 100644
--- a/group11/252308879/dataStructure/src/test/java/org/apn/coding2017/basic/StackTest.java
+++ b/group11/252308879/dataStructure/src/test/java/org/pan/coding2017/basic/StackTest.java
@@ -1,10 +1,8 @@
-package org.apn.coding2017.basic;
+package org.pan.coding2017.basic;
import org.junit.Before;
import org.junit.Test;
-import static org.junit.Assert.*;
-
/**
* Created by Pan on 2017/2/26.
*/
From fb798cf9fd84f1f26d6d5a8b048378d01bb96a18 Mon Sep 17 00:00:00 2001
From: x_zhaohu
Date: Wed, 1 Mar 2017 19:57:15 +0800
Subject: [PATCH 11/30] =?UTF-8?q?=E8=AF=BB=E5=8F=96xml?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
group11/1178243325/DataStructure/build.gradle | 12 +++-
.../DataStructure/src/main/java/com/Main.java | 2 +
.../.Struts.java.swp} | Bin 16384 -> 12288 bytes
.../com/coderising/litestruts/Struts.java | 10 +--
.../com/coderising/litestruts/XmlUtil.java | 33 ++++++++++
.../src/main/java/com/coding/Main.java | 58 ------------------
.../java/com/coding/basic/BinaryTreeNode.java | 9 +--
group11/1178243325/DataStructure/struts.xml | 11 ++++
8 files changed, 67 insertions(+), 68 deletions(-)
rename group11/1178243325/DataStructure/src/main/java/com/coderising/{array/.ArrayUtil.java.swp => litestruts/.Struts.java.swp} (55%)
create mode 100644 group11/1178243325/DataStructure/src/main/java/com/coderising/litestruts/XmlUtil.java
delete mode 100644 group11/1178243325/DataStructure/src/main/java/com/coding/Main.java
create mode 100644 group11/1178243325/DataStructure/struts.xml
diff --git a/group11/1178243325/DataStructure/build.gradle b/group11/1178243325/DataStructure/build.gradle
index 5c3694d8ec..9c6bc859e6 100644
--- a/group11/1178243325/DataStructure/build.gradle
+++ b/group11/1178243325/DataStructure/build.gradle
@@ -1,10 +1,20 @@
+
apply plugin: 'java'
apply plugin: 'eclipse'
jar {
+ from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) }}
manifest {
- attributes 'Main-Class' : 'com.coding.Main'
+ attributes 'Main-Class' : 'com.Main'
}
}
+repositories {
+ mavenCentral()
+}
+
+dependencies {
+ compile 'junit:junit:4.12'
+ compile 'dom4j:dom4j:1.6.1'
+}
diff --git a/group11/1178243325/DataStructure/src/main/java/com/Main.java b/group11/1178243325/DataStructure/src/main/java/com/Main.java
index 7b27f11aec..c5d56779c1 100644
--- a/group11/1178243325/DataStructure/src/main/java/com/Main.java
+++ b/group11/1178243325/DataStructure/src/main/java/com/Main.java
@@ -1,5 +1,6 @@
package com;
+import com.coderising.litestruts.*;
import com.coderising.array.*;
public class Main {
public static void main(String[] args) {
@@ -47,5 +48,6 @@ public static void main(String[] args) {
System.out.print("\njoin测试:");
int[] jArray = new int[]{2, 3, 8};
System.out.print(ArrayUtil.join(jArray, "-"));
+ Struts.test();
}
}
diff --git a/group11/1178243325/DataStructure/src/main/java/com/coderising/array/.ArrayUtil.java.swp b/group11/1178243325/DataStructure/src/main/java/com/coderising/litestruts/.Struts.java.swp
similarity index 55%
rename from group11/1178243325/DataStructure/src/main/java/com/coderising/array/.ArrayUtil.java.swp
rename to group11/1178243325/DataStructure/src/main/java/com/coderising/litestruts/.Struts.java.swp
index 562760a67f7d3e5b0175ec4f8b8c72c563fdb0e7..5ff0f0622e0264939929151bb724ed26c12a7bb7 100644
GIT binary patch
literal 12288
zcmeI2&u<$=6vwAMVHFC3KY;1>l2m3lwu4fUwh}5xMXCV_wF)=3o5kJYAFJKjwo(ek{&8JAt8Z~IM5TGwR_5yBj52laavUsSClu(cgLA|
z^WK}!%pNSiQ#~hNOY=Uxm!UnwSoP-O!08dj-q^#K?|M#NsENn7|7!PsWN4f*&zgo+
z7_`;H$!C&1i9RFa6#_SrFcOKrgUQ}hD*2-EiYd&ugcn#M@NC2PEF)(+`OW3ImJ84E
z;lao{!uDY*d_%1ezOI5iK5d#M0y~F5Al`l9;9izWCVJGS_iOw3bI+dGIs2!b5&@uP9!kIVvM5=sRvV!m}jFlHqY}xHrpSKw4Q42fU)(F#bV*qx*V;ZbnJ7ovfNy_
z+L#?V4PMa=|
z^ZNS7^4np4LCe{`Z)R-mCC;_R7d5#y4Qn}mMH_+@N1T+-9|$$30Byku$BN;XV;Nf@
zt8ivH{9$@yb+qjqqv^=|#_Cw)4E~Z2`it`3@~2RVz~-C2N?a~4Hb41Mu3z5HE{dS}
zfn_0r2DggH@Heu$AXlcEl{OCU+v0T~0}On6)Aapw1#d9&jRjp=9+TQ(O%+9JYQLJ>
zw!vT`nd;TL)hJr)L?+6e6NnBxoUY;;fcit*K(uW@N^RVaULAg3!7Yu&5}UWmw1iX0
ztGvS&?8e*@_+VeSKvotBa&^oRg5!mZlYhCjKqb2Uq-1$s*_38*B64(2)>b0QI1Cle
zH~<3pLmfCO!?`d$oYzt1UPb1I`9LmvLO59+S^M@t`goVtx$at=ce3p6hnpUqH!C$c
zITPLdaOPsYw%A#)?JbL5Nd*-tFx9)ksjOphUzh@&dil5)w0G6j&aV?L&T)kgMZ@u^
zJHk6?yZHrtb&fnnv|xiucQx$f+=3^#s(IG~wKsU`hqYz?n-
z-8ny-VyF2X|44)L+ew?BBn@_)Ha{FYX_Nw`LZB)LwLqmRgxj+tN`E0#6^h{d-t4UR
zoU`5X7gE;I$G+X2c{B6o&6_uGFN;bae(*b@qNGg2&lfc9QqAc{_ni-ERiD+gbYsd&
zWaz=zKOeW;ld@pA-dJLUtCKY*{jw5uky5=PT$f5VHR^g;*DGd4%A(Ood3e5&F}{~c
zHC1PtQf4@vstz|8Rzg*8U=b-R4GCc*l`@ux@1x%fGgiEWni#v&{!?EAH0s)z^Tp0bc{Y27C?p8t^sXYrxmQ4X=SrgP4>&)^mCGPnd*gZW?rcyE%X+29K31v^0-*a$WN3p@y>
zfl1&upVPEc;3PN!o&yWO>k~EYEI0^ufURH)_yL#?%0MXygFC@r@x6rKflJ^5SO@L_
zcL5E2aGR#R58eiEfIooOz-3SlUdCWgfdgPWcp7woM?e_d1#SYb+=_mIW#Az&4gBL4
zP5UkA0vS*X3=jj~2LinN8BKc?w1UULY)}SDK{2=uy!mNOdkOS_i*&}w;19kRQWX=m)}my>sIIoA
z<659>(Ml~KW`yaNxL1mkpBs&o(Lg2mlB8A&JtXW6yM``y+I#j59_!C->m3|eBdTIt
zB>UoK`^f5d&bLw}DqJqS#doif#qIvip%aI*ef^?JM`0oYqM#hi0(w+R%x&M2d*Q&f
z)d%gvPouKEVF#+cbAI>e^-wvYm++4exELJRW%umP_BChwp38ML+lPK?H=oCSA;)0%
zc4Yh8(H-0!J20rqHji@4mB5kcOV{-)eKy}VD
z`}A1MMU$hnG&q0uU}PnX4RP@$A~;8M04ue&HRn8%)*l$HSCP?s74h^+H6#}lX+?ELcRQnx>`cV%jH*tZ$yb&f
zP%uafdelxrbv!s|lgoJ&qEySzp=+fWStAmo)i%0djGih+#uq$KPNJ$18%M1pdrayY
z(bc&HB`#fT#Z70Pub)hz=DDzH*~>{ofYp_fuB6-JrlYv0oL-)(VLkD+nk7~;xhuz{
zASxt3!}6q9*J*qFqLfKfKzk*1RZ3NNMsb%7W~$C4e+hRfMNnhzRfJ}cJk6;4r)-6t
z(Y5W=9rRF(0qnV|~0MLVxBq5>`lWy?b4@Uu>7
zxKiaLcMIw2a%VPN+jS`0zwX-lHv3Q;H>WnkL)Z+RQteyq{to-_1@?xg>z7T^psNCV}?3
zGugh*>_FS#nlrhbC+Jy!2g;4R-_jys7Z#{jYf<^bs`>(ZFRy>)mf=EZrI*Szk-sg6
zL_OO~q1~BGq#m2LYUz5WG~Jmn;4&C68FBe40WkjWrMMq0#r@fErx2h{E4zp5;~@)xw}sOiA%Lr^+Avk+Oxf7B
z4ZBVQb?p=9aHbfJRh!StkWzL@nT4~^s^dmFEm#xuJ$MR28jb45jXG0QCmTxWOZV~{
z^Ci4<%+culAH>=71Ds3g{2zA?gzw^ve+9e*PJ``W6{rQ@0$&GrgAZ}Ge-r!({0jU6
z{2c57?VtrL230@@#UKbMFYq?b|IdSiU
z@2X&)5~~HHa&IY5YESn6{w6DqeH^*iloM&?-N*2#F9kw$mg+`RBcpREMARp(g!hmd
z63&C+K_jpq=x0)~wDv)YP!ZOp)>(VRW=&C63hj7OWYP3;
zfD_bWq&3qZVxrE>6f=p5~k-{nu)zHVeC
z^;xg-CMHfHY1~g3Uckttki>%U{sw3*n*VY6
zJyEO|1@o>Wd3%s_h2%MDUUZrb`Vjlu`RSX;2Bh!gg0w$4+lP=f
k=khyL)tqy)pg0=5d>IHKavgF5o<)es9Mf&mOcZJV1$ parameters) {
/*
- 0. 读取配置文件struts.xml
-
+ 0. 读取配置文件struts.xml*/
+ String targetClassName = XmlUtil.parseXML("struts.xml", actionName);
+
+ /*
1. 根据actionName找到相对应的class , 例如LoginAction, 通过反射实例化(创建对象)
据parameters中的数据,调用对象的setter方法, 例如parameters中的数据是
("name"="test" , "password"="1234") ,
@@ -30,5 +30,5 @@ public static View runAction(String actionName, Map parameters) {
return null;
}
-
+
}
diff --git a/group11/1178243325/DataStructure/src/main/java/com/coderising/litestruts/XmlUtil.java b/group11/1178243325/DataStructure/src/main/java/com/coderising/litestruts/XmlUtil.java
new file mode 100644
index 0000000000..46c673daf9
--- /dev/null
+++ b/group11/1178243325/DataStructure/src/main/java/com/coderising/litestruts/XmlUtil.java
@@ -0,0 +1,33 @@
+package com.coderising.litestruts;
+
+import java.io.*;
+import java.util.*;
+import org.dom4j.Attribute;
+import org.dom4j.Document;
+import org.dom4j.Element;
+import org.dom4j.io.SAXReader;
+import org.dom4j.io.XMLWriter;
+public class XmlUtil {
+
+ public static String parseXML(String filePath, String actionName) {
+ try {
+ File file = new File(filePath);
+ SAXReader reader = new SAXReader();
+ Document doc = reader.read(file);
+ Element root = doc.getRootElement();
+ for (Iterator iter = root.elementIterator("action"); iter.hasNext();) {
+ Element element = (Element)iter.next();
+ Attribute nameAttr = element.attribute("name");
+ if (nameAttr.getValue().equals(actionName)) {
+ Attribute classAttr = element.attribute("class");
+ return classAttr.getValue();
+ }
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ System.out.println("parse error");
+ }
+ return null;
+ }
+
+}
diff --git a/group11/1178243325/DataStructure/src/main/java/com/coding/Main.java b/group11/1178243325/DataStructure/src/main/java/com/coding/Main.java
deleted file mode 100644
index 3260081ca1..0000000000
--- a/group11/1178243325/DataStructure/src/main/java/com/coding/Main.java
+++ /dev/null
@@ -1,58 +0,0 @@
-package com.coding;
-
-import com.coding.basic.*;
-public class Main {
- public static void main(String[] args) {
- ArrayList list = new ArrayList();
-
- list.add(0, "2xxx");
- list.add(1, "we");
- list.add(2, "sss");
- list.add("xing");
- list.remove(2);
- System.out.println(list.get(2));
- Iterator iterator = list.iterator();
- while(iterator.hasNext()) {
- System.out.println(iterator.next());
- }
- System.out.println(list.size());
-
- LinkedList llist = new LinkedList();
- llist.add("hu");
- llist.add("zhao");
- llist.add(2,"xing");
- llist.addFirst("身骑白马");
- llist.addLast("德州小老虎");
- llist.add(5, "sf");
- llist.remove(5);
- llist.removeFirst();
- llist.removeLast();
- for (int i = 2; i >=0; i--)
- System.out.print(llist.get(i));
- System.out.println(llist.size());
-
- Iterator literator = llist.iterator();
- while(literator.hasNext()) {
- System.out.println(literator.next());
- }
-
- Stack stack = new Stack();
- stack.push(1);
- stack.push(2);
- stack.push(3);
- stack.push(4);
- System.out.println(stack.peek());
- while(!stack.isEmpty())
- System.out.println(stack.pop());
-
- Queue queue = new Queue();
- queue.enQueue(1);
- queue.enQueue(2);
- queue.enQueue(3);
- System.out.println(queue.size());
- while (!queue.isEmpty()) {
- System.out.println(queue.deQueue());
- }
-
- }
-}
diff --git a/group11/1178243325/DataStructure/src/main/java/com/coding/basic/BinaryTreeNode.java b/group11/1178243325/DataStructure/src/main/java/com/coding/basic/BinaryTreeNode.java
index 266eff3d56..1cf38aee30 100644
--- a/group11/1178243325/DataStructure/src/main/java/com/coding/basic/BinaryTreeNode.java
+++ b/group11/1178243325/DataStructure/src/main/java/com/coding/basic/BinaryTreeNode.java
@@ -9,24 +9,25 @@ public class BinaryTreeNode {
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/group11/1178243325/DataStructure/struts.xml b/group11/1178243325/DataStructure/struts.xml
new file mode 100644
index 0000000000..ae0ce37fd8
--- /dev/null
+++ b/group11/1178243325/DataStructure/struts.xml
@@ -0,0 +1,11 @@
+
+
+
+ /jsp/homepage.jsp
+ /jsp/showLogin.jsp
+
+
+ /jsp/welcome.jsp
+ /jsp/error.jsp
+
+
From 16f10f4759d54eb07b8e09353ba1c91b51768b81 Mon Sep 17 00:00:00 2001
From: Fred Qin
Date: Wed, 1 Mar 2017 15:58:18 -0800
Subject: [PATCH 12/30] structs.xml is updated
---
.../src/com/coderising/array/ArrayUtilTest.java | 2 --
.../src/com/coderising/litestruts/struts.xml | 16 ++++++++--------
2 files changed, 8 insertions(+), 10 deletions(-)
diff --git a/group11/395443277/src/com/coderising/array/ArrayUtilTest.java b/group11/395443277/src/com/coderising/array/ArrayUtilTest.java
index 8dee13e718..704ea09591 100644
--- a/group11/395443277/src/com/coderising/array/ArrayUtilTest.java
+++ b/group11/395443277/src/com/coderising/array/ArrayUtilTest.java
@@ -1,7 +1,5 @@
package com.coderising.array;
-import static org.junit.Assert.*;
-
import org.junit.Assert;
import org.junit.Test;
diff --git a/group11/395443277/src/com/coderising/litestruts/struts.xml b/group11/395443277/src/com/coderising/litestruts/struts.xml
index 4c9967dbaf..dd598a3664 100644
--- a/group11/395443277/src/com/coderising/litestruts/struts.xml
+++ b/group11/395443277/src/com/coderising/litestruts/struts.xml
@@ -1,11 +1,11 @@
-
- /jsp/homepage.jsp
- /jsp/showLogin.jsp
-
-
- /jsp/welcome.jsp
- /jsp/error.jsp
-
+
+ /jsp/homepage.jsp
+ /jsp/showLogin.jsp
+
+
+ /jsp/welcome.jsp
+ /jsp/error.jsp
+
\ No newline at end of file
From c801015ad111c031c2356837dcab9901c3c127c7 Mon Sep 17 00:00:00 2001
From: Fred Qin
Date: Thu, 2 Mar 2017 20:39:49 -0800
Subject: [PATCH 13/30] complete Struts.java
the class in struts.xml should be com.coderising.litestruts.LoginAction
---
.../src/com/coderising/litestruts/Struts.java | 122 ++++++++++++++----
.../src/com/coderising/litestruts/struts.xml | 4 +-
2 files changed, 100 insertions(+), 26 deletions(-)
diff --git a/group11/395443277/src/com/coderising/litestruts/Struts.java b/group11/395443277/src/com/coderising/litestruts/Struts.java
index 85e2e22de3..c5d3d602fc 100644
--- a/group11/395443277/src/com/coderising/litestruts/Struts.java
+++ b/group11/395443277/src/com/coderising/litestruts/Struts.java
@@ -1,34 +1,108 @@
package com.coderising.litestruts;
+import java.io.InputStream;
+import java.lang.reflect.Method;
+import java.util.HashMap;
import java.util.Map;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.NamedNodeMap;
+import org.w3c.dom.NodeList;
public class Struts {
- public static View runAction(String actionName, Map parameters) {
-
- /*
-
- 0. 读取配置文件struts.xml
-
- 1. 根据actionName找到相对应的class , 例如LoginAction, 通过反射实例化(创建对象)
- 据parameters中的数据,调用对象的setter方法, 例如parameters中的数据是
- ("name"="test" , "password"="1234") ,
- 那就应该调用 setName和setPassword方法
-
- 2. 通过反射调用对象的exectue 方法, 并获得返回值,例如"success"
-
- 3. 通过反射找到对象的所有getter方法(例如 getMessage),
- 通过反射来调用, 把值和属性形成一个HashMap , 例如 {"message": "登录成功"} ,
- 放到View对象的parameters
-
- 4. 根据struts.xml中的 配置,以及execute的返回值, 确定哪一个jsp,
- 放到View对象的jsp字段中。
-
- */
-
- return null;
- }
+ 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字段中。
+ *
+ */
+
+ // create a new DocumentBuilderFactory
+ DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
+
+ try {
+ // use the factory to create a documentbuilder
+ DocumentBuilder builder = factory.newDocumentBuilder();
+ InputStream istream = Struts.class.getResourceAsStream("struts.xml");
+ Document doc = builder.parse(istream);
+
+ // find jsp page based on the result from execute result
+ Element element = doc.getDocumentElement();
+ NodeList actionNodeList = element.getElementsByTagName("action");
+
+ for (int i = 0; i < actionNodeList.getLength(); i++) {
+ NamedNodeMap actionNodeAttr = actionNodeList.item(i).getAttributes();
+
+ if (actionNodeAttr.getNamedItem("name").getTextContent().equals(actionName)) {
+ String className = actionNodeAttr.getNamedItem("class").getTextContent();
+
+ Class> cls = Class.forName(className);
+ Object obj = cls.newInstance();
+
+ // set name and password
+ Method setName = cls.getDeclaredMethod("setName", String.class);
+ Method setPassword = cls.getDeclaredMethod("setPassword", String.class);
+ setName.invoke(obj, parameters.get("name"));
+ setPassword.invoke(obj, parameters.get("password"));
+
+ // execute
+ Method execute = cls.getDeclaredMethod("execute");
+ String executeResult = (String) execute.invoke(obj);
+
+ // get message and jsp
+ Method getMessage = cls.getDeclaredMethod("getMessage");
+ String msg = (String) getMessage.invoke(obj);
+ Map params = new HashMap();
+ params.put("message",msg);
+
+ // check result nodes
+ NodeList resultNodes = actionNodeList.item(i).getChildNodes();
+
+ String jsp = "";
+ for (int j=0; j viewCls = Class.forName("com.coderising.litestruts.View");
+ View viewObj = (View) viewCls.newInstance();
+ Method setParameters = viewCls.getDeclaredMethod("setParameters", Map.class);
+ setParameters.invoke(viewObj, params);
+ Method setJsp = viewCls.getDeclaredMethod("setJsp", String.class);
+ setJsp.invoke(viewObj, jsp);
+
+ return viewObj;
+ }
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ return null;
+ }
}
diff --git a/group11/395443277/src/com/coderising/litestruts/struts.xml b/group11/395443277/src/com/coderising/litestruts/struts.xml
index dd598a3664..7f8d558286 100644
--- a/group11/395443277/src/com/coderising/litestruts/struts.xml
+++ b/group11/395443277/src/com/coderising/litestruts/struts.xml
@@ -1,10 +1,10 @@
-
+
/jsp/homepage.jsp
/jsp/showLogin.jsp
-
+
/jsp/welcome.jsp
/jsp/error.jsp
From d369c38e07f1d5643894278ccdec566a16a1f2e0 Mon Sep 17 00:00:00 2001
From: "wangxg922@chinaunincom.cn" <996108220@qq.com>
Date: Fri, 3 Mar 2017 18:33:47 +0800
Subject: [PATCH 14/30] =?UTF-8?q?Struts=E5=92=8C=E6=95=B0=E6=8D=AE?=
=?UTF-8?q?=E7=BB=93=E6=9E=84=E4=BD=9C=E4=B8=9A?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Signed-off-by: 996108220@qq.com
---
group11/996108220/.classpath | 2 +
.../src/com/coderising/array/ArrayUtil.java | 194 ++++++++++++++++++
.../com/coderising/array/ArrayUtilTest.java | 71 +++++++
.../src/com/coderising/litestruts/Action.java | 11 +
.../coderising/litestruts/ActionConfig.java | 44 ++++
.../coderising/litestruts/LoginAction.java | 40 ++++
.../coderising/litestruts/LogoutAction.java | 35 ++++
.../src/com/coderising/litestruts/Struts.java | 167 +++++++++++++++
.../com/coderising/litestruts/StrutsTest.java | 63 ++++++
.../src/com/coderising/litestruts/View.java | 23 +++
.../src/com/coderising/litestruts/struts.xml | 11 +
.../src/com/coding/basic/ArrayList.java | 8 +
12 files changed, 669 insertions(+)
create mode 100644 group11/996108220/src/com/coderising/array/ArrayUtil.java
create mode 100644 group11/996108220/src/com/coderising/array/ArrayUtilTest.java
create mode 100644 group11/996108220/src/com/coderising/litestruts/Action.java
create mode 100644 group11/996108220/src/com/coderising/litestruts/ActionConfig.java
create mode 100644 group11/996108220/src/com/coderising/litestruts/LoginAction.java
create mode 100644 group11/996108220/src/com/coderising/litestruts/LogoutAction.java
create mode 100644 group11/996108220/src/com/coderising/litestruts/Struts.java
create mode 100644 group11/996108220/src/com/coderising/litestruts/StrutsTest.java
create mode 100644 group11/996108220/src/com/coderising/litestruts/View.java
create mode 100644 group11/996108220/src/com/coderising/litestruts/struts.xml
diff --git a/group11/996108220/.classpath b/group11/996108220/.classpath
index d171cd4c12..11cc9c31cb 100644
--- a/group11/996108220/.classpath
+++ b/group11/996108220/.classpath
@@ -2,5 +2,7 @@
+
+
diff --git a/group11/996108220/src/com/coderising/array/ArrayUtil.java b/group11/996108220/src/com/coderising/array/ArrayUtil.java
new file mode 100644
index 0000000000..0637eb921c
--- /dev/null
+++ b/group11/996108220/src/com/coderising/array/ArrayUtil.java
@@ -0,0 +1,194 @@
+package com.coderising.array;
+
+import com.coding.basic.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 mid=origin.length%2==1?origin.length/2:origin.length/2-1;
+ for (int i = 0; i <= mid; i++) {
+ int vlaue=origin[i];
+ origin[i]=origin[origin.length-1-i];
+ origin[origin.length-1-i]=vlaue;
+ }
+ }
+
+ /**
+ * 现在有如下的一个数组: int oldArr[]={1,3,4,5,0,0,6,6,0,5,4,7,6,7,0,5}
+ * 要求将以上数组中值为0的项去掉,将不为0的值存入一个新的数组,生成的新数组为:
+ * {1,3,4,5,6,6,5,4,7,6,7,5}
+ * @param oldArray
+ * @return
+ */
+
+ public int[] removeZero(int[] oldArray){
+ ArrayList list=new ArrayList();
+ for (int i = 0; i < oldArray.length; i++) {
+ if (oldArray[i]!=0) {
+ list.add(oldArray[i]);
+ }
+ }
+ int[] array=new int[list.size()];
+ for (int i = 0; i < list.size(); i++) {
+ array[i]=(int) list.get(i);
+ }
+
+ return array;
+ }
+
+ /**
+ * 给定两个已经排序好的整形数组, 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[] array=new int[array1.length+array2.length];
+ int ptr1=0;int ptr2=0;int index=0;
+ while (ptr1!=array1.length&&ptr2!=array2.length) {
+ array[index++]=array1[ptr1]>array2[ptr2]?array2[ptr2++]:array1[ptr1++];
+ }
+ if (ptr1==array1.length) {
+ for (int i = ptr2; i < array2.length; i++)array[index++]=array2[i];
+ }
+ else {
+ for (int i = ptr1; i < array1.length; i++)array[index++]=array1[i];
+ }
+ 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 [] array=new int[oldArray.length+size];
+ for (int i = 0; i < oldArray.length; i++) {
+ array[i]=oldArray[i];
+ }
+ return array;
+ }
+
+ /**
+ * 斐波那契数列为:1,1,2,3,5,8,13,21...... ,给定一个最大值, 返回小于该值的数列
+ * 例如, max = 15 , 则返回的数组应该为 [1,1,2,3,5,8,13]
+ * max = 1, 则返回空数组 []
+ * @param max
+ * @return
+ */
+ public int[] fibonacci(int max){
+
+ if (max==1) {
+ return null;
+ }
+ else if (max==2) {
+ return new int[]{1,1};
+ }
+ else {
+ ArrayList list=new ArrayList();
+ list.add(1);
+ list.add(1);
+ int next=2;
+ while (next messageToresult=null;
+ public String getActionName() {
+ return actionName;
+ }
+ public void setActionName(String actionName) {
+ this.actionName = actionName;
+ }
+ public String getClazzName() {
+ return clazzName;
+ }
+ public void setClazzName(String clazzName) {
+ this.clazzName = clazzName;
+ }
+ public HashMap getMessageToresult() {
+ return messageToresult;
+ }
+ public void setMessageToresult(HashMap messageToresult) {
+ this.messageToresult = messageToresult;
+ }
+ public ActionConfig(String actionName, String clazzName,
+ HashMap messageToresult) {
+ super();
+ this.actionName = actionName;
+ this.clazzName = clazzName;
+ this.messageToresult = messageToresult;
+ }
+
+
+}
diff --git a/group11/996108220/src/com/coderising/litestruts/LoginAction.java b/group11/996108220/src/com/coderising/litestruts/LoginAction.java
new file mode 100644
index 0000000000..01b51fdd88
--- /dev/null
+++ b/group11/996108220/src/com/coderising/litestruts/LoginAction.java
@@ -0,0 +1,40 @@
+package com.coderising.litestruts;
+
+
+/**
+ * 这是一个用来展示登录的业务类, 其中的用户名和密码都是硬编码的。
+ * @author liuxin
+ *
+ */
+public class LoginAction implements Action{
+ 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/group11/996108220/src/com/coderising/litestruts/LogoutAction.java b/group11/996108220/src/com/coderising/litestruts/LogoutAction.java
new file mode 100644
index 0000000000..8043fae56e
--- /dev/null
+++ b/group11/996108220/src/com/coderising/litestruts/LogoutAction.java
@@ -0,0 +1,35 @@
+package com.coderising.litestruts;
+
+public class LogoutAction implements Action{
+ 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 = "logout successful";
+ return "success";
+ }
+ this.message = "logout failed,please try again";
+ return "error";
+ }
+
+ 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/group11/996108220/src/com/coderising/litestruts/Struts.java b/group11/996108220/src/com/coderising/litestruts/Struts.java
new file mode 100644
index 0000000000..8f961f2175
--- /dev/null
+++ b/group11/996108220/src/com/coderising/litestruts/Struts.java
@@ -0,0 +1,167 @@
+package com.coderising.litestruts;
+import java.lang.reflect.Method;
+import java.util.HashMap;
+import java.util.Map;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+import com.coderising.litestruts.Action;
+
+
+
+/*
+
+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字段中。
+
+*/
+
+public class Struts {
+ //strut.xml文件所在的路径
+ public static final String dir="/mycoding2017/group11/996108220/src/com/coderising/litestruts/struts.xml";
+
+ /**
+ * 用户提供action动作,以及用户名和密码,对应返回view视图
+ * @param actionName 登入登出
+ * @param parameters 用户名密码
+ */
+ public static View runAction(String actionName, Map parameters) throws Exception {
+ ActionConfig actionConfig=getActionConfig(actionName);
+ Action action=createAction(actionConfig.getClazzName(),parameters);
+ String message=getActionMessage(action);
+ View view=updaView(getALL(action), actionConfig, message);
+ return view;
+ }
+
+ /**
+ * 步骤0:读取配置文件,将文件中的action生成ActionDao
+ * @param actionName传入action的名字
+ */
+ private static ActionConfig getActionConfig(String name) throws Exception {
+ // 生成一个Dom解析器
+ DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
+ // 解析XML文件
+ Document document = builder.parse(dir);
+ NodeList actions = document.getElementsByTagName("action");
+ int j = 0;String actionName="";String clazzName="";
+ for (; j < actions.getLength(); j++) {
+ actionName= actions.item(j).getAttributes().getNamedItem("name").getNodeValue();
+ if (actionName.equals(name)) {
+ clazzName=actions.item(j).getAttributes().getNamedItem("class").getNodeValue();
+ break;
+ }
+ }
+ if (actions.item(0).getNodeType() == Node.ELEMENT_NODE) {
+
+ Element action =(Element) actions.item(j);
+ NodeList results =action.getElementsByTagName("result");
+ HashMap map=new HashMap();
+ for (int i = 0; i < results.getLength(); i++) {
+ String nameString=results.item(i).getAttributes().getNamedItem("name").getNodeValue();
+ String pageString=results.item(i).getTextContent();
+ map.put(nameString, pageString);
+ }
+ return new ActionConfig(actionName, clazzName, map);
+ }
+ return null;
+ }
+ /**
+ * 步骤1:反射创建action的对象,将name和password赋值
+ * @param clazzName
+ * @return
+ */
+ private static Action createAction(String clazzName,Map parameters) throws Exception {
+ Class> clazz=Class.forName(clazzName);
+ Object action = clazz.newInstance() ;
+ Method nameSetter = action.getClass().getMethod("setName", String.class);
+ nameSetter .invoke(action, parameters.get("name"));
+ Method passwordSetter = action.getClass().getMethod("setPassword", String.class);
+ passwordSetter.invoke(action, parameters.get("password"));
+ return (Action) action;
+ }
+ /**
+ * 步骤2:反射运行execute方法,获得message
+ * @param action
+ * @return message
+ */
+ private static String getActionMessage (Action action) throws Exception {
+
+ return (String) action.getClass().getMethod("execute").invoke(action);
+
+ }
+ /**
+ * 步骤3:将action中get方法与get到的值的映射关系记录到view里的Parameters表中
+ * @param action
+ * @return view
+ */
+ private static View getALL(Action action) throws Exception {
+ HashMap map=new HashMap<>();
+ Method nameGetter = action.getClass().getMethod("getName");
+ map.put("name", (String) nameGetter.invoke(action));
+ Method passwordGetter = action.getClass().getMethod("getPassword");
+ map.put("password", (String) passwordGetter.invoke(action));
+ Method MessageGetter = action.getClass().getMethod("getMessage");
+ map.put("message", (String) MessageGetter.invoke(action));
+ View view=new View();
+ view.setParameters(map);
+ return view;
+ }
+ /**
+ * 步骤4:将execute获得的message查找Struts配置文件将对应的页面记录到view中
+ * @param view
+ * @param actionConfig
+ * @param message
+ * @return
+ */
+ private static View updaView(View view,ActionConfig actionConfig,String message) {
+ return view.setJsp(actionConfig.getMessageToresult().get(message));
+ }
+// public static void main(String[] args) {
+// DocumentBuilder builder;
+// try {
+// builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
+// Document doc = builder.parse(dir);
+// NodeList beans = doc.getElementsByTagName("action");
+// for (int j = 0; j < beans.getLength(); j++) {
+// System.out.println(beans.item(j).getAttributes().getNamedItem("name").getNodeValue());
+// System.out.println(beans.item(j).getAttributes().getNamedItem("class").getNodeValue());
+// }
+// if (beans.item(0).getNodeType() == Node.ELEMENT_NODE) {
+//
+// Element action =(Element) beans.item(0);
+// NodeList results =action.getElementsByTagName("result");
+// HashMap map=new HashMap();
+// System.out.println(results.getLength());
+// for (int i = 0; i < results.getLength(); i++) {
+// System.out.println(results.item(i).getAttributes().getNamedItem("name").getNodeValue());
+// System.out.println(results.item(i).getTextContent());
+// }
+// }
+//
+//// NamedNodeMap name = beans.item(0).getAttributes();
+//
+// } catch (Exception e) {
+// // TODO Auto-generated catch block
+// e.printStackTrace();
+// }
+
+
+// }
+
+}
diff --git a/group11/996108220/src/com/coderising/litestruts/StrutsTest.java b/group11/996108220/src/com/coderising/litestruts/StrutsTest.java
new file mode 100644
index 0000000000..af5f82d275
--- /dev/null
+++ b/group11/996108220/src/com/coderising/litestruts/StrutsTest.java
@@ -0,0 +1,63 @@
+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() throws Exception {
+
+ 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 Exception {
+ 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"));
+ }
+ @Test
+ public void testLogoutActionSuccess() throws Exception {
+
+ String actionName = "logout";
+
+ Map params = new HashMap();
+ params.put("name","test");
+ params.put("password","1234");
+
+
+ View view = Struts.runAction(actionName,params);
+ Assert.assertEquals("/jsp/welcome.jsp", view.getJsp());
+ Assert.assertEquals("logout successful", view.getParameters().get("message"));
+ }
+
+ @Test
+ public void testLogoutActionFailed() throws Exception {
+ String actionName = "logout";
+ Map params = new HashMap();
+ params.put("name","test");
+ params.put("password","123456"); //密码和预设的不一致
+
+ View view = Struts.runAction(actionName,params);
+ Assert.assertEquals("/jsp/error.jsp", view.getJsp());
+ Assert.assertEquals("logout failed,please try again", view.getParameters().get("message"));
+ }
+}
diff --git a/group11/996108220/src/com/coderising/litestruts/View.java b/group11/996108220/src/com/coderising/litestruts/View.java
new file mode 100644
index 0000000000..0194c681f6
--- /dev/null
+++ b/group11/996108220/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/group11/996108220/src/com/coderising/litestruts/struts.xml b/group11/996108220/src/com/coderising/litestruts/struts.xml
new file mode 100644
index 0000000000..246b3595ad
--- /dev/null
+++ b/group11/996108220/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/group11/996108220/src/com/coding/basic/ArrayList.java b/group11/996108220/src/com/coding/basic/ArrayList.java
index 6fe727645b..2445d52ae5 100644
--- a/group11/996108220/src/com/coding/basic/ArrayList.java
+++ b/group11/996108220/src/com/coding/basic/ArrayList.java
@@ -1,5 +1,6 @@
package com.coding.basic;
+
public class ArrayList implements List {
private int size = 0;
@@ -94,6 +95,13 @@ public Object next() {
}
}
+ public Object[] toArray() {
+ Object[] array= new Object[size];
+ for (int i = 0; i < elementData.length; i++) {
+ array[i]=elementData[i];
+ }
+ return array;
+ }
public void grow(Object[] elementData2){
int[] elementData=new int[elementData2.length+elementData2.length/2];
System.arraycopy(elementData2,0,elementData,0,elementData2.length);
From bd081616b7e25e879ab733f354f0489964c249cd Mon Sep 17 00:00:00 2001
From: peter <729245768@qq.com>
Date: Fri, 3 Mar 2017 20:48:39 +0800
Subject: [PATCH 15/30] =?UTF-8?q?=E6=B7=BB=E5=8A=A0ArrayUtil=E7=B1=BB?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../src/main/coding_170302/ArrayUtil.java | 211 ++++++++++++++++++
1 file changed, 211 insertions(+)
create mode 100644 group11/729245768/DataStructure/src/main/coding_170302/ArrayUtil.java
diff --git a/group11/729245768/DataStructure/src/main/coding_170302/ArrayUtil.java b/group11/729245768/DataStructure/src/main/coding_170302/ArrayUtil.java
new file mode 100644
index 0000000000..db8d8bef49
--- /dev/null
+++ b/group11/729245768/DataStructure/src/main/coding_170302/ArrayUtil.java
@@ -0,0 +1,211 @@
+package main.coding_170302;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+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){
+ for(int i=0,j=origin.length-1;i list = new ArrayList<>();
+ for(int i=6;i<=max;i++){
+ if(isPerfectNumbers(i)){
+ list.add(i);
+ }
+ }
+ int[] array = new int[list.size()];
+ for(int i=0;i list = new ArrayList<>();
+ int end =(int) Math.sqrt(element);//
+ for(int i=2;i<=end;){
+ if(element%i==0){
+ list.add(i);
+ element=element/i;
+ }else{
+ i++;
+ }
+ }
+ int sum =1;
+ for(Integer i:list){
+ sum+=i;
+ }
+ if(element==sum){
+ return true;
+ }else{
+ return false;
+ }
+ }
+
+ /**
+ * 用seperator 把数组 array给连接起来
+ * 例如array= [3,8,9], seperator = "-"
+ * 则返回值为"3-8-9"
+ * @param array
+ * @param s
+ * @return
+ */
+ public String join(int[] array, String seperator){
+ StringBuilder sb = new StringBuilder();
+ for(int i=0;i
Date: Fri, 3 Mar 2017 20:49:26 +0800
Subject: [PATCH 16/30] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E4=B8=9A=E5=8A=A1?=
=?UTF-8?q?=E7=B1=BB=EF=BC=8C=E7=94=A8=E6=9D=A5=E7=99=BB=E5=BD=95?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../src/main/coding_170302/LoginAction.java | 38 +++++++++++++++++++
1 file changed, 38 insertions(+)
create mode 100644 group11/729245768/DataStructure/src/main/coding_170302/LoginAction.java
diff --git a/group11/729245768/DataStructure/src/main/coding_170302/LoginAction.java b/group11/729245768/DataStructure/src/main/coding_170302/LoginAction.java
new file mode 100644
index 0000000000..0ff359efaa
--- /dev/null
+++ b/group11/729245768/DataStructure/src/main/coding_170302/LoginAction.java
@@ -0,0 +1,38 @@
+package main.coding_170302;
+
+/**这是一个用来显示登录的业务类,其中的用户名和密码都是硬编码
+ * Created by peter on 2017/3/3.
+ */
+public class LoginAction {
+ private String name;
+ private String password;
+ private String message;
+
+ public String getName() {
+ return name;
+ }
+
+ public String getPassword() {
+ return password;
+ }
+
+ public String getMessage() {
+ return message;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public void setPassword(String password) {
+ this.password = password;
+ }
+ public String execute(){
+ if("test".equals(name)&&"1234".equals(password)){
+ this.message = "login successful";
+ return message;
+ }
+ this.message = "login failed,please check your user/pwd";
+ return message;
+ }
+}
From 491f5130b40a0004c54cfc62c628ce17317dfd64 Mon Sep 17 00:00:00 2001
From: peter <729245768@qq.com>
Date: Fri, 3 Mar 2017 20:50:20 +0800
Subject: [PATCH 17/30] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E9=85=8D=E7=BD=AE?=
=?UTF-8?q?=E6=96=87=E4=BB=B6?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../DataStructure/src/main/coding_170302/struts.xml | 11 +++++++++++
1 file changed, 11 insertions(+)
create mode 100644 group11/729245768/DataStructure/src/main/coding_170302/struts.xml
diff --git a/group11/729245768/DataStructure/src/main/coding_170302/struts.xml b/group11/729245768/DataStructure/src/main/coding_170302/struts.xml
new file mode 100644
index 0000000000..a500b2d24f
--- /dev/null
+++ b/group11/729245768/DataStructure/src/main/coding_170302/struts.xml
@@ -0,0 +1,11 @@
+
+
+
+ /jsp/homepage.jsp
+ /jsp/showLogin.jsp
+
+
+ /jsp/welcome.jsp
+ /jsp/error.jsp
+
+
\ No newline at end of file
From c07f985447bd9b59bf6198686fbb1b6ecfb384cd Mon Sep 17 00:00:00 2001
From: peter <729245768@qq.com>
Date: Fri, 3 Mar 2017 20:50:56 +0800
Subject: [PATCH 18/30] =?UTF-8?q?Struts=E7=B1=BB=E7=94=A8=E6=9D=A5?=
=?UTF-8?q?=E8=AF=BB=E5=8F=96=E9=85=8D=E7=BD=AE=E6=96=87=E4=BB=B6?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../src/main/coding_170302/Struts.java | 108 ++++++++++++++++++
1 file changed, 108 insertions(+)
create mode 100644 group11/729245768/DataStructure/src/main/coding_170302/Struts.java
diff --git a/group11/729245768/DataStructure/src/main/coding_170302/Struts.java b/group11/729245768/DataStructure/src/main/coding_170302/Struts.java
new file mode 100644
index 0000000000..f0f9b7b67f
--- /dev/null
+++ b/group11/729245768/DataStructure/src/main/coding_170302/Struts.java
@@ -0,0 +1,108 @@
+package main.coding_170302;
+
+import org.dom4j.Document;
+import org.dom4j.DocumentException;
+import org.dom4j.Element;
+import org.dom4j.io.SAXReader;
+
+import java.io.File;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * Created by peter on 2017/3/3.
+ */
+public class Struts {
+ public static View runAction(String actionName, Map parameters) throws DocumentException {
+ /*
+
+ 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字段中。
+
+ */
+ View view = new View();
+ SAXReader saxReader = new SAXReader();
+ Document document = saxReader.read(new File("DataStructure/src/main/coding_170302/struts.xml"));
+ Element root = document.getRootElement();//获取根元素
+ List listOfAction = root.elements("action");//获取action子元素
+ int i=0;
+ for(;i> inputs = parameters.entrySet();
+ //执行setName和setPassword
+ for(Map.Entry input:inputs){
+ String key = input.getKey();
+ String value = input.getValue();
+ String methodName = "set"+Character.toUpperCase(key.charAt(0))+key.substring(1);
+ Method method = c.getDeclaredMethod(methodName,String.class);
+ method.invoke(o,value);
+ }
+ //执行execute方法,并返回message
+ Method execute = c.getDeclaredMethod("execute");
+ String returnMessage = (String)execute.invoke(o);
+
+ Method[] methods = c.getDeclaredMethods();
+ //获取所有getter方法,并且将值放到view的parameters中
+ Map paraMap = new HashMap<>();
+ for(int j=0;j 配置,以及execute的返回值, 确定哪一个jsp,
+ // 放到View对象的jsp字段中。
+ List resultOfElements = action.elements("result");
+ for(int k=0;k
Date: Fri, 3 Mar 2017 20:51:34 +0800
Subject: [PATCH 19/30] =?UTF-8?q?=E7=94=A8=E6=9D=A5=E5=A4=84=E7=90=86?=
=?UTF-8?q?=E9=A1=B5=E9=9D=A2=E6=98=BE=E7=A4=BA?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../src/main/coding_170302/View.java | 27 +++++++++++++++++++
1 file changed, 27 insertions(+)
create mode 100644 group11/729245768/DataStructure/src/main/coding_170302/View.java
diff --git a/group11/729245768/DataStructure/src/main/coding_170302/View.java b/group11/729245768/DataStructure/src/main/coding_170302/View.java
new file mode 100644
index 0000000000..fa8155abe9
--- /dev/null
+++ b/group11/729245768/DataStructure/src/main/coding_170302/View.java
@@ -0,0 +1,27 @@
+package main.coding_170302;
+
+import java.util.Map;
+
+/**
+ * Created by peter on 2017/3/3.
+ */
+public class View {
+ private String jsp;
+ private Map parameters;
+
+ public View setJsp(String jsp){
+ this.jsp = jsp;
+ return this;
+ }
+ public View setPatameters(Map parameters){
+ this.parameters = parameters;
+ return this;
+ }
+ public String getJsp() {
+ return jsp;
+ }
+
+ public Map getParameters() {
+ return parameters;
+ }
+}
From 9d173a3d334ba2b71a4eac81b8d5a5b8d7cb975d Mon Sep 17 00:00:00 2001
From: peter <729245768@qq.com>
Date: Fri, 3 Mar 2017 20:55:43 +0800
Subject: [PATCH 20/30] =?UTF-8?q?=E4=B8=BAArrayUtil=E6=B7=BB=E5=8A=A0?=
=?UTF-8?q?=E6=B5=8B=E8=AF=95=E7=B1=BB?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../main/coding_170302/ArrayUtilTest.java | 78 +++++++++++++++++++
1 file changed, 78 insertions(+)
create mode 100644 group11/729245768/DataStructure/tests/main/coding_170302/ArrayUtilTest.java
diff --git a/group11/729245768/DataStructure/tests/main/coding_170302/ArrayUtilTest.java b/group11/729245768/DataStructure/tests/main/coding_170302/ArrayUtilTest.java
new file mode 100644
index 0000000000..4d5cc38728
--- /dev/null
+++ b/group11/729245768/DataStructure/tests/main/coding_170302/ArrayUtilTest.java
@@ -0,0 +1,78 @@
+package main.coding_170302;
+
+import junit.framework.TestCase;
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * Created by peter on 2017/3/2.
+ */
+public class ArrayUtilTest extends TestCase {
+ @Before
+ public void setUp() throws Exception {
+
+ }
+
+ @After
+ public void tearDown() throws Exception {
+
+ }
+
+ @Test
+ public void testReverseArray() throws Exception {
+ int[] array1 = {1,2,3,4,5,6,7};
+ int[] array2 = {7,6,5,4,3,2,1};
+ ArrayUtil util = new ArrayUtil();
+ util.reverseArray(array1);
+ Assert.assertArrayEquals(array1,array2);
+ }
+
+ @Test
+ public void testRemoveZero() throws Exception {
+ int[] array1 = {1,3,4,5,0,0,6,6,0,5,4,7,6,7,0,5};
+ int[] arry2 = {1,3,4,5,6,6,5,4,7,6,7,5};
+ Assert.assertArrayEquals(new ArrayUtil().removeZero(array1),arry2);
+}
+
+ @Test
+ public void testMerge() throws Exception {
+ int[] array1 = {3,5,7,8};
+ int[] array2 = {4,5,6,7};
+ int[] array = {3,4,5,6,7,8};
+ Assert.assertArrayEquals(array,new ArrayUtil().merge(array1,array2));
+ }
+
+ @Test
+ public void testGrow() throws Exception {
+ int[] array1 ={2,3,6};
+ int[] array2 = {2,3,6,0,0,0};
+ Assert.assertArrayEquals(array2,new ArrayUtil().grow(array1,3));
+ }
+
+ @Test
+ public void testFibonacci() throws Exception {
+ int[] array1 = {1,1,2,3,5,8,13};
+ Assert.assertArrayEquals(array1,new ArrayUtil().fibonacci(15));
+ }
+
+ @Test
+ public void testGetPrimes() throws Exception {
+ int[] array1 = {2,3,5,7,11,13,17,19};
+ Assert.assertArrayEquals(array1,new ArrayUtil().getPrimes(23));
+ }
+
+ @Test
+ public void testGetPerfectNumbers() throws Exception {
+ int[] array1 = {6};
+ Assert.assertArrayEquals(array1,new ArrayUtil().getPerfectNumbers(10));
+ }
+
+ @Test
+ public void testJoin() throws Exception {
+ int[] array1 = {3,8,9};
+ Assert.assertEquals("3-8-9",new ArrayUtil().join(array1,"-"));
+ }
+
+}
\ No newline at end of file
From 3f14482267e747e5e6e8aaf29e2939f3364b42ae Mon Sep 17 00:00:00 2001
From: peter <729245768@qq.com>
Date: Fri, 3 Mar 2017 20:56:10 +0800
Subject: [PATCH 21/30] =?UTF-8?q?=E4=B8=BAStruts=E6=B7=BB=E5=8A=A0?=
=?UTF-8?q?=E6=B5=8B=E8=AF=95=E7=B1=BB?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../tests/main/coding_170302/StrutsTest.java | 42 +++++++++++++++++++
1 file changed, 42 insertions(+)
create mode 100644 group11/729245768/DataStructure/tests/main/coding_170302/StrutsTest.java
diff --git a/group11/729245768/DataStructure/tests/main/coding_170302/StrutsTest.java b/group11/729245768/DataStructure/tests/main/coding_170302/StrutsTest.java
new file mode 100644
index 0000000000..309bdfc9ba
--- /dev/null
+++ b/group11/729245768/DataStructure/tests/main/coding_170302/StrutsTest.java
@@ -0,0 +1,42 @@
+package main.coding_170302;
+
+import junit.framework.TestCase;
+import org.dom4j.DocumentException;
+import org.junit.Assert;
+import org.junit.Test;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * Created by peter on 2017/3/3.
+ */
+public class StrutsTest extends TestCase {
+ @Test
+ public void testLoginActionSuccess() throws DocumentException {
+ 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 {
+ 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"));
+ }
+
+}
\ No newline at end of file
From 41989a1b2cfe875a61af8b8ce15963f0a3766bc4 Mon Sep 17 00:00:00 2001
From: Pan
Date: Sat, 4 Mar 2017 19:48:34 +0800
Subject: [PATCH 22/30] ArrayUtils Finsh
---
.../org/pan/coding2017/array/ArrayUtil.java | 177 ++++++++++++++----
.../pan/coding2017/array/ArrayUtilTest.java | 21 ++-
2 files changed, 160 insertions(+), 38 deletions(-)
diff --git a/group11/252308879/dataStructure/src/main/java/org/pan/coding2017/array/ArrayUtil.java b/group11/252308879/dataStructure/src/main/java/org/pan/coding2017/array/ArrayUtil.java
index 9fa21a8155..82d7073a0f 100644
--- a/group11/252308879/dataStructure/src/main/java/org/pan/coding2017/array/ArrayUtil.java
+++ b/group11/252308879/dataStructure/src/main/java/org/pan/coding2017/array/ArrayUtil.java
@@ -10,18 +10,19 @@ public class ArrayUtil {
/**
* 给定一个整形数组a , 对该数组的值进行置换
- 例如: a = [7, 9 , 30, 3] , 置换后为 [3, 30, 9,7]
- 如果 a = [7, 9, 30, 3, 4] , 置换后为 [4,3, 30 , 9,7]
+ * 例如: 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){
+ public static void reverseArray(int[] origin) {
// 如果是null, 或者长度小于等于1, 直接返回
- if (origin == null || origin.length <= 1){
+ if (origin == null || origin.length <= 1) {
return;
}
- for (int i = 0; i < origin.length/2; i++) {
+ for (int i = 0; i < origin.length / 2; i++) {
int tmp = origin[i];
origin[i] = origin[origin.length - 1 - i];
origin[origin.length - 1 - i] = tmp;
@@ -32,56 +33,58 @@ public static void reverseArray(int[] 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 static int[] removeZero(int[] oldArray){
+ public static int[] removeZero(int[] oldArray) {
- if (oldArray == null){
+ if (oldArray == null) {
return oldArray;
}
int[] newArray = null;
int count = 0; //统计被移出的数组的个数
for (int i = 0; i < oldArray.length; i++) {
int num = oldArray[i];
- if (num == 0){
+ if (num == 0) {
count++;
- System.arraycopy(oldArray, i+1, oldArray, i, oldArray.length - i - 1);
+ System.arraycopy(oldArray, i + 1, oldArray, i, oldArray.length - i - 1);
i--;
}
}
- if (count == 0){
+ if (count == 0) {
newArray = oldArray;
- }else {
- newArray = new int [oldArray.length - count];
- System.arraycopy(oldArray, 0, newArray, 0 , oldArray.length - count);
+ } else {
+ newArray = new int[oldArray.length - count];
+ System.arraycopy(oldArray, 0, newArray, 0, oldArray.length - count);
}
return newArray;
}
/**
* 不用JavaAPI来做
+ *
* @param oldArray
* @return
*/
- public static int[] removeZero_2(int[] oldArray){
+ public static int[] removeZero_2(int[] oldArray) {
- if (oldArray == null){
+ if (oldArray == null) {
return oldArray;
}
int count = 0;
for (int num : oldArray) {
- if (num == 0){
- count ++;
+ if (num == 0) {
+ count++;
}
}
int[] newArray = new int[oldArray.length - count];
for (int i = 0, j = 0; i < oldArray.length; i++, j++) {
int num = oldArray[i];
- if (num == 0){
+ if (num == 0) {
j--;
- }else {
+ } else {
newArray[j] = num;
}
}
@@ -91,12 +94,43 @@ public static int[] removeZero_2(int[] 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;
+ public static int[] merge(int[] array1, int[] array2) {
+ //先初始化一个array3,但不是最后返回的数组
+ int[] array3 = new int[array1.length + array2.length];
+ int i = 0, j = 0;
+ int array3Size = 0; // 统计实际上合并数组后的大小
+ while (i < array1.length && j < array2.length) {
+ if (array1[i] < array2[j]) {// 如果array1中元素小,则插入到array3中
+ array3[array3Size++] = array1[i];
+ ++i;
+ } else if (array1[i] > array2[j]) {//如果array2中元素小,则插入到array3中
+ array3[array3Size++] = array2[j];
+ ++j;
+ } else {//否则随便插入一个,但是计数要同时加1
+ array3[array3Size++] = array1[i];
+ ++i;
+ ++j;
+ }
+ }
+
+ if (i == array1.length) { //如果array1中全部循环完毕了,那么需要去处理array2中剩余的元素
+ for (int n = j; n < array2.length; n++) {
+ array3[array3Size++] = array2[n];
+ }
+ } else if (j == array2.length) {// 如果array2中全部循环完毕,那么需要去处理array1中剩余的元素
+ for (int n = i; n < array1.length; n++) {
+ array3[array3Size++] = array1[n];
+ }
+ }
+ int[] returnResultArray = new int[array3Size];
+ System.arraycopy(array3, 0, returnResultArray, 0,
+ array3Size);
+ return returnResultArray;
}
/**
@@ -104,12 +138,13 @@ public static int[] merge(int[] array1, int[] array2){
* 注意,老数组的元素在新数组中需要保持
* 例如 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){
- if (oldArray == null){
+ public static int[] grow(int[] oldArray, int size) {
+ if (oldArray == null) {
oldArray = new int[size];
}
oldArray = Arrays.copyOf(oldArray, oldArray.length + size);
@@ -120,50 +155,126 @@ public static int[] grow(int [] oldArray, int size){
* 斐波那契数列为:1,1,2,3,5,8,13,21...... ,给定一个最大值, 返回小于该值的数列
* 例如, max = 15 , 则返回的数组应该为 [1,1,2,3,5,8,13]
* max = 1, 则返回空数组 []
+ *
* @param max
* @return
*/
- public int[] fibonacci(int max){
- return null;
+ public static int[] fibonacci(int max) {
+ if (max <= 1) {
+ return new int[0];
+ }
+ int[] arrays = new int[max / 2];
+ int firstNum = 1; //第一个数字
+ int secondNum = 1; // 第二个数字
+ int arraySize = 0;
+ arrays[arraySize++] = 1; // 初始化第一位
+ while (secondNum < max) {
+ arrays[arraySize++] = secondNum;
+ int tmpNum = secondNum; // 保存第二个数,得会需要付给第一个数
+ secondNum = firstNum + secondNum; // 为前两个数之和
+ firstNum = tmpNum; // 第一个数,后移
+ }
+ return Arrays.copyOf(arrays, arraySize);
}
/**
* 返回小于给定最大值max的所有素数数组
* 例如max = 23, 返回的数组为[2,3,5,7,11,13,17,19]
+ *
* @param max
* @return
*/
- public int[] getPrimes(int max){
- return null;
+ public static int[] getPrimes(int max) {
+ int[] returnResultArray = new int[max + 1];
+ int arraySize = 0;
+ for (int i = 2; i < max; i++) {
+ if (isPrime(i)) {
+ returnResultArray[arraySize++] = i;
+ }
+
+ }
+ if (arraySize == returnResultArray.length) {
+ return returnResultArray;
+ }
+ return Arrays.copyOf(returnResultArray, arraySize);
+ }
+
+ private static boolean isPrime(final int number) {
+ if (number < 2) {
+ return false;
+ }
+ // 因为不可能将一个数除与所有小于它的数字,只要检查到N的平方根就好了。
+ // 但直接开根号还有个精度的问题。这个可能会产生误差。 索性将判断条件写成 i*i<=number
+ for (int i = 2; i * i <= number; i++) {
+ if (number % i == 0) {//查看所有小于number平方根的数,能够被整除
+ return false;
+ }
+ }
+ // 如果一个都没有,那么就是素数
+ return true;
}
/**
* 所谓“完数”, 是指这个数恰好等于它的因子之和,例如6=1+2+3
* 给定一个最大值max, 返回一个数组, 数组中是小于max 的所有完数
+ *
* @param max
* @return
*/
- public int[] getPerfectNumbers(int max){
- return null;
+ public static int[] getPerfectNumbers(int max) {
+ int[] array = new int[max];
+ int arraySize = 0;
+ for (int n = 0; n < max; n++) {
+ int fac,// 被除的因子
+ sum,// 用来统计因子之和
+ num;// 除数的因子,中间变量
+ for (sum = 1, num = n, fac = 2; fac < num; fac++) {
+
+ if (n % fac == 0) {// 如果余数为0,那么说明有因子
+ sum += fac; // 统计因子和
+ num = n / fac; // num=等于除数的最大因子
+ if (num == fac) // 如果最大和最小相等跳出循环
+ break;
+ sum += num; // 再统计因子
+ }
+ }
+
+ if (sum == n) { //因子和与整数相等,那么就是一个完美数
+ if (n != 1) {
+ System.out.println(n + "是一个完全数,其因子为:");
+ }
+ for (fac = 1; fac < n; fac++) {
+ if (n % fac == 0) {// 列出所有的因子
+ System.out.print(fac + " ");
+ }
+ }
+ System.out.println();
+ array[arraySize++] = n; // 放到数组中
+ }
+ }
+ return Arrays.copyOf(array, arraySize);
}
/**
* 用seperator 把数组 array给连接起来
* 例如array= [3,8,9], seperator = "-"
* 则返回值为"3-8-9"
+ *
* @param array
* @param seperator
* @return
*/
- public String join(int[] array, String seperator){
- if (array == null){
+ public static String join(int[] array, String seperator) {
+ if (array == null) {
return null;
}
StringBuilder str = new StringBuilder();
for (int i = 0; i < array.length; i++) {
- if (i == array.length - 1){
-
+ if (i == array.length - 1) {
+ str.append(array[i]);
+ continue;
}
+ str.append(array[i]).append(seperator);
}
return str.toString();
}
diff --git a/group11/252308879/dataStructure/src/test/java/org/pan/coding2017/array/ArrayUtilTest.java b/group11/252308879/dataStructure/src/test/java/org/pan/coding2017/array/ArrayUtilTest.java
index 52434a98ed..29ab6bf6dc 100644
--- a/group11/252308879/dataStructure/src/test/java/org/pan/coding2017/array/ArrayUtilTest.java
+++ b/group11/252308879/dataStructure/src/test/java/org/pan/coding2017/array/ArrayUtilTest.java
@@ -39,7 +39,10 @@ public void reverseArray() throws Exception {
@Test
public void merge() throws Exception {
-
+ int[] a1 = {3, 5, 7,8}, a2 = {4, 5, 6,7};
+ //则 a3 为[3,4,5,6,7,8]
+ int[] merge = ArrayUtil.merge(a1, a2);
+ System.out.println(Arrays.toString(merge));
}
@Test
@@ -54,22 +57,30 @@ public void grow() throws Exception {
@Test
public void fibonacci() throws Exception {
-
+ //max = 15 , 则返回的数组应该为 [1,1,2,3,5,8,13]
+ int[] fibonacci = ArrayUtil.fibonacci(988);
+ System.out.println(Arrays.toString(fibonacci));
}
@Test
public void getPrimes() throws Exception {
-
+ //例如max = 23, 返回的数组为[2,3,5,7,11,13,17,19]
+ int[] primes = ArrayUtil.getPrimes(23);
+ System.out.println(Arrays.toString(primes));
}
@Test
public void getPerfectNumbers() throws Exception {
-
+ int[] primes = ArrayUtil.getPerfectNumbers(10000);
+ System.out.println(Arrays.toString(primes));
}
@Test
public void join() throws Exception {
-
+ int [] array= {3,8,9};
+ String seperator = "-";
+ String result = ArrayUtil.join(array, seperator);
+ System.out.println(result);
}
From 670a639d9b7eb941e2fc2cfd5327ec196438448a Mon Sep 17 00:00:00 2001
From: GZ-RXP <283091182@qq.com>
Date: Sun, 5 Mar 2017 14:32:16 +0800
Subject: [PATCH 23/30] 20170226 assignment:ArrayUtil and litestructs
---
.../src/com/coderising/array/ArrayUtil.java | 303 ++++++++++++++++++
.../com/coderising/array/ArrayUtilTest.java | 151 +++++++++
.../src/com/coderising/litestruts/Action.java | 71 ++++
.../coderising/litestruts/LoginAction.java | 39 +++
.../src/com/coderising/litestruts/Struts.java | 229 +++++++++++++
.../com/coderising/litestruts/StrutsTest.java | 43 +++
.../src/com/coderising/litestruts/View.java | 23 ++
.../src/com/coderising/litestruts/struts.xml | 11 +
.../src/com/coding/basic/ArrayListTest.java | 142 ++++++++
9 files changed, 1012 insertions(+)
create mode 100644 group11/283091182/src/com/coderising/array/ArrayUtil.java
create mode 100644 group11/283091182/src/com/coderising/array/ArrayUtilTest.java
create mode 100644 group11/283091182/src/com/coderising/litestruts/Action.java
create mode 100644 group11/283091182/src/com/coderising/litestruts/LoginAction.java
create mode 100644 group11/283091182/src/com/coderising/litestruts/Struts.java
create mode 100644 group11/283091182/src/com/coderising/litestruts/StrutsTest.java
create mode 100644 group11/283091182/src/com/coderising/litestruts/View.java
create mode 100644 group11/283091182/src/com/coderising/litestruts/struts.xml
create mode 100644 group11/283091182/src/com/coding/basic/ArrayListTest.java
diff --git a/group11/283091182/src/com/coderising/array/ArrayUtil.java b/group11/283091182/src/com/coderising/array/ArrayUtil.java
new file mode 100644
index 0000000000..93c43d9500
--- /dev/null
+++ b/group11/283091182/src/com/coderising/array/ArrayUtil.java
@@ -0,0 +1,303 @@
+package com.coderising.array;
+
+public class ArrayUtil {
+
+ /**
+ * 给定一个整形数组a , 对该数组的值进行置换
+ 例如: a = [7, 9 , 30, 3] , 置换后为 [3, 30, 9,7]
+ 如果 a = [7, 9, 30, 3, 4] , 置换后为 [4,3, 30 , 9,7]
+ * @param origin
+ * @return
+ */
+ public void reverseArray(int[] origin){
+ if(origin==null||origin.length==0){
+ throw new RuntimeException("invalid array argument!");
+ }
+ if(origin.length>1){
+ int temp;
+ for(int i=0;iarray2[pos2]){
+ array3[pos3]=array2[pos2];
+ pos2++;
+ pos3++;
+ }else if(array1[pos1]3){
+ result[pos]=2;
+ pos++;
+ }
+ if(max>4){
+ result[pos]=3;
+ pos++;
+ }
+ for(int i=4;i0){
+ sb.append(seperator);
+ }
+ sb.append(i);
+ }
+ return sb.toString();
+ }
+
+ private void printArray(String msg,int[] array){
+ System.out.print(msg);
+ for(int i=0;i resultMap= new HashMap();
+ public static final String CONST_ACTION = "action";
+ public static final String CONST_NAME = "name";
+ public static final String CONST_CLASS = "class";
+ public static final String CONST_RESULT = "result";
+
+ private String actionName;
+ private String actionClass;
+
+ public Action(){};
+
+ public Action(String actionName,String actionClass){
+ this.actionName = actionName;
+ this.actionClass = actionClass;
+ }
+
+ public void setActionResultJsp(String result,String dispatcherJsp){
+ this.resultMap.put(result, dispatcherJsp);
+ }
+
+ public String getActionResultJsp(String result){
+ return this.resultMap.get(result);
+ }
+
+
+ public String getActionName() {
+ return actionName;
+ }
+
+ public void setActionName(String actionName) {
+ this.actionName = actionName;
+ }
+
+ public String getActionClass() {
+ return actionClass;
+ }
+
+ public void setActionClass(String actionClass) {
+ this.actionClass = actionClass;
+ }
+
+ /**
+ * @param args
+ */
+ public static void main(String[] args) {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public String toString(){
+ StringBuilder sb = new StringBuilder();
+ sb.append(CONST_ACTION).append(":").append(this.actionName).append(",");
+ sb.append(CONST_CLASS).append(":").append(this.actionClass).append(",");
+ sb.append("ResultMap").append(":").append(this.resultMap.toString());
+ return sb.toString();
+ }
+}
diff --git a/group11/283091182/src/com/coderising/litestruts/LoginAction.java b/group11/283091182/src/com/coderising/litestruts/LoginAction.java
new file mode 100644
index 0000000000..1005f35a29
--- /dev/null
+++ b/group11/283091182/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/group11/283091182/src/com/coderising/litestruts/Struts.java b/group11/283091182/src/com/coderising/litestruts/Struts.java
new file mode 100644
index 0000000000..dbe4691938
--- /dev/null
+++ b/group11/283091182/src/com/coderising/litestruts/Struts.java
@@ -0,0 +1,229 @@
+package com.coderising.litestruts;
+
+import java.beans.BeanInfo;
+import java.beans.Introspector;
+import java.beans.PropertyDescriptor;
+import java.io.IOException;
+import java.io.InputStream;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Method;
+import java.util.HashMap;
+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.Element;
+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 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. Load Structs.xml and return a map
+ Map actionMap = loadActionMap();
+
+ //1.Find and initialize action instance to actionName provided
+ Action action = actionMap.get(actionName);
+ Object instance = initializeActionInstance(action.getActionClass(),parameters);
+
+ //2.invoke the execute method and get the result
+ String result = executeAction(instance);
+
+ //3.Extract info for view
+ View view = new View();
+ view.setParameters(extractInfo(instance));
+
+ //4.set dispatcher jsp according to execution result
+ view.setJsp(action.getActionResultJsp(result));
+
+ return view;
+ }
+
+ private static Map loadActionMap() {
+ try {
+
+ InputStream is = Struts.class.getResourceAsStream("struts.xml");
+
+ DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
+ DocumentBuilder builder = factory.newDocumentBuilder();
+ Document document = builder.parse(is);
+ Element struct = document.getDocumentElement();
+
+ return getActions(struct);
+
+ } catch (IOException e) {
+ throw new RuntimeException("Error Reading Configuration XML",e);
+ } catch (ParserConfigurationException e) {
+ throw new RuntimeException("Error Parsing Configuration XML",e);
+ } catch (SAXException e) {
+ throw new RuntimeException("Error Parsing Configuration XML",e);
+ }
+ }
+
+ /**
+ * Parse the XML and construct ActionName:Action map
+ *
+ * @param Element struct, root of the struct xml
+ * @return Map
+ */
+ private static Map getActions(Element struct) {
+
+ Map map = new HashMap();
+
+ NodeList nl = struct.getElementsByTagName(Action.CONST_ACTION);
+
+ for (int i = 0; i < nl.getLength(); i++)
+ {
+ Node actionNode = nl.item(i);
+ // Get action name and corresponding action class from property
+ String actionClass = getAttribute(actionNode,Action.CONST_CLASS);
+ String actionName = getAttribute(actionNode,Action.CONST_NAME);
+
+ Action action = new Action(actionName, actionClass);
+
+ // get results under action
+ NodeList childNodes = actionNode.getChildNodes();
+
+ for (int j = 0; j < childNodes.getLength(); j++)
+ {
+ Node result = childNodes.item(j);
+ //Only accept if Node Type is element and Node name is "result"
+ if ((result.getNodeType() == result.ELEMENT_NODE)
+ && (result.getNodeName() == Action.CONST_RESULT))
+ {
+ String resultName = getAttribute(result,Action.CONST_NAME);
+ String dispatcherJsp = result.getTextContent();
+ action.setActionResultJsp(resultName, dispatcherJsp);
+ }
+ }
+ map.put(action.getActionName(), action);
+ }
+ System.out.println(map);
+ return map;
+ }
+ /**
+ * Get property from given node
+ * @param node
+ * @param key
+ * @return attribute as String
+ */
+ private static String getAttribute(Node node,String key){
+ NamedNodeMap map = node.getAttributes();
+ Node attriNode = map.getNamedItem(key);
+ if(attriNode!=null && attriNode.getNodeType()==Node.ATTRIBUTE_NODE){
+ return attriNode.getNodeValue();
+ }
+ return null;
+ }
+
+ /**
+ * Initialize instance from given class name and parameters map
+ * @param actionClass
+ * @param parameters
+ * @return instance of specified class
+ */
+ private static Object initializeActionInstance(String actionClass,Map parameters){
+ try {
+ Class clazz= Class.forName(actionClass);
+ //Instantiate by calling constructor
+ Constructor constructor = clazz.getConstructor();
+
+ constructor.setAccessible(true);
+ Object instance = constructor.newInstance(new Object[]{});
+
+ //Check class propertes with instrospector
+ BeanInfo beanInfo = Introspector.getBeanInfo(clazz);
+ PropertyDescriptor[] props = beanInfo.getPropertyDescriptors();
+
+ for(PropertyDescriptor prop:props){
+ String propName = prop.getName();
+ Method propSetter = prop.getWriteMethod();
+ //If there is a setter for the property and also there is a value in parameter map
+ //then invoke the setter method to set the values
+ if(propSetter!=null && parameters.containsKey(propName))
+ {
+ propSetter.invoke(instance, parameters.get(propName));
+ }
+ }
+
+ return instance;
+ } catch (Exception e) {
+ e.printStackTrace();
+ throw new RuntimeException("Error initializing instance: ClassName="+actionClass,e);
+ }
+ }
+
+
+ /**
+ * Invoke the "execute" method from the action instance
+ * @param Action instance
+ * @return execute result as String
+ */
+ private static String executeAction(Object instance){
+ Class clazz = instance.getClass();
+ try {
+ //exepct no argument for execute method
+ Method execute = clazz.getMethod("execute", new Class[0]);
+ return (String)execute.invoke(instance, new Object[0]);
+ } catch (Exception e) {
+ throw new RuntimeException("Error executing action,class name="+clazz.getCanonicalName());
+ }
+ }
+
+
+ /**
+ * Extracting Bean info by calling the getting method in the Action instance
+ * @param instance
+ * @return map
+ */
+ private static Map extractInfo(Object instance){
+ Map map = new HashMap();
+ Class clazz = instance.getClass();
+ try{
+ Method[] methods = clazz.getMethods();
+ for(Method method:methods)
+ {
+ String methodName = method.getName();
+ if(methodName.startsWith("get")&&method.getParameterTypes().length==0)
+ {
+ Object methodReturn = method.invoke(instance, new Object[0]);
+ //construct the properties name by getter method name,first character toLower case
+ String propName = methodName.replaceFirst("get", "");
+ char[] propNameCharArr = propName.toCharArray();
+ propNameCharArr[0]=Character.toLowerCase(propNameCharArr[0]);
+
+ map.put(String.valueOf(propNameCharArr), methodReturn);
+ }
+ }
+
+ }catch(Exception e){
+ throw new RuntimeException("Error extracting info from Action Insance,class="+clazz.getCanonicalName(),e);
+ }
+ return map;
+ }
+
+}
diff --git a/group11/283091182/src/com/coderising/litestruts/StrutsTest.java b/group11/283091182/src/com/coderising/litestruts/StrutsTest.java
new file mode 100644
index 0000000000..a44c1878ac
--- /dev/null
+++ b/group11/283091182/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/group11/283091182/src/com/coderising/litestruts/View.java b/group11/283091182/src/com/coderising/litestruts/View.java
new file mode 100644
index 0000000000..0194c681f6
--- /dev/null
+++ b/group11/283091182/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/group11/283091182/src/com/coderising/litestruts/struts.xml b/group11/283091182/src/com/coderising/litestruts/struts.xml
new file mode 100644
index 0000000000..4c6eeabbd4
--- /dev/null
+++ b/group11/283091182/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/group11/283091182/src/com/coding/basic/ArrayListTest.java b/group11/283091182/src/com/coding/basic/ArrayListTest.java
new file mode 100644
index 0000000000..7807fa831e
--- /dev/null
+++ b/group11/283091182/src/com/coding/basic/ArrayListTest.java
@@ -0,0 +1,142 @@
+/**
+ *
+ */
+package com.coding.basic;
+
+import static org.junit.Assert.*;
+
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+/**
+ * @author Administrator
+ *
+ */
+public class ArrayListTest {
+
+ private ArrayList al;
+ /**
+ * @throws java.lang.Exception
+ */
+ @BeforeClass
+ public static void setUpBeforeClass() throws Exception {
+ }
+
+ /**
+ * @throws java.lang.Exception
+ */
+ @AfterClass
+ public static void tearDownAfterClass() throws Exception {
+ }
+
+ /**
+ * @throws java.lang.Exception
+ */
+ @Before
+ public void setUp() throws Exception {
+ System.out.println("SetUp");
+ al= new ArrayList();
+ }
+
+ /**
+ * @throws java.lang.Exception
+ */
+ @After
+ public void tearDown() throws Exception {
+ System.out.println("TearDown");
+ al = null;
+ }
+
+ /**
+ * Test method for {@link com.coding.basic.ArrayList#add(java.lang.Object)}.
+ */
+ @Test
+ public final void testAddObject() {
+ al.add("aaa");
+ al.add("bbb");
+ al.add("ccc");
+ assertEquals("aaa",al.get(0));
+ assertEquals("bbb",al.get(1));
+ assertEquals("ccc",al.get(2));
+ assertEquals(3,al.size());
+ }
+
+ /**
+ * Test method for {@link com.coding.basic.ArrayList#add(int, java.lang.Object)}.
+ */
+ @Test
+ public final void testAddIntObject() {
+ al.add("aaa");
+ al.add(0,"bbb");
+ al.add(1,"ccc");
+ assertEquals("bbb",al.get(0));
+ assertEquals("ccc",al.get(1));
+ assertEquals("aaa",al.get(2));
+ assertEquals(3,al.size());
+ }
+ /**
+ * Test method for {@link com.coding.basic.ArrayList#add(int, java.lang.Object)}.
+ */
+ @Test(expected=IndexOutOfBoundsException.class)
+ public final void testAddIntObjectWithException1() {
+ al.add(-1, "aaa");
+ }
+ /**
+ * Test method for {@link com.coding.basic.ArrayList#add(int, java.lang.Object)}.
+ */
+ @Test(expected=IndexOutOfBoundsException.class)
+ public final void testAddIntObjectWithException2() {
+ al.add("aaa");
+ al.add(1,"bbb");
+ }
+
+ /**
+ * Test method for {@link com.coding.basic.ArrayList#get(int)}.
+ */
+ @Test
+ public final void testGet() {
+ fail("Not yet implemented"); // TODO
+ }
+ /**
+ * Test method for {@link com.coding.basic.ArrayList#get(int)}.
+ */
+ @Test
+ public final void testGetWithException1() {
+ fail("Not yet implemented"); // TODO
+ }
+ /**
+ * Test method for {@link com.coding.basic.ArrayList#get(int)}.
+ */
+ @Test
+ public final void testGetWithException2() {
+ fail("Not yet implemented"); // TODO
+ }
+
+ /**
+ * Test method for {@link com.coding.basic.ArrayList#remove(int)}.
+ */
+ @Test
+ public final void testRemove() {
+ fail("Not yet implemented"); // TODO
+ }
+
+ /**
+ * Test method for {@link com.coding.basic.ArrayList#size()}.
+ */
+ @Test
+ public final void testSize() {
+ fail("Not yet implemented"); // TODO
+ }
+
+ /**
+ * Test method for {@link com.coding.basic.ArrayList#iterator()}.
+ */
+ @Test
+ public final void testIterator() {
+ fail("Not yet implemented"); // TODO
+ }
+
+}
From 0270497f0e8ad83e3c281e28f9d08c3d4aa3c1a6 Mon Sep 17 00:00:00 2001
From: Pan
Date: Sun, 5 Mar 2017 19:39:01 +0800
Subject: [PATCH 24/30] =?UTF-8?q?=E6=9A=82=E5=AD=98?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
group11/252308879/dataStructure/pom.xml | 10 ++
.../coding2017/parsingXML/LoginAction.java | 39 +++++
.../org/pan/coding2017/parsingXML/Struts.java | 34 ++++
.../pan/coding2017/parsingXML/StrutsTest.java | 43 +++++
.../org/pan/coding2017/parsingXML/View.java | 23 +++
.../org/pan/coding2017/utils/Dom4JUtil.java | 50 ++++++
.../org/pan/coding2017/utils/JaxpDomUtil.java | 152 ++++++++++++++++++
.../pan/coding2017/utils/JaxpSAXPUtil.java | 89 ++++++++++
.../src/main/resources/struts.xml | 11 ++
9 files changed, 451 insertions(+)
create mode 100644 group11/252308879/dataStructure/src/main/java/org/pan/coding2017/parsingXML/LoginAction.java
create mode 100644 group11/252308879/dataStructure/src/main/java/org/pan/coding2017/parsingXML/Struts.java
create mode 100644 group11/252308879/dataStructure/src/main/java/org/pan/coding2017/parsingXML/StrutsTest.java
create mode 100644 group11/252308879/dataStructure/src/main/java/org/pan/coding2017/parsingXML/View.java
create mode 100644 group11/252308879/dataStructure/src/main/java/org/pan/coding2017/utils/Dom4JUtil.java
create mode 100644 group11/252308879/dataStructure/src/main/java/org/pan/coding2017/utils/JaxpDomUtil.java
create mode 100644 group11/252308879/dataStructure/src/main/java/org/pan/coding2017/utils/JaxpSAXPUtil.java
create mode 100644 group11/252308879/dataStructure/src/main/resources/struts.xml
diff --git a/group11/252308879/dataStructure/pom.xml b/group11/252308879/dataStructure/pom.xml
index 4b756e4f0d..0bf21adba4 100644
--- a/group11/252308879/dataStructure/pom.xml
+++ b/group11/252308879/dataStructure/pom.xml
@@ -21,5 +21,15 @@
4.12
test
+
+ junit
+ junit
+ RELEASE
+
+
+ dom4j
+ dom4j
+ 1.6.1
+
diff --git a/group11/252308879/dataStructure/src/main/java/org/pan/coding2017/parsingXML/LoginAction.java b/group11/252308879/dataStructure/src/main/java/org/pan/coding2017/parsingXML/LoginAction.java
new file mode 100644
index 0000000000..f38cbcb084
--- /dev/null
+++ b/group11/252308879/dataStructure/src/main/java/org/pan/coding2017/parsingXML/LoginAction.java
@@ -0,0 +1,39 @@
+package org.pan.coding2017.parsingXML;
+
+/**
+ * 这是一个用来展示登录的业务类, 其中的用户名和密码都是硬编码的。
+ * @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/group11/252308879/dataStructure/src/main/java/org/pan/coding2017/parsingXML/Struts.java b/group11/252308879/dataStructure/src/main/java/org/pan/coding2017/parsingXML/Struts.java
new file mode 100644
index 0000000000..50c5dea752
--- /dev/null
+++ b/group11/252308879/dataStructure/src/main/java/org/pan/coding2017/parsingXML/Struts.java
@@ -0,0 +1,34 @@
+package org.pan.coding2017.parsingXML;
+
+import java.util.Map;
+
+
+
+public class Struts {
+
+ public static View runAction(String actionName, Map parameters) {
+
+ /*
+
+ 0. 读取配置文件struts.xml
+
+ 1. 根据actionName找到相对应的class , 例如LoginAction, 通过反射实例化(创建对象)
+ 据parameters中的数据,调用对象的setter方法, 例如parameters中的数据是
+ ("name"="test" , "password"="1234") ,
+ 那就应该调用 setName和setPassword方法
+
+ 2. 通过反射调用对象的exectue 方法, 并获得返回值,例如"success"
+
+ 3. 通过反射找到对象的所有getter方法(例如 getMessage),
+ 通过反射来调用, 把值和属性形成一个HashMap , 例如 {"message": "登录成功"} ,
+ 放到View对象的parameters
+
+ 4. 根据struts.xml中的 配置,以及execute的返回值, 确定哪一个jsp,
+ 放到View对象的jsp字段中。
+
+ */
+
+ return null;
+ }
+
+}
diff --git a/group11/252308879/dataStructure/src/main/java/org/pan/coding2017/parsingXML/StrutsTest.java b/group11/252308879/dataStructure/src/main/java/org/pan/coding2017/parsingXML/StrutsTest.java
new file mode 100644
index 0000000000..ccdacc514c
--- /dev/null
+++ b/group11/252308879/dataStructure/src/main/java/org/pan/coding2017/parsingXML/StrutsTest.java
@@ -0,0 +1,43 @@
+package org.pan.coding2017.parsingXML;
+
+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/group11/252308879/dataStructure/src/main/java/org/pan/coding2017/parsingXML/View.java b/group11/252308879/dataStructure/src/main/java/org/pan/coding2017/parsingXML/View.java
new file mode 100644
index 0000000000..3271ab4ed1
--- /dev/null
+++ b/group11/252308879/dataStructure/src/main/java/org/pan/coding2017/parsingXML/View.java
@@ -0,0 +1,23 @@
+package org.pan.coding2017.parsingXML;
+
+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/group11/252308879/dataStructure/src/main/java/org/pan/coding2017/utils/Dom4JUtil.java b/group11/252308879/dataStructure/src/main/java/org/pan/coding2017/utils/Dom4JUtil.java
new file mode 100644
index 0000000000..6f5287ebaf
--- /dev/null
+++ b/group11/252308879/dataStructure/src/main/java/org/pan/coding2017/utils/Dom4JUtil.java
@@ -0,0 +1,50 @@
+package org.pan.coding2017.utils;
+
+
+
+import java.io.FileWriter;
+import java.io.IOException;
+import java.io.UnsupportedEncodingException;
+
+import org.dom4j.Document;
+import org.dom4j.DocumentException;
+import org.dom4j.io.OutputFormat;
+import org.dom4j.io.SAXReader;
+import org.dom4j.io.XMLWriter;
+
+public class Dom4JUtil {
+
+ public static final String PATH = "src/p1.xml";
+
+
+ public static Document getDocuent(String xmlPath) {
+
+ try {
+ //创建解析器
+ SAXReader saxReader = new SAXReader();
+ //得到Documment
+ Document document = saxReader.read(xmlPath);
+ return document;
+ } catch (DocumentException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+
+ return null;
+ }
+
+ public static void xmlWrite(Document document,String xmlPath){
+
+ try {
+ OutputFormat format = OutputFormat.createPrettyPrint();
+ XMLWriter xmlWriter = new XMLWriter(new FileWriter(xmlPath),format);
+ xmlWriter.write(document);
+ xmlWriter.close();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+
+
+ }
+
+}
diff --git a/group11/252308879/dataStructure/src/main/java/org/pan/coding2017/utils/JaxpDomUtil.java b/group11/252308879/dataStructure/src/main/java/org/pan/coding2017/utils/JaxpDomUtil.java
new file mode 100644
index 0000000000..8db355bbba
--- /dev/null
+++ b/group11/252308879/dataStructure/src/main/java/org/pan/coding2017/utils/JaxpDomUtil.java
@@ -0,0 +1,152 @@
+package org.pan.coding2017.utils;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.dom.DOMSource;
+import javax.xml.transform.stream.StreamResult;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+
+public class JaxpDomUtil {
+ public static final String XMLPATH = "src/person.xml";
+
+ /**
+ * 通过 解析器 获取到 Document
+ * @return
+ */
+ public static Document getDocument() {
+ try {
+ DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory
+ .newInstance();
+ DocumentBuilder documentBuilder = documentBuilderFactory
+ .newDocumentBuilder();
+ Document document = documentBuilder.parse(XMLPATH);
+ return document;
+ } catch (Exception e) {
+ e.printStackTrace();
+
+ }
+ return null;
+ }
+
+ /**
+ * 回写 XML 方法
+ * @param document
+ */
+ public static void tranFormMethod(Document document) {
+ try {
+ TransformerFactory transformerFactory = TransformerFactory
+ .newInstance();
+ Transformer transformer = transformerFactory.newTransformer();
+ transformer.transform(new DOMSource(document), new StreamResult(
+ XMLPATH));
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ /**
+ * 递归调用 获取所有的元素 并打印元素名称
+ * @param node
+ */
+ private static void listElement(Node node) {
+ // 判断是元素类型时才打印
+ if (node.getNodeType() == Node.ELEMENT_NODE) {
+ System.out.println(node.getNodeName());
+ }
+
+ // 获得一层子节点
+ NodeList nodelist = node.getChildNodes();
+ for (int i = 0; i < nodelist.getLength(); i++) {
+ // 得到每一个子节点
+ Node nodeChild = nodelist.item(i);
+
+ // 递归调用
+ listElement(nodeChild);
+ }
+
+ }
+
+ /**
+ * 获取所有的 元素名称
+ */
+ public static void getListElement() {
+
+ Document document = JaxpDomUtil.getDocument();
+ listElement(document);
+ }
+
+ /**
+ * 删除nan节点
+ */
+ public static void delSex() {
+
+ Document document = JaxpDomUtil.getDocument();
+
+ // 获取元素
+ Node nodeSex = document.getElementsByTagName("sex").item(0);
+
+ // 得到父节点
+ Node parent = nodeSex.getParentNode();
+
+ // 通过父节点删除
+ parent.removeChild(nodeSex);
+
+ // 回写XML
+ JaxpDomUtil.tranFormMethod(document);
+
+ }
+
+ /**
+ * 修改 sex 标签的 内容为nv
+ */
+ public static void modifySex() {
+ Document document = JaxpDomUtil.getDocument();
+ Node nodeSex = document.getElementsByTagName("sex").item(0);
+ nodeSex.setTextContent("nv");
+ JaxpDomUtil.tranFormMethod(document);
+
+ }
+
+ /**
+ * 为第一个p1 增加 nv
+ */
+ public static void addSex(){
+ Document document = JaxpDomUtil.getDocument();
+ Node p1Node = document.getElementsByTagName("p1").item(0);
+
+ //通过 Document 创建 Element
+ Element sexElement = document.createElement("sex");
+ sexElement.setTextContent("nv");
+ p1Node.appendChild(sexElement);
+ JaxpDomUtil.tranFormMethod(document);
+
+ }
+
+ /**
+ * 查询xml中第一个name元素的值
+ */
+ public static void selectSin(){
+ Document document = JaxpDomUtil.getDocument();
+ Node nameNode = document.getElementsByTagName("name").item(0);
+ String name = nameNode.getTextContent();
+ System.out.println(name);
+ }
+
+ /**
+ * 查询所有name元素的值
+ */
+ public static void selectAll(){
+ Document document = JaxpDomUtil.getDocument();
+ NodeList nodeList = document.getElementsByTagName("name");
+ for (int i = 0; i < nodeList.getLength(); i++) {
+ System.out.println(nodeList.item(i).getTextContent());
+ }
+ }
+
+}
diff --git a/group11/252308879/dataStructure/src/main/java/org/pan/coding2017/utils/JaxpSAXPUtil.java b/group11/252308879/dataStructure/src/main/java/org/pan/coding2017/utils/JaxpSAXPUtil.java
new file mode 100644
index 0000000000..8756c8ab95
--- /dev/null
+++ b/group11/252308879/dataStructure/src/main/java/org/pan/coding2017/utils/JaxpSAXPUtil.java
@@ -0,0 +1,89 @@
+package org.pan.coding2017.utils;
+
+import javax.xml.parsers.SAXParser;
+import javax.xml.parsers.SAXParserFactory;
+
+import org.xml.sax.Attributes;
+import org.xml.sax.SAXException;
+import org.xml.sax.helpers.DefaultHandler;
+
+public class JaxpSAXPUtil {
+ public static void main(String[] args) {
+ /*
+ * 1、创建解析器工厂
+ * 2、创建解析器
+ * 3、执行 parse 方法
+ *
+ * 4、自己创建一个类、继承DefaultHandler
+ * 5、重写类里面的三个方法
+ */
+
+ try {
+ SAXParserFactory saxParserFactory = SAXParserFactory.newInstance();
+ SAXParser saxParser = saxParserFactory.newSAXParser();
+ saxParser.parse("src/p1.xml",new MyDeafultHandler2() );
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+
+
+ }
+
+}
+
+class MyDeafultHandler1 extends DefaultHandler{
+
+ @Override
+ public void startElement(String uri, String localName, String qName,
+ Attributes attributes) throws SAXException {
+ System.out.println("<"+qName+">");
+ }
+
+ @Override
+ public void characters(char[] ch, int start, int length)
+ throws SAXException {
+ System.out.println(new String(ch,start,length));
+ }
+
+ @Override
+ public void endElement(String uri, String localName, String qName)
+ throws SAXException {
+ System.out.println("<"+qName+"/>");
+ }
+
+}
+
+//实现获取所有的name元素的值
+class MyDeafultHandler2 extends DefaultHandler{
+
+ boolean flag = false;
+ int index = 1;
+
+ @Override
+ public void startElement(String uri, String localName, String qName,
+ Attributes attributes) throws SAXException {
+ //判断qName 是否为 name 元素
+ if("name".equals(qName) && index == 2){
+ flag = true;
+ }
+ }
+
+ @Override
+ public void characters(char[] ch, int start, int length)
+ throws SAXException {
+ if(flag == true){
+ System.out.println(new String(ch, start, length));
+ }
+ }
+
+ @Override
+ public void endElement(String uri, String localName, String qName)
+ throws SAXException {
+ if("name".equals(qName)){
+ flag = false;
+ index++ ;
+ }
+ }
+
+
+}
diff --git a/group11/252308879/dataStructure/src/main/resources/struts.xml b/group11/252308879/dataStructure/src/main/resources/struts.xml
new file mode 100644
index 0000000000..35830922ba
--- /dev/null
+++ b/group11/252308879/dataStructure/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
From 3541d1fb3617c1b3388ca31f0914b15c2fe22206 Mon Sep 17 00:00:00 2001
From: SarahhLee <1059156023@qq.com>
Date: Sun, 5 Mar 2017 20:40:51 +0800
Subject: [PATCH 25/30] struts and array
---
group11/1059156023/Array/.classpath | 6 +
group11/1059156023/Array/.gitignore | 1 +
group11/1059156023/Array/.project | 17 ++
.../Array/src/com/coding/basic/ArrayUtil.java | 158 ++++++++++++++++++
group11/1059156023/struts/.classpath | 8 +
group11/1059156023/struts/.gitignore | 1 +
group11/1059156023/struts/.project | 17 ++
.../src/com/coding/basic/LoginAction.java | 39 +++++
.../struts/src/com/coding/basic/Struts.java | 59 +++++++
.../src/com/coding/basic/StrutsTest.java | 51 ++++++
.../struts/src/com/coding/basic/View.java | 23 +++
.../struts/src/com/coding/basic/struts.xml | 11 ++
12 files changed, 391 insertions(+)
create mode 100644 group11/1059156023/Array/.classpath
create mode 100644 group11/1059156023/Array/.gitignore
create mode 100644 group11/1059156023/Array/.project
create mode 100644 group11/1059156023/Array/src/com/coding/basic/ArrayUtil.java
create mode 100644 group11/1059156023/struts/.classpath
create mode 100644 group11/1059156023/struts/.gitignore
create mode 100644 group11/1059156023/struts/.project
create mode 100644 group11/1059156023/struts/src/com/coding/basic/LoginAction.java
create mode 100644 group11/1059156023/struts/src/com/coding/basic/Struts.java
create mode 100644 group11/1059156023/struts/src/com/coding/basic/StrutsTest.java
create mode 100644 group11/1059156023/struts/src/com/coding/basic/View.java
create mode 100644 group11/1059156023/struts/src/com/coding/basic/struts.xml
diff --git a/group11/1059156023/Array/.classpath b/group11/1059156023/Array/.classpath
new file mode 100644
index 0000000000..fb5011632c
--- /dev/null
+++ b/group11/1059156023/Array/.classpath
@@ -0,0 +1,6 @@
+
+
+
+
+
+
diff --git a/group11/1059156023/Array/.gitignore b/group11/1059156023/Array/.gitignore
new file mode 100644
index 0000000000..ae3c172604
--- /dev/null
+++ b/group11/1059156023/Array/.gitignore
@@ -0,0 +1 @@
+/bin/
diff --git a/group11/1059156023/Array/.project b/group11/1059156023/Array/.project
new file mode 100644
index 0000000000..1b5c14fe3f
--- /dev/null
+++ b/group11/1059156023/Array/.project
@@ -0,0 +1,17 @@
+
+
+ Array
+
+
+
+
+
+ org.eclipse.jdt.core.javabuilder
+
+
+
+
+
+ org.eclipse.jdt.core.javanature
+
+
diff --git a/group11/1059156023/Array/src/com/coding/basic/ArrayUtil.java b/group11/1059156023/Array/src/com/coding/basic/ArrayUtil.java
new file mode 100644
index 0000000000..2b47957623
--- /dev/null
+++ b/group11/1059156023/Array/src/com/coding/basic/ArrayUtil.java
@@ -0,0 +1,158 @@
+package com.coding.basic;
+
+import java.util.Arrays;
+import java.util.HashSet;
+
+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){
+ for (int i = 0; i < origin.length/2; i++) {//前后交换元素
+ int temp = origin[i];
+ origin[i] = origin[origin.length-i-1];
+ origin[origin.length-i-1]= temp;
+ }
+ System.out.println(Arrays.toString(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[] arr = new int[oldArray.length];
+ int count = 0;
+ for(int i=0;i set1 = new HashSet(Arrays.asList(array1));//以array1建立集合
+ HashSet set2 = new HashSet(Arrays.asList(array2));
+ set1.addAll(set2);//求并集
+ Integer[] arr = set1.toArray(new Integer[set1.size()]);//获取并集后的数组
+ Arrays.sort(arr);//数组排序
+ for(int i=0;i
+
+
+
+
+
+
+
diff --git a/group11/1059156023/struts/.gitignore b/group11/1059156023/struts/.gitignore
new file mode 100644
index 0000000000..ae3c172604
--- /dev/null
+++ b/group11/1059156023/struts/.gitignore
@@ -0,0 +1 @@
+/bin/
diff --git a/group11/1059156023/struts/.project b/group11/1059156023/struts/.project
new file mode 100644
index 0000000000..2c00c2049a
--- /dev/null
+++ b/group11/1059156023/struts/.project
@@ -0,0 +1,17 @@
+
+
+ struts
+
+
+
+
+
+ org.eclipse.jdt.core.javabuilder
+
+
+
+
+
+ org.eclipse.jdt.core.javanature
+
+
diff --git a/group11/1059156023/struts/src/com/coding/basic/LoginAction.java b/group11/1059156023/struts/src/com/coding/basic/LoginAction.java
new file mode 100644
index 0000000000..23683995f2
--- /dev/null
+++ b/group11/1059156023/struts/src/com/coding/basic/LoginAction.java
@@ -0,0 +1,39 @@
+package com.coding.basic;
+
+/**
+ * 这是一个用来展示登录的业务类, 其中的用户名和密码都是硬编码的。
+ * @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/group11/1059156023/struts/src/com/coding/basic/Struts.java b/group11/1059156023/struts/src/com/coding/basic/Struts.java
new file mode 100644
index 0000000000..a0d26a207b
--- /dev/null
+++ b/group11/1059156023/struts/src/com/coding/basic/Struts.java
@@ -0,0 +1,59 @@
+package com.coding.basic;
+
+import java.io.File;
+import java.util.List;
+import java.util.Map;
+
+import org.dom4j.Document;
+import org.dom4j.DocumentException;
+import org.dom4j.Element;
+import org.dom4j.io.SAXReader;
+import org.junit.experimental.theories.Theories;
+
+import com.sun.corba.se.impl.orbutil.graph.Node;
+import com.sun.org.apache.bcel.internal.classfile.Attribute;
+
+
+
+public class Struts {
+
+ public static View runAction(String actionName, Map parameters) throws DocumentException {
+ //创建SAXReader对象
+ SAXReader reader = new SAXReader();
+ //读取文件 转换成Document
+ Document document = reader.read(new File("src/com/coding/basic/struts.xml"));
+ //获取根节点元素对象
+ Element root = document.getRootElement();
+ //遍历根节点
+ listNodes(root);
+
+ /*
+
+ 0. 读取配置文件struts.xml
+
+ 1. 根据actionName找到相对应的class , 例如LoginAction, 通过反射实例化(创建对象)
+ 据parameters中的数据,调用对象的setter方法, 例如parameters中的数据是
+ ("name"="test" , "password"="1234") ,
+ 那就应该调用 setName和setPassword方法
+
+ 2. 通过反射调用对象的exectue 方法, 并获得返回值,例如"success"
+
+ 3. 通过反射找到对象的所有getter方法(例如 getMessage),
+ 通过反射来调用, 把值和属性形成一个HashMap , 例如 {"message": "登录成功"} ,
+ 放到View对象的parameters
+
+ 4. 根据struts.xml中的 配置,以及execute的返回值, 确定哪一个jsp,
+ 放到View对象的jsp字段中。
+
+ */
+
+ return null;
+ }
+
+ public static void listNodes(Element node) {
+ String name;
+ List list = node.attributes();
+
+ }
+
+}
diff --git a/group11/1059156023/struts/src/com/coding/basic/StrutsTest.java b/group11/1059156023/struts/src/com/coding/basic/StrutsTest.java
new file mode 100644
index 0000000000..5bac52805d
--- /dev/null
+++ b/group11/1059156023/struts/src/com/coding/basic/StrutsTest.java
@@ -0,0 +1,51 @@
+package com.coding.basic;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.dom4j.DocumentException;
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+public class StrutsTest {
+
+ @Before
+ public void setUp() throws Exception {
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ }
+
+ @Test
+ public void testLoginActionSuccess() throws DocumentException {
+
+ 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 {
+ 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/group11/1059156023/struts/src/com/coding/basic/View.java b/group11/1059156023/struts/src/com/coding/basic/View.java
new file mode 100644
index 0000000000..9e479018c8
--- /dev/null
+++ b/group11/1059156023/struts/src/com/coding/basic/View.java
@@ -0,0 +1,23 @@
+package com.coding.basic;
+
+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/group11/1059156023/struts/src/com/coding/basic/struts.xml b/group11/1059156023/struts/src/com/coding/basic/struts.xml
new file mode 100644
index 0000000000..b3b576c15f
--- /dev/null
+++ b/group11/1059156023/struts/src/com/coding/basic/struts.xml
@@ -0,0 +1,11 @@
+
+
+
+ /jsp/homepage.jsp
+ /jsp/showLogin.jsp
+
+
+ /jsp/welcome.jsp
+ /jsp/error.jsp
+
+
\ No newline at end of file
From 657bcc142e1e0f6a8110cd822e5b837750d4d5d5 Mon Sep 17 00:00:00 2001
From: XMT-CN <542194147@qq.com>
Date: Sun, 5 Mar 2017 20:50:09 +0800
Subject: [PATCH 26/30] myDataStructure
---
group11/542194147/myDataStructure/.classpath | 8 +
group11/542194147/myDataStructure/.gitignore | 1 +
group11/542194147/myDataStructure/.project | 17 ++
.../src/com/coderising/array/ArrayUtil.java | 208 ++++++++++++++++++
.../com/coderising/array/ArrayUtilTest.java | 66 ++++++
.../coderising/litestruts/LoginAction.java | 39 ++++
.../src/com/coderising/litestruts/Struts.java | 94 ++++++++
.../com/coderising/litestruts/StrutsTest.java | 40 ++++
.../src/com/coderising/litestruts/View.java | 24 ++
.../src/com/coderising/litestruts/struts.xml | 11 +
.../src/com/coding/basic/MyArrayList.java | 133 +++++++++++
.../src/com/coding/basic/MyLinkedList.java | 194 ++++++++++++++++
.../src/com/coding/basic/MyList.java | 34 +++
.../src/com/coding/basic/MyQueue.java | 19 ++
.../src/com/coding/basic/MyStack.java | 25 +++
15 files changed, 913 insertions(+)
create mode 100644 group11/542194147/myDataStructure/.classpath
create mode 100644 group11/542194147/myDataStructure/.gitignore
create mode 100644 group11/542194147/myDataStructure/.project
create mode 100644 group11/542194147/myDataStructure/src/com/coderising/array/ArrayUtil.java
create mode 100644 group11/542194147/myDataStructure/src/com/coderising/array/ArrayUtilTest.java
create mode 100644 group11/542194147/myDataStructure/src/com/coderising/litestruts/LoginAction.java
create mode 100644 group11/542194147/myDataStructure/src/com/coderising/litestruts/Struts.java
create mode 100644 group11/542194147/myDataStructure/src/com/coderising/litestruts/StrutsTest.java
create mode 100644 group11/542194147/myDataStructure/src/com/coderising/litestruts/View.java
create mode 100644 group11/542194147/myDataStructure/src/com/coderising/litestruts/struts.xml
create mode 100644 group11/542194147/myDataStructure/src/com/coding/basic/MyArrayList.java
create mode 100644 group11/542194147/myDataStructure/src/com/coding/basic/MyLinkedList.java
create mode 100644 group11/542194147/myDataStructure/src/com/coding/basic/MyList.java
create mode 100644 group11/542194147/myDataStructure/src/com/coding/basic/MyQueue.java
create mode 100644 group11/542194147/myDataStructure/src/com/coding/basic/MyStack.java
diff --git a/group11/542194147/myDataStructure/.classpath b/group11/542194147/myDataStructure/.classpath
new file mode 100644
index 0000000000..ddd63c6d08
--- /dev/null
+++ b/group11/542194147/myDataStructure/.classpath
@@ -0,0 +1,8 @@
+
+
+
+
+
+
+
+
diff --git a/group11/542194147/myDataStructure/.gitignore b/group11/542194147/myDataStructure/.gitignore
new file mode 100644
index 0000000000..ae3c172604
--- /dev/null
+++ b/group11/542194147/myDataStructure/.gitignore
@@ -0,0 +1 @@
+/bin/
diff --git a/group11/542194147/myDataStructure/.project b/group11/542194147/myDataStructure/.project
new file mode 100644
index 0000000000..56bfc21f79
--- /dev/null
+++ b/group11/542194147/myDataStructure/.project
@@ -0,0 +1,17 @@
+
+
+ myDataStructure
+
+
+
+
+
+ org.eclipse.jdt.core.javabuilder
+
+
+
+
+
+ org.eclipse.jdt.core.javanature
+
+
diff --git a/group11/542194147/myDataStructure/src/com/coderising/array/ArrayUtil.java b/group11/542194147/myDataStructure/src/com/coderising/array/ArrayUtil.java
new file mode 100644
index 0000000000..7512dac816
--- /dev/null
+++ b/group11/542194147/myDataStructure/src/com/coderising/array/ArrayUtil.java
@@ -0,0 +1,208 @@
+package com.coderising.array;
+
+import java.util.Arrays;
+
+/**
+ * Array集合工具类
+ * @author 小摩托
+ *
+ */
+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){
+ if(origin.length==0){
+ throw new RuntimeException("数组为空");
+ }
+ int[]exchange=new int[origin.length];
+ for(int i=origin.length-1;i>=0;i--){
+ exchange[origin.length-1-i]=origin[i];
+ }
+ return exchange;
+ }
+
+ /**
+ * 现在有如下的一个数组: 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 exchange[]={};
+ for(int i=0;i parameters) {
+
+ /*
+ 0. 读取配置文件struts.xml
+
+ 1. 根据actionName找到相对应的class , 例如LoginAction, 通过反射实例化(创建对象)
+ 据parameters中的数据,调用对象的setter方法, 例如parameters中的数据是
+ ("name"="test" , "password"="1234") ,
+ 那就应该调用 setName和setPassword方法
+
+ 2. 通过反射调用对象的exectue 方法, 并获得返回值,例如"success"
+
+ 3. 通过反射找到对象的所有getter方法(例如 getMessage),
+ 通过反射来调用, 把值和属性形成一个HashMap , 例如 {"message": "登录成功"} ,
+ 放到View对象的parameters
+
+ 4. 根据struts.xml中的 配置,以及execute的返回值, 确定哪一个jsp,
+ 放到View对象的jsp字段中。
+
+ */
+ View view=new View();
+ try {
+ SAXReader sr=new SAXReader();
+ Document document= sr.read(new File("src/com/coderising/litestruts/struts.xml"));
+ Element root=document.getRootElement();
+ List actions=root.elements("action");
+ for(Iterator it=actions.iterator();it.hasNext();){
+ Element action =it.next();
+ if(action.attribute("name").getText().equals(actionName)){
+ LoginAction loginAction=(LoginAction)Class.forName(
+ action.attribute("class").getText()).newInstance();
+ loginAction.setName(parameters.get("name"));
+ loginAction.setPassword(parameters.get("password"));
+ String loginMsg=loginAction.execute();
+ if(loginMsg.equals("success")){
+ Listresults=action.elements("result");
+ for(it=results.iterator();it.hasNext();){
+ Element result=it.next();
+ if(result.attribute("name").getText().equals("success")){
+ createView(view, loginAction, result);
+ }
+ }
+ }
+ if(loginMsg.equals("fail")){
+ Listresults=action.elements("result");
+ for(it=results.iterator();it.hasNext();){
+ Element result=it.next();
+ if(result.attribute("name").getText().equals("fail")){
+ createView(view, loginAction, result);
+ }
+ }
+ }
+ if(loginMsg.equals("error")){
+ Listresults=action.elements("result");
+ for(it=results.iterator();it.hasNext();){
+ Element result=it.next();
+ if(result.attribute("name").getText().equals("error")){
+ createView(view, loginAction, result);
+ }
+ }
+ }
+ }
+ }
+ } catch (Exception e) {
+ System.out.println("have exception:"+e);
+ e.printStackTrace();
+ }
+ return view;
+ }
+
+ private static void createView(View view, LoginAction loginAction, Element result) {
+ Map msgMap=new HashMap();
+ msgMap.put("message", loginAction.getMessage());
+ view.setParameters(msgMap);
+ view.setJsp(result.getText());
+ }
+
+}
diff --git a/group11/542194147/myDataStructure/src/com/coderising/litestruts/StrutsTest.java b/group11/542194147/myDataStructure/src/com/coderising/litestruts/StrutsTest.java
new file mode 100644
index 0000000000..7fa9e9a4e5
--- /dev/null
+++ b/group11/542194147/myDataStructure/src/com/coderising/litestruts/StrutsTest.java
@@ -0,0 +1,40 @@
+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/group11/542194147/myDataStructure/src/com/coderising/litestruts/View.java b/group11/542194147/myDataStructure/src/com/coderising/litestruts/View.java
new file mode 100644
index 0000000000..610ce0d092
--- /dev/null
+++ b/group11/542194147/myDataStructure/src/com/coderising/litestruts/View.java
@@ -0,0 +1,24 @@
+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/group11/542194147/myDataStructure/src/com/coderising/litestruts/struts.xml b/group11/542194147/myDataStructure/src/com/coderising/litestruts/struts.xml
new file mode 100644
index 0000000000..e5d9aebba8
--- /dev/null
+++ b/group11/542194147/myDataStructure/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/group11/542194147/myDataStructure/src/com/coding/basic/MyArrayList.java b/group11/542194147/myDataStructure/src/com/coding/basic/MyArrayList.java
new file mode 100644
index 0000000000..fbede89fa1
--- /dev/null
+++ b/group11/542194147/myDataStructure/src/com/coding/basic/MyArrayList.java
@@ -0,0 +1,133 @@
+package com.coding.basic;
+
+import java.util.Iterator;
+
+public class MyArrayList implements MyList {
+
+ /**
+ * 数组默认大小
+ */
+ private static final int DEFAULT_SIZE = 10;
+ /**
+ * 储存元素的数组
+ */
+ private Object[] elementData =null;
+ /**
+ * 数组大小指针;
+ */
+ private int capacity;
+ /**
+ * 当前游标
+ */
+ private int current;
+
+ public MyArrayList(int size){
+ if(size<0){
+ throw new RuntimeException("大小不能小于0");
+ }else{
+ this.elementData= new Object[size];
+ this.current=0;
+ this.capacity=size;
+ }
+ }
+
+ public MyArrayList(){
+ this(DEFAULT_SIZE);
+ }
+
+ @Override
+ public void add(Object o) {
+ isOverSize();//判断数组容量是否满足,不满足增加空间
+ this.elementData[current]=o;
+ this.current++;
+ }
+
+ @Override
+ public void add(int index, Object o) {
+ isOverSize();//判断数组容量是否满足,不满足增加空间
+ isOutOfBoundIndex(index);//判断数组下标是否越界
+ System.arraycopy(elementData, index, elementData, index+1, this.elementData.length-index);
+ this.current++;
+ }
+
+ @Override
+ public Object get(int index) {
+ isOutOfBoundIndex(index);//判断数组下标是否越界
+ return this.elementData[index];
+ }
+
+ @Override
+ public Object remove(int index) {
+ isOutOfBoundIndex(index);//判断数组下标是否越界
+ Object o=this.elementData[index];
+ if(this.elementData.length>index+1){
+ System.arraycopy(elementData, index+1, elementData, index,this.elementData.length-index-1);
+ }
+ this.elementData[this.elementData.length-1]=null;
+ return o;
+ }
+
+ public Iterator> iterator(){
+ return new MyArrayListIterator();
+ }
+
+ @Override
+ public int size() {
+ return this.elementData.length;
+ }
+
+ /**
+ * 判断数组容量是否满足,不满足增加空间
+ */
+ private void isOverSize() {
+ if(this.current==this.capacity){
+ this.capacity+=MyArrayList.DEFAULT_SIZE;
+ }
+ Object[]newElementData=new Object[this.capacity];
+ for(int i=0;ithis.capacity||index<0){
+ throw new RuntimeException("数组下标越界");
+ }
+ }
+
+ /**
+ * MyArrayList的迭代器
+ * @author 小摩托
+ *
+ */
+ private class MyArrayListIterator implements Iterator