From 4cd003657ced885f137abd1479bbe4e79982203b Mon Sep 17 00:00:00 2001 From: gongxun Date: Mon, 13 Mar 2017 18:57:44 +0800 Subject: [PATCH 01/32] =?UTF-8?q?=E4=B8=AD=E9=80=94=E6=8F=90=E4=BA=A4?= =?UTF-8?q?=E4=BF=9D=E5=AD=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- group17/785396327/3.12/link/LinkedList.java | 202 ++++++++++++++++++ .../785396327/3.12/link/LinkedListTest.java | 35 +++ 2 files changed, 237 insertions(+) create mode 100644 group17/785396327/3.12/link/LinkedList.java create mode 100644 group17/785396327/3.12/link/LinkedListTest.java diff --git a/group17/785396327/3.12/link/LinkedList.java b/group17/785396327/3.12/link/LinkedList.java new file mode 100644 index 0000000000..1a47b812da --- /dev/null +++ b/group17/785396327/3.12/link/LinkedList.java @@ -0,0 +1,202 @@ +package link; + +import java.util.Iterator; + +/** + * Created by gongxun on 2017/3/13. + */ +public class LinkedList { + private Node head; + private int size = 0; + + public void add(T o) { + if (head == null) + head = new Node(null, o); + else + addLast(o); + } + + private Node getLast() { + Node last = null; + while (head.next != null) { + last = head; + head = head.next; + } + return last; + } + + private Node getNodeIndex(int index) { + if (index > size - 1) + throw new IndexOutOfBoundsException("size : " + size + ", index : " + index); + Node target = head; + for (int i = 0; i < size; i++) { + if (i == index) + return target; + target = target.next; + } + return null; + } + + public void add(int index, T o) { + Node node = getNodeIndex(index - 1); + Node nextNode = node.next; + Node newNode = new Node(node, o); + newNode.next = nextNode; + size++; + } + + public T get(int index) { + Node node = getNodeIndex(index); + return node.data; + } + + public T remove(int index) { + Node prev = getNodeIndex(index - 1); + Node now = getNodeIndex(index); + prev.next = now.next; + size--; + return now.data; + } + + public int size() { + return size; + } + + public void addFirst(T o) { + if (head != null) + head = new Node(null, o); + else { + Node newNode = new Node(head, o); + head = newNode; + } + size++; + } + + public void addLast(T o) { + Node last = getNodeIndex(size - 1); + last.next = new Node(null, o); + size++; + } + + public T removeFirst() { + Node removeNode = head; + if (head != null) + head = head.next; + size--; + return removeNode == null ? null : removeNode.data; + } + + public T removeLast() { + Node last = getNodeIndex(size - 1); + Node prev = getNodeIndex(size - 2); + prev.next = null; + size--; + return last.data; + } + + public Iterator iterator() { + return null; + } + + + private static class Node { + T data; + Node next; + + Node(Node next, T data) { + this.next = next; + this.data = data; + } + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + Node temp = head; + while (temp != null) { + sb.append(temp.data).append("-->"); + temp = temp.next; + } + return sb.toString(); + } + + /** + * 把该链表逆置 + * 例如链表为 3->7->10 , 逆置后变为 10->7->3 + */ + public void reverse() { + + } + + /** + * 删除一个单链表的前半部分 + * 例如:list = 2->5->7->8 , 删除以后的值为 7->8 + * 如果list = 2->5->7->8->10 ,删除以后的值为7,8,10 + */ + public void removeFirstHalf() { + + } + + /** + * 从第i个元素开始, 删除length 个元素 , 注意i从0开始 + * + * @param i + * @param length + */ + public void remove(int i, int length) { + + } + + /** + * 假定当前链表和list均包含已升序排列的整数 + * 从当前链表中取出那些list所指定的元素 + * 例如当前链表 = 11->101->201->301->401->501->601->701 + * listB = 1->3->4->6 + * 返回的结果应该是[101,301,401,601] + * + * @param list + */ + public static int[] getElements(LinkedList list) { + return null; + } + + /** + * 已知链表中的元素以值递增有序排列,并以单链表作存储结构。 + * 从当前链表中中删除在list中出现的元素 + * + * @param list + */ + + public void subtract(LinkedList list) { + + } + + /** + * 已知当前链表中的元素以值递增有序排列,并以单链表作存储结构。 + * 删除表中所有值相同的多余元素(使得操作后的线性表中所有元素的值均不相同) + */ + public void removeDuplicateValues() { + + } + + /** + * 已知链表中的元素以值递增有序排列,并以单链表作存储结构。 + * 试写一高效的算法,删除表中所有值大于min且小于max的元素(若表中存在这样的元素) + * + * @param min + * @param max + */ + public void removeRange(int min, int max) { + + } + + /** + * 假设当前链表和参数list指定的链表均以元素依值递增有序排列(同一表中的元素值各不相同) + * 现要求生成新链表C,其元素为当前链表和list中元素的交集,且表C中的元素有依值递增有序排列 + * + * @param list + */ + public LinkedList intersection(LinkedList list) { + return null; + } +} diff --git a/group17/785396327/3.12/link/LinkedListTest.java b/group17/785396327/3.12/link/LinkedListTest.java new file mode 100644 index 0000000000..58a060b2c8 --- /dev/null +++ b/group17/785396327/3.12/link/LinkedListTest.java @@ -0,0 +1,35 @@ +package link; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +/** + * Created by gongxun on 2017/3/13. + */ +public class LinkedListTest { + private LinkedList linkedList; + + @Before + public void startUp() { + linkedList = new LinkedList(); + } + + @After + public void tearDown() { + + } + + @Test + public void addFirst() { + linkedList.addFirst("1"); + System.out.println(linkedList); + } + + @Test + public void add() { + linkedList.add("1"); + linkedList.add("2"); + System.out.println(linkedList); + } +} From 4849ef4ebe57a037dab01cfc249a047b4211ae09 Mon Sep 17 00:00:00 2001 From: gongxun Date: Mon, 13 Mar 2017 23:26:05 +0800 Subject: [PATCH 02/32] =?UTF-8?q?=E4=BA=8C=E5=88=86=E4=B9=8B=E4=B8=80?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E7=BB=93=E6=9E=84=E5=92=8C=E7=AE=97=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- group17/785396327/3.12/link/LinkedList.java | 46 +++++++++---- .../785396327/3.12/link/LinkedListTest.java | 66 +++++++++++++++++++ 2 files changed, 99 insertions(+), 13 deletions(-) diff --git a/group17/785396327/3.12/link/LinkedList.java b/group17/785396327/3.12/link/LinkedList.java index 1a47b812da..43083aea32 100644 --- a/group17/785396327/3.12/link/LinkedList.java +++ b/group17/785396327/3.12/link/LinkedList.java @@ -10,9 +10,10 @@ public class LinkedList { private int size = 0; public void add(T o) { - if (head == null) + if (head == null) { head = new Node(null, o); - else + size++; + } else addLast(o); } @@ -40,8 +41,7 @@ private Node getNodeIndex(int index) { public void add(int index, T o) { Node node = getNodeIndex(index - 1); Node nextNode = node.next; - Node newNode = new Node(node, o); - newNode.next = nextNode; + node.next = new Node(nextNode, o); size++; } @@ -73,9 +73,7 @@ public void addFirst(T o) { } public void addLast(T o) { - Node last = getNodeIndex(size - 1); - last.next = new Node(null, o); - size++; + add(size, o); } public T removeFirst() { @@ -117,7 +115,7 @@ public String toString() { sb.append(temp.data).append("-->"); temp = temp.next; } - return sb.toString(); + return sb.toString().substring(0, sb.lastIndexOf("-->")); } /** @@ -125,7 +123,15 @@ public String toString() { * 例如链表为 3->7->10 , 逆置后变为 10->7->3 */ public void reverse() { - + Node cur = null; + Node prev = null; + while (head != null) { + cur = head; + head = head.next; + cur.next = prev; + prev = cur; + } + head = cur; } /** @@ -134,7 +140,7 @@ public void reverse() { * 如果list = 2->5->7->8->10 ,删除以后的值为7,8,10 */ public void removeFirstHalf() { - + head = getNodeIndex(size / 2); } /** @@ -144,7 +150,15 @@ public void removeFirstHalf() { * @param length */ public void remove(int i, int length) { - + if (size <= (i + length) || i < 0) + throw new IndexOutOfBoundsException("size : " + size + ", i + length : " + (i + length)); + Node rightNode = getNodeIndex(i + length); + if (i == 0) + head = rightNode; + else { + Node leftNode = getNodeIndex(i - 1); + leftNode.next = rightNode; + } } /** @@ -156,8 +170,14 @@ public void remove(int i, int length) { * * @param list */ - public static int[] getElements(LinkedList list) { - return null; + public Object[] getElements(LinkedList list) { + Object[] result = new Object[list.size]; + if (list != null) { + for (int i = 0; i < list.size; i++) { + result[i] = get(list.get(i)); + } + } + return result; } /** diff --git a/group17/785396327/3.12/link/LinkedListTest.java b/group17/785396327/3.12/link/LinkedListTest.java index 58a060b2c8..6699c5531a 100644 --- a/group17/785396327/3.12/link/LinkedListTest.java +++ b/group17/785396327/3.12/link/LinkedListTest.java @@ -4,6 +4,8 @@ import org.junit.Before; import org.junit.Test; +import java.util.Arrays; + /** * Created by gongxun on 2017/3/13. */ @@ -13,6 +15,10 @@ public class LinkedListTest { @Before public void startUp() { linkedList = new LinkedList(); + linkedList.add("1"); + linkedList.add("2"); + linkedList.add("3"); + linkedList.add(1, "0"); } @After @@ -32,4 +38,64 @@ public void add() { linkedList.add("2"); System.out.println(linkedList); } + + @Test + public void add2() { + linkedList.add("1"); + linkedList.add("2"); + linkedList.add("3"); + linkedList.add(1, "0"); + System.out.println(linkedList); + } + + @Test + public void addLast() { + linkedList.add("1"); + linkedList.addLast("2"); + System.out.println(linkedList); + } + + @Test + public void get() { + String value = linkedList.get(2); + System.out.println(value); + } + + @Test + public void remove() { + String removeValue = linkedList.remove(3); + System.out.println(removeValue); + } + + @Test + public void reverse() { + System.out.println(linkedList); + linkedList.reverse(); + System.out.println(linkedList); + } + + @Test + public void removeFirstHalf() { + System.out.println(linkedList); + linkedList.removeFirstHalf(); + System.out.println(linkedList); + } + + @Test + public void removeByRange() { + System.out.println(linkedList); + linkedList.remove(0, 2); + System.out.println(linkedList); + } + + @Test + public void getElements() { + System.out.println(linkedList); + LinkedList indexList = new LinkedList(); + indexList.add(0); + indexList.add(2); + indexList.add(3); + Object[] elements = linkedList.getElements(indexList); + System.out.println(Arrays.toString(elements)); + } } From 3c81c87340530106e33c709ddac59c097b83b0c6 Mon Sep 17 00:00:00 2001 From: gongxun Date: Tue, 14 Mar 2017 18:55:41 +0800 Subject: [PATCH 03/32] =?UTF-8?q?=E4=B8=AD=E9=80=94=E6=8F=90=E4=BA=A4?= =?UTF-8?q?=E4=BF=9D=E5=AD=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- group17/785396327/3.12/link/LinkedList.java | 39 +++++++++++++++++-- .../785396327/3.12/link/LinkedListTest.java | 16 +++++--- 2 files changed, 47 insertions(+), 8 deletions(-) diff --git a/group17/785396327/3.12/link/LinkedList.java b/group17/785396327/3.12/link/LinkedList.java index 43083aea32..7947519f80 100644 --- a/group17/785396327/3.12/link/LinkedList.java +++ b/group17/785396327/3.12/link/LinkedList.java @@ -1,5 +1,6 @@ package link; +import java.util.Arrays; import java.util.Iterator; /** @@ -96,6 +97,29 @@ public Iterator iterator() { return null; } + private int getIndex(Node node) { + Node temp = head; + int index = 0; + while (temp != null) { + if (temp == node) { + return index; + } + } + return -1; + } + + private int getIndexByData(T data) { + Node temp = head; + int index = 0; + while (temp != null) { + if ((data == null && temp.data == null) || temp.data.equals(data)) + return index; + index++; + temp = temp.next; + } + return -1; + } + private static class Node { T data; @@ -105,6 +129,7 @@ private static class Node { this.next = next; this.data = data; } + } @Override @@ -171,7 +196,7 @@ public void remove(int i, int length) { * @param list */ public Object[] getElements(LinkedList list) { - Object[] result = new Object[list.size]; + Object[] result = new Object[list.size]; if (list != null) { for (int i = 0; i < list.size; i++) { result[i] = get(list.get(i)); @@ -187,8 +212,16 @@ public Object[] getElements(LinkedList list) { * @param list */ - public void subtract(LinkedList list) { - + public void subtract(LinkedList list) { + if (list != null && list.size > 0) { + for (int i = 0; i < list.size; i++) { + int index = getIndexByData(list.get(i)); + if (index != -1) + remove(index); + else + throw new RuntimeException("wrong element of removed list"); + } + } } /** diff --git a/group17/785396327/3.12/link/LinkedListTest.java b/group17/785396327/3.12/link/LinkedListTest.java index 6699c5531a..923623f458 100644 --- a/group17/785396327/3.12/link/LinkedListTest.java +++ b/group17/785396327/3.12/link/LinkedListTest.java @@ -18,7 +18,7 @@ public void startUp() { linkedList.add("1"); linkedList.add("2"); linkedList.add("3"); - linkedList.add(1, "0"); + System.out.println(linkedList); } @After @@ -69,28 +69,24 @@ public void remove() { @Test public void reverse() { - System.out.println(linkedList); linkedList.reverse(); System.out.println(linkedList); } @Test public void removeFirstHalf() { - System.out.println(linkedList); linkedList.removeFirstHalf(); System.out.println(linkedList); } @Test public void removeByRange() { - System.out.println(linkedList); linkedList.remove(0, 2); System.out.println(linkedList); } @Test public void getElements() { - System.out.println(linkedList); LinkedList indexList = new LinkedList(); indexList.add(0); indexList.add(2); @@ -98,4 +94,14 @@ public void getElements() { Object[] elements = linkedList.getElements(indexList); System.out.println(Arrays.toString(elements)); } + + @Test + public void subtract() { + LinkedList indexList = new LinkedList(); + indexList.add("2"); + indexList.add("0"); + linkedList.subtract(indexList); + System.out.println(linkedList); + } + } From 8ca1d722d2630743cf20ad6d5322a043366ab1f2 Mon Sep 17 00:00:00 2001 From: gongxun Date: Tue, 14 Mar 2017 23:30:20 +0800 Subject: [PATCH 04/32] =?UTF-8?q?=E4=B8=AD=E9=80=94=E6=8F=90=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- group17/785396327/3.12/link/LinkedList.java | 18 +++++++++++++++--- .../785396327/3.12/link/LinkedListTest.java | 11 +++++++++++ 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/group17/785396327/3.12/link/LinkedList.java b/group17/785396327/3.12/link/LinkedList.java index 7947519f80..e9925e8ae8 100644 --- a/group17/785396327/3.12/link/LinkedList.java +++ b/group17/785396327/3.12/link/LinkedList.java @@ -1,7 +1,9 @@ package link; -import java.util.Arrays; -import java.util.Iterator; +import list.ArrayList; +import list.List; + +import java.util.*; /** * Created by gongxun on 2017/3/13. @@ -229,7 +231,17 @@ public void subtract(LinkedList list) { * 删除表中所有值相同的多余元素(使得操作后的线性表中所有元素的值均不相同) */ public void removeDuplicateValues() { - + Node temp = head; + List list = new ArrayList(); + int index = 0; + while (temp != null) { + if (list.contains(temp.data)) + remove(index--); + else + list.add(temp.data); + temp = temp.next; + index++; + } } /** diff --git a/group17/785396327/3.12/link/LinkedListTest.java b/group17/785396327/3.12/link/LinkedListTest.java index 923623f458..83df19d4fa 100644 --- a/group17/785396327/3.12/link/LinkedListTest.java +++ b/group17/785396327/3.12/link/LinkedListTest.java @@ -104,4 +104,15 @@ public void subtract() { System.out.println(linkedList); } + @Test + public void removeDuplicateValues() { + linkedList.add("3"); + linkedList.add("7"); + linkedList.add("0"); + linkedList.add("1"); + System.out.println(linkedList); + linkedList.removeDuplicateValues(); + System.out.println(linkedList); + } + } From c2e16447cecea1791f3e9692f36e680677975ea9 Mon Sep 17 00:00:00 2001 From: gongxun Date: Tue, 21 Mar 2017 18:45:14 +0800 Subject: [PATCH 05/32] =?UTF-8?q?=E4=B8=AD=E9=80=94=E6=8F=90=E4=BA=A4?= =?UTF-8?q?=E4=BF=9D=E5=AD=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- group17/785396327/3.12/link/LinkedList.java | 25 ++++++++++++++----- .../785396327/3.12/link/LinkedListTest.java | 15 ++++++++++- 2 files changed, 33 insertions(+), 7 deletions(-) diff --git a/group17/785396327/3.12/link/LinkedList.java b/group17/785396327/3.12/link/LinkedList.java index e9925e8ae8..f9fc09bfef 100644 --- a/group17/785396327/3.12/link/LinkedList.java +++ b/group17/785396327/3.12/link/LinkedList.java @@ -21,10 +21,9 @@ public void add(T o) { } private Node getLast() { - Node last = null; - while (head.next != null) { - last = head; - head = head.next; + Node last = head; + while (last.next != null) { + last = last.next; } return last; } @@ -252,7 +251,21 @@ public void removeDuplicateValues() { * @param max */ public void removeRange(int min, int max) { - + Integer first = (Integer) get(0); + Integer last = (Integer) getLast().data; + if (first > max || last < min) + return; + List indexRange = new ArrayList(); + Node temp = (Node) head; + int index = 0; + while (temp != null) { + if (temp.data >= min && temp.data <= max) { + indexRange.add(index); + } + index++; + temp = temp.next; + } + remove(indexRange.get(0), indexRange.size()); } /** @@ -261,7 +274,7 @@ public void removeRange(int min, int max) { * * @param list */ - public LinkedList intersection(LinkedList list) { + public LinkedList intersection(LinkedList list) { return null; } } diff --git a/group17/785396327/3.12/link/LinkedListTest.java b/group17/785396327/3.12/link/LinkedListTest.java index 83df19d4fa..057844b0c8 100644 --- a/group17/785396327/3.12/link/LinkedListTest.java +++ b/group17/785396327/3.12/link/LinkedListTest.java @@ -18,7 +18,7 @@ public void startUp() { linkedList.add("1"); linkedList.add("2"); linkedList.add("3"); - System.out.println(linkedList); +// System.out.println(linkedList); } @After @@ -115,4 +115,17 @@ public void removeDuplicateValues() { System.out.println(linkedList); } + @Test + public void removeRange() { + LinkedList list = new LinkedList(); + list.add(1); + list.add(3); + list.add(4); + list.add(5); + list.add(7); + System.out.println(list); + list.removeRange(1, 6); + System.out.println(list); + } + } From 743e20deb9c6aa2617fb2271bdeb5f22ed144893 Mon Sep 17 00:00:00 2001 From: wzy <1264835468@qq.com> Date: Tue, 28 Mar 2017 13:13:54 +0800 Subject: [PATCH 06/32] addignore --- group17/1264835468/.gitignore | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/group17/1264835468/.gitignore b/group17/1264835468/.gitignore index 71f96b185c..cba8f5eb06 100644 --- a/group17/1264835468/.gitignore +++ b/group17/1264835468/.gitignore @@ -2,4 +2,6 @@ .classpath .project -.gitignore \ No newline at end of file +.gitignore +/idea/ +.iml \ No newline at end of file From 3ff26bcf3b36b900a5d9b9e7fc597ba2a5851afd Mon Sep 17 00:00:00 2001 From: wzy <1264835468@qq.com> Date: Tue, 28 Mar 2017 13:14:39 +0800 Subject: [PATCH 07/32] addignore2 --- group17/1264835468/.gitignore | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/group17/1264835468/.gitignore b/group17/1264835468/.gitignore index cba8f5eb06..37a597f996 100644 --- a/group17/1264835468/.gitignore +++ b/group17/1264835468/.gitignore @@ -1,7 +1,7 @@ -/bin/ +/bin/ .classpath .project .gitignore -/idea/ +/.idea/ .iml \ No newline at end of file From 9caa1040c4a657627866537971382eae11311643 Mon Sep 17 00:00:00 2001 From: wzy <1264835468@qq.com> Date: Wed, 29 Mar 2017 18:35:00 +0800 Subject: [PATCH 08/32] lru --- group17/1264835468/.gitignore | 2 +- .../ArrayUtil.java | 367 +++++++++--------- .../ArrayUtilTest.java | 200 +++++----- .../LoginAction.java | 84 ++-- .../Struts.java | 198 +++++----- .../StrutsTest.java | 76 ++-- .../View.java | 52 +-- .../XmlParser.java | 144 +++---- .../src/assignment0326/lru/Clock.java | 50 +++ .../src/assignment0326/lru/EmployeeV1.java | 31 ++ .../src/assignment0326/lru/LRUPageFrame.java | 128 ++++++ .../assignment0326/lru/LRUPageFrameTest.java | 34 ++ group17/1264835468/src/struts.xml | 2 +- 13 files changed, 806 insertions(+), 562 deletions(-) rename group17/1264835468/src/{assignment2_26 => assignment0226}/ArrayUtil.java (95%) rename group17/1264835468/src/{assignment2_26 => assignment0226}/ArrayUtilTest.java (95%) rename group17/1264835468/src/{assignment2_26 => assignment0226}/LoginAction.java (91%) rename group17/1264835468/src/{assignment2_26 => assignment0226}/Struts.java (96%) rename group17/1264835468/src/{assignment2_26 => assignment0226}/StrutsTest.java (94%) rename group17/1264835468/src/{assignment2_26 => assignment0226}/View.java (87%) rename group17/1264835468/src/{assignment2_26 => assignment0226}/XmlParser.java (95%) create mode 100644 group17/1264835468/src/assignment0326/lru/Clock.java create mode 100644 group17/1264835468/src/assignment0326/lru/EmployeeV1.java create mode 100644 group17/1264835468/src/assignment0326/lru/LRUPageFrame.java create mode 100644 group17/1264835468/src/assignment0326/lru/LRUPageFrameTest.java diff --git a/group17/1264835468/.gitignore b/group17/1264835468/.gitignore index 37a597f996..1517b9e684 100644 --- a/group17/1264835468/.gitignore +++ b/group17/1264835468/.gitignore @@ -4,4 +4,4 @@ .project .gitignore /.idea/ -.iml \ No newline at end of file +.iml diff --git a/group17/1264835468/src/assignment2_26/ArrayUtil.java b/group17/1264835468/src/assignment0226/ArrayUtil.java similarity index 95% rename from group17/1264835468/src/assignment2_26/ArrayUtil.java rename to group17/1264835468/src/assignment0226/ArrayUtil.java index 89d2a0db29..8b279dca28 100644 --- a/group17/1264835468/src/assignment2_26/ArrayUtil.java +++ b/group17/1264835468/src/assignment0226/ArrayUtil.java @@ -1,183 +1,184 @@ -package assignment2_26; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import java.util.TreeSet; - -public class ArrayUtil { - - /** - * 给定一个整形数组a , 对该数组的值进行置换 例如: a = [7, 9 , 30, 3] , 置换后为 [3, 30, 9,7] 如果 a = - * [7, 9, 30, 3, 4] , 置换后为 [4,3, 30 , 9,7] - * - * @param origin - * @return - */ - public static void reverseArray(int[] origin) { - int mid = origin.length / 2; - for (int i = 0; i < mid; i++) { - int temp = origin[i]; - int reversePosition = origin.length - 1; - origin[i] = origin[reversePosition]; - origin[reversePosition] = temp; - } - } - - /** - * 现在有如下的一个数组: int oldArr[]={1,3,4,5,0,0,6,6,0,5,4,7,6,7,0,5} - * 要求将以上数组中值为0的项去掉,将不为0的值存入一个新的数组,生成的新数组为: {1,3,4,5,6,6,5,4,7,6,7,5} - * - * @param oldArray - * @return - */ - - public static int[] removeZero(int[] oldArray) { - int count = 0; - for (int i : oldArray) { - if (i != 0) - count++; - } - int[] newArray = new int[count]; - int currentPos = 0; - for (int i = 0; i < oldArray.length; i++) { - if (oldArray[i] != 0) - newArray[currentPos++] = oldArray[i]; - } - 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) { - TreeSet set = new TreeSet<>(); - for (Integer integer : array1) { - set.add(integer); - } - for (Integer integer : array2) { - set.add(integer); - } - int[] result = new int[set.size()]; - for (int i = 0; i < result.length; i++) { - result[i] = set.pollFirst(); - } - return result; - } - - /** - * 把一个已经存满数据的数组 oldArray的容量进行扩展, 扩展后的新数据大小为oldArray.length + size - * 注意,老数组的元素在新数组中需要保持 例如 oldArray = [2,3,6] , size = 3,则返回的新数组为 - * [2,3,6,0,0,0] - * - * @param oldArray - * @param size - * @return - */ - public static int[] grow(int[] oldArray, int size) { - return Arrays.copyOf(oldArray, size); - } - - /** - * 斐波那契数列为:1,1,2,3,5,8,13,21...... ,给定一个最大值, 返回小于该值的数列 例如, max = 15 , - * 则返回的数组应该为 [1,1,2,3,5,8,13] max = 1, 则返回空数组 [] - * - * @param max - * @return - */ - public static int[] fibonacci(int max) { - if (max <= 1) - return new int[0]; - List fList = new ArrayList<>(); - fList.add(1); - fList.add(1); - int last = fList.size() - 1; - while (fList.get(last) < max) { - fList.add(fList.get(last) + fList.get(last - 1)); - last++; - } - int[] result = new int[fList.size() - 1]; - for (int i = 0; i < result.length; i++) { - result[i] = fList.get(i); - } - return result; - } - - /** - * 返回小于给定最大值max的所有素数数组 例如max = 23, 返回的数组为[2,3,5,7,11,13,17,19] - * - * @param max - * @return - */ - public static int[] getPrimes(int max) { - boolean[] isPrime = new boolean[max]; - List primes = new ArrayList<>(); - for (int i = 0; i < isPrime.length; i++) { - isPrime[i] = true; - } - for (int i = 2; i * i < max; i++) { - for (int j = i; i * j < max; j++) - isPrime[i * j] = false; - } - for (int i = 2; i < isPrime.length; i++) { - if (isPrime[i]) - primes.add(i); - } - int[] result = new int[primes.size()]; - for (int i = 0; i < result.length; i++) { - result[i] = primes.get(i); - } - return result; - } - - /** - * 所谓“完数”, 是指这个数恰好等于它的因子之和,例如6=1+2+3 给定一个最大值max, 返回一个数组, 数组中是小于max 的所有完数 - * - * @param max - * @return - */ - public static int[] getPerfectNumbers(int max) { - int sum = 0; - ArrayList perfectNumbers = new ArrayList<>(); - for (int i = 1; i < max; i++) { - for (int j = 1; j < i; j++) { - if (i % j == 0) { - sum += j; - } - } - if (sum == i) - perfectNumbers.add(i); - sum = 0; - } - - int[] result = new int[perfectNumbers.size()]; - for (int i = 0; i < result.length; i++) { - result[i] = perfectNumbers.get(i); - } - return result; - } - - /** - * 用seperator 把数组 array给连接起来 例如array= [3,8,9], seperator = "-" 则返回值为"3-8-9" - * - * @param array - * @param s - * @return - */ - public static String join(int[] array, String seperator) { - StringBuilder stringBuilder = new StringBuilder(); - for (int i : array) { - stringBuilder.append(i + seperator); - } - stringBuilder.delete(stringBuilder.length() - seperator.length(), stringBuilder.length()); - - return stringBuilder.toString(); - } - -} +package assignment0226; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.TreeSet; + +public class ArrayUtil { + + /** + * 给定一个整形数组a , 对该数组的值进行置换 例如: a = [7, 9 , 30, 3] , 置换后为 [3, 30, 9,7] 如果 a = + * [7, 9, 30, 3, 4] , 置换后为 [4,3, 30 , 9,7] + * + * @param origin + * @return + */ + public static void reverseArray(int[] origin) { + int mid = origin.length / 2; + for (int i = 0; i < mid; i++) { + int temp = origin[i]; + int reversePosition = origin.length - 1; + origin[i] = origin[reversePosition]; + origin[reversePosition] = temp; + } + } + + /** + * 现在有如下的一个数组: int oldArr[]={1,3,4,5,0,0,6,6,0,5,4,7,6,7,0,5} + * 要求将以上数组中值为0的项去掉,将不为0的值存入一个新的数组,生成的新数组为: {1,3,4,5,6,6,5,4,7,6,7,5} + * + * @param oldArray + * @return + */ + + public static int[] removeZero(int[] oldArray) { + int count = 0; + + for (int i : oldArray) { + if (i != 0) + count++; + } + int[] newArray = new int[count]; + int currentPos = 0; + for (int i = 0; i < oldArray.length; i++) { + if (oldArray[i] != 0) + newArray[currentPos++] = oldArray[i]; + } + 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) { + TreeSet set = new TreeSet<>(); + for (Integer integer : array1) { + set.add(integer); + } + for (Integer integer : array2) { + set.add(integer); + } + int[] result = new int[set.size()]; + for (int i = 0; i < result.length; i++) { + result[i] = set.pollFirst(); + } + return result; + } + + /** + * 把一个已经存满数据的数组 oldArray的容量进行扩展, 扩展后的新数据大小为oldArray.length + size + * 注意,老数组的元素在新数组中需要保持 例如 oldArray = [2,3,6] , size = 3,则返回的新数组为 + * [2,3,6,0,0,0] + * + * @param oldArray + * @param size + * @return + */ + public static int[] grow(int[] oldArray, int size) { + return Arrays.copyOf(oldArray, size); + } + + /** + * 斐波那契数列为:1,1,2,3,5,8,13,21...... ,给定一个最大值, 返回小于该值的数列 例如, max = 15 , + * 则返回的数组应该为 [1,1,2,3,5,8,13] max = 1, 则返回空数组 [] + * + * @param max + * @return + */ + public static int[] fibonacci(int max) { + if (max <= 1) + return new int[0]; + List fList = new ArrayList<>(); + fList.add(1); + fList.add(1); + int last = fList.size() - 1; + while (fList.get(last) < max) { + fList.add(fList.get(last) + fList.get(last - 1)); + last++; + } + int[] result = new int[fList.size() - 1]; + for (int i = 0; i < result.length; i++) { + result[i] = fList.get(i); + } + return result; + } + + /** + * 返回小于给定最大值max的所有素数数组 例如max = 23, 返回的数组为[2,3,5,7,11,13,17,19] + * + * @param max + * @return + */ + public static int[] getPrimes(int max) { + boolean[] isPrime = new boolean[max]; + List primes = new ArrayList<>(); + for (int i = 0; i < isPrime.length; i++) { + isPrime[i] = true; + } + for (int i = 2; i * i < max; i++) { + for (int j = i; i * j < max; j++) + isPrime[i * j] = false; + } + for (int i = 2; i < isPrime.length; i++) { + if (isPrime[i]) + primes.add(i); + } + int[] result = new int[primes.size()]; + for (int i = 0; i < result.length; i++) { + result[i] = primes.get(i); + } + return result; + } + + /** + * 所谓“完数”, 是指这个数恰好等于它的因子之和,例如6=1+2+3 给定一个最大值max, 返回一个数组, 数组中是小于max 的所有完数 + * + * @param max + * @return + */ + public static int[] getPerfectNumbers(int max) { + int sum = 0; + ArrayList perfectNumbers = new ArrayList<>(); + for (int i = 1; i < max; i++) { + for (int j = 1; j < i; j++) { + if (i % j == 0) { + sum += j; + } + } + if (sum == i) + perfectNumbers.add(i); + sum = 0; + } + + int[] result = new int[perfectNumbers.size()]; + for (int i = 0; i < result.length; i++) { + result[i] = perfectNumbers.get(i); + } + return result; + } + + /** + * 用seperator 把数组 array给连接起来 例如array= [3,8,9], seperator = "-" 则返回值为"3-8-9" + * + * @param array + * @param seperator + * @return + */ + public static String join(int[] array, String seperator) { + StringBuilder stringBuilder = new StringBuilder(); + for (int i : array) { + stringBuilder.append(i + seperator); + } + stringBuilder.delete(stringBuilder.length() - seperator.length(), stringBuilder.length()); + + return stringBuilder.toString(); + } + +} diff --git a/group17/1264835468/src/assignment2_26/ArrayUtilTest.java b/group17/1264835468/src/assignment0226/ArrayUtilTest.java similarity index 95% rename from group17/1264835468/src/assignment2_26/ArrayUtilTest.java rename to group17/1264835468/src/assignment0226/ArrayUtilTest.java index 753c026796..1ccd845e1c 100644 --- a/group17/1264835468/src/assignment2_26/ArrayUtilTest.java +++ b/group17/1264835468/src/assignment0226/ArrayUtilTest.java @@ -1,100 +1,100 @@ -package assignment2_26; - -import static org.junit.Assert.assertArrayEquals; -import static org.junit.Assert.assertEquals; - -import org.junit.Test; - -public class ArrayUtilTest { - - @Test - public void testReverseArray() { - int[] array = new int[] {}; - ArrayUtil.reverseArray(array); - assertArrayEquals(new int[] {}, array); - - array = new int[] { 1 }; - ArrayUtil.reverseArray(array); - assertArrayEquals(new int[] { 1 }, array); - - array = new int[] { 1, 2, 3 }; - ArrayUtil.reverseArray(array); - assertArrayEquals(new int[] { 3, 2, 1 }, array); - } - - @Test - public void testRemoveZero() { - int[] array = new int[] {}; - assertArrayEquals(new int[] {}, ArrayUtil.removeZero(array)); - - array = new int[] { 0 }; - assertArrayEquals(new int[] {}, ArrayUtil.removeZero(array)); - - array = new int[] { 1 }; - assertArrayEquals(new int[] { 1 }, ArrayUtil.removeZero(array)); - - array = new int[] { 1, 2, 0, 0, 3 }; - assertArrayEquals(new int[] { 1, 2, 3 }, ArrayUtil.removeZero(array)); - - array = new int[] { 1, 2, 3 }; - assertArrayEquals(new int[] { 1, 2, 3 }, ArrayUtil.removeZero(array)); - } - - @Test - public void testMerge() { - int[] array1 = { 3, 5, 7, 8 }; - int[] array2 = { 4, 5, 6, 7 }; - assertArrayEquals(new int[] { 3, 4, 5, 6, 7, 8 }, ArrayUtil.merge(array1, array2)); - } - - @Test - public void testGrow() { - int[] array = { 3, 5, 7 }; - assertArrayEquals(new int[] { 3, 5, 7, 0, 0 }, ArrayUtil.grow(array, 5)); - assertArrayEquals(new int[] { 3, 5, 7 }, ArrayUtil.grow(array, 3)); - } - - @Test - public void testFibonacci() { - assertArrayEquals(new int[] {}, ArrayUtil.fibonacci(1)); - - assertArrayEquals(new int[] { 1, 1 }, ArrayUtil.fibonacci(2)); - - assertArrayEquals(new int[] { 1, 1, 2, 3, 5, 8, 13 }, ArrayUtil.fibonacci(15)); - } - - @Test - public void testGetPrimes() { - assertArrayEquals(new int[] {}, ArrayUtil.getPrimes(1)); - - assertArrayEquals(new int[] {}, ArrayUtil.getPrimes(2)); - - assertArrayEquals(new int[] { 2 }, ArrayUtil.getPrimes(3)); - - assertArrayEquals(new int[] { 2, 3, 5, 7, 11, 13, 17, 19 }, ArrayUtil.getPrimes(20)); - } - - @Test - public void testGetPerfectNumbers() { - assertArrayEquals(new int[] { 6 }, ArrayUtil.getPerfectNumbers(10)); - - assertArrayEquals(new int[] { 6, 28 }, ArrayUtil.getPerfectNumbers(100)); - - assertArrayEquals(new int[] { 6, 28, 496 }, ArrayUtil.getPerfectNumbers(1000)); - - assertArrayEquals(new int[] { 6, 28, 496, 8128 }, ArrayUtil.getPerfectNumbers(10000)); - - } - - @Test - public void testJoin() { - assertEquals("3-4-5", ArrayUtil.join(new int[] { 3, 4, 5 }, "-")); - - assertEquals("345", ArrayUtil.join(new int[] { 3, 4, 5 }, "")); - - assertEquals("3", ArrayUtil.join(new int[] { 3 }, "")); - - assertEquals("3--4--5", ArrayUtil.join(new int[] { 3, 4, 5 }, "--")); - } - -} +package assignment0226; + +import org.junit.Test; + +import static org.junit.Assert.assertArrayEquals; +import static org.junit.Assert.assertEquals; + +public class ArrayUtilTest { + + @Test + public void testReverseArray() { + int[] array = new int[] {}; + ArrayUtil.reverseArray(array); + assertArrayEquals(new int[] {}, array); + + array = new int[] { 1 }; + ArrayUtil.reverseArray(array); + assertArrayEquals(new int[] { 1 }, array); + + array = new int[] { 1, 2, 3 }; + ArrayUtil.reverseArray(array); + assertArrayEquals(new int[] { 3, 2, 1 }, array); + } + + @Test + public void testRemoveZero() { + int[] array = new int[] {}; + assertArrayEquals(new int[] {}, ArrayUtil.removeZero(array)); + + array = new int[] { 0 }; + assertArrayEquals(new int[] {}, ArrayUtil.removeZero(array)); + + array = new int[] { 1 }; + assertArrayEquals(new int[] { 1 }, ArrayUtil.removeZero(array)); + + array = new int[] { 1, 2, 0, 0, 3 }; + assertArrayEquals(new int[] { 1, 2, 3 }, ArrayUtil.removeZero(array)); + + array = new int[] { 1, 2, 3 }; + assertArrayEquals(new int[] { 1, 2, 3 }, ArrayUtil.removeZero(array)); + } + + @Test + public void testMerge() { + int[] array1 = { 3, 5, 7, 8 }; + int[] array2 = { 4, 5, 6, 7 }; + assertArrayEquals(new int[] { 3, 4, 5, 6, 7, 8 }, ArrayUtil.merge(array1, array2)); + } + + @Test + public void testGrow() { + int[] array = { 3, 5, 7 }; + assertArrayEquals(new int[] { 3, 5, 7, 0, 0 }, ArrayUtil.grow(array, 5)); + assertArrayEquals(new int[] { 3, 5, 7 }, ArrayUtil.grow(array, 3)); + } + + @Test + public void testFibonacci() { + assertArrayEquals(new int[] {}, ArrayUtil.fibonacci(1)); + + assertArrayEquals(new int[] { 1, 1 }, ArrayUtil.fibonacci(2)); + + assertArrayEquals(new int[] { 1, 1, 2, 3, 5, 8, 13 }, ArrayUtil.fibonacci(15)); + } + + @Test + public void testGetPrimes() { + assertArrayEquals(new int[] {}, ArrayUtil.getPrimes(1)); + + assertArrayEquals(new int[] {}, ArrayUtil.getPrimes(2)); + + assertArrayEquals(new int[] { 2 }, ArrayUtil.getPrimes(3)); + + assertArrayEquals(new int[] { 2, 3, 5, 7, 11, 13, 17, 19 }, ArrayUtil.getPrimes(20)); + } + + @Test + public void testGetPerfectNumbers() { + assertArrayEquals(new int[] { 6 }, ArrayUtil.getPerfectNumbers(10)); + + assertArrayEquals(new int[] { 6, 28 }, ArrayUtil.getPerfectNumbers(100)); + + assertArrayEquals(new int[] { 6, 28, 496 }, ArrayUtil.getPerfectNumbers(1000)); + + assertArrayEquals(new int[] { 6, 28, 496, 8128 }, ArrayUtil.getPerfectNumbers(10000)); + + } + + @Test + public void testJoin() { + assertEquals("3-4-5", ArrayUtil.join(new int[] { 3, 4, 5 }, "-")); + + assertEquals("345", ArrayUtil.join(new int[] { 3, 4, 5 }, "")); + + assertEquals("3", ArrayUtil.join(new int[] { 3 }, "")); + + assertEquals("3--4--5", ArrayUtil.join(new int[] { 3, 4, 5 }, "--")); + } + +} diff --git a/group17/1264835468/src/assignment2_26/LoginAction.java b/group17/1264835468/src/assignment0226/LoginAction.java similarity index 91% rename from group17/1264835468/src/assignment2_26/LoginAction.java rename to group17/1264835468/src/assignment0226/LoginAction.java index 3101d322b8..652b5359ac 100644 --- a/group17/1264835468/src/assignment2_26/LoginAction.java +++ b/group17/1264835468/src/assignment0226/LoginAction.java @@ -1,42 +1,42 @@ -package assignment2_26; - -/** - * 这是一个用来展示登录的业务类, 其中的用户名和密码都是硬编码的。 - * - * @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; - } -} +package assignment0226; + +/** + * 这是一个用来展示登录的业务类, 其中的用户名和密码都是硬编码的。 + * + * @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/group17/1264835468/src/assignment2_26/Struts.java b/group17/1264835468/src/assignment0226/Struts.java similarity index 96% rename from group17/1264835468/src/assignment2_26/Struts.java rename to group17/1264835468/src/assignment0226/Struts.java index ad704e0433..457b6ad953 100644 --- a/group17/1264835468/src/assignment2_26/Struts.java +++ b/group17/1264835468/src/assignment0226/Struts.java @@ -1,99 +1,99 @@ -package assignment2_26; - -import java.io.File; -import java.lang.reflect.Constructor; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.util.HashMap; -import java.util.Map; - -public class Struts { - - private static File configFile = new File("./src/struts.xml");; - - 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 - XmlParser phraser = new XmlParser(configFile); - String className = phraser.getClassNameByActionName(actionName); - View view = new View(); - try { - // 1 - Class actionClass = Class.forName(className); - Constructor constructor = actionClass.getConstructor(); - Object instance = constructor.newInstance(); - invokeSetters(actionClass, instance, parameters); - - // 2 - String result = invokeExecute(actionClass, instance); - - // 3 - Map getterResult = invokeGetters(actionClass, instance); - view.setParameters(getterResult); - - // 4 - String resultJsp = phraser.getResultJsp(actionName, result); - view.setJsp(resultJsp); - - } catch (ClassNotFoundException | NoSuchMethodException | SecurityException | InstantiationException - | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { - e.printStackTrace(); - } - - return view; - } - - private static Map invokeGetters(Class actionClass, Object instance) - throws IllegalAccessException, IllegalArgumentException, InvocationTargetException { - Map result = new HashMap<>(); - for (Method method : actionClass.getDeclaredMethods()) { - if (method.getName().matches("get.*")) { - String fieldName = method.getName().substring(3).toLowerCase(); - String value = (String) (method.invoke(instance)); - result.put(fieldName, value); - } - } - return result; - } - - private static String invokeExecute(Class actionClass, Object instance) throws NoSuchMethodException, - SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException { - Method method = actionClass.getDeclaredMethod("execute"); - return (String) method.invoke(instance); - } - - private static void invokeSetters(Class actionClass, Object instance, Map parameters) - throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, - InvocationTargetException { - for (String fieldName : parameters.keySet()) { - invokeSetter(actionClass, instance, fieldName, parameters.get(fieldName)); - } - } - - private static void invokeSetter(Class actionClass, Object instance, String fieldName, String value) - throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, - InvocationTargetException { - String setterName = "set" + Character.toUpperCase(fieldName.charAt(0)) + fieldName.substring(1); - Method setter = actionClass.getDeclaredMethod(setterName, String.class); - setter.invoke(instance, value); - } -} +package assignment0226; + +import java.io.File; +import java.lang.reflect.Constructor; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.util.HashMap; +import java.util.Map; + +public class Struts { + + private static File configFile = new File("./src/struts.xml");; + + 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 + XmlParser phraser = new XmlParser(configFile); + String className = phraser.getClassNameByActionName(actionName); + View view = new View(); + try { + // 1 + Class actionClass = Class.forName(className); + Constructor constructor = actionClass.getConstructor(); + Object instance = constructor.newInstance(); + invokeSetters(actionClass, instance, parameters); + + // 2 + String result = invokeExecute(actionClass, instance); + + // 3 + Map getterResult = invokeGetters(actionClass, instance); + view.setParameters(getterResult); + + // 4 + String resultJsp = phraser.getResultJsp(actionName, result); + view.setJsp(resultJsp); + + } catch (ClassNotFoundException | NoSuchMethodException | SecurityException | InstantiationException + | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { + e.printStackTrace(); + } + + return view; + } + + private static Map invokeGetters(Class actionClass, Object instance) + throws IllegalAccessException, IllegalArgumentException, InvocationTargetException { + Map result = new HashMap<>(); + for (Method method : actionClass.getDeclaredMethods()) { + if (method.getName().matches("get.*")) { + String fieldName = method.getName().substring(3).toLowerCase(); + String value = (String) (method.invoke(instance)); + result.put(fieldName, value); + } + } + return result; + } + + private static String invokeExecute(Class actionClass, Object instance) throws NoSuchMethodException, + SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException { + Method method = actionClass.getDeclaredMethod("execute"); + return (String) method.invoke(instance); + } + + private static void invokeSetters(Class actionClass, Object instance, Map parameters) + throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, + InvocationTargetException { + for (String fieldName : parameters.keySet()) { + invokeSetter(actionClass, instance, fieldName, parameters.get(fieldName)); + } + } + + private static void invokeSetter(Class actionClass, Object instance, String fieldName, String value) + throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, + InvocationTargetException { + String setterName = "set" + Character.toUpperCase(fieldName.charAt(0)) + fieldName.substring(1); + Method setter = actionClass.getDeclaredMethod(setterName, String.class); + setter.invoke(instance, value); + } +} diff --git a/group17/1264835468/src/assignment2_26/StrutsTest.java b/group17/1264835468/src/assignment0226/StrutsTest.java similarity index 94% rename from group17/1264835468/src/assignment2_26/StrutsTest.java rename to group17/1264835468/src/assignment0226/StrutsTest.java index f47410209b..1e677c38b3 100644 --- a/group17/1264835468/src/assignment2_26/StrutsTest.java +++ b/group17/1264835468/src/assignment0226/StrutsTest.java @@ -1,38 +1,38 @@ -package assignment2_26; - -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")); - } -} +package assignment0226; + +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/group17/1264835468/src/assignment2_26/View.java b/group17/1264835468/src/assignment0226/View.java similarity index 87% rename from group17/1264835468/src/assignment2_26/View.java rename to group17/1264835468/src/assignment0226/View.java index e96197fad6..3bd518e451 100644 --- a/group17/1264835468/src/assignment2_26/View.java +++ b/group17/1264835468/src/assignment0226/View.java @@ -1,26 +1,26 @@ -package assignment2_26; - -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; - } -} +package assignment0226; + +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/group17/1264835468/src/assignment2_26/XmlParser.java b/group17/1264835468/src/assignment0226/XmlParser.java similarity index 95% rename from group17/1264835468/src/assignment2_26/XmlParser.java rename to group17/1264835468/src/assignment0226/XmlParser.java index aa34335cb6..4969951082 100644 --- a/group17/1264835468/src/assignment2_26/XmlParser.java +++ b/group17/1264835468/src/assignment0226/XmlParser.java @@ -1,72 +1,72 @@ -package assignment2_26; - -import java.io.File; -import java.io.IOException; -import java.util.ArrayList; -import java.util.List; - -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.Node; -import org.w3c.dom.NodeList; -import org.xml.sax.SAXException; - -public class XmlParser { - private File file; - List actionElements; - - public XmlParser(File file) { - this.file = file; - actionElements = new ArrayList<>(); - getActionsFromFile(); - } - - public String getClassNameByActionName(String actionName) { - Element action = getElementByActionName(actionName); - return action.getAttribute("class"); - } - - public String getResultJsp(String actionName, String resultName) { - Element action = getElementByActionName(actionName); - NodeList results = action.getChildNodes(); - for (int i = 0; i < results.getLength(); i++) { - Node child = results.item(i); - if (child instanceof Element) { - Element result = (Element) child; - if (result.getAttribute("name").equals(resultName)) - return result.getTextContent(); - } - } - throw new RuntimeException("not found result named:" + resultName); - } - - private Element getElementByActionName(String actionName) { - for (Element element : actionElements) { - if (element.getAttribute("name").equals(actionName)) { - return element; - } - } - throw new RuntimeException("no such element named " + actionName); - } - - private void getActionsFromFile() { - DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); - try { - DocumentBuilder builder = factory.newDocumentBuilder(); - Document document = builder.parse(file); - Element root = document.getDocumentElement(); - NodeList children = root.getChildNodes(); - for (int i = 0; i < children.getLength(); i++) { - Node child = children.item(i); - if (child instanceof Element) - actionElements.add((Element) child); - } - } catch (ParserConfigurationException | SAXException | IOException e) { - e.printStackTrace(); - } - } -} +package assignment0226; + +import java.io.File; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +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.Node; +import org.w3c.dom.NodeList; +import org.xml.sax.SAXException; + +public class XmlParser { + private File file; + List actionElements; + + public XmlParser(File file) { + this.file = file; + actionElements = new ArrayList<>(); + getActionsFromFile(); + } + + public String getClassNameByActionName(String actionName) { + Element action = getElementByActionName(actionName); + return action.getAttribute("class"); + } + + public String getResultJsp(String actionName, String resultName) { + Element action = getElementByActionName(actionName); + NodeList results = action.getChildNodes(); + for (int i = 0; i < results.getLength(); i++) { + Node child = results.item(i); + if (child instanceof Element) { + Element result = (Element) child; + if (result.getAttribute("name").equals(resultName)) + return result.getTextContent(); + } + } + throw new RuntimeException("not found result named:" + resultName); + } + + private Element getElementByActionName(String actionName) { + for (Element element : actionElements) { + if (element.getAttribute("name").equals(actionName)) { + return element; + } + } + throw new RuntimeException("no such element named " + actionName); + } + + private void getActionsFromFile() { + DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); + try { + DocumentBuilder builder = factory.newDocumentBuilder(); + Document document = builder.parse(file); + Element root = document.getDocumentElement(); + NodeList children = root.getChildNodes(); + for (int i = 0; i < children.getLength(); i++) { + Node child = children.item(i); + if (child instanceof Element) + actionElements.add((Element) child); + } + } catch (ParserConfigurationException | SAXException | IOException e) { + e.printStackTrace(); + } + } +} diff --git a/group17/1264835468/src/assignment0326/lru/Clock.java b/group17/1264835468/src/assignment0326/lru/Clock.java new file mode 100644 index 0000000000..23198886fe --- /dev/null +++ b/group17/1264835468/src/assignment0326/lru/Clock.java @@ -0,0 +1,50 @@ +package assignment0326.lru; + +/** + * Created by Administrator on 2017/3/29. + */ +public class Clock { + private PageFrame[] pages; + private int capacity; + private int accessPtr; + public Clock(int capacity) { + this.capacity = capacity; + pages = new PageFrame[capacity]; + accessPtr=0; + } + + private void access(int pageNum){ + if (pages[accessPtr] == null) { + pages[accessPtr] = new PageFrame(pageNum); + }else{ + int indexToReplace=findLRUIndex(); + pages[indexToReplace].pageNum=pageNum; + } + accessPtr = (accessPtr + 1) % capacity; + } + + private int findLRUIndex() { + while(pages[accessPtr].shouldGiveAnotherChance()){ + accessPtr = (accessPtr + 1) % capacity; + } + return accessPtr; + } + + private static class PageFrame{ + int pageNum; + boolean accessFlag; + + public PageFrame(int pageNum) { + this.pageNum = pageNum; + accessFlag=true; + } + + public boolean shouldGiveAnotherChance() { + if(accessFlag){ + accessFlag=false; + return true; + } + return false; + } + } +} diff --git a/group17/1264835468/src/assignment0326/lru/EmployeeV1.java b/group17/1264835468/src/assignment0326/lru/EmployeeV1.java new file mode 100644 index 0000000000..bad73de115 --- /dev/null +++ b/group17/1264835468/src/assignment0326/lru/EmployeeV1.java @@ -0,0 +1,31 @@ +package assignment0326.lru; + +/** + * Created by Administrator on 2017/3/29. + */ +public class EmployeeV1 { + + + private String name; + private int age; + + public EmployeeV1(String name, int age) { + this.name = name; + this.age = age; + } + + public void setName(String name) { + this.name = name; + } + public void setAge(int age){ + this.age = age; + } + public void sayHello() { + System.out.println("Hello , this is class Employee "); + } + public static void main(String[] args){ + EmployeeV1 p = new EmployeeV1("Andy",29); + p.sayHello(); + + } +} diff --git a/group17/1264835468/src/assignment0326/lru/LRUPageFrame.java b/group17/1264835468/src/assignment0326/lru/LRUPageFrame.java new file mode 100644 index 0000000000..542075129f --- /dev/null +++ b/group17/1264835468/src/assignment0326/lru/LRUPageFrame.java @@ -0,0 +1,128 @@ +package assignment0326.lru; + +/** + * 用双向链表实现LRU算法 + * @author liuxin + * + */ +public class LRUPageFrame { + + private static class Node { + + Node prev; + Node next; + int pageNum; + Node() { + } + public Node(int pageNum) { + this.pageNum = pageNum; + } + + } + + private int capacity; + + + private Node first;// 链表头 + private Node last;// 链表尾 + + private int size; + public LRUPageFrame(int capacity) { + if(capacity<=0) + throw new IllegalArgumentException("capacity:"+capacity+" < 0"); + this.capacity = capacity; + first=null; + last=null; + size=0; + + } + + /** + * 获取缓存中对象 + * + * @param pageNum + * @return + */ + public void access(int pageNum) { + Node target=search(pageNum); + if (target == null) { + target=new Node(pageNum); + linkFirst(target); + }else{ + moveToFirst(target); + } + if(size>capacity){ + removeLast(); + } + } + + private Node search(int pageNum) { + Node f=first; + while (f!=null){ + if (f.pageNum == pageNum) { + return f; + } + f=f.next; + } + return null; + } + + private void linkFirst(Node target) { + if(first==null){ + first=last=target; + }else { + target.next = first; + first.prev = target; + first = target; + } + size++; + } + + private void moveToFirst(Node target) { + if(target==first){ + return; + } + Node prevOfTarget=target.prev; + prevOfTarget.next=target.next; + + if(target==last) { + last=prevOfTarget; + }else { + target.next.prev = prevOfTarget; + } + + target.next=first; + first.prev=target; + first=target; + + } + + private void removeLast() { + Node prevOfLast=last.prev; + last.prev=null; + last=prevOfLast; + + if(last==null){ + first=null; + }else { + last.next=null; + } + size--; + } + + + public String toString(){ + StringBuilder buffer = new StringBuilder(); + Node node = first; + while(node != null){ + buffer.append(node.pageNum); + + node = node.next; + if(node != null){ + buffer.append(","); + } + } + return buffer.toString(); + } + +} \ No newline at end of file diff --git a/group17/1264835468/src/assignment0326/lru/LRUPageFrameTest.java b/group17/1264835468/src/assignment0326/lru/LRUPageFrameTest.java new file mode 100644 index 0000000000..7a54f54c8d --- /dev/null +++ b/group17/1264835468/src/assignment0326/lru/LRUPageFrameTest.java @@ -0,0 +1,34 @@ +package assignment0326.lru; + +import org.junit.Assert; +import org.junit.Test; + +/** + * Created by Administrator on 2017/3/29. + */ + + +public class LRUPageFrameTest { + + @Test + public void testAccess() { + LRUPageFrame frame = new LRUPageFrame(3); + frame.access(7); + frame.access(0); + frame.access(1); + Assert.assertEquals("1,0,7", frame.toString()); + frame.access(2); + Assert.assertEquals("2,1,0", frame.toString()); + frame.access(0); + Assert.assertEquals("0,2,1", frame.toString()); + frame.access(0); + Assert.assertEquals("0,2,1", frame.toString()); + frame.access(3); + Assert.assertEquals("3,0,2", frame.toString()); + frame.access(0); + Assert.assertEquals("0,3,2", frame.toString()); + frame.access(4); + Assert.assertEquals("4,0,3", frame.toString()); + } + +} \ No newline at end of file diff --git a/group17/1264835468/src/struts.xml b/group17/1264835468/src/struts.xml index ad43b47967..9ba23d1e24 100644 --- a/group17/1264835468/src/struts.xml +++ b/group17/1264835468/src/struts.xml @@ -1,6 +1,6 @@ - + /jsp/homepage.jsp /jsp/showLogin.jsp From e772308943814368d5b7c9fe9a943c872dd5e1ca Mon Sep 17 00:00:00 2001 From: gongxun Date: Thu, 30 Mar 2017 17:12:08 +0800 Subject: [PATCH 09/32] finish half --- group17/785396327/3.12/link/LinkedList.java | 41 ++++++++++++++++++- .../785396327/3.12/link/LinkedListTest.java | 14 +++++++ 2 files changed, 53 insertions(+), 2 deletions(-) diff --git a/group17/785396327/3.12/link/LinkedList.java b/group17/785396327/3.12/link/LinkedList.java index f9fc09bfef..3c3b987f41 100644 --- a/group17/785396327/3.12/link/LinkedList.java +++ b/group17/785396327/3.12/link/LinkedList.java @@ -274,7 +274,44 @@ public void removeRange(int min, int max) { * * @param list */ - public LinkedList intersection(LinkedList list) { - return null; + public LinkedList intersection(LinkedList list) { + LinkedList newList = new LinkedList(); + merge(newList, (Node) this.head, list.head); + return newList; + } + + private void merge(LinkedList newList, Node thisHead, Node mergeHead) { + if (thisHead == null && mergeHead == null) + return; + if (thisHead == null) { + //无论是否包含,有元素的链表必须指向next + if (!newList.contains(mergeHead.data)) + newList.add(mergeHead.data); + mergeHead = mergeHead.next; + merge(newList, null, mergeHead); + } + if (mergeHead == null) { + if (!newList.contains(thisHead.data)) + newList.add(thisHead.data); + thisHead = thisHead.next; + merge(newList, thisHead, null); + } + //要再进行一次判断是因为递归到最底层return之后,返回上一层时某个链表已经为null了,但是上一层还是会将剩下的执行完 + if (thisHead != null && mergeHead != null) { + if (thisHead.data < mergeHead.data && !newList.contains(thisHead.data)) { + newList.add(thisHead.data); + thisHead = thisHead.next; + merge(newList, thisHead, mergeHead); + } else if (!newList.contains(mergeHead.data)) { + newList.add(mergeHead.data); + mergeHead = mergeHead.next; + merge(newList, thisHead, mergeHead); + } + } + } + + private boolean contains(Integer data) { + int index = this.getIndexByData((T) data); + return index != -1; } } diff --git a/group17/785396327/3.12/link/LinkedListTest.java b/group17/785396327/3.12/link/LinkedListTest.java index 057844b0c8..87edc35e99 100644 --- a/group17/785396327/3.12/link/LinkedListTest.java +++ b/group17/785396327/3.12/link/LinkedListTest.java @@ -128,4 +128,18 @@ public void removeRange() { System.out.println(list); } + @Test + public void intersection() { + LinkedList list1 = new LinkedList(); + list1.add(2); + list1.add(3); + list1.add(7); + LinkedList list2 = new LinkedList(); + list2.add(2); + list2.add(3); + list2.add(7); + LinkedList newList = list1.intersection(list2); + System.out.println(newList); + } + } From 39e466276d4b15beedcfb1acbe398b9c931b905a Mon Sep 17 00:00:00 2001 From: gongxun Date: Fri, 31 Mar 2017 17:50:55 +0800 Subject: [PATCH 10/32] finish lru --- group17/785396327/3.26/LRUPageFrame.java | 129 +++++++++++++++++++ group17/785396327/3.26/LRUPageFrameTest.java | 45 +++++++ 2 files changed, 174 insertions(+) create mode 100644 group17/785396327/3.26/LRUPageFrame.java create mode 100644 group17/785396327/3.26/LRUPageFrameTest.java diff --git a/group17/785396327/3.26/LRUPageFrame.java b/group17/785396327/3.26/LRUPageFrame.java new file mode 100644 index 0000000000..35a7f1e8ca --- /dev/null +++ b/group17/785396327/3.26/LRUPageFrame.java @@ -0,0 +1,129 @@ +/** + * Created by william on 2017/3/31. + * 1. 新数据插入到链表头部; + * 2. 每当缓存命中(即缓存数据被访问),则将数据移到链表头部; + * 3. 当链表满的时候,将链表尾部的数据丢弃。 + */ +public class LRUPageFrame { + private static class Node { + + Node prev; + Node next; + int pageNum; + + Node() { + } + + @Override + public String toString() { + return pageNum + ""; + } + } + + private int capacity; + + + private Node first;// 链表头 + private Node last;// 链表尾 + private int size; + + private void removeLast() { + if (last != null) { + if (size == 1) { + first = last = null; + size = 0; + } else { + last = last.prev; + last.next = null; + size--; + } + } + } + + private void remove(Integer pageNum) { + for (Node temp = first; temp != null; temp = temp.next) { + if (temp.pageNum == pageNum) { + unlink(temp); + } + } + } + + private void unlink(Node node) { + final Node prev = node.prev; + final Node next = node.next; + if (prev == null) { + first = next; + size--; + } else if (next == null) + removeLast(); + else { + node.next.prev = prev; + node.prev.next = next; + size--; + } + } + + private void addFirst(Integer pageNum) { + Node newNode = new Node(); + newNode.pageNum = pageNum; + if (first == null) { + first = last = newNode; + } else { + newNode.next = first; + first.prev = newNode; + first = newNode; + //在插入第二个元素时设置last元素的前项 + if (size == 1) last.prev = first; + } + size++; + } + + private boolean contains(Integer pageNum) { + Node temp = first; + while (temp != null) { + if (temp.pageNum == pageNum) + return true; + temp = temp.next; + } + return false; + } + + + public LRUPageFrame(int capacity) { + this.capacity = capacity; + } + + /** + * 获取缓存中对象 + * + * @param pageNum + * @return + */ + public void access(int pageNum) { + //存在链表元素 + if (this.contains(pageNum)) { + remove(pageNum); + addFirst(pageNum); + } else { + //不存在 + if (size == capacity) + removeLast(); + addFirst(pageNum); + } + } + + + public String toString() { + StringBuilder buffer = new StringBuilder(); + Node node = first; + while (node != null) { + buffer.append(node.pageNum); + + node = node.next; + if (node != null) { + buffer.append(","); + } + } + return buffer.toString(); + } +} diff --git a/group17/785396327/3.26/LRUPageFrameTest.java b/group17/785396327/3.26/LRUPageFrameTest.java new file mode 100644 index 0000000000..7b13e17815 --- /dev/null +++ b/group17/785396327/3.26/LRUPageFrameTest.java @@ -0,0 +1,45 @@ +import org.junit.Assert; +import org.junit.Test; + +/** + * Created by william on 2017/3/31. + */ +public class LRUPageFrameTest { + @Test + public void testAccess() { + LRUPageFrame frame = new LRUPageFrame(3); + frame.access(7); + frame.access(0); + frame.access(1); + Assert.assertEquals("1,0,7", frame.toString()); + frame.access(2); + Assert.assertEquals("2,1,0", frame.toString()); + frame.access(0); + Assert.assertEquals("0,2,1", frame.toString()); + frame.access(0); + Assert.assertEquals("0,2,1", frame.toString()); + frame.access(3); + Assert.assertEquals("3,0,2", frame.toString()); + frame.access(0); + Assert.assertEquals("0,3,2", frame.toString()); + frame.access(4); + Assert.assertEquals("4,0,3", frame.toString()); + } + + @Test + public void testInnerMethod() { +// LRUPageFrame lruPageFrame = new LRUPageFrame(3); +// lruPageFrame.access(1); +// lruPageFrame.access(2); +// lruPageFrame.access(3); +// lruPageFrame.access(4); +// System.out.println(lruPageFrame); +// System.out.println(lruPageFrame.last); +// lruPageFrame.removeLast(); +// System.out.println(lruPageFrame); +// lruPageFrame.addFirst(0); +// System.out.println(lruPageFrame); +// lruPageFrame.remove(2); +// System.out.println(lruPageFrame); + } +} From 983e4a849b6f3e6e1a2010da5cf44559154b7ab9 Mon Sep 17 00:00:00 2001 From: mengxz <82427129@qq.com> Date: Fri, 31 Mar 2017 18:07:52 +0800 Subject: [PATCH 11/32] homework of 17/3/26 finished ,first jvm homework and LRU --- .../jvm/loader/ClassFileLoader.java | 104 +++++++++++++ .../com/coderising/jvm/test/EmployeeV1.java | 29 ++++ .../com/coding/basic/LRU/LRUPageFrame.java | 147 ++++++++++++++++++ .../jvm/loader/ClassFileLoaderTest.java | 73 +++++++++ .../coding/basic/LRU/LRUPageFrameTest.java | 29 ++++ 5 files changed, 382 insertions(+) create mode 100644 group17/82427129/JavaUtil/src/main/java/com/coderising/jvm/loader/ClassFileLoader.java create mode 100644 group17/82427129/JavaUtil/src/main/java/com/coderising/jvm/test/EmployeeV1.java create mode 100644 group17/82427129/JavaUtil/src/main/java/com/coding/basic/LRU/LRUPageFrame.java create mode 100644 group17/82427129/JavaUtil/src/test/java/com/coderising/jvm/loader/ClassFileLoaderTest.java create mode 100644 group17/82427129/JavaUtil/src/test/java/com/coding/basic/LRU/LRUPageFrameTest.java diff --git a/group17/82427129/JavaUtil/src/main/java/com/coderising/jvm/loader/ClassFileLoader.java b/group17/82427129/JavaUtil/src/main/java/com/coderising/jvm/loader/ClassFileLoader.java new file mode 100644 index 0000000000..fafac43407 --- /dev/null +++ b/group17/82427129/JavaUtil/src/main/java/com/coderising/jvm/loader/ClassFileLoader.java @@ -0,0 +1,104 @@ +package com.coderising.jvm.loader; + +import java.io.ByteArrayOutputStream; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +public class ClassFileLoader { + private static final int BUFFERSIZE = 1024; + private List clzPaths = new ArrayList(); + + public byte[] readBinaryCode(String className) { + if (clzPaths.size()<=0){ + return null; + } + for (int i = 0; i < clzPaths.size(); i++) { + String path = clzPaths.get(i) + convertName(className); + File f = new File(path); + if(f.exists()){ + try { + return readFile(f); + } catch (FileNotFoundException e) { + e.printStackTrace(); + } + }else{ + f = null; + continue; + } + } + System.err.println("classpath:" +getClassPath()+ "class:" + convertName(className)+" not found."); + return null; + } + /** + * 文件读取二进制字节流 + * @param f + * @return + * @throws FileNotFoundException + */ + private byte[] readFile(File f) throws FileNotFoundException { + FileInputStream fis = new FileInputStream(f); + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + byte[] b = new byte[BUFFERSIZE]; + try { + int len = 0; + while((len = fis.read(b))!=-1){ + baos.write(b,0,len); + } + } catch (IOException e) { + e.printStackTrace(); + } finally{ + try { + fis.close(); + baos.flush(); + baos.close(); + } catch (IOException e) { + e.printStackTrace(); + } + + } + return baos.toByteArray(); + } + + public void addClassPath(String path) { + clzPaths.add(path); + } + + public String getClassPath() { + StringBuilder sb = new StringBuilder(); + for (int i = 0; i < clzPaths.size(); i++) { + sb.append(clzPaths.get(i)).append(";"); + } + int len = sb.length(); + if(len!=0){ + sb.deleteCharAt(len-1); + } + return sb.toString(); + } + + /** + * convert className to FilePath style className
+ * For example:com.sun.lang to \com\sun\lang + * + * @param className + * @return FilePath style className + */ + private String convertName(String className) { + StringBuilder sb = new StringBuilder(); + String[] pack = className.split("\\."); + for (int i = 0; i < pack.length; i++) { + sb.append("\\").append(pack[i]); + } + sb.append(".class"); + return sb.toString(); + } + + public static void main(String[] args) { + String d = "com.taiji.array.Load"; + ClassFileLoader cc = new ClassFileLoader(); + System.out.print(cc.convertName(d)); + } +} diff --git a/group17/82427129/JavaUtil/src/main/java/com/coderising/jvm/test/EmployeeV1.java b/group17/82427129/JavaUtil/src/main/java/com/coderising/jvm/test/EmployeeV1.java new file mode 100644 index 0000000000..70ec469ee6 --- /dev/null +++ b/group17/82427129/JavaUtil/src/main/java/com/coderising/jvm/test/EmployeeV1.java @@ -0,0 +1,29 @@ +package com.coderising.jvm.test; + +public class EmployeeV1 { + private String name; + private int age; + + public EmployeeV1(String name, int age) { + this.name = name; + this.age = age; + } + + public void setName(String name) { + this.name = name; + } + + public void setAge(int age) { + this.age = age; + } + + public void sayHello() { + System.out.println("Hello , this is class Employee "); + } + + public static void main(String[] args) { + EmployeeV1 p = new EmployeeV1("Andy", 29); + p.sayHello(); + + } +} diff --git a/group17/82427129/JavaUtil/src/main/java/com/coding/basic/LRU/LRUPageFrame.java b/group17/82427129/JavaUtil/src/main/java/com/coding/basic/LRU/LRUPageFrame.java new file mode 100644 index 0000000000..45638bd851 --- /dev/null +++ b/group17/82427129/JavaUtil/src/main/java/com/coding/basic/LRU/LRUPageFrame.java @@ -0,0 +1,147 @@ +package com.coding.basic.LRU; + +public class LRUPageFrame { + private int capacity; + private Node first;// 链表头 + private Node last;// 链表尾 + private int length = 0; + + public LRUPageFrame(int capacity) { + this.capacity = capacity; + } + + /** + * 获取缓存中对象 + * + * @param key + * @return + */ + public void access(int pageNum) { + // this loop select for pageNum,grow it first when 'found'. + for (Node n = first; n != null; n = n.next) { + if (n.pageNum == pageNum) { + growFirst(n); + return; + } + } + // if didn't found it + if (ensureFull()) { + removeLast(); + } + add(pageNum); + } + + private void add(int pageNum) { + if (isEmpty()) { + Node newNode = new Node(null, null, pageNum); + first = newNode; + last = newNode; + length++; + } else { + addToFirst(pageNum); + } + } + + private void addToFirst(int pageNum) { + Node newNode = new Node(null, null, pageNum); + newNode.next = first; + first.prev = newNode; + first = newNode; + length++; + } + + /** + * ensure the LRUPageFrame is full or Not + * + * @return if full return true,else false + */ + private boolean ensureFull() { + if (length < capacity) { + return false; + } else { + return true; + } + } + + /** + * grow the Node'position to first + * + * @param n + */ + private void growFirst(Node n) { + // if the node is already first ,return. + if (first.pageNum == n.pageNum) { + return; + } + remove(n); + addToFirst(n.pageNum); + } + + private void remove(Node n) { + if (isEmpty()) { + return; + } + if (n.next == null) { + removeLast(); + return; + } + if (n.prev == null) { + removeFirst(); + return; + } + Node prev = n.prev; + Node next = n.next; + n.next = null; + n.prev = null; + prev.next = next; + next.prev = prev; + length--; + } + + private void removeFirst() { + Node next = first.next; + first.next = null; + first = next; + } + + private void removeLast() { + Node prev = last.prev; + prev.next = null; + last.prev = null; + last = prev; + length--; + } + /** + * ensure the LRUPageFrame is empty or Not. + * @return + */ + public boolean isEmpty() { + return length < 1; + } + + public String toString() { + StringBuilder buffer = new StringBuilder(); + Node node = first; + while (node != null) { + buffer.append(node.pageNum); + + node = node.next; + if (node != null) { + buffer.append(","); + } + } + return buffer.toString(); + } + + private static class Node { + Node prev; + Node next; + int pageNum; + + Node(Node prev, Node next, int pageNum) { + this.prev = prev; + this.next = next; + this.pageNum = pageNum; + } + } +} diff --git a/group17/82427129/JavaUtil/src/test/java/com/coderising/jvm/loader/ClassFileLoaderTest.java b/group17/82427129/JavaUtil/src/test/java/com/coderising/jvm/loader/ClassFileLoaderTest.java new file mode 100644 index 0000000000..e2ed056cc3 --- /dev/null +++ b/group17/82427129/JavaUtil/src/test/java/com/coderising/jvm/loader/ClassFileLoaderTest.java @@ -0,0 +1,73 @@ +package com.coderising.jvm.loader; + +import org.junit.After; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +public class ClassFileLoaderTest { + static String path1 = "C:\\Users\\liuxin\\git\\coding2017\\liuxin\\mini-jvm\\bin"; + static String path2 = "D:\\workProgram\\GitRepo\\coding2017\\group17\\82427129\\JavaUtil\\target\\classes"; + @Before + public void setUp() throws Exception { + } + + @After + public void tearDown() throws Exception { + } + + @Test + public void testClassFileLength() { + + ClassFileLoader loader = new ClassFileLoader(); + loader.addClassPath(path2); + + String className = "com.coderising.jvm.test.EmployeeV1"; + + byte[] byteCodes = loader.readBinaryCode(className); + + // 注意:这个字节数可能和你的JVM版本有关系, 你可以看看编译好的类到底有多大 + Assert.assertEquals(1056, byteCodes.length); + + } + + @Test + public void testGetClassPath() { + ClassFileLoader loader = new ClassFileLoader(); + loader.addClassPath(path1); + loader.addClassPath(path2); + + String clzPath = loader.getClassPath(); + + Assert.assertEquals(path1+";"+path2,clzPath); + } + + @Test + public void testMagicNumber(){ + ClassFileLoader loader = new ClassFileLoader(); + loader.addClassPath(path2); + String className = "com.coderising.jvm.test.EmployeeV1"; + byte[] byteCodes = loader.readBinaryCode(className); + byte[] codes = new byte[]{byteCodes[0],byteCodes[1],byteCodes[2],byteCodes[3]}; + + + String acctualValue = this.byteToHexString(codes); + + Assert.assertEquals("cafebabe", acctualValue); + } + + private String byteToHexString(byte[] codes) { + StringBuffer buffer = new StringBuffer(); + for (int i = 0; i < codes.length; i++) { + byte b = codes[i]; + int value = b & 0xFF; + String strHex = Integer.toHexString(value); + if (strHex.length() < 2) { + strHex = "0" + strHex; + } + buffer.append(strHex); + } + return buffer.toString(); + } + +} diff --git a/group17/82427129/JavaUtil/src/test/java/com/coding/basic/LRU/LRUPageFrameTest.java b/group17/82427129/JavaUtil/src/test/java/com/coding/basic/LRU/LRUPageFrameTest.java new file mode 100644 index 0000000000..e05d4b750e --- /dev/null +++ b/group17/82427129/JavaUtil/src/test/java/com/coding/basic/LRU/LRUPageFrameTest.java @@ -0,0 +1,29 @@ +package com.coding.basic.LRU; + +import org.junit.Assert; +import org.junit.Test; + +public class LRUPageFrameTest { + + @Test + public void testAccess() { + LRUPageFrame frame = new LRUPageFrame(3); + frame.access(7); + frame.access(0); + frame.access(1); + Assert.assertEquals("1,0,7", frame.toString()); + frame.access(2); + Assert.assertEquals("2,1,0", frame.toString()); + frame.access(0); + Assert.assertEquals("0,2,1", frame.toString()); + frame.access(0); + Assert.assertEquals("0,2,1", frame.toString()); + frame.access(3); + Assert.assertEquals("3,0,2", frame.toString()); + frame.access(0); + Assert.assertEquals("0,3,2", frame.toString()); + frame.access(4); + Assert.assertEquals("4,0,3", frame.toString()); + } + +} From d9efccd000a74dc3a2bd74bc0dae91b1e4db36c1 Mon Sep 17 00:00:00 2001 From: luoziyihao Date: Fri, 31 Mar 2017 23:12:54 +0800 Subject: [PATCH 12/32] com --- .../java/com/coding/api/ArrayListTest.java | 25 ------------------- .../1204187480/code/homework/parent/pom.xml | 9 +++++++ 2 files changed, 9 insertions(+), 25 deletions(-) delete mode 100644 group17/1204187480/code/homework/basic/src/test/java/com/coding/api/ArrayListTest.java diff --git a/group17/1204187480/code/homework/basic/src/test/java/com/coding/api/ArrayListTest.java b/group17/1204187480/code/homework/basic/src/test/java/com/coding/api/ArrayListTest.java deleted file mode 100644 index 95f0085b66..0000000000 --- a/group17/1204187480/code/homework/basic/src/test/java/com/coding/api/ArrayListTest.java +++ /dev/null @@ -1,25 +0,0 @@ -package com.coding.api; - -import org.junit.Test; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -/** - * Created by luoziyihao on 2/25/17. - */ -public class ArrayListTest { - - private final Logger logger = LoggerFactory.getLogger(this.getClass()); - - @Test - public void testAdd(){ - List list = new ArrayList(Arrays.asList(0, 1, 2, 3)); - logger.info("list={}", list); - list.add(5, 2); - logger.info("list={}", list); - } -} diff --git a/group17/1204187480/code/homework/parent/pom.xml b/group17/1204187480/code/homework/parent/pom.xml index 7af48c6fed..ace9bf9cc5 100644 --- a/group17/1204187480/code/homework/parent/pom.xml +++ b/group17/1204187480/code/homework/parent/pom.xml @@ -92,4 +92,13 @@ + + + + org.apache.maven.plugins + maven-surefire-report-plugin + 2.19.1 + + + \ No newline at end of file From 12c5a2a026ac6a30d30a54c12451c4ad165d92ce Mon Sep 17 00:00:00 2001 From: earliest Date: Sun, 2 Apr 2017 01:13:03 -0700 Subject: [PATCH 13/32] add jvm homework --- group17/1282579502/src/com/coding/basic/LinkedList.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/group17/1282579502/src/com/coding/basic/LinkedList.java b/group17/1282579502/src/com/coding/basic/LinkedList.java index 55db7e97bc..8f6ce0a9d3 100644 --- a/group17/1282579502/src/com/coding/basic/LinkedList.java +++ b/group17/1282579502/src/com/coding/basic/LinkedList.java @@ -2,9 +2,9 @@ public class LinkedList implements List { - private Node head = null; - private Node tail = null; - private int size = 0; + protected Node head = null; + protected Node tail = null; + protected int size = 0; public void add(Object o){ if(head == null){ @@ -109,7 +109,7 @@ public Iterator iterator(){ return new LinkedListIterator(this); } - private class Node{ + protected class Node{ public Object data = null; public Node next = null; public Node(Object o){ From 459904fd14482ada91f91cc32dd9567baa276c99 Mon Sep 17 00:00:00 2001 From: earliest Date: Sun, 2 Apr 2017 01:13:57 -0700 Subject: [PATCH 14/32] add jvm --- .../jvm/loader/ClassFileLoader.java | 86 +++++++++++++++ .../jvm/test/ClassFileloaderTest.java | 103 ++++++++++++++++++ .../com/coderising/jvm/test/EmployeeV1.java | 28 +++++ 3 files changed, 217 insertions(+) create mode 100644 group17/1282579502/src/com/coderising/jvm/loader/ClassFileLoader.java create mode 100644 group17/1282579502/src/com/coderising/jvm/test/ClassFileloaderTest.java create mode 100644 group17/1282579502/src/com/coderising/jvm/test/EmployeeV1.java diff --git a/group17/1282579502/src/com/coderising/jvm/loader/ClassFileLoader.java b/group17/1282579502/src/com/coderising/jvm/loader/ClassFileLoader.java new file mode 100644 index 0000000000..6d669e294f --- /dev/null +++ b/group17/1282579502/src/com/coderising/jvm/loader/ClassFileLoader.java @@ -0,0 +1,86 @@ +package com.coderising.jvm.loader; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; + + + +public class ClassFileLoader { + + private List clzPaths = new ArrayList(); + + public byte[] readBinaryCode(String className) { + String classPath = convertToFilePath(className); + File targetFile = null; + for(int i = 0; i< clzPaths.size(); i++){ + String fullPath = clzPaths.get(i)+File.separator+classPath; + System.out.println("path: " + fullPath); + File temp = new File(fullPath); + if(temp.exists()) { + targetFile = temp; + break; + } + } + + if(targetFile != null){ + System.out.println("targetFile: " + targetFile.getAbsolutePath()); + } + long fileLength = targetFile.length(); + System.out.println("File length: " + fileLength); + byte[] byteArray = new byte[(int)fileLength]; + FileInputStream is = null; + try { + is = new FileInputStream(targetFile); + is.read(byteArray); + } catch (FileNotFoundException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + }finally{ + if(is != null){ + try { + is.close(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + } + + + return byteArray; + + + } + + private String convertToFilePath(String className){ + return className.replaceAll("\\.", File.separator) + ".class"; + } + + public void addClassPath(String path) { + clzPaths.add(path); + } + + + + public String getClassPath(){ + StringBuilder sb = new StringBuilder(); + for(String item : clzPaths){ + sb.append(item + ";"); + } + return sb.substring(0, sb.length()-1); + } + + + + + +} \ No newline at end of file diff --git a/group17/1282579502/src/com/coderising/jvm/test/ClassFileloaderTest.java b/group17/1282579502/src/com/coderising/jvm/test/ClassFileloaderTest.java new file mode 100644 index 0000000000..4df3f4b529 --- /dev/null +++ b/group17/1282579502/src/com/coderising/jvm/test/ClassFileloaderTest.java @@ -0,0 +1,103 @@ +package com.coderising.jvm.test; + +import org.junit.After; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +import com.coderising.jvm.loader.ClassFileLoader; + + + + + +public class ClassFileloaderTest { + + + static String path1 = "C:\\Users\\liuxin\\git\\coding2017\\liuxin\\mini-jvm\\bin"; + static String path2 = "C:\temp"; + static String path3 = "/Users/erlisuo/Documents/workspace/codeRising2017working/1282579502/bin"; + + + @Before + public void setUp() throws Exception { + } + + @After + public void tearDown() throws Exception { + } + + @Test + public void testClassPath(){ + + ClassFileLoader loader = new ClassFileLoader(); + loader.addClassPath(path1); + loader.addClassPath(path2); + + String clzPath = loader.getClassPath(); + + Assert.assertEquals(path1+";"+path2,clzPath); + + } + + @Test + public void testClassFileLength() { + + ClassFileLoader loader = new ClassFileLoader(); + loader.addClassPath(path1); + loader.addClassPath(path2); + loader.addClassPath(path3); + String className = "com.coderising.jvm.test.EmployeeV1"; + + byte[] byteCodes = loader.readBinaryCode(className); + + // 注意:这个字节数可能和你的JVM版本有关系, 你可以看看编译好的类到底有多大 + Assert.assertEquals(1056, byteCodes.length); + + } + + + @Test + public void testMagicNumber(){ + ClassFileLoader loader = new ClassFileLoader(); + loader.addClassPath(path1); + loader.addClassPath(path3); + String className = "com.coderising.jvm.test.EmployeeV1"; + byte[] byteCodes = loader.readBinaryCode(className); + byte[] codes = new byte[]{byteCodes[0],byteCodes[1],byteCodes[2],byteCodes[3]}; + + + String acctualValue = this.byteToHexString(codes); + + Assert.assertEquals("cafebabe", acctualValue); + } + + + @Test + public void testToHexString(){ + byte b1 = 'a'; + byte b2 = 'b'; + System.out.println("Binary: " + Integer.toBinaryString(b1) + " decimal: " + Integer.toString(b1) + " hex: " + Integer.toHexString(b1)); + System.out.println("Binary: " + Integer.toBinaryString(b2) + " decimal: " + Integer.toString(b2) + " hex: " + Integer.toHexString(b2)); + + byte[] bArray = new byte[]{b1, b2}; + System.out.println(byteToHexString(bArray)); + } + + + + private String byteToHexString(byte[] codes ){ + StringBuffer buffer = new StringBuffer(); + for(int i=0;i Date: Sun, 2 Apr 2017 01:16:31 -0700 Subject: [PATCH 15/32] add LRU --- .../coding/basic/linklist/LRUPageFrame.java | 170 ++++++++++++++++++ .../basic/linklist/LRUPageFrameTest.java | 55 ++++++ 2 files changed, 225 insertions(+) create mode 100644 group17/1282579502/src/com/coding/basic/linklist/LRUPageFrame.java create mode 100644 group17/1282579502/src/com/coding/basic/linklist/LRUPageFrameTest.java diff --git a/group17/1282579502/src/com/coding/basic/linklist/LRUPageFrame.java b/group17/1282579502/src/com/coding/basic/linklist/LRUPageFrame.java new file mode 100644 index 0000000000..7e8a8a531a --- /dev/null +++ b/group17/1282579502/src/com/coding/basic/linklist/LRUPageFrame.java @@ -0,0 +1,170 @@ +package com.coding.basic.linklist; + +import java.util.HashMap; + +/** + * 用双向链表实现LRU算法 + * @author liuxin + * + */ +public class LRUPageFrame { + + public static void main(String[] args){ + LRUPageFrame frame = new LRUPageFrame(3); + frame.access(7); + frame.access(0); + frame.access(1); + System.out.println("array: " + frame.toString()); + frame.access(2); + System.out.println("array: " + frame.toString()); + + frame.access(0); + System.out.println("array: " + frame.toString()); + frame.access(0); + System.out.println("array: " + frame.toString()); + frame.access(3); + System.out.println("array: " + frame.toString()); + //frame.printList(); + frame.access(0); + //frame.printList(); + System.out.println("array: " + frame.toString()); + System.out.println(); + frame.access(4); + //frame.printList(); + System.out.println(frame); + } + + private static class Node { + + Node prev; + Node next; + int pageNum; + + Node() { + } + } + + private int capacity; + + private int count; + private Node first;// 链表头 + private Node last;// 链表尾 + + private HashMap keyHash; + + public LRUPageFrame(int capacity) { + + this.capacity = capacity; + this.count = 0; + keyHash = new HashMap(); + first = new Node(); + first.pageNum = -99; + last = new Node(); + last.pageNum = -99; + first.next = last; + } + + /** + * 获取缓存中对象 + * + * @param key + * @return + */ + public void access(int pageNum) { + Node targetPageNode = keyHash.get(new Integer(pageNum)); + + if(targetPageNode == null){ + targetPageNode = new Node(); + targetPageNode.pageNum = pageNum; + addNewPage(targetPageNode); + } + else{ + moveToTop(targetPageNode); + } + + } + /* + * null - first - f1 - f2 -f3 + */ + private void moveToTop(Node targetNode){ + if(targetNode != first.next){ + targetNode.prev.next = targetNode.next; + if(targetNode.next != null){ + targetNode.next.prev = targetNode.prev; + } + + targetNode.next = first.next; + if(first.next != null){ + first.next.prev = targetNode; + } + + first.next = targetNode; + targetNode.prev = first; + } + } + + private void addNewPage(Node targetPageNode){ + //first.next ?= null + // + targetPageNode.next = first.next; + if(first.next != null){ + first.next.prev = targetPageNode; + } + + first.next = targetPageNode; + targetPageNode.prev = first; + + keyHash.put(targetPageNode.pageNum, targetPageNode); + count++; + if(count > capacity){ + popOutLast(); + } + } + /* + * t3 - t2 - t1 - last - null + */ + private void popOutLast(){ + Node tailNode = last.prev; //t1 + if(tailNode != null){ + Node preTailNode = tailNode.prev; //t2 + if(preTailNode != null){ + keyHash.remove(preTailNode.pageNum); + preTailNode.next = last; //t2 -> last + last.prev = preTailNode; + count --; + } + } + } + public void printList(){ + int tmpcount = 0; + Node node = first.next; + while(node != last && tmpcount++<20){ + System.out.println("current: "+node.pageNum+ " parent: " + node.prev.pageNum); + node = node.next; + } + } + + public String toString(){ + StringBuilder buffer = new StringBuilder(); + Node node = first.next; + while(node != null){ + if(node == last) break; + buffer.append(node.pageNum); + + node = node.next; + if(node != null){ + buffer.append(","); + } + + } + + String returnStr = null; + if(buffer.charAt(buffer.length() -1 ) == ','){ + returnStr = buffer.substring(0, buffer.length() -1); + }else{ + returnStr = buffer.toString(); + } + return returnStr; + } + +} \ No newline at end of file diff --git a/group17/1282579502/src/com/coding/basic/linklist/LRUPageFrameTest.java b/group17/1282579502/src/com/coding/basic/linklist/LRUPageFrameTest.java new file mode 100644 index 0000000000..0bfbe14fd0 --- /dev/null +++ b/group17/1282579502/src/com/coding/basic/linklist/LRUPageFrameTest.java @@ -0,0 +1,55 @@ +package com.coding.basic.linklist; + +import org.junit.Assert; + +import org.junit.Test; + + +public class LRUPageFrameTest { + +// @Test +// public void toStringTest(){ +// LRUPageFrame frame = new LRUPageFrame(3); +// frame.access(7); +// frame.access(0); +// frame.access(1); +// System.out.println("array: " + frame.toString()); +// frame.access(2); +// System.out.println("array: " + frame.toString()); +// +// frame.access(0); +// System.out.println("array: " + frame.toString()); +// frame.access(0); +// System.out.println("array: " + frame.toString()); +// frame.access(3); +// System.out.println("array: " + frame.toString()); +// +// frame.access(0); +// System.out.println("array: " + frame.toString()); +// +// frame.access(4); +// System.out.println("array: " + frame.toString()); +// } + + @Test + public void testAccess() { + LRUPageFrame frame = new LRUPageFrame(3); + frame.access(7); + frame.access(0); + frame.access(1); + Assert.assertEquals("1,0,7", frame.toString()); + frame.access(2); + Assert.assertEquals("2,1,0", frame.toString()); + frame.access(0); + Assert.assertEquals("0,2,1", frame.toString()); + frame.access(0); + Assert.assertEquals("0,2,1", frame.toString()); + frame.access(3); + Assert.assertEquals("3,0,2", frame.toString()); + frame.access(0); + Assert.assertEquals("0,3,2", frame.toString()); + frame.access(4); + Assert.assertEquals("4,0,3", frame.toString()); + } + +} \ No newline at end of file From c9b213b8b4c88adfe4667551d51d8416571ccd9b Mon Sep 17 00:00:00 2001 From: liuxianan// <1264835468@qq.com> Date: Tue, 4 Apr 2017 22:16:09 +0800 Subject: [PATCH 16/32] lru classloader --- .../src/assignment0226/ArrayUtil.java | 1 - .../jvm/loader/ClassFileLoader.java | 59 ++++++++++++ .../jvm/test/ClassFileLoaderTest.java | 95 +++++++++++++++++++ .../{lru => jvm/test}/EmployeeV1.java | 7 +- .../src/assignment0326/lru/Clock.java | 73 +++++++++++--- .../src/assignment0326/lru/LRUPageFrame.java | 4 +- 6 files changed, 219 insertions(+), 20 deletions(-) create mode 100644 group17/1264835468/src/assignment0326/jvm/loader/ClassFileLoader.java create mode 100644 group17/1264835468/src/assignment0326/jvm/test/ClassFileLoaderTest.java rename group17/1264835468/src/assignment0326/{lru => jvm/test}/EmployeeV1.java (86%) diff --git a/group17/1264835468/src/assignment0226/ArrayUtil.java b/group17/1264835468/src/assignment0226/ArrayUtil.java index 8b279dca28..f8be858ad9 100644 --- a/group17/1264835468/src/assignment0226/ArrayUtil.java +++ b/group17/1264835468/src/assignment0226/ArrayUtil.java @@ -180,5 +180,4 @@ public static String join(int[] array, String seperator) { return stringBuilder.toString(); } - } diff --git a/group17/1264835468/src/assignment0326/jvm/loader/ClassFileLoader.java b/group17/1264835468/src/assignment0326/jvm/loader/ClassFileLoader.java new file mode 100644 index 0000000000..a5add91113 --- /dev/null +++ b/group17/1264835468/src/assignment0326/jvm/loader/ClassFileLoader.java @@ -0,0 +1,59 @@ +package assignment0326.jvm.loader; + +import java.io.BufferedInputStream; +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +/** + * Created by Administrator on 2017/3/30. + */ +public class ClassFileLoader { + + + private List clzPaths = new ArrayList(); + + public byte[] readBinaryCode(String className) { + String path = className.replace(".", File.separator); + File classFile=null; + for (String p: clzPaths) { + classFile=new File(p+File.separator+path+".class"); + if(classFile.exists()) + break; + } + if(classFile==null) + throw new RuntimeException("no such class file"); + + byte[] bytes=new byte[(int)classFile.length()]; + try (BufferedInputStream bufferedInputStream = new BufferedInputStream(new FileInputStream(classFile))){ + bufferedInputStream.read(bytes, 0, bytes.length); + + } catch (IOException e) { + e.printStackTrace(); + } + return bytes; + } + + + public void addClassPath(String path) { + clzPaths.add(path); + } + + + + public String getClassPath(){ + StringBuilder stringBuilder=new StringBuilder(); + for (int i = 0; i strings=new ArrayList<>(); + for (int i = 0; i <10; i++) { + strings.add(String.valueOf(new Random().nextInt(3000))); + } + System.out.println(strings); + System.out.println(strings.stream().map(s-> s.charAt(0)).sorted().distinct().limit(5).collect(Collectors.toList())); + } + + public int findMinDifference(List timePoints) { + List list=new ArrayList<>(); + + for (String s:timePoints) { + list.add(parse(s)); + } + Collections.sort(list); + int min=Integer.MAX_VALUE; + for (int i = 0; i < list.size()-1; i++) { + min=Math.min(min,Math.min(Math.abs(list.get(i+1)-list.get(i)),24*60-Math.abs(list.get(i+1)-list.get(i)))); + } + return min; + } + + private Integer parse(String s) { + return Integer.parseInt(s.substring(0, 2)) * 60 + Integer.parseInt(s.substring(3, 5)); + } } diff --git a/group17/1264835468/src/assignment0326/lru/LRUPageFrame.java b/group17/1264835468/src/assignment0326/lru/LRUPageFrame.java index 542075129f..fd2f2693c4 100644 --- a/group17/1264835468/src/assignment0326/lru/LRUPageFrame.java +++ b/group17/1264835468/src/assignment0326/lru/LRUPageFrame.java @@ -8,7 +8,6 @@ public class LRUPageFrame { private static class Node { - Node prev; Node next; int pageNum; @@ -29,7 +28,7 @@ public Node(int pageNum) { private int size; public LRUPageFrame(int capacity) { if(capacity<=0) - throw new IllegalArgumentException("capacity:"+capacity+" < 0"); + throw new IllegalArgumentException("capacity:"+capacity+" <= 0"); this.capacity = capacity; first=null; last=null; @@ -82,6 +81,7 @@ private void moveToFirst(Node target) { if(target==first){ return; } + Node prevOfTarget=target.prev; prevOfTarget.next=target.next; From 282b6265e85e05266ced2946853831fd9dc8742e Mon Sep 17 00:00:00 2001 From: Ren650119726 <102228177@qq.com> Date: Tue, 4 Apr 2017 22:36:05 +0800 Subject: [PATCH 17/32] =?UTF-8?q?=E6=96=87=E7=AB=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- group17/article/template.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/group17/article/template.md b/group17/article/template.md index 09c7951d71..f8f2e4414a 100644 --- a/group17/article/template.md +++ b/group17/article/template.md @@ -12,7 +12,7 @@ 1204187480 http://blog.leanote.com/post/luoziyihao/js%E9%97%AD%E5%8C%85 -102228177 +102228177 http://note.youdao.com/noteshare?id=1f8f4a9d861e24948cdf0219a0d39f4e 876385982 From a6781e39fc5c848483edf5ece7513885a76a76e7 Mon Sep 17 00:00:00 2001 From: luoziyihao Date: Wed, 5 Apr 2017 21:19:06 +0800 Subject: [PATCH 18/32] com --- group17/count/reward.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 group17/count/reward.md diff --git a/group17/count/reward.md b/group17/count/reward.md new file mode 100644 index 0000000000..4a0fe7ea81 --- /dev/null +++ b/group17/count/reward.md @@ -0,0 +1,16 @@ +## 17组 201703 获奖 + +### 代码坚持奖 + +82427129 +1282579502 +102228177 +1264835468 + +### 博客坚持奖 + +82427129 +1282579502 +102228177 +1264835468 + From 0d7544454649d723203c221d312e58b49e1f96d8 Mon Sep 17 00:00:00 2001 From: luoziyihao Date: Wed, 5 Apr 2017 21:35:39 +0800 Subject: [PATCH 19/32] add 20170326-20170402.md --- group17/article/20170326-20170402.md | 56 ++++++++++++++++++++++++++++ group17/article/template.md | 6 +-- 2 files changed, 59 insertions(+), 3 deletions(-) create mode 100644 group17/article/20170326-20170402.md diff --git a/group17/article/20170326-20170402.md b/group17/article/20170326-20170402.md new file mode 100644 index 0000000000..3d45ad0516 --- /dev/null +++ b/group17/article/20170326-20170402.md @@ -0,0 +1,56 @@ +# 自由写作 + +## 须知 +--- + +交作业时请在QQ 号后面填上各自的文章链接, 比如: + +51075907 http://m.blog.csdn.net/article/details?id=57083764 + +## 文章 +--- + +1204187480 + +102228177 + +876385982 + +785396327 + +1059107701 + +240094626 + +82427129 + +296910598 + +1264835468 + +516886559 + +1282579502 + +614982500 + +865797761 + +1540186032 + +176653813 + +116665530 + +51075907 + +1158154002 + +345450234 + +919764878 + +1368331120 + +517970312 + diff --git a/group17/article/template.md b/group17/article/template.md index 09c7951d71..3d45ad0516 100644 --- a/group17/article/template.md +++ b/group17/article/template.md @@ -10,7 +10,7 @@ ## 文章 --- -1204187480 http://blog.leanote.com/post/luoziyihao/js%E9%97%AD%E5%8C%85 +1204187480 102228177 @@ -26,11 +26,11 @@ 296910598 -1264835468 http://www.jianshu.com/p/634ca8cdd6e3 +1264835468 516886559 -1282579502 https://www.evernote.com/shard/s413/sh/142601dd-edc3-4e37-871e-37a7489d7634/a092bf080e1aefbaeab96d34edac8cf0 +1282579502 614982500 From bbfef7b85a3d0c352bfdc04eaf38a2006e5b192d Mon Sep 17 00:00:00 2001 From: luoziyihao Date: Wed, 5 Apr 2017 21:37:26 +0800 Subject: [PATCH 20/32] add 20170326-20170402.md --- group17/count/homework.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/group17/count/homework.md b/group17/count/homework.md index e474336779..a0abf5cadd 100644 --- a/group17/count/homework.md +++ b/group17/count/homework.md @@ -17,3 +17,5 @@ * [20170305-20170312](https://github.com/luoziyihao/coding2017/blob/master/group17/article/20170305-20170312.md) + * [20170305-20170312](https://github.com/luoziyihao/coding2017/blob/master/group17/article/20170326-20170402.md) + From 500a40868b713940f9e1b8886d90ec262f6da811 Mon Sep 17 00:00:00 2001 From: liuxianan// <1264835468@qq.com> Date: Wed, 5 Apr 2017 22:04:57 +0800 Subject: [PATCH 21/32] Merge branch 'master' of https://github.com/luoziyihao/coding2017.git # Conflicts: # group17/240094626/.gitignore --- group17/LearnProject/src/CodeAssistance.java | 27 ++++++++++++++ group17/LearnProject/src/Navigation.java | 37 ++++++++++++++++++++ group17/LearnProject/src/Refactorings.java | 30 ++++++++++++++++ 3 files changed, 94 insertions(+) create mode 100644 group17/LearnProject/src/CodeAssistance.java create mode 100644 group17/LearnProject/src/Navigation.java create mode 100644 group17/LearnProject/src/Refactorings.java diff --git a/group17/LearnProject/src/CodeAssistance.java b/group17/LearnProject/src/CodeAssistance.java new file mode 100644 index 0000000000..adf5369ed5 --- /dev/null +++ b/group17/LearnProject/src/CodeAssistance.java @@ -0,0 +1,27 @@ +import java.io.BufferedReader; +import java.io.FileReader; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Arrays; + +class CodeAssistance { + + public static final String EXT = "txt"; + + public static void main(String[] args) throws IOException { + FileReader fileReader = new FileReader("input." + EXT); + try { + BufferedReader reader = new BufferedReader(fileReader); + ArrayList lines = new ArrayList(); + String line; + while ((line = reader.readLine()) != null) { + lines.add(line); + } + String[] array = lines.toArray(new String[lines.size()]); + Arrays.sort(array); + for (String s : array) System.out.println(s); + } finally { + fileReader.close(); + } + } +} \ No newline at end of file diff --git a/group17/LearnProject/src/Navigation.java b/group17/LearnProject/src/Navigation.java new file mode 100644 index 0000000000..f767faf5bd --- /dev/null +++ b/group17/LearnProject/src/Navigation.java @@ -0,0 +1,37 @@ +class FileStructureDemo{ + + + final private String DATABASE = "MyDataBase"; + DataEntry myPerson; + + FileStructureDemo(String name, int age, String cellphone){ + myPerson = new Person(name, age, cellphone); + } + + interface DataEntry{ + String getCellphone(); + String getName(); + } + + class Person implements DataEntry { + + public Person(String name, int age, String cellphone) { + this.name = name; + this.age = age; + this.cellphone = cellphone; + } + + private String name; + private int age; + private String cellphone; + + public String getCellphone() { + return cellphone; + } + + public String getName() { + return name; + } + + } +} \ No newline at end of file diff --git a/group17/LearnProject/src/Refactorings.java b/group17/LearnProject/src/Refactorings.java new file mode 100644 index 0000000000..3422b59877 --- /dev/null +++ b/group17/LearnProject/src/Refactorings.java @@ -0,0 +1,30 @@ +import java.io.BufferedReader; +import java.io.FileReader; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Arrays; + +class Refactorings { + public static final String TXT = "txt"; + + public static void main(String[] args) throws IOException { + FileReader in = new FileReader("input." + TXT); + String[] array = getStrings( + in); + Arrays.sort(array); + for (String s : array) { + System.out.println(s); + } + } + + private static String[] getStrings(FileReader in) throws IOException { + BufferedReader reader = new BufferedReader(in); + ArrayList lines = new ArrayList(); + String line; + while ((line = reader.readLine()) != null) { + lines.add(line); + } + reader.close(); + return lines.toArray(new String[lines.size()]); + } +} \ No newline at end of file From 7e3076fb3f8bbde73da1decc9c2b9fdb074a9abb Mon Sep 17 00:00:00 2001 From: liuxianan// <1264835468@qq.com> Date: Wed, 5 Apr 2017 22:05:28 +0800 Subject: [PATCH 22/32] 12 --- group17/LearnProject/src/CodeAssistance.java | 27 -------------- group17/LearnProject/src/Navigation.java | 37 -------------------- group17/LearnProject/src/Refactorings.java | 30 ---------------- 3 files changed, 94 deletions(-) delete mode 100644 group17/LearnProject/src/CodeAssistance.java delete mode 100644 group17/LearnProject/src/Navigation.java delete mode 100644 group17/LearnProject/src/Refactorings.java diff --git a/group17/LearnProject/src/CodeAssistance.java b/group17/LearnProject/src/CodeAssistance.java deleted file mode 100644 index adf5369ed5..0000000000 --- a/group17/LearnProject/src/CodeAssistance.java +++ /dev/null @@ -1,27 +0,0 @@ -import java.io.BufferedReader; -import java.io.FileReader; -import java.io.IOException; -import java.util.ArrayList; -import java.util.Arrays; - -class CodeAssistance { - - public static final String EXT = "txt"; - - public static void main(String[] args) throws IOException { - FileReader fileReader = new FileReader("input." + EXT); - try { - BufferedReader reader = new BufferedReader(fileReader); - ArrayList lines = new ArrayList(); - String line; - while ((line = reader.readLine()) != null) { - lines.add(line); - } - String[] array = lines.toArray(new String[lines.size()]); - Arrays.sort(array); - for (String s : array) System.out.println(s); - } finally { - fileReader.close(); - } - } -} \ No newline at end of file diff --git a/group17/LearnProject/src/Navigation.java b/group17/LearnProject/src/Navigation.java deleted file mode 100644 index f767faf5bd..0000000000 --- a/group17/LearnProject/src/Navigation.java +++ /dev/null @@ -1,37 +0,0 @@ -class FileStructureDemo{ - - - final private String DATABASE = "MyDataBase"; - DataEntry myPerson; - - FileStructureDemo(String name, int age, String cellphone){ - myPerson = new Person(name, age, cellphone); - } - - interface DataEntry{ - String getCellphone(); - String getName(); - } - - class Person implements DataEntry { - - public Person(String name, int age, String cellphone) { - this.name = name; - this.age = age; - this.cellphone = cellphone; - } - - private String name; - private int age; - private String cellphone; - - public String getCellphone() { - return cellphone; - } - - public String getName() { - return name; - } - - } -} \ No newline at end of file diff --git a/group17/LearnProject/src/Refactorings.java b/group17/LearnProject/src/Refactorings.java deleted file mode 100644 index 3422b59877..0000000000 --- a/group17/LearnProject/src/Refactorings.java +++ /dev/null @@ -1,30 +0,0 @@ -import java.io.BufferedReader; -import java.io.FileReader; -import java.io.IOException; -import java.util.ArrayList; -import java.util.Arrays; - -class Refactorings { - public static final String TXT = "txt"; - - public static void main(String[] args) throws IOException { - FileReader in = new FileReader("input." + TXT); - String[] array = getStrings( - in); - Arrays.sort(array); - for (String s : array) { - System.out.println(s); - } - } - - private static String[] getStrings(FileReader in) throws IOException { - BufferedReader reader = new BufferedReader(in); - ArrayList lines = new ArrayList(); - String line; - while ((line = reader.readLine()) != null) { - lines.add(line); - } - reader.close(); - return lines.toArray(new String[lines.size()]); - } -} \ No newline at end of file From e5f94d81113a1ba092858e1f64f148f8763c076c Mon Sep 17 00:00:00 2001 From: liuxianan// <1264835468@qq.com> Date: Wed, 5 Apr 2017 22:08:52 +0800 Subject: [PATCH 23/32] article --- group17/article/20170326-20170402.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/group17/article/20170326-20170402.md b/group17/article/20170326-20170402.md index 3d45ad0516..7882e2b171 100644 --- a/group17/article/20170326-20170402.md +++ b/group17/article/20170326-20170402.md @@ -26,7 +26,7 @@ 296910598 -1264835468 +1264835468 http://www.jianshu.com/p/848fd6be5247 516886559 From 362e7371e6559cbf8f6a2dd79161287414eb0ce5 Mon Sep 17 00:00:00 2001 From: liuxianan// <1264835468@qq.com> Date: Wed, 5 Apr 2017 22:11:09 +0800 Subject: [PATCH 24/32] article. --- group17/1264835468/src/assignment0326/lru/Clock.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/group17/1264835468/src/assignment0326/lru/Clock.java b/group17/1264835468/src/assignment0326/lru/Clock.java index 1e515af5d2..274b6ebc80 100644 --- a/group17/1264835468/src/assignment0326/lru/Clock.java +++ b/group17/1264835468/src/assignment0326/lru/Clock.java @@ -4,7 +4,7 @@ import java.util.stream.Collectors; /** - * Created by Administrator on 2017/3/29. + * Created by Administrator on 2017/3/29. */ public class Clock { private PageFrame[] pages; From e75f61bc6304fa2d7ac7fab3e77c257ec54e1e82 Mon Sep 17 00:00:00 2001 From: gongxun Date: Wed, 5 Apr 2017 23:15:19 +0800 Subject: [PATCH 25/32] =?UTF-8?q?=E5=AE=8C=E6=88=90jvm=E7=AC=AC=E4=B8=80?= =?UTF-8?q?=E6=AC=A1=E4=BD=9C=E4=B8=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../785396327/3.12/jvm_1/ClassFileLoader.java | 50 +++++++++++ .../3.12/jvm_1/ClassFileloaderTest.java | 86 +++++++++++++++++++ group17/785396327/3.12/jvm_1/EmployeeV1.java | 32 +++++++ 3 files changed, 168 insertions(+) create mode 100644 group17/785396327/3.12/jvm_1/ClassFileLoader.java create mode 100644 group17/785396327/3.12/jvm_1/ClassFileloaderTest.java create mode 100644 group17/785396327/3.12/jvm_1/EmployeeV1.java diff --git a/group17/785396327/3.12/jvm_1/ClassFileLoader.java b/group17/785396327/3.12/jvm_1/ClassFileLoader.java new file mode 100644 index 0000000000..95f68a5a7f --- /dev/null +++ b/group17/785396327/3.12/jvm_1/ClassFileLoader.java @@ -0,0 +1,50 @@ +package jvm_1; + +import java.io.*; +import java.util.ArrayList; +import java.util.List; + +/** + * Created by william on 2017/4/5. + */ +public class ClassFileLoader { + private List clzPaths = new ArrayList(); + + public byte[] readBinaryCode(String className) { + InputStream fis = null; + String filePath = clzPaths.get(0) + "\\\\" + className.replaceAll("\\.", "\\\\") + ".class"; + byte[] buffer = new byte[(int) new File(filePath).length()]; + try { + if (clzPaths.size() > 0 && className != null && !className.trim().equals("")) { + fis = new FileInputStream(filePath); + while (fis.read(buffer) != -1) ; + } + } catch (Exception e) { + e.printStackTrace(); + } finally { + if (fis != null) + try { + fis.close(); + } catch (IOException e) { + e.printStackTrace(); + } finally { + fis = null; + } + } + return buffer; + } + + + public void addClassPath(String path) { + clzPaths.add(path); + } + + + public String getClassPath() { + StringBuilder sb = new StringBuilder(); + for (String clzPath : clzPaths) { + sb.append(clzPath).append(";"); + } + return sb.substring(0, sb.length() - 1); + } +} diff --git a/group17/785396327/3.12/jvm_1/ClassFileloaderTest.java b/group17/785396327/3.12/jvm_1/ClassFileloaderTest.java new file mode 100644 index 0000000000..067cd93c2b --- /dev/null +++ b/group17/785396327/3.12/jvm_1/ClassFileloaderTest.java @@ -0,0 +1,86 @@ +package jvm_1; + +import org.junit.After; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +/** + * Created by william on 2017/4/5. + */ +public class ClassFileloaderTest { + static String path1 = "D:\\workspace\\IDEA\\homework\\coding2017\\group17\\785396327\\out\\production\\785396327"; + static String path2 = "C:\temp"; + + + + @Before + public void setUp() throws Exception { + } + + @After + public void tearDown() throws Exception { + } + + @Test + public void testClassPath(){ + + ClassFileLoader loader = new ClassFileLoader(); + loader.addClassPath(path1); + loader.addClassPath(path2); + + String clzPath = loader.getClassPath(); + + Assert.assertEquals(path1+";"+path2,clzPath); + + } + + @Test + public void testClassFileLength() { + + ClassFileLoader loader = new ClassFileLoader(); + loader.addClassPath(path1); + + String className = "jvm_1.EmployeeV1"; + + byte[] byteCodes = loader.readBinaryCode(className); + + // 注意:这个字节数可能和你的JVM版本有关系, 你可以看看编译好的类到底有多大 + Assert.assertEquals(1020, byteCodes.length); + + } + + + @Test + public void testMagicNumber(){ + ClassFileLoader loader = new ClassFileLoader(); + loader.addClassPath(path1); + String className = "jvm_1.EmployeeV1"; + byte[] byteCodes = loader.readBinaryCode(className); + byte[] codes = new byte[]{byteCodes[0],byteCodes[1],byteCodes[2],byteCodes[3]}; + + + String acctualValue = this.byteToHexString(codes); + + Assert.assertEquals("cafebabe", acctualValue); + } + + + + + + + private String byteToHexString(byte[] codes ){ + StringBuffer buffer = new StringBuffer(); + for(int i=0;i Date: Wed, 5 Apr 2017 23:18:14 +0800 Subject: [PATCH 26/32] =?UTF-8?q?=E5=AE=8C=E6=88=903=E6=9C=8826=E6=97=A5?= =?UTF-8?q?=E4=BD=9C=E4=B8=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- group17/785396327/{3.12 => 3.26}/jvm_1/ClassFileLoader.java | 0 .../785396327/{3.12 => 3.26}/jvm_1/ClassFileloaderTest.java | 0 group17/785396327/{3.12 => 3.26}/jvm_1/EmployeeV1.java | 0 group17/785396327/3.26/{ => lru}/LRUPageFrame.java | 2 ++ group17/785396327/3.26/{ => lru}/LRUPageFrameTest.java | 4 +++- 5 files changed, 5 insertions(+), 1 deletion(-) rename group17/785396327/{3.12 => 3.26}/jvm_1/ClassFileLoader.java (100%) rename group17/785396327/{3.12 => 3.26}/jvm_1/ClassFileloaderTest.java (100%) rename group17/785396327/{3.12 => 3.26}/jvm_1/EmployeeV1.java (100%) rename group17/785396327/3.26/{ => lru}/LRUPageFrame.java (99%) rename group17/785396327/3.26/{ => lru}/LRUPageFrameTest.java (94%) diff --git a/group17/785396327/3.12/jvm_1/ClassFileLoader.java b/group17/785396327/3.26/jvm_1/ClassFileLoader.java similarity index 100% rename from group17/785396327/3.12/jvm_1/ClassFileLoader.java rename to group17/785396327/3.26/jvm_1/ClassFileLoader.java diff --git a/group17/785396327/3.12/jvm_1/ClassFileloaderTest.java b/group17/785396327/3.26/jvm_1/ClassFileloaderTest.java similarity index 100% rename from group17/785396327/3.12/jvm_1/ClassFileloaderTest.java rename to group17/785396327/3.26/jvm_1/ClassFileloaderTest.java diff --git a/group17/785396327/3.12/jvm_1/EmployeeV1.java b/group17/785396327/3.26/jvm_1/EmployeeV1.java similarity index 100% rename from group17/785396327/3.12/jvm_1/EmployeeV1.java rename to group17/785396327/3.26/jvm_1/EmployeeV1.java diff --git a/group17/785396327/3.26/LRUPageFrame.java b/group17/785396327/3.26/lru/LRUPageFrame.java similarity index 99% rename from group17/785396327/3.26/LRUPageFrame.java rename to group17/785396327/3.26/lru/LRUPageFrame.java index 35a7f1e8ca..d296335978 100644 --- a/group17/785396327/3.26/LRUPageFrame.java +++ b/group17/785396327/3.26/lru/LRUPageFrame.java @@ -1,3 +1,5 @@ +package lru; + /** * Created by william on 2017/3/31. * 1. 新数据插入到链表头部; diff --git a/group17/785396327/3.26/LRUPageFrameTest.java b/group17/785396327/3.26/lru/LRUPageFrameTest.java similarity index 94% rename from group17/785396327/3.26/LRUPageFrameTest.java rename to group17/785396327/3.26/lru/LRUPageFrameTest.java index 7b13e17815..ff619f5b6d 100644 --- a/group17/785396327/3.26/LRUPageFrameTest.java +++ b/group17/785396327/3.26/lru/LRUPageFrameTest.java @@ -1,3 +1,5 @@ +package lru; + import org.junit.Assert; import org.junit.Test; @@ -28,7 +30,7 @@ public void testAccess() { @Test public void testInnerMethod() { -// LRUPageFrame lruPageFrame = new LRUPageFrame(3); +// lru.LRUPageFrame lruPageFrame = new lru.LRUPageFrame(3); // lruPageFrame.access(1); // lruPageFrame.access(2); // lruPageFrame.access(3); From ffe1628f1907ad20e15c9bd0fb602328247460e9 Mon Sep 17 00:00:00 2001 From: 240094626 Date: Thu, 6 Apr 2017 11:34:46 +0800 Subject: [PATCH 27/32] =?UTF-8?q?=E7=AC=AC=E5=9B=9B=E5=91=A8=E4=BD=9C?= =?UTF-8?q?=E4=B8=9A=E2=80=94-=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../jvm/loader/ClassFileLoader.java | 73 +++++++++++++++ .../jvm/test/ClassFileloaderTest.java | 92 +++++++++++++++++++ .../com/coderising/jvm/test/EmployeeV1.java | 28 ++++++ 3 files changed, 193 insertions(+) create mode 100644 group17/240094626/work_week_4/src/com/coderising/jvm/loader/ClassFileLoader.java create mode 100644 group17/240094626/work_week_4/src/com/coderising/jvm/test/ClassFileloaderTest.java create mode 100644 group17/240094626/work_week_4/src/com/coderising/jvm/test/EmployeeV1.java diff --git a/group17/240094626/work_week_4/src/com/coderising/jvm/loader/ClassFileLoader.java b/group17/240094626/work_week_4/src/com/coderising/jvm/loader/ClassFileLoader.java new file mode 100644 index 0000000000..b9d924a887 --- /dev/null +++ b/group17/240094626/work_week_4/src/com/coderising/jvm/loader/ClassFileLoader.java @@ -0,0 +1,73 @@ +package com.coderising.jvm.loader; + +import java.io.ByteArrayOutputStream; +import java.io.File; +import java.io.FileInputStream; +import java.io.InputStream; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + + + +public class ClassFileLoader { + + private List clzPaths = new ArrayList(); + + public byte[] readBinaryCode(String className) { + if(null == className || "".equals(className)){ + return null; + } + className = className.replace(".", File.separator)+".class"; + Iterator it = clzPaths.iterator(); + byte[] bytes = null; + while(it.hasNext() && bytes == null){ + String filePath = it.next()+File.separator+className; + bytes = getClassFile(filePath); + } + return bytes; + + } + + + private byte[] getClassFile(String filePath) { + ByteArrayOutputStream bos = new ByteArrayOutputStream(); + try { + InputStream is = new FileInputStream(new File(filePath)); + byte[] buffer = new byte[1024]; + int len = 0; + while((len=is.read(buffer)) > 0){ + bos.write(buffer,0, len); + } + } catch (Exception e) { + e.printStackTrace(); + } + return bos.toByteArray(); + } + + + public void addClassPath(String path) { + if(null != path && !"".equals(path)){ + clzPaths.add(path); + } + } + + + + public String getClassPath(){ + StringBuilder sb = new StringBuilder(); + Iterator it = clzPaths.iterator(); + while(it.hasNext()){ + if(sb.length() > 0){ + sb.append(";"); + } + sb.append(it.next()); + } + return sb.toString(); + } + + + + + +} diff --git a/group17/240094626/work_week_4/src/com/coderising/jvm/test/ClassFileloaderTest.java b/group17/240094626/work_week_4/src/com/coderising/jvm/test/ClassFileloaderTest.java new file mode 100644 index 0000000000..a205045d2e --- /dev/null +++ b/group17/240094626/work_week_4/src/com/coderising/jvm/test/ClassFileloaderTest.java @@ -0,0 +1,92 @@ +package com.coderising.jvm.test; + +import java.io.File; + +import org.junit.After; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +import com.coderising.jvm.loader.ClassFileLoader; + + + + + +public class ClassFileloaderTest { + + + static String path1 = "E:\\workspace-indigo-32-statsdb\\warm-up\\bin";//"C:\\Users\\liuxin\\git\\coding2017\\liuxin\\mini-jvm\\bin"; + static String path2 = "C:\temp"; + + + + @Before + public void setUp() throws Exception { + } + + @After + public void tearDown() throws Exception { + } + + @Test + public void testClassPath(){ + + ClassFileLoader loader = new ClassFileLoader(); + loader.addClassPath(path1); + loader.addClassPath(path2); + + String clzPath = loader.getClassPath(); + + Assert.assertEquals(path1+";"+path2,clzPath); + + } + + @Test + public void testClassFileLength() { + ClassFileLoader loader = new ClassFileLoader(); + loader.addClassPath(path1); + + String className = "com.coderising.jvm.test.EmployeeV1"; + + byte[] byteCodes = loader.readBinaryCode(className); + + // 注意:这个字节数可能和你的JVM版本有关系, 你可以看看编译好的类到底有多大 + Assert.assertEquals(1056, byteCodes.length); + + } + + @Test + public void testMagicNumber(){ + ClassFileLoader loader = new ClassFileLoader(); + loader.addClassPath(path1); + String className = "com.coderising.jvm.test.EmployeeV1"; + byte[] byteCodes = loader.readBinaryCode(className); + byte[] codes = new byte[]{byteCodes[0],byteCodes[1],byteCodes[2],byteCodes[3]}; + + + String acctualValue = this.byteToHexString(codes); + + Assert.assertEquals("cafebabe", acctualValue); + } + + + + + + + private String byteToHexString(byte[] codes ){ + StringBuffer buffer = new StringBuffer(); + for(int i=0;i Date: Wed, 5 Apr 2017 21:54:19 -0700 Subject: [PATCH 28/32] add article link --- group17/article/20170326-20170402.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/group17/article/20170326-20170402.md b/group17/article/20170326-20170402.md index 3d45ad0516..6451f60f6b 100644 --- a/group17/article/20170326-20170402.md +++ b/group17/article/20170326-20170402.md @@ -30,7 +30,7 @@ 516886559 -1282579502 +1282579502 https://www.evernote.com/l/AZ2Rx5pxgf9I-JqkSpFANMwTK9fXR0KFV50 614982500 From 53f753cd966ff0764469de390ec1ce7fc7559826 Mon Sep 17 00:00:00 2001 From: 240094626 Date: Thu, 6 Apr 2017 13:42:42 +0800 Subject: [PATCH 29/32] work_jvm_1_LRU --- .../coding/basic/linklist/LRUPageFrame.java | 126 ++++++++++++++++++ .../basic/linklist/LRUPageFrameTest.java | 31 +++++ .../com/coding/basic/linklist/LinkedList.java | 125 +++++++++++++++++ .../jvm/loader/ClassFileLoader.java | 0 .../jvm/test/ClassFileloaderTest.java | 0 .../com/coderising/jvm/test/EmployeeV1.java | 0 6 files changed, 282 insertions(+) create mode 100644 group17/240094626/work_jvm_1/data-structure/src/com/coding/basic/linklist/LRUPageFrame.java create mode 100644 group17/240094626/work_jvm_1/data-structure/src/com/coding/basic/linklist/LRUPageFrameTest.java create mode 100644 group17/240094626/work_jvm_1/data-structure/src/com/coding/basic/linklist/LinkedList.java rename group17/240094626/{work_week_4 => work_jvm_1}/src/com/coderising/jvm/loader/ClassFileLoader.java (100%) rename group17/240094626/{work_week_4 => work_jvm_1}/src/com/coderising/jvm/test/ClassFileloaderTest.java (100%) rename group17/240094626/{work_week_4 => work_jvm_1}/src/com/coderising/jvm/test/EmployeeV1.java (100%) diff --git a/group17/240094626/work_jvm_1/data-structure/src/com/coding/basic/linklist/LRUPageFrame.java b/group17/240094626/work_jvm_1/data-structure/src/com/coding/basic/linklist/LRUPageFrame.java new file mode 100644 index 0000000000..638cf181ae --- /dev/null +++ b/group17/240094626/work_jvm_1/data-structure/src/com/coding/basic/linklist/LRUPageFrame.java @@ -0,0 +1,126 @@ +package com.coding.basic.linklist; + +/** + * 用双向链表实现LRU算法 + * @author liuxin + * + */ +public class LRUPageFrame { + + private static class Node { + + Node prev; + Node next; + int pageNum; + + Node() { + } + } + + private int capacity; + private int currentSize; + + private Node first;// 链表头 + private Node last;// 链表尾 + + + public LRUPageFrame(int capacity) { + + this.capacity = capacity; + currentSize = 0; + } + + /** + * 获取缓存中对象 + * + * @param key + * @return + */ + public void access(int pageNum) { + + // 判断缓存是否命中 + Node n = find(pageNum); + if(n != null){ + // 命中,则把节点提到表头 + moveNodeToHead(n); + }else{ + // 若未命中,新增节点放到表头,如果链表长度超过capacity,移除链表尾部节点 + n = new Node(); + n.pageNum = pageNum; + + if(currentSize >= capacity){ + removeLast(); + } + addNodeToHead(n); + } + } + + + + private void addNodeToHead(Node n) { + if(first == null){ + first = n; + last = n; + }else{ + n.next = first; + first.prev = n; + first = n; + } + currentSize++; + } + + private void removeLast() { + Node prevN = last.prev; + prevN.next = null; + last.prev = null; + last = prevN; + currentSize--; + } + + private void moveNodeToHead(Node n) { + if(n == first){ + return ; + }else if(n == last){ + Node preN = n.prev; + preN.next = null; + last.prev = null; + last = preN; + }else{ + // 中间节点 + Node preN = n.prev; + Node nextN = n.next; + preN.next = nextN; + nextN.prev = preN; + } + n.prev = null; + n.next = first; + first.prev = n; + first = n; + } + + private Node find(int pageNum) { + Node n = first; + while(n != null){ + if(n.pageNum == pageNum){ + return n; + } + n = n.next; + } + return null; + } + + public String toString(){ + StringBuilder buffer = new StringBuilder(); + Node node = first; + while(node != null){ + buffer.append(node.pageNum); + + node = node.next; + if(node != null){ + buffer.append(","); + } + } + return buffer.toString(); + } + +} diff --git a/group17/240094626/work_jvm_1/data-structure/src/com/coding/basic/linklist/LRUPageFrameTest.java b/group17/240094626/work_jvm_1/data-structure/src/com/coding/basic/linklist/LRUPageFrameTest.java new file mode 100644 index 0000000000..67cf36067b --- /dev/null +++ b/group17/240094626/work_jvm_1/data-structure/src/com/coding/basic/linklist/LRUPageFrameTest.java @@ -0,0 +1,31 @@ +package com.coding.basic.linklist; + +import org.junit.Assert; + +import org.junit.Test; + + +public class LRUPageFrameTest { + + @Test + public void testAccess() { + LRUPageFrame frame = new LRUPageFrame(3); + frame.access(7); + frame.access(0); + frame.access(1); + Assert.assertEquals("1,0,7", frame.toString()); + frame.access(2); + Assert.assertEquals("2,1,0", frame.toString()); + frame.access(0); + Assert.assertEquals("0,2,1", frame.toString()); + frame.access(0); + Assert.assertEquals("0,2,1", frame.toString()); + frame.access(3); + Assert.assertEquals("3,0,2", frame.toString()); + frame.access(0); + Assert.assertEquals("0,3,2", frame.toString()); + frame.access(4); + Assert.assertEquals("4,0,3", frame.toString()); + } + +} diff --git a/group17/240094626/work_jvm_1/data-structure/src/com/coding/basic/linklist/LinkedList.java b/group17/240094626/work_jvm_1/data-structure/src/com/coding/basic/linklist/LinkedList.java new file mode 100644 index 0000000000..f4c7556a2e --- /dev/null +++ b/group17/240094626/work_jvm_1/data-structure/src/com/coding/basic/linklist/LinkedList.java @@ -0,0 +1,125 @@ +package com.coding.basic.linklist; + +import com.coding.basic.Iterator; +import com.coding.basic.List; + +public class LinkedList implements List { + + private Node head; + + public void add(Object o){ + + } + public void add(int index , Object o){ + + } + public Object get(int index){ + return null; + } + public Object remove(int index){ + return null; + } + + public int size(){ + return -1; + } + + public void addFirst(Object o){ + + } + public void addLast(Object o){ + + } + public Object removeFirst(){ + return null; + } + public Object removeLast(){ + return null; + } + public Iterator iterator(){ + return null; + } + + + private static class Node{ + Object data; + Node next; + + } + + /** + * 把该链表逆置 + * 例如链表为 3->7->10 , 逆置后变为 10->7->3 + */ + public void reverse(){ + + } + + /** + * 删除一个单链表的前半部分 + * 例如:list = 2->5->7->8 , 删除以后的值为 7->8 + * 如果list = 2->5->7->8->10 ,删除以后的值为7,8,10 + + */ + public void removeFirstHalf(){ + + } + + /** + * 从第i个元素开始, 删除length 个元素 , 注意i从0开始 + * @param i + * @param length + */ + public void remove(int i, int length){ + + } + /** + * 假定当前链表和listB均包含已升序排列的整数 + * 从当前链表中取出那些listB所指定的元素 + * 例如当前链表 = 11->101->201->301->401->501->601->701 + * listB = 1->3->4->6 + * 返回的结果应该是[101,301,401,601] + * @param list + */ + public int[] getElements(LinkedList list){ + return null; + } + + /** + * 已知链表中的元素以值递增有序排列,并以单链表作存储结构。 + * 从当前链表中中删除在listB中出现的元素 + + * @param list + */ + + public void subtract(LinkedList list){ + + } + + /** + * 已知当前链表中的元素以值递增有序排列,并以单链表作存储结构。 + * 删除表中所有值相同的多余元素(使得操作后的线性表中所有元素的值均不相同) + */ + public void removeDuplicateValues(){ + + } + + /** + * 已知链表中的元素以值递增有序排列,并以单链表作存储结构。 + * 试写一高效的算法,删除表中所有值大于min且小于max的元素(若表中存在这样的元素) + * @param min + * @param max + */ + public void removeRange(int min, int max){ + + } + + /** + * 假设当前链表和参数list指定的链表均以元素依值递增有序排列(同一表中的元素值各不相同) + * 现要求生成新链表C,其元素为当前链表和list中元素的交集,且表C中的元素有依值递增有序排列 + * @param list + */ + public LinkedList intersection( LinkedList list){ + return null; + } +} diff --git a/group17/240094626/work_week_4/src/com/coderising/jvm/loader/ClassFileLoader.java b/group17/240094626/work_jvm_1/src/com/coderising/jvm/loader/ClassFileLoader.java similarity index 100% rename from group17/240094626/work_week_4/src/com/coderising/jvm/loader/ClassFileLoader.java rename to group17/240094626/work_jvm_1/src/com/coderising/jvm/loader/ClassFileLoader.java diff --git a/group17/240094626/work_week_4/src/com/coderising/jvm/test/ClassFileloaderTest.java b/group17/240094626/work_jvm_1/src/com/coderising/jvm/test/ClassFileloaderTest.java similarity index 100% rename from group17/240094626/work_week_4/src/com/coderising/jvm/test/ClassFileloaderTest.java rename to group17/240094626/work_jvm_1/src/com/coderising/jvm/test/ClassFileloaderTest.java diff --git a/group17/240094626/work_week_4/src/com/coderising/jvm/test/EmployeeV1.java b/group17/240094626/work_jvm_1/src/com/coderising/jvm/test/EmployeeV1.java similarity index 100% rename from group17/240094626/work_week_4/src/com/coderising/jvm/test/EmployeeV1.java rename to group17/240094626/work_jvm_1/src/com/coderising/jvm/test/EmployeeV1.java From 0d5165470073e10e0f769cce62d3c10aa81e0c7d Mon Sep 17 00:00:00 2001 From: luoziyihao Date: Thu, 6 Apr 2017 23:08:13 +0800 Subject: [PATCH 30/32] half getElements --- .../java/com/coding/basic/LinkedList.java | 50 ++++++++++++++++--- .../java/com/coding/basic/LinkedListTest.java | 10 +++- 2 files changed, 53 insertions(+), 7 deletions(-) diff --git a/group17/1204187480/code/homework/basic/src/main/java/com/coding/basic/LinkedList.java b/group17/1204187480/code/homework/basic/src/main/java/com/coding/basic/LinkedList.java index 3c3462637e..1f19ad1fa5 100644 --- a/group17/1204187480/code/homework/basic/src/main/java/com/coding/basic/LinkedList.java +++ b/group17/1204187480/code/homework/basic/src/main/java/com/coding/basic/LinkedList.java @@ -185,16 +185,21 @@ public void removeFirstSize(int firstSize) { * @param length */ public void remove(int i, int length) { - if (i == 0 ) {removeFirstSize(length); return;} - if (i >= size || length == 0) {return;} + if (i == 0) { + removeFirstSize(length); + return; + } + if (i >= size || length == 0) { + return; + } int lastLenth = size - i; - length = length <= lastLenth? length : lastLenth; - Node pre = node(i-1); + length = length <= lastLenth ? length : lastLenth; + Node pre = node(i - 1); int j = 0; Node next = pre; - while (j++ < length){ + while (j++ < length) { next = next.next; } pre.next = next.next; @@ -213,9 +218,42 @@ public void remove(int i, int length) { * @param list */ public int[] getElements(LinkedList list) { - return null; + if (size() == 0) { + return new int[0]; + } + Iterator iterator = list.iterator(); + Node fromNode = iterator().nextNode(); + int fromIndex = 0; + + int[] retArray = new int[list.size()]; + int retIndex = 0; + while (iterator.hasNext()) { + int index = (int) iterator.next(); + Node node = node(fromNode, fromIndex, index); + if (node == null) { + return retArray; + } else { + retArray[retIndex++] = (int)node.data; + } + } + return retArray; } + private Node node(Node fromNode, int fromIndex, int index) { + Node next = fromNode; + int nextIndex = fromIndex; + while (next != null && nextIndex < index) { + next = next.next; + nextIndex++; + } + if (nextIndex == index) { + return next; + } else { + return null; + } + } + + /** * 已知链表中的元素以值递增有序排列,并以单链表作存储结构。 * 从当前链表中中删除在listB中出现的元素 diff --git a/group17/1204187480/code/homework/basic/src/test/java/com/coding/basic/LinkedListTest.java b/group17/1204187480/code/homework/basic/src/test/java/com/coding/basic/LinkedListTest.java index baca03b06b..0424c2945e 100644 --- a/group17/1204187480/code/homework/basic/src/test/java/com/coding/basic/LinkedListTest.java +++ b/group17/1204187480/code/homework/basic/src/test/java/com/coding/basic/LinkedListTest.java @@ -3,6 +3,8 @@ import org.junit.Assert; import org.junit.Test; +import java.util.Arrays; + /** * Created by luoziyihao on 3/23/17. */ @@ -83,9 +85,12 @@ private LinkedList createAndFillLinkedList() { } private LinkedList createAndFillLinkedList(int length) { + return createAndFillLinkedList(1, length); + } + private LinkedList createAndFillLinkedList(int start, int length) { LinkedList linkedList = new LinkedList(); - for (int i = 1; i <= length; i++) { + for (int i = start; i <= length; i++) { linkedList.add(i); } return linkedList; @@ -136,6 +141,9 @@ public void remove7() throws Exception { @Test public void getElements() throws Exception { + LinkedList listA= createAndFillLinkedList(0,8); + LinkedList listB = createAndFillLinkedList(4, 4); + Assert.assertEquals("[4,5,6,7]", Arrays.toString(listA.getElements(listB))); } From 1696720b73d2d2da016d4b4d56aebb8c6cf8ff37 Mon Sep 17 00:00:00 2001 From: luoziyihao Date: Sun, 9 Apr 2017 11:37:49 +0800 Subject: [PATCH 31/32] home --- .../basic/src/main/java/com/coding/basic/LinkedList.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/group17/1204187480/code/homework/basic/src/main/java/com/coding/basic/LinkedList.java b/group17/1204187480/code/homework/basic/src/main/java/com/coding/basic/LinkedList.java index 1f19ad1fa5..c0cce5af0a 100644 --- a/group17/1204187480/code/homework/basic/src/main/java/com/coding/basic/LinkedList.java +++ b/group17/1204187480/code/homework/basic/src/main/java/com/coding/basic/LinkedList.java @@ -230,6 +230,8 @@ public int[] getElements(LinkedList list) { while (iterator.hasNext()) { int index = (int) iterator.next(); Node node = node(fromNode, fromIndex, index); + fromIndex = index; + fromNode = node; if (node == null) { return retArray; } else { From e1cec01e63221fb899e890e0febd2154d1edab53 Mon Sep 17 00:00:00 2001 From: luoziyihao Date: Sun, 9 Apr 2017 15:31:19 +0800 Subject: [PATCH 32/32] add 20170326-20170402.md 20170402-20170409.md --- group17/article/20170402-20170409.md | 56 ++++++++++++++++++++++++++++ group17/count/homework.md | 4 +- 2 files changed, 59 insertions(+), 1 deletion(-) create mode 100644 group17/article/20170402-20170409.md diff --git a/group17/article/20170402-20170409.md b/group17/article/20170402-20170409.md new file mode 100644 index 0000000000..3d45ad0516 --- /dev/null +++ b/group17/article/20170402-20170409.md @@ -0,0 +1,56 @@ +# 自由写作 + +## 须知 +--- + +交作业时请在QQ 号后面填上各自的文章链接, 比如: + +51075907 http://m.blog.csdn.net/article/details?id=57083764 + +## 文章 +--- + +1204187480 + +102228177 + +876385982 + +785396327 + +1059107701 + +240094626 + +82427129 + +296910598 + +1264835468 + +516886559 + +1282579502 + +614982500 + +865797761 + +1540186032 + +176653813 + +116665530 + +51075907 + +1158154002 + +345450234 + +919764878 + +1368331120 + +517970312 + diff --git a/group17/count/homework.md b/group17/count/homework.md index a0abf5cadd..640cf4698f 100644 --- a/group17/count/homework.md +++ b/group17/count/homework.md @@ -17,5 +17,7 @@ * [20170305-20170312](https://github.com/luoziyihao/coding2017/blob/master/group17/article/20170305-20170312.md) - * [20170305-20170312](https://github.com/luoziyihao/coding2017/blob/master/group17/article/20170326-20170402.md) + * [20170326-20170402](https://github.com/luoziyihao/coding2017/blob/master/group17/article/20170326-20170402.md) + * [20170402-20170409](https://github.com/luoziyihao/coding2017/blob/master/group17/article/20170402-20170409.md) +20170326-20170402.md 20170402-20170409.md