From 49c1e7837fcc496b1edc0aa93f6aeace622e6c5d Mon Sep 17 00:00:00 2001
From: Pickacat
Date: Sun, 12 Mar 2017 18:04:44 +0800
Subject: [PATCH 001/262] =?UTF-8?q?=E5=AE=9E=E7=8E=B0=E5=9F=BA=E6=9C=AC?=
=?UTF-8?q?=E6=95=B0=E6=8D=AE=E7=BB=93=E6=9E=84=EF=BC=8C=E8=BF=AD=E4=BB=A3?=
=?UTF-8?q?=E5=99=A8=E8=BF=98=E6=B2=A1=E5=81=9A=E3=80=82?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../src/com/xiaol/study/ArrayList.java | 94 +++++++
.../src/com/xiaol/study/ArrayListTest.java | 82 ++++++
.../src/com/xiaol/study/BinaryTreeNode.java | 59 +++++
.../com/xiaol/study/BinaryTreeNodeTest.java | 82 ++++++
.../src/com/xiaol/study/Iterator.java | 12 +
.../src/com/xiaol/study/LinkedList.java | 237 ++++++++++++++++++
.../src/com/xiaol/study/LinkedListTest.java | 131 ++++++++++
.../src/com/xiaol/study/List.java | 13 +
.../src/com/xiaol/study/Queue.java | 41 +++
.../src/com/xiaol/study/QueueTest.java | 64 +++++
.../src/com/xiaol/study/Stack.java | 49 ++++
.../src/com/xiaol/study/StackTest.java | 68 +++++
12 files changed, 932 insertions(+)
create mode 100644 group23/381519422/DataStructure/src/com/xiaol/study/ArrayList.java
create mode 100644 group23/381519422/DataStructure/src/com/xiaol/study/ArrayListTest.java
create mode 100644 group23/381519422/DataStructure/src/com/xiaol/study/BinaryTreeNode.java
create mode 100644 group23/381519422/DataStructure/src/com/xiaol/study/BinaryTreeNodeTest.java
create mode 100644 group23/381519422/DataStructure/src/com/xiaol/study/Iterator.java
create mode 100644 group23/381519422/DataStructure/src/com/xiaol/study/LinkedList.java
create mode 100644 group23/381519422/DataStructure/src/com/xiaol/study/LinkedListTest.java
create mode 100644 group23/381519422/DataStructure/src/com/xiaol/study/List.java
create mode 100644 group23/381519422/DataStructure/src/com/xiaol/study/Queue.java
create mode 100644 group23/381519422/DataStructure/src/com/xiaol/study/QueueTest.java
create mode 100644 group23/381519422/DataStructure/src/com/xiaol/study/Stack.java
create mode 100644 group23/381519422/DataStructure/src/com/xiaol/study/StackTest.java
diff --git a/group23/381519422/DataStructure/src/com/xiaol/study/ArrayList.java b/group23/381519422/DataStructure/src/com/xiaol/study/ArrayList.java
new file mode 100644
index 0000000000..53fec62e67
--- /dev/null
+++ b/group23/381519422/DataStructure/src/com/xiaol/study/ArrayList.java
@@ -0,0 +1,94 @@
+package com.xiaol.study;
+
+/**
+ * @Description TODO
+ * @date 创建时间:2017年3月4日 下午11:03:26
+ */
+public class ArrayList implements List {
+
+ // 记录有多少元素
+ private int size = 0;
+
+ // 存放元素的数组
+ private Object[] elementData = new Object[10];
+
+ // 添加元素
+ public void add(Object o) {
+ checkSizeAndGrow();
+ elementData[size++] = o;
+ }
+
+ // 检查数组容量大小,不足就扩容
+ private void checkSizeAndGrow() {
+ if (size >= elementData.length) {
+ Object[] oldData = elementData;
+ elementData = new Object[size * 2];
+ System.arraycopy(oldData, 0, elementData, 0, size);
+ }
+ }
+
+ // 在指定位置添加元素
+ public void add(int index, Object o) {
+ checkIndex(index);
+ checkSizeAndGrow();
+ // 把index位置的元素往后移一位
+ System.arraycopy(elementData, index, elementData, index + 1, size - index);
+ elementData[index] = o;
+ size++;
+ }
+
+ // 检查插入元素的位置是否非法
+ private void checkIndex(int index) {
+ if (index < 0 || index > size) {
+ throw new RuntimeException("参数非法");
+ }
+ }
+
+ // 获取指定位置元素
+ public Object get(int index) {
+ checkIndex(index);
+ return elementData[index];
+ }
+
+ // 移除指定位置元素
+ public Object remove(int index) {
+ checkIndex(index);
+ Object returnVal = elementData[index];
+ System.arraycopy(elementData, index + 1, elementData, index, size - index - 1);
+ size--;
+ return returnVal;
+ }
+
+ // 获取ArrayList元素数量
+ public int size() {
+ return size;
+ }
+
+ // 获取迭代器
+ public Iterator iterator() {
+ return new ArrayListIterator();
+ }
+
+ // 尽量实现迭代器
+ private class ArrayListIterator implements Iterator {
+
+ ArrayList list = null;
+
+ @Override
+ public boolean hasNext() {
+
+ return false;
+ }
+
+ @Override
+ public Object next() {
+ return null;
+ }
+
+ public Object remove() {
+ return null;
+ }
+
+ }
+
+}
diff --git a/group23/381519422/DataStructure/src/com/xiaol/study/ArrayListTest.java b/group23/381519422/DataStructure/src/com/xiaol/study/ArrayListTest.java
new file mode 100644
index 0000000000..fc54a78e47
--- /dev/null
+++ b/group23/381519422/DataStructure/src/com/xiaol/study/ArrayListTest.java
@@ -0,0 +1,82 @@
+package com.xiaol.study;
+
+import static org.junit.Assert.assertEquals;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+public class ArrayListTest {
+
+ @Before
+ public void setUp() throws Exception {
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ }
+
+ @Test
+ public void testAddObject() {
+ ArrayList list = new ArrayList();
+ list.add("a");
+ list.add("b");
+ list.add("c");
+ list.add("d");
+ list.add("e");
+ list.add("f");
+ list.add(1);
+ list.add(2);
+ list.add(3);
+ list.add(4);
+ list.add(5);
+ list.add(6);
+ assertEquals(12, list.size());
+ }
+
+ @Test
+ public void testAddIntObject() {
+ ArrayList list = new ArrayList();
+ list.add(1);
+ list.add(2);
+ list.add(0, 3);
+ assertEquals(3, list.get(0));
+ assertEquals(1, list.get(1));
+ assertEquals(2, list.get(2));
+ assertEquals(3, list.size());
+ }
+
+ @Test
+ public void testGet() {
+ ArrayList list = new ArrayList();
+ list.add(1);
+ list.add(2);
+ list.add(0, 3);
+ assertEquals(3, list.get(0));
+ assertEquals(1, list.get(1));
+ assertEquals(2, list.get(2));
+ assertEquals(3, list.size());
+ }
+
+ @Test
+ public void testRemove() {
+ ArrayList list = new ArrayList();
+ list.add(1);
+ list.add(2);
+ list.add(0, 3);
+ assertEquals(3, list.remove(0));
+ assertEquals(1, list.remove(0));
+ assertEquals(2, list.remove(0));
+ assertEquals(0, list.size());
+ }
+
+ @Test
+ public void testSize() {
+ ArrayList list = new ArrayList();
+ list.add(1);
+ list.add(2);
+ list.add(0, 3);
+ assertEquals(3, list.size());
+ }
+
+}
diff --git a/group23/381519422/DataStructure/src/com/xiaol/study/BinaryTreeNode.java b/group23/381519422/DataStructure/src/com/xiaol/study/BinaryTreeNode.java
new file mode 100644
index 0000000000..7572a945df
--- /dev/null
+++ b/group23/381519422/DataStructure/src/com/xiaol/study/BinaryTreeNode.java
@@ -0,0 +1,59 @@
+package com.xiaol.study;
+
+/**
+ * @Description TODO
+ * @date 创建时间:2017年3月5日 上午12:57:18
+ */
+public class BinaryTreeNode {
+ // 要求,左节点比父节点小,右节点比父节点大
+ private Object data;
+ private BinaryTreeNode left;
+ private BinaryTreeNode right;
+
+ public BinaryTreeNode insert(Object o) {
+ // 当前没有数据就放入当前节点
+ if (data == null) {
+ this.data = o;
+ } else if ((int) data >= (int) o) {// 放入左节点
+ if (left == null) {
+ left = new BinaryTreeNode();
+ left.setData(o);
+ } else {
+ left.insert(o);
+ }
+ } else if ((int) data < (int) o) {// 放入右节点
+ if (right == null) {
+ right = new BinaryTreeNode();
+ right.setData(o);
+ } else {
+ right.insert(o);
+ }
+ }
+ return this;
+ }
+
+ public Object getData() {
+ return data;
+ }
+
+ public void setData(Object data) {
+ this.data = data;
+ }
+
+ public BinaryTreeNode getLeft() {
+ return left;
+ }
+
+ public void setLeft(BinaryTreeNode left) {
+ this.left = left;
+ }
+
+ public BinaryTreeNode getRight() {
+ return right;
+ }
+
+ public void setRight(BinaryTreeNode right) {
+ this.right = right;
+ }
+
+}
diff --git a/group23/381519422/DataStructure/src/com/xiaol/study/BinaryTreeNodeTest.java b/group23/381519422/DataStructure/src/com/xiaol/study/BinaryTreeNodeTest.java
new file mode 100644
index 0000000000..7e028ac8a5
--- /dev/null
+++ b/group23/381519422/DataStructure/src/com/xiaol/study/BinaryTreeNodeTest.java
@@ -0,0 +1,82 @@
+package com.xiaol.study;
+
+import static org.junit.Assert.*;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+public class BinaryTreeNodeTest {
+
+ @Before
+ public void setUp() throws Exception {
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ }
+
+ @Test
+ public void testInsert() {
+ BinaryTreeNode btn = new BinaryTreeNode();
+ btn.insert(1);
+ btn.insert(2);
+ btn.insert(0);
+ btn.insert(3);
+ assertEquals(0, btn.getLeft().getData());
+ assertEquals(1, btn.getData());
+ assertEquals(2, btn.getRight().getData());
+ assertEquals(3, btn.getRight().getRight().getData());
+ }
+
+ @Test
+ public void testGetData() {
+ BinaryTreeNode btn = new BinaryTreeNode();
+ btn.insert(1);
+ assertEquals(1, btn.getData());
+ }
+
+ @Test
+ public void testSetData() {
+ BinaryTreeNode btn = new BinaryTreeNode();
+ btn.setData(1);
+ assertEquals(1, btn.getData());
+ }
+
+ @Test
+ public void testGetLeft() {
+ BinaryTreeNode btn = new BinaryTreeNode();
+ btn.insert(1);
+ btn.insert(0);
+ assertEquals(0, btn.getLeft().getData());
+ }
+
+ @Test
+ public void testSetLeft() {
+ BinaryTreeNode btn = new BinaryTreeNode();
+ btn.insert(1);
+ BinaryTreeNode left = new BinaryTreeNode();
+ left.setData(2);
+ btn.setLeft(left);
+ assertEquals(2, btn.getLeft().getData());
+ }
+
+ @Test
+ public void testGetRight() {
+ BinaryTreeNode btn = new BinaryTreeNode();
+ btn.insert(1);
+ btn.insert(2);
+ assertEquals(2, btn.getRight().getData());
+ }
+
+ @Test
+ public void testSetRight() {
+ BinaryTreeNode btn = new BinaryTreeNode();
+ btn.insert(1);
+ BinaryTreeNode right = new BinaryTreeNode();
+ right.setData(2);
+ btn.setRight(right);
+ assertEquals(2, btn.getRight().getData());
+ }
+
+}
diff --git a/group23/381519422/DataStructure/src/com/xiaol/study/Iterator.java b/group23/381519422/DataStructure/src/com/xiaol/study/Iterator.java
new file mode 100644
index 0000000000..3f9192d422
--- /dev/null
+++ b/group23/381519422/DataStructure/src/com/xiaol/study/Iterator.java
@@ -0,0 +1,12 @@
+package com.xiaol.study;
+
+/**
+ * @Description TODO
+ * @date 创建时间:2017年3月5日 上午1:12:05
+ */
+public interface Iterator {
+
+ public boolean hasNext();
+
+ public Object next();
+}
diff --git a/group23/381519422/DataStructure/src/com/xiaol/study/LinkedList.java b/group23/381519422/DataStructure/src/com/xiaol/study/LinkedList.java
new file mode 100644
index 0000000000..d60ede59a1
--- /dev/null
+++ b/group23/381519422/DataStructure/src/com/xiaol/study/LinkedList.java
@@ -0,0 +1,237 @@
+package com.xiaol.study;
+
+/**
+ * @Description TODO
+ * @date 创建时间:2017年3月5日 上午12:30:18
+ */
+public class LinkedList implements List {
+
+ // 头指针
+ private Node head;
+
+ // 最后一个节点
+ private Node lastNode;
+
+ // 链表长度
+ private int size;
+
+ // 添加元素到最后一个节点
+ public void add(Object o) {
+ if (null == head) {
+ head = new Node(o);
+ head.next = null;
+ lastNode = head;
+ size++;
+ } else {
+ lastNode.next = new Node(o);
+ lastNode = getLastNode();
+ size++;
+ }
+ }
+
+ // 获取最后一个节点
+ private Node getLastNode() {
+ Node last = head;
+ while (last.next != null) {
+ last = last.next;
+ }
+ return last;
+ }
+
+ // 获取指定位置的Node
+ private Node getIndexNode(int index) {
+ Node node = head;
+ for (int i = 0; i < index; i++) {
+ node = node.next;
+ }
+ return node;
+ }
+
+ // 添加元素到指定位置
+ public void add(int index, Object o) {
+ checkIndex(index);
+ if (index == 0) {
+ // 将head暂存为headNext
+ Node headNext = head;
+ // 创建新的head
+ Node newHead = new Node(o);
+ head = newHead;
+ head.next = headNext;
+ } else {
+ // 获取第index-1个位置的Node
+ Node node = getIndexNode(index - 1);
+ // 暂存index位置的Node
+ Node nodeNext = node.next;
+ // 向index位置插入数据
+ node.next = new Node(o);
+ node.next.next = nodeNext;
+ }
+ size++;
+ }
+
+ // 获取指定位置元素
+ public Object get(int index) {
+ checkIndex(index);
+ Node node = head;
+ for (int i = 0; i < index; i++) {
+ node = node.next;
+ }
+ return node.data;
+ }
+
+ private void checkIndex(int index) {
+ if (index < 0 || index > size) {
+ throw new RuntimeException("非法参数");
+ }
+ }
+
+ // 移除指定位置元素
+ public Object remove(int index) {
+ checkIndex(index);
+ Object data = null;
+ if (index == 0) {
+ // 新的head
+ Node newHead = head.next;
+ // 获取移除元素
+ data = head.data;
+ // 将newHead设为head
+ head = newHead;
+ } else {
+ // 获取第index-1个位置的Node
+ Node node = getIndexNode(index - 1);
+ // 获取返回的元素
+ data = node.next.data;
+ // 将index位置从链表删除
+ node.next = node.next.next;
+ }
+ size--;
+ return data;
+ }
+
+ // 获取链表长度
+ public int size() {
+ return size;
+ }
+
+ // 添加元素到第一个节点
+ public void addFirst(Object o) {
+ add(0, o);
+ }
+
+ public void addLast(Object o) {
+ Node lastNode = getLastNode();
+ lastNode.next = new Node(o);
+ size++;
+ }
+
+ // 移除第一个元素
+ public Object removeFirst() {
+ return remove(0);
+ }
+
+ // 移除最后一个元素
+ public Object removeLast() {
+ Node lastNode = getLastNode();
+ Object data = lastNode.data;
+ lastNode = null;
+ size--;
+ return data;
+ }
+
+ public Iterator iterator() {
+ return null;
+ }
+
+ // 用于存储数据的节点
+ private static class Node {
+ Object data;
+ Node next;
+
+ // 无参构造
+ private Node() {
+
+ }
+
+ // 有参构造
+ private Node(Object o) {
+ this.data = o;
+ }
+ }
+
+ //---------------下面的方法暂时先不实现
+
+ /**
+ * 把该链表逆置
+ * 例如链表为 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/group23/381519422/DataStructure/src/com/xiaol/study/LinkedListTest.java b/group23/381519422/DataStructure/src/com/xiaol/study/LinkedListTest.java
new file mode 100644
index 0000000000..f6399c1a1a
--- /dev/null
+++ b/group23/381519422/DataStructure/src/com/xiaol/study/LinkedListTest.java
@@ -0,0 +1,131 @@
+package com.xiaol.study;
+
+import static org.junit.Assert.assertEquals;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+public class LinkedListTest {
+
+ @Before
+ public void setUp() throws Exception {
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ }
+
+ @Test
+ public void testAddObject() {
+ LinkedList ll = new LinkedList();
+ ll.add(1);
+ ll.add(2);
+ ll.add(3);
+ assertEquals(1, ll.get(0));
+ assertEquals(2, ll.get(1));
+ assertEquals(3, ll.get(2));
+ }
+
+ @Test
+ public void testAddIntObject() {
+ LinkedList ll = new LinkedList();
+ ll.add(1);
+ ll.add(2);
+ ll.add(3);
+ ll.add(3, 0);
+ assertEquals(1, ll.get(0));
+ assertEquals(2, ll.get(1));
+ assertEquals(3, ll.get(2));
+ assertEquals(0, ll.get(3));
+ assertEquals(4, ll.size());
+ }
+
+ @Test
+ public void testGet() {
+ LinkedList ll = new LinkedList();
+ ll.add(1);
+ ll.add(2);
+ ll.add(3);
+ ll.add(3, 0);
+ assertEquals(1, ll.get(0));
+ assertEquals(2, ll.get(1));
+ assertEquals(3, ll.get(2));
+ assertEquals(0, ll.get(3));
+ assertEquals(4, ll.size());
+ }
+
+ @Test
+ public void testRemove() {
+ LinkedList ll = new LinkedList();
+ ll.add(1);
+ ll.add(2);
+ ll.add(3);
+ ll.add(0, 0);
+ ll.remove(0);
+ assertEquals(1, ll.get(0));
+ assertEquals(2, ll.get(1));
+ assertEquals(3, ll.get(2));
+ }
+
+ @Test
+ public void testSize() {
+ LinkedList ll = new LinkedList();
+ ll.add(1);
+ ll.add(2);
+ ll.add(3);
+ ll.add(0, 0);
+ assertEquals(4, ll.size());
+ }
+
+ @Test
+ public void testAddFirst() {
+ LinkedList ll = new LinkedList();
+ ll.add(1);
+ ll.add(2);
+ ll.addFirst(001);
+ ll.addFirst(002);
+ assertEquals(002, ll.get(0));
+ assertEquals(001, ll.get(1));
+ assertEquals(1, ll.get(2));
+ assertEquals(2, ll.get(3));
+ }
+
+ @Test
+ public void testAddLast() {
+ LinkedList ll = new LinkedList();
+ ll.add(1);
+ ll.add(2);
+ ll.addLast(001);
+ ll.addLast(002);
+ assertEquals(1, ll.get(0));
+ assertEquals(2, ll.get(1));
+ assertEquals(001, ll.get(2));
+ assertEquals(002, ll.get(3));
+ }
+
+ @Test
+ public void testRemoveFirst() {
+ LinkedList ll = new LinkedList();
+ ll.add(1);
+ ll.add(2);
+ ll.add(3);
+ ll.removeFirst();
+ ll.removeFirst();
+ assertEquals(3, ll.get(0));
+ assertEquals(1, ll.size());
+ }
+
+ @Test
+ public void testRemoveLast() {
+ LinkedList ll = new LinkedList();
+ ll.add(1);
+ ll.add(2);
+ ll.add(3);
+ ll.removeLast();
+ assertEquals(1, ll.get(0));
+ assertEquals(2, ll.get(1));
+ assertEquals(2, ll.size());
+ }
+
+}
diff --git a/group23/381519422/DataStructure/src/com/xiaol/study/List.java b/group23/381519422/DataStructure/src/com/xiaol/study/List.java
new file mode 100644
index 0000000000..870635c7bb
--- /dev/null
+++ b/group23/381519422/DataStructure/src/com/xiaol/study/List.java
@@ -0,0 +1,13 @@
+package com.xiaol.study;
+
+public interface List {
+ public void add(Object o);
+
+ public void add(int index, Object o);
+
+ public Object get(int index);
+
+ public Object remove(int index);
+
+ public int size();
+}
diff --git a/group23/381519422/DataStructure/src/com/xiaol/study/Queue.java b/group23/381519422/DataStructure/src/com/xiaol/study/Queue.java
new file mode 100644
index 0000000000..6a18fe5c4e
--- /dev/null
+++ b/group23/381519422/DataStructure/src/com/xiaol/study/Queue.java
@@ -0,0 +1,41 @@
+package com.xiaol.study;
+
+import java.util.LinkedList;
+
+/**
+ * @Description TODO
+ * @date 创建时间:2017年3月5日 上午12:51:34
+ */
+public class Queue {
+
+ // 队列
+ private LinkedList elementData = new LinkedList();
+ // 队列长度
+ private int size;
+
+ // 添加元素到队列尾
+ public void enQueue(Object o) {
+ elementData.add(o);
+ size++;
+ }
+
+ // 移除队列头的元素
+ public Object deQueue() {
+ Object data = elementData.removeLast();
+ size--;
+ return data;
+ }
+
+ // 队列是否为空
+ public boolean isEmpty() {
+ if (size == 0) {
+ return true;
+ }
+ return false;
+ }
+
+ // 队列长度
+ public int size() {
+ return size;
+ }
+}
diff --git a/group23/381519422/DataStructure/src/com/xiaol/study/QueueTest.java b/group23/381519422/DataStructure/src/com/xiaol/study/QueueTest.java
new file mode 100644
index 0000000000..a89e8840ce
--- /dev/null
+++ b/group23/381519422/DataStructure/src/com/xiaol/study/QueueTest.java
@@ -0,0 +1,64 @@
+package com.xiaol.study;
+
+import static org.junit.Assert.*;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+public class QueueTest {
+
+ @Before
+ public void setUp() throws Exception {
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ }
+
+ @Test
+ public void testEnQueue() {
+ Queue q = new Queue();
+ assertEquals(0, q.size());
+ q.enQueue(1);
+ q.enQueue(2);
+ assertEquals(2, q.size());
+ }
+
+ @Test
+ public void testDeQueue() {
+ Queue q = new Queue();
+ assertEquals(0, q.size());
+ q.enQueue(1);
+ q.enQueue(2);
+ assertEquals(2, q.size());
+ q.deQueue();
+ q.deQueue();
+ assertEquals(0, q.size());
+ }
+
+ @Test
+ public void testIsEmpty() {
+ Queue q = new Queue();
+ assertEquals(true, q.isEmpty());
+ q.enQueue(1);
+ q.enQueue(2);
+ assertEquals(false, q.isEmpty());
+ q.deQueue();
+ q.deQueue();
+ assertEquals(true, q.isEmpty());
+ }
+
+ @Test
+ public void testSize() {
+ Queue q = new Queue();
+ assertEquals(0, q.size());
+ q.enQueue(1);
+ q.enQueue(2);
+ assertEquals(2, q.size());
+ q.deQueue();
+ q.deQueue();
+ assertEquals(0, q.size());
+ }
+
+}
diff --git a/group23/381519422/DataStructure/src/com/xiaol/study/Stack.java b/group23/381519422/DataStructure/src/com/xiaol/study/Stack.java
new file mode 100644
index 0000000000..6e1eaf2cf8
--- /dev/null
+++ b/group23/381519422/DataStructure/src/com/xiaol/study/Stack.java
@@ -0,0 +1,49 @@
+package com.xiaol.study;
+
+import java.util.ArrayList;
+
+/**
+ * @Description TODO
+ * @date 创建时间:2017年3月5日 上午12:47:15
+ */
+public class Stack {
+ // 存数据的List
+ private ArrayList elementData = new ArrayList();
+
+ // 栈元素数量
+ private int size;
+
+ // 压栈
+ public void push(Object o) {
+ elementData.add(o);
+ size++;
+ }
+
+ // 弹出栈顶元素
+ public Object pop() {
+ if (size == 0) {
+ throw new RuntimeException("Stack is Empty");
+ }
+ Object data = elementData.remove(size - 1);
+ size--;
+ return data;
+ }
+
+ // 获取栈顶元素
+ public Object peek() {
+ return elementData.get(size - 1);
+ }
+
+ // 是否为空
+ public boolean isEmpty() {
+ if (size == 0) {
+ return true;
+ }
+ return false;
+ }
+
+ // 栈大小
+ public int size() {
+ return size;
+ }
+}
diff --git a/group23/381519422/DataStructure/src/com/xiaol/study/StackTest.java b/group23/381519422/DataStructure/src/com/xiaol/study/StackTest.java
new file mode 100644
index 0000000000..90eae7470d
--- /dev/null
+++ b/group23/381519422/DataStructure/src/com/xiaol/study/StackTest.java
@@ -0,0 +1,68 @@
+package com.xiaol.study;
+
+import static org.junit.Assert.*;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+public class StackTest {
+
+ @Before
+ public void setUp() throws Exception {
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ }
+
+ @Test
+ public void testPush() {
+ Stack s = new Stack();
+ s.push(1);
+ s.push(2);
+ s.push(3);
+ assertEquals(3, s.size());
+ }
+
+ @Test
+ public void testPop() {
+ Stack s = new Stack();
+ s.push(1);
+ s.push(2);
+ s.push(3);
+ assertEquals(3, s.pop());
+ assertEquals(2, s.pop());
+ assertEquals(1, s.pop());
+ assertEquals(0, s.size());
+ }
+
+ @Test
+ public void testPeek() {
+ Stack s = new Stack();
+ s.push(1);
+ s.push(2);
+ s.push(3);
+ assertEquals(3, s.peek());
+ }
+
+ @Test
+ public void testIsEmpty() {
+ Stack s = new Stack();
+ assertEquals(true, s.isEmpty());
+ s.push(1);
+ s.push(2);
+ s.push(3);
+ assertEquals(false, s.isEmpty());
+ }
+
+ @Test
+ public void testSize() {
+ Stack s = new Stack();
+ s.push(1);
+ s.push(2);
+ s.push(3);
+ assertEquals(3, s.size());
+ }
+
+}
From b3f08719cb9f97d20fa922dffe14816c0c7aa4ef Mon Sep 17 00:00:00 2001
From: tanghaojie
Date: Wed, 15 Mar 2017 21:06:48 +0800
Subject: [PATCH 002/262] week3
---
.../Code/src/week3/DownloadThread.java | 20 ++++++
.../Code/src/week3/FileDownloader.java | 72 +++++++++++++++++++
.../Code/src/week3/FileDownloaderTest.java | 61 ++++++++++++++++
.../Code/src/week3/api/Connection.java | 23 ++++++
.../src/week3/api/ConnectionException.java | 5 ++
.../Code/src/week3/api/ConnectionManager.java | 10 +++
.../Code/src/week3/api/DownloadListener.java | 5 ++
.../Code/src/week3/impl/ConnectionImpl.java | 26 +++++++
.../src/week3/impl/ConnectionManagerImpl.java | 18 +++++
9 files changed, 240 insertions(+)
create mode 100644 group12/495473393/Code/src/week3/DownloadThread.java
create mode 100644 group12/495473393/Code/src/week3/FileDownloader.java
create mode 100644 group12/495473393/Code/src/week3/FileDownloaderTest.java
create mode 100644 group12/495473393/Code/src/week3/api/Connection.java
create mode 100644 group12/495473393/Code/src/week3/api/ConnectionException.java
create mode 100644 group12/495473393/Code/src/week3/api/ConnectionManager.java
create mode 100644 group12/495473393/Code/src/week3/api/DownloadListener.java
create mode 100644 group12/495473393/Code/src/week3/impl/ConnectionImpl.java
create mode 100644 group12/495473393/Code/src/week3/impl/ConnectionManagerImpl.java
diff --git a/group12/495473393/Code/src/week3/DownloadThread.java b/group12/495473393/Code/src/week3/DownloadThread.java
new file mode 100644
index 0000000000..53d7ed3101
--- /dev/null
+++ b/group12/495473393/Code/src/week3/DownloadThread.java
@@ -0,0 +1,20 @@
+package week3;
+
+import week3.api.Connection;
+
+public class DownloadThread extends Thread{
+
+ Connection conn;
+ int startPos;
+ int endPos;
+
+ public DownloadThread( Connection conn, int startPos, int endPos){
+
+ this.conn = conn;
+ this.startPos = startPos;
+ this.endPos = endPos;
+ }
+ public void run(){
+
+ }
+}
diff --git a/group12/495473393/Code/src/week3/FileDownloader.java b/group12/495473393/Code/src/week3/FileDownloader.java
new file mode 100644
index 0000000000..7a6b104245
--- /dev/null
+++ b/group12/495473393/Code/src/week3/FileDownloader.java
@@ -0,0 +1,72 @@
+package week3;
+
+import week3.api.Connection;
+import week3.api.ConnectionException;
+import week3.api.ConnectionManager;
+import week3.api.DownloadListener;
+
+public class FileDownloader {
+
+ String url;
+
+ DownloadListener listener;
+
+ ConnectionManager cm;
+
+
+ public FileDownloader(String _url) {
+ this.url = _url;
+
+ }
+
+ public void execute(){
+ // 在这里实现你的代码, 注意: 需要用多线程实现下载
+ // 这个类依赖于其他几个接口, 你需要写这几个接口的实现代码
+ // (1) ConnectionManager , 可以打开一个连接,通过Connection可以读取其中的一段(用startPos, endPos来指定)
+ // (2) DownloadListener, 由于是多线程下载, 调用这个类的客户端不知道什么时候结束,所以你需要实现当所有
+ // 线程都执行完以后, 调用listener的notifiedFinished方法, 这样客户端就能收到通知。
+ // 具体的实现思路:
+ // 1. 需要调用ConnectionManager的open方法打开连接, 然后通过Connection.getContentLength方法获得文件的长度
+ // 2. 至少启动3个线程下载, 注意每个线程需要先调用ConnectionManager的open方法
+ // 然后调用read方法, read方法中有读取文件的开始位置和结束位置的参数, 返回值是byte[]数组
+ // 3. 把byte数组写入到文件中
+ // 4. 所有的线程都下载完成以后, 需要调用listener的notifiedFinished方法
+
+ // 下面的代码是示例代码, 也就是说只有一个线程, 你需要改造成多线程的。
+ Connection conn = null;
+ try {
+
+ conn = cm.open(this.url);
+
+ int length = conn.getContentLength();
+
+ new DownloadThread(conn,0,length-1).start();
+
+ } catch (ConnectionException e) {
+ e.printStackTrace();
+ }finally{
+ if(conn != null){
+ conn.close();
+ }
+ }
+
+
+
+
+ }
+
+ public void setListener(DownloadListener listener) {
+ this.listener = listener;
+ }
+
+
+
+ public void setConnectionManager(ConnectionManager ucm){
+ this.cm = ucm;
+ }
+
+ public DownloadListener getListener(){
+ return this.listener;
+ }
+
+}
diff --git a/group12/495473393/Code/src/week3/FileDownloaderTest.java b/group12/495473393/Code/src/week3/FileDownloaderTest.java
new file mode 100644
index 0000000000..b6ddb18069
--- /dev/null
+++ b/group12/495473393/Code/src/week3/FileDownloaderTest.java
@@ -0,0 +1,61 @@
+package week3;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+import week3.api.ConnectionManager;
+import week3.api.DownloadListener;
+import week3.impl.ConnectionManagerImpl;
+
+
+
+public class FileDownloaderTest {
+ boolean downloadFinished = false;
+ @Before
+ public void setUp() throws Exception {
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ }
+
+ @Test
+ public void testDownload() {
+
+ String url = "http://localhost:8080/test.jpg";
+
+ FileDownloader downloader = new FileDownloader(url);
+
+
+ ConnectionManager cm = new ConnectionManagerImpl();
+ downloader.setConnectionManager(cm);
+
+ downloader.setListener(new DownloadListener() {
+ @Override
+ public void notifyFinished() {
+ downloadFinished = true;
+ }
+
+ });
+
+
+ downloader.execute();
+
+ // 等待多线程下载程序执行完毕
+ while (!downloadFinished) {
+ try {
+ System.out.println("还没有下载完成,休眠五秒");
+ //休眠5秒
+ Thread.sleep(5000);
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+ }
+ System.out.println("下载完成!");
+
+
+
+ }
+
+}
diff --git a/group12/495473393/Code/src/week3/api/Connection.java b/group12/495473393/Code/src/week3/api/Connection.java
new file mode 100644
index 0000000000..bba3230710
--- /dev/null
+++ b/group12/495473393/Code/src/week3/api/Connection.java
@@ -0,0 +1,23 @@
+package week3.api;
+
+import java.io.IOException;
+
+public interface Connection {
+ /**
+ * 给定开始和结束位置, 读取数据, 返回值是字节数组
+ * @param startPos 开始位置, 从0开始
+ * @param endPos 结束位置
+ * @return
+ */
+ public byte[] read(int startPos,int endPos) throws IOException;
+ /**
+ * 得到数据内容的长度
+ * @return
+ */
+ public int getContentLength();
+
+ /**
+ * 关闭连接
+ */
+ public void close();
+}
diff --git a/group12/495473393/Code/src/week3/api/ConnectionException.java b/group12/495473393/Code/src/week3/api/ConnectionException.java
new file mode 100644
index 0000000000..e760e23ddb
--- /dev/null
+++ b/group12/495473393/Code/src/week3/api/ConnectionException.java
@@ -0,0 +1,5 @@
+package week3.api;
+
+public class ConnectionException extends Exception {
+
+}
diff --git a/group12/495473393/Code/src/week3/api/ConnectionManager.java b/group12/495473393/Code/src/week3/api/ConnectionManager.java
new file mode 100644
index 0000000000..9b20c0177b
--- /dev/null
+++ b/group12/495473393/Code/src/week3/api/ConnectionManager.java
@@ -0,0 +1,10 @@
+package week3.api;
+
+public interface ConnectionManager {
+ /**
+ * 给定一个url , 打开一个连接
+ * @param url
+ * @return
+ */
+ public Connection open(String url) throws ConnectionException;
+}
diff --git a/group12/495473393/Code/src/week3/api/DownloadListener.java b/group12/495473393/Code/src/week3/api/DownloadListener.java
new file mode 100644
index 0000000000..da4eb7abc3
--- /dev/null
+++ b/group12/495473393/Code/src/week3/api/DownloadListener.java
@@ -0,0 +1,5 @@
+package week3.api;
+
+public interface DownloadListener {
+ public void notifyFinished();
+}
diff --git a/group12/495473393/Code/src/week3/impl/ConnectionImpl.java b/group12/495473393/Code/src/week3/impl/ConnectionImpl.java
new file mode 100644
index 0000000000..e354f10029
--- /dev/null
+++ b/group12/495473393/Code/src/week3/impl/ConnectionImpl.java
@@ -0,0 +1,26 @@
+package week3.impl;
+
+import java.io.IOException;
+import week3.api.Connection;
+
+public class ConnectionImpl implements Connection{
+
+ @Override
+ public byte[] read(int startPos, int endPos) throws IOException {
+
+ return null;
+ }
+
+ @Override
+ public int getContentLength() {
+
+ return 0;
+ }
+
+ @Override
+ public void close() {
+
+
+ }
+
+}
diff --git a/group12/495473393/Code/src/week3/impl/ConnectionManagerImpl.java b/group12/495473393/Code/src/week3/impl/ConnectionManagerImpl.java
new file mode 100644
index 0000000000..d58a2b600d
--- /dev/null
+++ b/group12/495473393/Code/src/week3/impl/ConnectionManagerImpl.java
@@ -0,0 +1,18 @@
+package week3.impl;
+
+import java.net.HttpURLConnection;
+import java.net.URL;
+
+import week3.api.Connection;
+import week3.api.ConnectionException;
+import week3.api.ConnectionManager;
+
+public class ConnectionManagerImpl implements ConnectionManager {
+
+ @Override
+ public Connection open(String url) throws ConnectionException {
+
+ return null;
+ }
+
+}
From c5b690dc9e147e0cc771ed4f6785c597e6bf39aa Mon Sep 17 00:00:00 2001
From: Pickacat
Date: Sun, 19 Mar 2017 18:54:38 +0800
Subject: [PATCH 003/262] =?UTF-8?q?=E6=B7=BB=E5=8A=A0array=E9=A1=B9?=
=?UTF-8?q?=E7=9B=AE?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
group23/381519422/array/.classpath | 7 +
group23/381519422/array/.gitignore | 1 +
group23/381519422/array/.project | 17 +
.../381519422/array/src/array/ArrayUtil.java | 354 ++++++++++++++++++
.../array/src/array/ArrayUtilTest.java | 116 ++++++
5 files changed, 495 insertions(+)
create mode 100644 group23/381519422/array/.classpath
create mode 100644 group23/381519422/array/.gitignore
create mode 100644 group23/381519422/array/.project
create mode 100644 group23/381519422/array/src/array/ArrayUtil.java
create mode 100644 group23/381519422/array/src/array/ArrayUtilTest.java
diff --git a/group23/381519422/array/.classpath b/group23/381519422/array/.classpath
new file mode 100644
index 0000000000..3e0fb272a8
--- /dev/null
+++ b/group23/381519422/array/.classpath
@@ -0,0 +1,7 @@
+
+
+
+
+
+
+
diff --git a/group23/381519422/array/.gitignore b/group23/381519422/array/.gitignore
new file mode 100644
index 0000000000..ae3c172604
--- /dev/null
+++ b/group23/381519422/array/.gitignore
@@ -0,0 +1 @@
+/bin/
diff --git a/group23/381519422/array/.project b/group23/381519422/array/.project
new file mode 100644
index 0000000000..ef3cae8954
--- /dev/null
+++ b/group23/381519422/array/.project
@@ -0,0 +1,17 @@
+
+
+ array
+
+
+
+
+
+ org.eclipse.jdt.core.javabuilder
+
+
+
+
+
+ org.eclipse.jdt.core.javanature
+
+
diff --git a/group23/381519422/array/src/array/ArrayUtil.java b/group23/381519422/array/src/array/ArrayUtil.java
new file mode 100644
index 0000000000..cb1d3f49dc
--- /dev/null
+++ b/group23/381519422/array/src/array/ArrayUtil.java
@@ -0,0 +1,354 @@
+package array;
+
+import java.util.ArrayList;
+
+public class ArrayUtil {
+
+ /**
+ * 给定一个整形数组a , 对该数组的值进行置换
+ 例如: a = [7, 9 , 30, 3] , 置换后为 [3, 30, 9,7]
+ 如果 a = [7, 9, 30, 3, 4] , 置换后为 [4,3, 30 , 9,7]
+ * @param origin
+ * @return
+ */
+ public void reverseArray(int[] origin) {
+ if (origin == null || origin.length <= 1) {
+ return;
+ }
+ //第1和第length互换位置,第2和第length-1互换,以此类推
+ for (int i = 0; i < origin.length / 2; i++) {
+ int temp = origin[i];
+ origin[i] = origin[origin.length - 1 - i];
+ origin[origin.length - 1 - i] = temp;
+ }
+ }
+
+ /**
+ * 现在有如下的一个数组: int oldArr[]={1,3,4,5,0,0,6,6,0,5,4,7,6,7,0,5}
+ * 要求将以上数组中值为0的项去掉,将不为0的值存入一个新的数组,生成的新数组为:
+ * {1,3,4,5,6,6,5,4,7,6,7,5}
+ * @param oldArray
+ * @return
+ */
+ public int[] removeZero(int[] oldArray) {
+ // 判断非法输入
+ if (oldArray == null || oldArray.length == 0) {
+ return null;
+ }
+
+ // 创建临时数组,长度与原oldArray一样长
+ int[] temp = new int[oldArray.length];
+ int tempCount = 0;
+ for (int i = 0; i < oldArray.length; i++) {
+ // 判断元素是0跳过
+ if (oldArray[i] == 0) {
+ continue;
+ } else {// 非零放入临时数组,计数器加1
+ temp[tempCount++] = oldArray[i];
+ }
+ }
+
+ // 如果计数器与原数组长度一致,直接返回临时数组
+ if (tempCount == oldArray.length) {
+ return temp;
+ } else {// 否则返回长度为tempCount的数组
+ int[] retVal = new int[tempCount];
+ System.arraycopy(temp, 0, retVal, 0, tempCount);
+ return retVal;
+ }
+ }
+
+ /**
+ * 给定两个已经排序好的整形数组, a1和a2 , 创建一个新的数组a3, 使得a3 包含a1和a2 的所有元素, 并且仍然是有序的
+ * 例如 a1 = [3, 5, 7,8] a2 = [4, 5, 6,7] 则 a3 为[3,4,5,6,7,8] , 注意: 已经消除了重复
+ * @param array1
+ * @param array2
+ * @return
+ */
+ public int[] merge(int[] array1, int[] array2) {
+ // 创建临时数组,长度为array1+array2的长度
+ int[] temp = new int[array1.length + array2.length];
+ int index = 0;// temp的下标
+ int i = 0;// array1的下标
+ int j = 0;// array2的下标
+ int count = 0;// temp存放元素的计数器
+
+ while (true) {
+
+ if (i == array1.length) {// 当array1已经全部添加到temp,就把array2剩余的放入temp
+ for (int l = j; l < array2.length; l++) {
+ temp[index++] = array2[l];
+ count++;
+ }
+ break;
+ } else if (j == array2.length) {// 当array2已经全部添加到temp,就把array1剩余的放入temp
+ for (int l = i; l < array1.length; l++) {
+ temp[index++] = array1[l];
+ count++;
+ }
+ break;
+ }
+
+ // 取array1第i和array2第j个元素比较。如果array1[i]的小于array2[j],则array1[i]放入temp
+ // 同时i++,使得下次为i+1和j个元素比较。
+ // 如果array1第i和array2第j个元素相等。则array1[i]放入temp
+ // 同时i++,j++,使得下次为i+1和j+1个元素比较。
+ if (array1[i] < array2[j]) {
+ temp[index++] = array1[i++];
+ count++;
+ } else if (array1[i] > array2[j]) {
+ temp[index++] = array2[j++];
+ count++;
+ } else {
+ temp[index++] = array1[i];
+ i++;
+ j++;
+ count++;
+ }
+ }
+
+ // 如果计数器和temp.length相等,直接返回
+ if (count == temp.length) {
+ return temp;
+ } else {// 否则创建长度为count的新数组返回
+ int[] retVal = new int[count];
+ System.arraycopy(temp, 0, retVal, 0, count);
+ return retVal;
+ }
+ }
+
+ /**
+ * 把一个已经存满数据的数组 oldArray的容量进行扩展, 扩展后的新数据大小为oldArray.length + size
+ * 注意,老数组的元素在新数组中需要保持
+ * 例如 oldArray = [2,3,6] , size = 3,则返回的新数组为
+ * [2,3,6,0,0,0]
+ * @param oldArray
+ * @param size
+ * @return
+ */
+ public int[] grow(int[] oldArray, int size) {
+ // 参数校验
+ if (size < 0) {
+ throw new RuntimeException("非法参数");
+ }
+ if (size == 0) {
+ return oldArray;
+ }
+
+ // 扩容
+ int[] retVal = new int[oldArray.length + size];
+ for (int i = 0; i < oldArray.length; i++) {
+ retVal[i] = oldArray[i];
+ }
+ return retVal;
+ }
+
+ /**
+ * 斐波那契数列为:1,1,2,3,5,8,13,21...... ,给定一个最大值, 返回小于该值的数列
+ * 例如, max = 15 , 则返回的数组应该为 [1,1,2,3,5,8,13]
+ * max = 1, 则返回空数组 []
+ * @param max
+ * @return
+ */
+ public int[] fibonacci(int max) {
+ // 0直接返回空数组
+ if (max == 1) {
+ return new int[0];
+ }
+
+ int retVal = 0;// 每一轮循环的斐波那契数
+ int i = 1;// 获取第几个斐波那契数
+ ArrayList list = new ArrayList();// 用于暂时保存斐波那契数
+ while (retVal < max) {// 获取所有小于max的斐波那契数
+ retVal = getFibonacci(i++);
+ if (retVal < max) {
+ list.add(retVal);
+ } else {
+ break;
+ }
+ }
+
+ // 将arraylist转为array
+ int[] retArray = new int[list.size()];
+ for (int j = 0; j < list.size(); j++) {
+ retArray[j] = list.get(j);
+ }
+ return retArray;
+ }
+
+ /**
+ * 循环获取第N个斐波那契数
+ * @param index
+ * @return
+ */
+ private int getFibonacci(int index) {
+ if (index < 1) {
+ throw new RuntimeException("非法参数");
+ }
+ if (index == 1 || index == 2) {
+ return 1;
+ }
+
+ int first = 1;
+ int second = 1;
+ int retVal = 0;
+ for (int i = 3; i <= index; i++) {
+ retVal = first + second;
+ first = second;
+ second = retVal;
+ }
+ return retVal;
+ }
+
+ /**
+ * 返回小于给定最大值max的所有素数数组
+ * 例如max = 23, 返回的数组为[2,3,5,7,11,13,17,19]
+ * @param max
+ * @return
+ */
+ public int[] getPrimes(int max) {
+ // 排除非法参数
+ if (max < 0) {
+ throw new RuntimeException("非法参数");
+ }
+
+ // 小于2没有素数
+ if (max <= 1) {
+ return new int[0];
+ }
+
+ ArrayList list = new ArrayList();
+ // 取出每个数判断是不是素数,是就放入arraylist
+ for (int i = 2; i < max; i++) {
+ boolean primes = isPrimes(i);
+ if (primes) {
+ list.add(i);
+ }
+ }
+
+ int[] retArray = new int[list.size()];
+ // 将ArrayList转为数组返回
+ for (int i = 0; i < list.size(); i++) {
+ retArray[i] = list.get(i);
+ }
+ return retArray;
+ }
+
+ /**
+ * 判断输入的数字是不是素数
+ * @param num
+ * @return
+ */
+ private boolean isPrimes(int num) {
+ // 排除非法参数
+ if (num <= 0) {
+ throw new RuntimeException("非法参数");
+ }
+
+ // 小于2没有素数
+ if (num == 1) {
+ return false;
+ }
+
+ // 2是素数,但是2%2==0为true,所以单独列出
+ if (num == 2) {
+ return true;
+ }
+
+ // num依次从2到num的平方根取余数,如果余数为零说明不是素数
+ for (int i = 2; i <= Math.sqrt(num); i++) {
+ if (num % i == 0) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ /**
+ * 所谓“完数”, 是指这个数恰好等于它的因子之和,例如6=1+2+3
+ * 给定一个最大值max, 返回一个数组, 数组中是小于max 的所有完数
+ * @param max
+ * @return
+ */
+ public int[] getPerfectNumbers(int max) {
+ if (max < 0) {
+ throw new RuntimeException("非法参数");
+ }
+ if (max <= 2) {
+ return new int[0];
+ }
+
+ // 获取小于max 的所有完数
+ ArrayList list = new ArrayList();
+ for (int i = 1; i < max; i++) {
+ if (isPerfectNumber(i)) {
+ list.add(i);
+ }
+ }
+
+ // 将ArrayList转为array返回
+ int[] array = new int[list.size()];
+ for (int i = 0; i < list.size(); i++) {
+ array[i] = list.get(i);
+ }
+ return array;
+ }
+
+ /**
+ * 判断输入的数是不是完美数
+ * @param num
+ * @return
+ */
+ private boolean isPerfectNumber(int num) {
+ if (num <= 0) {
+ throw new RuntimeException("非法参数");
+ }
+
+ // 放置num的所有约数
+ ArrayList divisorList = new ArrayList();
+ for (int i = 1; i < num; i++) {
+ if (num % i == 0) {
+ divisorList.add(i);
+ }
+ }
+
+ // 所有因数相加是否等于num,是就是完美数
+ int count = 0;
+ for (int i = 0; i < divisorList.size(); i++) {
+ count += divisorList.get(i);
+ }
+ if (count == num) {
+ return true;
+ } else {
+ return false;
+ }
+ }
+
+ /**
+ * 用seperator 把数组 array给连接起来
+ * 例如array= [3,8,9], seperator = "-"
+ * 则返回值为"3-8-9"
+ * @param array
+ * @param s
+ * @return
+ */
+ public String join(int[] array, String seperator) {
+ // 检查非法输入
+ if (array == null) {
+ return null;
+ }
+
+ StringBuilder sb = new StringBuilder();
+ for (int i = 0; i < array.length; i++) {
+ if (i == array.length - 1) {// 最后一个元素后面不拼接-
+ sb.append(array[i]);
+ } else {
+ sb.append(array[i]);
+ sb.append("-");
+ }
+ }
+ return sb.toString();
+ }
+
+
+}
\ No newline at end of file
diff --git a/group23/381519422/array/src/array/ArrayUtilTest.java b/group23/381519422/array/src/array/ArrayUtilTest.java
new file mode 100644
index 0000000000..a202afdb20
--- /dev/null
+++ b/group23/381519422/array/src/array/ArrayUtilTest.java
@@ -0,0 +1,116 @@
+package array;
+
+import static org.junit.Assert.*;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+public class ArrayUtilTest {
+
+ @Before
+ public void setUp() throws Exception {
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ }
+
+ @Test
+ public void testReverseArray() {
+ int[] a = { 7, 9, 30, 3, 4 };
+ int[] expecteds = { 4, 3, 30, 9, 7 };
+ ArrayUtil util = new ArrayUtil();
+ util.reverseArray(a);
+ assertArrayEquals(expecteds, a);
+ }
+
+ @Test
+ public void testRemoveZero() {
+ int[] oldArr = { 1, 3, 4, 5, 0, 0, 6, 6, 0, 5, 4, 7, 6, 7, 0, 5 };
+ int[] expecteds = { 1, 3, 4, 5, 6, 6, 5, 4, 7, 6, 7, 5 };
+ ArrayUtil util = new ArrayUtil();
+ int[] removeZero = util.removeZero(oldArr);
+ assertArrayEquals(expecteds, removeZero);
+ }
+
+ @Test
+ public void testMerge() {
+ int[] a1 = { 3, 5, 7, 8 };
+ int[] a2 = { 4, 5, 6, 7 };
+ ArrayUtil util = new ArrayUtil();
+ int[] merge = util.merge(a1, a2);
+ int[] expecteds = { 3, 4, 5, 6, 7, 8 };
+ assertArrayEquals(expecteds, merge);
+ }
+
+ @Test
+ public void testGrow() {
+ int[] oldArray = { 2, 3, 6 };
+ int size = 3;
+ int[] expecteds = { 2, 3, 6, 0, 0, 0 };
+ ArrayUtil util = new ArrayUtil();
+ int[] grow = util.grow(oldArray, size);
+ assertArrayEquals(expecteds, grow);
+ }
+
+ @Test
+ public void testFibonacci() {
+ int max1 = 15;
+ int[] expecteds1 = { 1, 1, 2, 3, 5, 8, 13 };
+ ArrayUtil util = new ArrayUtil();
+ int[] fibonacci1 = util.fibonacci(max1);
+ assertArrayEquals(expecteds1, fibonacci1);
+
+ int max2 = 1;
+ int[] expecteds2 = {};
+ int[] fibonacci2 = util.fibonacci(max2);
+ assertArrayEquals(expecteds2, fibonacci2);
+ }
+
+ @Test
+ public void testGetPrimes() {
+ int max1 = 23;
+ int[] expecteds1 = { 2, 3, 5, 7, 11, 13, 17, 19 };
+ ArrayUtil util = new ArrayUtil();
+ int[] primes1 = util.getPrimes(max1);
+ assertArrayEquals(expecteds1, primes1);
+
+ int max2 = 2;
+ int[] expecteds2 = {};
+ int[] primes2 = util.getPrimes(max2);
+ assertArrayEquals(expecteds2, primes2);
+ }
+
+ @Test
+ public void testGetPerfectNumbers() {
+ int max1 = 2;
+ int[] expecteds1 = {};
+ ArrayUtil util = new ArrayUtil();
+ int[] perfectNumbers1 = util.getPerfectNumbers(max1);
+ assertArrayEquals(expecteds1, perfectNumbers1);
+
+ // 6=1+2+3
+ int max2 = 7;
+ int[] expecteds2 = { 6 };
+ int[] perfectNumbers2 = util.getPerfectNumbers(max2);
+ assertArrayEquals(expecteds2, perfectNumbers2);
+
+ // 28=1+2+4+7+14
+ int max3 = 30;
+ int[] expecteds3 = { 6, 28 };
+ int[] perfectNumbers3 = util.getPerfectNumbers(max3);
+ assertArrayEquals(expecteds3, perfectNumbers3);
+ }
+
+ @Test
+ public void testJoin() {
+ int[] array = { 3, 8, 9 };
+ String seperator = "-";
+ String expecteds = "3-8-9";
+ ArrayUtil util = new ArrayUtil();
+ String join = util.join(array, seperator);
+ assertEquals(expecteds, join);
+ }
+
+}
From 35f923f1369b84b9ac4874750329e2c0677c5a80 Mon Sep 17 00:00:00 2001
From: Pickacat
Date: Sun, 19 Mar 2017 23:48:02 +0800
Subject: [PATCH 004/262] =?UTF-8?q?=E5=AE=8C=E6=88=90struts=E5=8A=9F?=
=?UTF-8?q?=E8=83=BD=EF=BC=8C=E4=B8=94=E5=8D=95=E5=85=83=E6=B5=8B=E8=AF=95?=
=?UTF-8?q?=E9=80=9A=E8=BF=87?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../java/com/xiaol/study/LoginAction.java | 36 ++++
.../src/main/java/com/xiaol/study/Struts.java | 176 ++++++++++++++++++
.../main/java/com/xiaol/study/StrutsTest.java | 43 +++++
.../src/main/java/com/xiaol/study/View.java | 26 +++
.../litestruts/src/main/resources/struts.xml | 24 +++
5 files changed, 305 insertions(+)
create mode 100644 group23/381519422/litestruts/src/main/java/com/xiaol/study/LoginAction.java
create mode 100644 group23/381519422/litestruts/src/main/java/com/xiaol/study/Struts.java
create mode 100644 group23/381519422/litestruts/src/main/java/com/xiaol/study/StrutsTest.java
create mode 100644 group23/381519422/litestruts/src/main/java/com/xiaol/study/View.java
create mode 100644 group23/381519422/litestruts/src/main/resources/struts.xml
diff --git a/group23/381519422/litestruts/src/main/java/com/xiaol/study/LoginAction.java b/group23/381519422/litestruts/src/main/java/com/xiaol/study/LoginAction.java
new file mode 100644
index 0000000000..d31d404165
--- /dev/null
+++ b/group23/381519422/litestruts/src/main/java/com/xiaol/study/LoginAction.java
@@ -0,0 +1,36 @@
+package com.xiaol.study;
+
+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/group23/381519422/litestruts/src/main/java/com/xiaol/study/Struts.java b/group23/381519422/litestruts/src/main/java/com/xiaol/study/Struts.java
new file mode 100644
index 0000000000..5adabb38ad
--- /dev/null
+++ b/group23/381519422/litestruts/src/main/java/com/xiaol/study/Struts.java
@@ -0,0 +1,176 @@
+package com.xiaol.study;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.InputStream;
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Set;
+
+import javax.management.RuntimeErrorException;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.NamedNodeMap;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+
+
+
+public class Struts {
+
+ // 每一个action的信息存放到一个Map里
+ // 所有的Map放到rootMap方便统一管理
+ private static HashMap> rootMap = new HashMap>();
+
+ public static View runAction(String actionName, Map parameters) {
+ View view = new View();
+ /*
+
+ 0. 读取配置文件struts.xml
+
+ 1. 根据actionName找到相对应的class , 例如LoginAction, 通过反射实例化(创建对象)
+ 据parameters中的数据,调用对象的setter方法, 例如parameters中的数据是
+ ("name"="test" , "password"="1234") ,
+ 那就应该调用 setName和setPassword方法
+
+ 2. 通过反射调用对象的exectue 方法, 并获得返回值,例如"success"
+
+ 3. 通过反射找到对象的所有getter方法(例如 getMessage),
+ 通过反射来调用, 把值和属性形成一个HashMap , 例如 {"message": "登录成功"} ,
+ 放到View对象的parameters
+
+ 4. 根据struts.xml中的 配置,以及execute的返回值, 确定哪一个jsp,
+ 放到View对象的jsp字段中。
+
+ */
+
+ try {
+ // 1、初始化读取配置文件
+ init();
+
+ // 2、获取根据参数获取对应的class的名字
+ Map actionMap = rootMap.get(actionName);
+ String className = actionMap.get("class");
+ // 3、根据名字获取Class对象
+ Class> clazzType = Class.forName(className);
+ // 4、通过无参构造获取一个对象
+ Object newInstance = clazzType.getConstructor(new Class[] {}).newInstance(new Object[] {});
+ // 5、调用set方法,把("name"="test" , "password"="1234")值set进去
+ Set> entrySet = parameters.entrySet();
+ Iterator> iterator = entrySet.iterator();
+ while (iterator.hasNext()) {
+ Entry next = iterator.next();
+ String key = next.getKey();
+ String value = next.getValue();
+ String setMethodName = "set" + key.substring(0, 1).toUpperCase() + key.substring(1);
+ Field declaredField = clazzType.getDeclaredField(key);
+ Method setMehtod = clazzType.getDeclaredMethod(setMethodName, new Class[] { declaredField.getType() });
+ setMehtod.invoke(newInstance, value);
+ }
+ // 6、执行execute方法
+ String executeMethodName = "execute";
+ Method executeMethod = clazzType.getDeclaredMethod(executeMethodName);
+ Object resultString = (String) executeMethod.invoke(newInstance);
+
+ // 7、通过反射获取message信息
+ String getMethodName = "getMessage";
+ Field declaredField = clazzType.getDeclaredField("message");
+ Method getMehtod = clazzType.getDeclaredMethod(getMethodName);
+ String message = (String) getMehtod.invoke(newInstance);
+
+ // 8\
+ String jsp = actionMap.get(resultString);
+ view.setJsp(jsp);
+ Map hashMap = new HashMap<>();
+ hashMap.put("message", message);
+ view.setParameters(hashMap);
+ } catch (Exception e) {
+ e.printStackTrace();
+ throw new ExceptionInInitializerError();
+ }
+ return view;
+ }
+
+ public static void init() throws Exception {
+
+ // 1、获取工厂实例
+ DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
+ // 2、获取dom解析器
+ DocumentBuilder db = dbf.newDocumentBuilder();
+ // 3、解析xml文档,获取document对象(根节点)
+ // 也可以获取流使用db.parse(InputStream)
+ // InputStream is =
+ // this.getClass().getResourceAsStream("D:\\GitHub\\coding2017\\group23\\381519422\\litestruts\\src\\main\\resources\\struts.xml");
+ Document document = db.parse(
+ new File("D:\\GitHub\\coding2017\\group23\\381519422\\litestruts\\src\\main\\resources\\struts.xml"));
+ NodeList list = document.getElementsByTagName("action");
+
+ /*
+ * 开始循环list,list中每一个元素结构如下
+ *
+ /jsp/homepage.jsp
+ /jsp/showLogin.jsp
+
+ */
+ for (int i = 0; i < list.getLength(); i++) {
+ Map actionMap = new HashMap();
+ // 注意:使用的都是org.w3c.dom包下的
+ Element element = (Element) list.item(i);
+ // 获取中 name对应的属性值
+ String actionAttributeName = element.getAttribute("name");
+ String className = element.getAttribute("class");
+ actionMap.put("class", className);
+
+ // 读取第一个action
+ NamedNodeMap nnm = element.getElementsByTagName("result").item(0).getAttributes();
+ // 获取的属性 name
+ // String nodeName = nnm.item(0).getNodeName();
+ // element.getElementsByTagName("result").item(0)
+ // 是/jsp/homepage.jsp
+ // getFirstChild().getNodeValue() 是获取上面内容的/jsp/homepage.jsp
+ String context = element.getElementsByTagName("result").item(0).getTextContent();
+ // 获取的属性 name对应的值success
+ String nodeValue = nnm.item(0).getNodeValue();
+ actionMap.put(nodeValue, context);
+
+ // 读取第二个action
+ nnm = element.getElementsByTagName("result").item(1).getAttributes();
+ // 获取的属性 name
+ // nodeName = nnm.item(0).getNodeName();
+ context = element.getElementsByTagName("result").item(1).getFirstChild().getNodeValue();
+ // 获取的属性 name对应的值success
+ nodeValue = nnm.item(0).getNodeValue();
+ actionMap.put(nodeValue, context);
+
+ rootMap.put(actionAttributeName, actionMap);
+ }
+ }
+
+ public static void main(String[] args) {
+ try {
+ init();
+ } catch (Exception e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+ // 内部类用于存放从配置文件读取的数据
+ class StrutsMap {
+ private HashMap map;
+
+ public String get(String key) {
+ return map.get(key);
+ }
+
+ public void set(String key, String value) {
+ map.put(key, value);
+ }
+ }
+}
diff --git a/group23/381519422/litestruts/src/main/java/com/xiaol/study/StrutsTest.java b/group23/381519422/litestruts/src/main/java/com/xiaol/study/StrutsTest.java
new file mode 100644
index 0000000000..53c1e7187c
--- /dev/null
+++ b/group23/381519422/litestruts/src/main/java/com/xiaol/study/StrutsTest.java
@@ -0,0 +1,43 @@
+package com.xiaol.study;
+
+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/group23/381519422/litestruts/src/main/java/com/xiaol/study/View.java b/group23/381519422/litestruts/src/main/java/com/xiaol/study/View.java
new file mode 100644
index 0000000000..41999670b8
--- /dev/null
+++ b/group23/381519422/litestruts/src/main/java/com/xiaol/study/View.java
@@ -0,0 +1,26 @@
+package com.xiaol.study;
+
+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/group23/381519422/litestruts/src/main/resources/struts.xml b/group23/381519422/litestruts/src/main/resources/struts.xml
new file mode 100644
index 0000000000..32cf9d90c4
--- /dev/null
+++ b/group23/381519422/litestruts/src/main/resources/struts.xml
@@ -0,0 +1,24 @@
+
+
+
+ /jsp/homepage.jsp
+ /jsp/showLogin.jsp
+
+
+ /jsp/welcome.jsp
+ /jsp/error.jsp
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
From a1658ba81bd99aaeac4c62112e87163404b85f16 Mon Sep 17 00:00:00 2001
From: em14Vito
Date: Wed, 22 Mar 2017 22:24:03 +0800
Subject: [PATCH 005/262] add homework3 demo
---
.../DataStruct/LinkedList.java | 122 ++++++++++++++++++
1 file changed, 122 insertions(+)
create mode 100644 group23/729693763/Third_Homework3/DataStruct/LinkedList.java
diff --git a/group23/729693763/Third_Homework3/DataStruct/LinkedList.java b/group23/729693763/Third_Homework3/DataStruct/LinkedList.java
new file mode 100644
index 0000000000..09fe0a8ff3
--- /dev/null
+++ b/group23/729693763/Third_Homework3/DataStruct/LinkedList.java
@@ -0,0 +1,122 @@
+package com.coding.basic;
+
+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;
+ }
+}
From 39332434a49fb4b0a114a61ea7ee32d18f929152 Mon Sep 17 00:00:00 2001
From: em14Vito
Date: Wed, 22 Mar 2017 22:24:37 +0800
Subject: [PATCH 006/262] add homework3 demo
---
.../Third_Homework3/download/.classpath | 5 ++
.../Third_Homework3/download/.project | 17 +++++
.../download/DownloadThread.java | 20 +++++
.../download/FileDownloader.java | 73 +++++++++++++++++++
.../download/FileDownloaderTest.java | 59 +++++++++++++++
.../download/api/Connection.java | 23 ++++++
.../download/api/ConnectionException.java | 5 ++
.../download/api/ConnectionManager.java | 10 +++
.../download/api/DownloadListener.java | 5 ++
.../download/impl/ConnectionImpl.java | 27 +++++++
.../download/impl/ConnectionManagerImpl.java | 15 ++++
11 files changed, 259 insertions(+)
create mode 100644 group23/729693763/Third_Homework3/download/.classpath
create mode 100644 group23/729693763/Third_Homework3/download/.project
create mode 100644 group23/729693763/Third_Homework3/download/DownloadThread.java
create mode 100644 group23/729693763/Third_Homework3/download/FileDownloader.java
create mode 100644 group23/729693763/Third_Homework3/download/FileDownloaderTest.java
create mode 100644 group23/729693763/Third_Homework3/download/api/Connection.java
create mode 100644 group23/729693763/Third_Homework3/download/api/ConnectionException.java
create mode 100644 group23/729693763/Third_Homework3/download/api/ConnectionManager.java
create mode 100644 group23/729693763/Third_Homework3/download/api/DownloadListener.java
create mode 100644 group23/729693763/Third_Homework3/download/impl/ConnectionImpl.java
create mode 100644 group23/729693763/Third_Homework3/download/impl/ConnectionManagerImpl.java
diff --git a/group23/729693763/Third_Homework3/download/.classpath b/group23/729693763/Third_Homework3/download/.classpath
new file mode 100644
index 0000000000..ac37fb2e4b
--- /dev/null
+++ b/group23/729693763/Third_Homework3/download/.classpath
@@ -0,0 +1,5 @@
+
+
+
+
+
diff --git a/group23/729693763/Third_Homework3/download/.project b/group23/729693763/Third_Homework3/download/.project
new file mode 100644
index 0000000000..9360f320db
--- /dev/null
+++ b/group23/729693763/Third_Homework3/download/.project
@@ -0,0 +1,17 @@
+
+
+ download
+
+
+
+
+
+ org.eclipse.jdt.core.javabuilder
+
+
+
+
+
+ org.eclipse.jdt.core.javanature
+
+
diff --git a/group23/729693763/Third_Homework3/download/DownloadThread.java b/group23/729693763/Third_Homework3/download/DownloadThread.java
new file mode 100644
index 0000000000..900a3ad358
--- /dev/null
+++ b/group23/729693763/Third_Homework3/download/DownloadThread.java
@@ -0,0 +1,20 @@
+package com.coderising.download;
+
+import com.coderising.download.api.Connection;
+
+public class DownloadThread extends Thread{
+
+ Connection conn;
+ int startPos;
+ int endPos;
+
+ public DownloadThread( Connection conn, int startPos, int endPos){
+
+ this.conn = conn;
+ this.startPos = startPos;
+ this.endPos = endPos;
+ }
+ public void run(){
+
+ }
+}
diff --git a/group23/729693763/Third_Homework3/download/FileDownloader.java b/group23/729693763/Third_Homework3/download/FileDownloader.java
new file mode 100644
index 0000000000..c3c8a3f27d
--- /dev/null
+++ b/group23/729693763/Third_Homework3/download/FileDownloader.java
@@ -0,0 +1,73 @@
+package com.coderising.download;
+
+import com.coderising.download.api.Connection;
+import com.coderising.download.api.ConnectionException;
+import com.coderising.download.api.ConnectionManager;
+import com.coderising.download.api.DownloadListener;
+
+
+public class FileDownloader {
+
+ String url;
+
+ DownloadListener listener;
+
+ ConnectionManager cm;
+
+
+ public FileDownloader(String _url) {
+ this.url = _url;
+
+ }
+
+ public void execute(){
+ // 在这里实现你的代码, 注意: 需要用多线程实现下载
+ // 这个类依赖于其他几个接口, 你需要写这几个接口的实现代码
+ // (1) ConnectionManager , 可以打开一个连接,通过Connection可以读取其中的一段(用startPos, endPos来指定)
+ // (2) DownloadListener, 由于是多线程下载, 调用这个类的客户端不知道什么时候结束,所以你需要实现当所有
+ // 线程都执行完以后, 调用listener的notifiedFinished方法, 这样客户端就能收到通知。
+ // 具体的实现思路:
+ // 1. 需要调用ConnectionManager的open方法打开连接, 然后通过Connection.getContentLength方法获得文件的长度
+ // 2. 至少启动3个线程下载, 注意每个线程需要先调用ConnectionManager的open方法
+ // 然后调用read方法, read方法中有读取文件的开始位置和结束位置的参数, 返回值是byte[]数组
+ // 3. 把byte数组写入到文件中
+ // 4. 所有的线程都下载完成以后, 需要调用listener的notifiedFinished方法
+
+ // 下面的代码是示例代码, 也就是说只有一个线程, 你需要改造成多线程的。
+ Connection conn = null;
+ try {
+
+ conn = cm.open(this.url);
+
+ int length = conn.getContentLength();
+
+ new DownloadThread(conn,0,length-1).start();
+
+ } catch (ConnectionException e) {
+ e.printStackTrace();
+ }finally{
+ if(conn != null){
+ conn.close();
+ }
+ }
+
+
+
+
+ }
+
+ public void setListener(DownloadListener listener) {
+ this.listener = listener;
+ }
+
+
+
+ public void setConnectionManager(ConnectionManager ucm){
+ this.cm = ucm;
+ }
+
+ public DownloadListener getListener(){
+ return this.listener;
+ }
+
+}
diff --git a/group23/729693763/Third_Homework3/download/FileDownloaderTest.java b/group23/729693763/Third_Homework3/download/FileDownloaderTest.java
new file mode 100644
index 0000000000..4ff7f46ae0
--- /dev/null
+++ b/group23/729693763/Third_Homework3/download/FileDownloaderTest.java
@@ -0,0 +1,59 @@
+package com.coderising.download;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+import com.coderising.download.api.ConnectionManager;
+import com.coderising.download.api.DownloadListener;
+import com.coderising.download.impl.ConnectionManagerImpl;
+
+public class FileDownloaderTest {
+ boolean downloadFinished = false;
+ @Before
+ public void setUp() throws Exception {
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ }
+
+ @Test
+ public void testDownload() {
+
+ String url = "http://localhost:8080/test.jpg";
+
+ FileDownloader downloader = new FileDownloader(url);
+
+
+ ConnectionManager cm = new ConnectionManagerImpl();
+ downloader.setConnectionManager(cm);
+
+ downloader.setListener(new DownloadListener() {
+ @Override
+ public void notifyFinished() {
+ downloadFinished = true;
+ }
+
+ });
+
+
+ downloader.execute();
+
+ // 等待多线程下载程序执行完毕
+ while (!downloadFinished) {
+ try {
+ System.out.println("还没有下载完成,休眠五秒");
+ //休眠5秒
+ Thread.sleep(5000);
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+ }
+ System.out.println("下载完成!");
+
+
+
+ }
+
+}
diff --git a/group23/729693763/Third_Homework3/download/api/Connection.java b/group23/729693763/Third_Homework3/download/api/Connection.java
new file mode 100644
index 0000000000..0957eaf7f4
--- /dev/null
+++ b/group23/729693763/Third_Homework3/download/api/Connection.java
@@ -0,0 +1,23 @@
+package com.coderising.download.api;
+
+import java.io.IOException;
+
+public interface Connection {
+ /**
+ * 给定开始和结束位置, 读取数据, 返回值是字节数组
+ * @param startPos 开始位置, 从0开始
+ * @param endPos 结束位置
+ * @return
+ */
+ public byte[] read(int startPos,int endPos) throws IOException;
+ /**
+ * 得到数据内容的长度
+ * @return
+ */
+ public int getContentLength();
+
+ /**
+ * 关闭连接
+ */
+ public void close();
+}
diff --git a/group23/729693763/Third_Homework3/download/api/ConnectionException.java b/group23/729693763/Third_Homework3/download/api/ConnectionException.java
new file mode 100644
index 0000000000..1551a80b3d
--- /dev/null
+++ b/group23/729693763/Third_Homework3/download/api/ConnectionException.java
@@ -0,0 +1,5 @@
+package com.coderising.download.api;
+
+public class ConnectionException extends Exception {
+
+}
diff --git a/group23/729693763/Third_Homework3/download/api/ConnectionManager.java b/group23/729693763/Third_Homework3/download/api/ConnectionManager.java
new file mode 100644
index 0000000000..ce045393b1
--- /dev/null
+++ b/group23/729693763/Third_Homework3/download/api/ConnectionManager.java
@@ -0,0 +1,10 @@
+package com.coderising.download.api;
+
+public interface ConnectionManager {
+ /**
+ * 给定一个url , 打开一个连接
+ * @param url
+ * @return
+ */
+ public Connection open(String url) throws ConnectionException;
+}
diff --git a/group23/729693763/Third_Homework3/download/api/DownloadListener.java b/group23/729693763/Third_Homework3/download/api/DownloadListener.java
new file mode 100644
index 0000000000..bf9807b307
--- /dev/null
+++ b/group23/729693763/Third_Homework3/download/api/DownloadListener.java
@@ -0,0 +1,5 @@
+package com.coderising.download.api;
+
+public interface DownloadListener {
+ public void notifyFinished();
+}
diff --git a/group23/729693763/Third_Homework3/download/impl/ConnectionImpl.java b/group23/729693763/Third_Homework3/download/impl/ConnectionImpl.java
new file mode 100644
index 0000000000..36a9d2ce15
--- /dev/null
+++ b/group23/729693763/Third_Homework3/download/impl/ConnectionImpl.java
@@ -0,0 +1,27 @@
+package com.coderising.download.impl;
+
+import java.io.IOException;
+
+import com.coderising.download.api.Connection;
+
+public class ConnectionImpl implements Connection{
+
+ @Override
+ public byte[] read(int startPos, int endPos) throws IOException {
+
+ return null;
+ }
+
+ @Override
+ public int getContentLength() {
+
+ return 0;
+ }
+
+ @Override
+ public void close() {
+
+
+ }
+
+}
diff --git a/group23/729693763/Third_Homework3/download/impl/ConnectionManagerImpl.java b/group23/729693763/Third_Homework3/download/impl/ConnectionManagerImpl.java
new file mode 100644
index 0000000000..172371dd55
--- /dev/null
+++ b/group23/729693763/Third_Homework3/download/impl/ConnectionManagerImpl.java
@@ -0,0 +1,15 @@
+package com.coderising.download.impl;
+
+import com.coderising.download.api.Connection;
+import com.coderising.download.api.ConnectionException;
+import com.coderising.download.api.ConnectionManager;
+
+public class ConnectionManagerImpl implements ConnectionManager {
+
+ @Override
+ public Connection open(String url) throws ConnectionException {
+
+ return null;
+ }
+
+}
From 7f30f8eb9cda2ec124a44aeb9634381c3e5b1b59 Mon Sep 17 00:00:00 2001
From: em14Vito
Date: Thu, 23 Mar 2017 12:35:52 +0800
Subject: [PATCH 007/262] =?UTF-8?q?=E5=AE=8C=E6=88=90=E5=A4=9A=E7=BA=BF?=
=?UTF-8?q?=E7=A8=8B=E4=B8=8B=E8=BD=BD?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../download/DownloadThread.java | 37 +++++++-
.../download/FileDownloader.java | 85 ++++++++++++-------
.../download/FileDownloaderTest.java | 23 +++--
.../download/api/Connection.java | 4 +-
.../download/api/ConnectionException.java | 2 +-
.../download/api/ConnectionManager.java | 2 +-
.../download/api/DownloadListener.java | 2 +-
.../download/impl/ConnectionImpl.java | 69 +++++++++++++--
.../download/impl/ConnectionManagerImpl.java | 24 ++++--
9 files changed, 182 insertions(+), 66 deletions(-)
diff --git a/group23/729693763/Third_Homework3/download/DownloadThread.java b/group23/729693763/Third_Homework3/download/DownloadThread.java
index 900a3ad358..3ab337e352 100644
--- a/group23/729693763/Third_Homework3/download/DownloadThread.java
+++ b/group23/729693763/Third_Homework3/download/DownloadThread.java
@@ -1,20 +1,49 @@
-package com.coderising.download;
+package com.zhous.download;
-import com.coderising.download.api.Connection;
+import com.zhous.download.api.Connection;
+import com.zhous.download.api.DownloadListener;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.RandomAccessFile;
public class DownloadThread extends Thread{
Connection conn;
int startPos;
int endPos;
+ File targetFile;
+ DownloadListener downloadListener;
- public DownloadThread( Connection conn, int startPos, int endPos){
+ public DownloadThread( Connection conn, int startPos, int endPos,File targetFile,DownloadListener downloadListener){
this.conn = conn;
this.startPos = startPos;
this.endPos = endPos;
+ this.targetFile = targetFile;
+ this.downloadListener = downloadListener;
}
public void run(){
-
+ try {
+ //读取到指定长度的二进制数据
+ System.out.println(this.getName()+"开始下载");
+ byte[] data = conn.read(startPos,endPos);
+
+ //插入的file中去
+ RandomAccessFile raFile = new RandomAccessFile(this.targetFile,"rw");
+ raFile.seek(startPos);
+ raFile.write(data,0,endPos-startPos );
+
+ raFile.close();
+ //做完了
+ if(FileDownloader.isDownloadFinish() ){
+ downloadListener.notifyFinished();
+ System.out.println(this.getName()+"完成最后的下载,并写入文件");
+ }
+
+
+ }catch (IOException e){
+
+ }
}
}
diff --git a/group23/729693763/Third_Homework3/download/FileDownloader.java b/group23/729693763/Third_Homework3/download/FileDownloader.java
index c3c8a3f27d..098f9408f0 100644
--- a/group23/729693763/Third_Homework3/download/FileDownloader.java
+++ b/group23/729693763/Third_Homework3/download/FileDownloader.java
@@ -1,25 +1,30 @@
-package com.coderising.download;
+package com.zhous.download;
-import com.coderising.download.api.Connection;
-import com.coderising.download.api.ConnectionException;
-import com.coderising.download.api.ConnectionManager;
-import com.coderising.download.api.DownloadListener;
+import com.zhous.download.api.Connection;
+import com.zhous.download.api.ConnectionException;
+import com.zhous.download.api.ConnectionManager;
+import com.zhous.download.api.DownloadListener;
+
+import java.io.File;
+import java.util.Set;
public class FileDownloader {
-
- String url;
-
+
+ String url="https://image.baidu.com/search/down?tn=download&word=download&ie=utf8&fr=detail&url=https%3A%2F%2Ftimgsa.baidu.com%2Ftimg%3Fimage%26quality%3D80%26size%3Db9999_10000%26sec%3D1490203615530%26di%3D2b1827956a01011d3634f3e04b01b15c%26imgtype%3D0%26src%3Dhttp%253A%252F%252Fimg15.3lian.com%252F2015%252Fh1%252F338%252Fd%252F157.jpg&thumburl=https%3A%2F%2Fss1.bdstatic.com%2F70cFvXSh_Q1YnxGkpoWK1HF6hhy%2Fit%2Fu%3D2613489365%2C2336631324%26fm%3D23%26gp%3D0.jpg";
+ private static int threadNum = 5;
+ private static int threadCount = 0;
+ int avgBytes = 0;
+
DownloadListener listener;
-
ConnectionManager cm;
-
+ File file = null;
- public FileDownloader(String _url) {
+ public FileDownloader(String _url,String fileName) {
this.url = _url;
-
+ this.file = new File(fileName);
}
-
+
public void execute(){
// 在这里实现你的代码, 注意: 需要用多线程实现下载
// 这个类依赖于其他几个接口, 你需要写这几个接口的实现代码
@@ -32,42 +37,60 @@ public void execute(){
// 然后调用read方法, read方法中有读取文件的开始位置和结束位置的参数, 返回值是byte[]数组
// 3. 把byte数组写入到文件中
// 4. 所有的线程都下载完成以后, 需要调用listener的notifiedFinished方法
-
+
// 下面的代码是示例代码, 也就是说只有一个线程, 你需要改造成多线程的。
Connection conn = null;
try {
-
+
conn = cm.open(this.url);
-
- int length = conn.getContentLength();
-
- new DownloadThread(conn,0,length-1).start();
-
- } catch (ConnectionException e) {
+ int length = conn.getContentLength();
+ avgBytes = length / threadNum;
+ //使用5个线程去下载;
+ for (int i = 0; i < threadNum; i++) {
+ int startPos = i*avgBytes;
+ int endPos = startPos + avgBytes - 1;
+ if(i == threadNum -1) {
+ endPos = length;
+ }
+
+ Connection c = cm.open(this.url);
+ DownloadThread thread = new DownloadThread(c,startPos,endPos,file,this.getListener());
+ thread.setName("Thread"+(i+1) );
+ thread.start();
+ }
+
+ } catch (ConnectionException e) {
e.printStackTrace();
}finally{
if(conn != null){
conn.close();
}
}
-
-
-
-
+
+
+
+
}
-
- public void setListener(DownloadListener listener) {
+
+
+
+ public void setListener (DownloadListener listener){
this.listener = listener;
}
-
-
+ public synchronized static boolean isDownloadFinish(){
+ threadCount++;
+ return threadCount == threadNum;
+ }
+
+
+
public void setConnectionManager(ConnectionManager ucm){
this.cm = ucm;
}
-
+
public DownloadListener getListener(){
return this.listener;
}
-
+
}
diff --git a/group23/729693763/Third_Homework3/download/FileDownloaderTest.java b/group23/729693763/Third_Homework3/download/FileDownloaderTest.java
index 4ff7f46ae0..ca8817ba88 100644
--- a/group23/729693763/Third_Homework3/download/FileDownloaderTest.java
+++ b/group23/729693763/Third_Homework3/download/FileDownloaderTest.java
@@ -1,12 +1,12 @@
-package com.coderising.download;
+package com.zhous.download;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
-import com.coderising.download.api.ConnectionManager;
-import com.coderising.download.api.DownloadListener;
-import com.coderising.download.impl.ConnectionManagerImpl;
+import com.zhous.download.api.ConnectionManager;
+import com.zhous.download.api.DownloadListener;
+import com.zhous.download.impl.ConnectionManagerImpl;
public class FileDownloaderTest {
boolean downloadFinished = false;
@@ -20,11 +20,12 @@ public void tearDown() throws Exception {
@Test
public void testDownload() {
-
- String url = "http://localhost:8080/test.jpg";
-
- FileDownloader downloader = new FileDownloader(url);
+ String url="http://www.mydeskcity.com//upload/pc/112/960x600/1351650816239.jpg";
+ String github = "https://github.com/em14Vito/coding2017/archive/master.zip";
+
+// FileDownloader downloader = new FileDownloader(url,"Data23.jpg");
+ FileDownloader downloader = new FileDownloader(github,"github.zip");
ConnectionManager cm = new ConnectionManagerImpl();
downloader.setConnectionManager(cm);
@@ -36,17 +37,15 @@ public void notifyFinished() {
}
});
-
-
downloader.execute();
-
+
// 等待多线程下载程序执行完毕
while (!downloadFinished) {
try {
System.out.println("还没有下载完成,休眠五秒");
//休眠5秒
Thread.sleep(5000);
- } catch (InterruptedException e) {
+ } catch (InterruptedException e) {
e.printStackTrace();
}
}
diff --git a/group23/729693763/Third_Homework3/download/api/Connection.java b/group23/729693763/Third_Homework3/download/api/Connection.java
index 0957eaf7f4..170791e8ba 100644
--- a/group23/729693763/Third_Homework3/download/api/Connection.java
+++ b/group23/729693763/Third_Homework3/download/api/Connection.java
@@ -1,4 +1,4 @@
-package com.coderising.download.api;
+package com.zhous.download.api;
import java.io.IOException;
@@ -9,7 +9,7 @@ public interface Connection {
* @param endPos 结束位置
* @return
*/
- public byte[] read(int startPos,int endPos) throws IOException;
+ public byte[] read(int startPos, int endPos) throws IOException;
/**
* 得到数据内容的长度
* @return
diff --git a/group23/729693763/Third_Homework3/download/api/ConnectionException.java b/group23/729693763/Third_Homework3/download/api/ConnectionException.java
index 1551a80b3d..925368135d 100644
--- a/group23/729693763/Third_Homework3/download/api/ConnectionException.java
+++ b/group23/729693763/Third_Homework3/download/api/ConnectionException.java
@@ -1,4 +1,4 @@
-package com.coderising.download.api;
+package com.zhous.download.api;
public class ConnectionException extends Exception {
diff --git a/group23/729693763/Third_Homework3/download/api/ConnectionManager.java b/group23/729693763/Third_Homework3/download/api/ConnectionManager.java
index ce045393b1..b331ee7f1f 100644
--- a/group23/729693763/Third_Homework3/download/api/ConnectionManager.java
+++ b/group23/729693763/Third_Homework3/download/api/ConnectionManager.java
@@ -1,4 +1,4 @@
-package com.coderising.download.api;
+package com.zhous.download.api;
public interface ConnectionManager {
/**
diff --git a/group23/729693763/Third_Homework3/download/api/DownloadListener.java b/group23/729693763/Third_Homework3/download/api/DownloadListener.java
index bf9807b307..07b1a950ce 100644
--- a/group23/729693763/Third_Homework3/download/api/DownloadListener.java
+++ b/group23/729693763/Third_Homework3/download/api/DownloadListener.java
@@ -1,4 +1,4 @@
-package com.coderising.download.api;
+package com.zhous.download.api;
public interface DownloadListener {
public void notifyFinished();
diff --git a/group23/729693763/Third_Homework3/download/impl/ConnectionImpl.java b/group23/729693763/Third_Homework3/download/impl/ConnectionImpl.java
index 36a9d2ce15..6a4b98fe06 100644
--- a/group23/729693763/Third_Homework3/download/impl/ConnectionImpl.java
+++ b/group23/729693763/Third_Homework3/download/impl/ConnectionImpl.java
@@ -1,27 +1,80 @@
-package com.coderising.download.impl;
+package com.zhous.download.impl;
+import java.io.ByteArrayOutputStream;
+import java.io.FileInputStream;
import java.io.IOException;
+import java.io.InputStream;
+import java.net.HttpURLConnection;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.net.URLConnection;
-import com.coderising.download.api.Connection;
+import com.zhous.download.api.*;
public class ConnectionImpl implements Connection{
+
+ InputStream is = null;
+ URL url = null;
+ HttpURLConnection http = null;
+ ByteArrayOutputStream bos = new ByteArrayOutputStream();
+
+ //构造方法:
+ public ConnectionImpl() {
+ }
+
+ //打开url并且创建连接
+ public ConnectionImpl(String url) {
+ try {
+ this.url = new URL(url);
+ http = (HttpURLConnection) this.url.openConnection();
+ //设置超时
+ http.setConnectTimeout(5000);
+ http.setReadTimeout(5000);
+
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+
@Override
public byte[] read(int startPos, int endPos) throws IOException {
-
- return null;
+
+ //指定http中读取一定长度的byte
+ http.setRequestProperty("Range","bytes= "+Integer.toString(startPos)+"-"+Integer.toString(endPos));
+ http.connect();
+
+ //读取输入流到其中
+ is = http.getInputStream();
+ byte[] buffer = new byte[1024];
+ int len = 0;
+ while( (len = is.read(buffer) ) != -1) {
+
+ bos.write(buffer, 0, len);
+ }
+
+ //关闭所有流,每次read的时候自动关闭。
+ close();
+ return bos.toByteArray();
}
@Override
public int getContentLength() {
-
- return 0;
+ return http.getContentLength();
}
@Override
public void close() {
-
-
+ try {
+ bos.close();
+ if(is != null) {
+ is.close();
+ }
+ http.disconnect();
+ } catch (IOException e) {
+ e.printStackTrace();
+ System.out.println(e.getMessage());
+ }
}
}
diff --git a/group23/729693763/Third_Homework3/download/impl/ConnectionManagerImpl.java b/group23/729693763/Third_Homework3/download/impl/ConnectionManagerImpl.java
index 172371dd55..28af08a0cd 100644
--- a/group23/729693763/Third_Homework3/download/impl/ConnectionManagerImpl.java
+++ b/group23/729693763/Third_Homework3/download/impl/ConnectionManagerImpl.java
@@ -1,15 +1,27 @@
-package com.coderising.download.impl;
+package com.zhous.download.impl;
-import com.coderising.download.api.Connection;
-import com.coderising.download.api.ConnectionException;
-import com.coderising.download.api.ConnectionManager;
+import com.zhous.download.api.*;
+
+import java.net.MalformedURLException;
+import java.net.URL;
public class ConnectionManagerImpl implements ConnectionManager {
+
+
@Override
public Connection open(String url) throws ConnectionException {
-
- return null;
+ Connection ct = null;
+ URL u = null;
+ try {
+ u = new URL(url);
+ ct = new ConnectionImpl(url);
+ } catch (MalformedURLException e) {
+ e.printStackTrace();
+ } finally {
+ //URL类不需要关闭
+ }
+ return ct;
}
}
From 349cd580aadfa428182d59f3e8f68d6fd33dbb47 Mon Sep 17 00:00:00 2001
From: em14Vito
Date: Sat, 25 Mar 2017 11:12:51 +0800
Subject: [PATCH 008/262] finish hw3
---
.../Third_Homework3/DataStruct/Iterator.java | 6 +
.../DataStruct/LinkedList.java | 255 ++++++++++++++++--
.../Third_Homework3/DataStruct/List.java | 10 +
3 files changed, 246 insertions(+), 25 deletions(-)
create mode 100644 group23/729693763/Third_Homework3/DataStruct/Iterator.java
create mode 100644 group23/729693763/Third_Homework3/DataStruct/List.java
diff --git a/group23/729693763/Third_Homework3/DataStruct/Iterator.java b/group23/729693763/Third_Homework3/DataStruct/Iterator.java
new file mode 100644
index 0000000000..2ca354f82a
--- /dev/null
+++ b/group23/729693763/Third_Homework3/DataStruct/Iterator.java
@@ -0,0 +1,6 @@
+package com.zhous.DataStruct;
+
+public interface Iterator {
+ public boolean hasNext();
+ public Object next();
+}
diff --git a/group23/729693763/Third_Homework3/DataStruct/LinkedList.java b/group23/729693763/Third_Homework3/DataStruct/LinkedList.java
index 09fe0a8ff3..2a6663a3ba 100644
--- a/group23/729693763/Third_Homework3/DataStruct/LinkedList.java
+++ b/group23/729693763/Third_Homework3/DataStruct/LinkedList.java
@@ -1,42 +1,152 @@
-package com.coding.basic;
+package com.zhous.DataStruct;
+
+import javafx.beans.binding.ObjectExpression;
+
+
public class LinkedList implements List {
- private Node head;
-
+ private Node head = null;
+ private int size = 0;
+
public void add(Object o){
-
+ addLast(o);
+ this.size++;
+ }
+
+ //内部调用的方法:
+ //2 返回添加到哪个Node
+ private Node findBeforeInsertNode(int needInsertIndex){
+ Node findGetNode = this.head;
+ for ( int i=0; i< needInsertIndex - 1; i++ ) {
+ findGetNode = findGetNode.next;
+ }
+ return findGetNode;
}
+ //3
+ private void checkPositionIndex(int index) {
+ if ( !( index >= 0 && index <= size ) )
+ throw new IndexOutOfBoundsException("Invalid Index:"+index);
+ }
+
+ //4
+ private void addBeforeNode(int index, Object o) {
+ Node newNode = new Node();
+ newNode.data = o;
+ newNode.next = null;
+
+ Node beforeInserNode = this.head;
+
+
+ beforeInserNode = findBeforeInsertNode(index);
+
+ newNode.next = beforeInserNode.next;
+ beforeInserNode.next = newNode;
+
+ }
+ //5
+ private Node findIndexNode(int index){
+ Node findGetNode = this.head;
+ for ( int i=0; i< index; i++ ) {
+ findGetNode = findGetNode.next;
+ }
+ return findGetNode;
+ }
+
+
public void add(int index , Object o){
-
+ checkPositionIndex(index);
+ if( index == size()){
+ addLast(o);
+ } else if ( index == 0 ) {
+ addFirst(o);
+ } else{
+ addBeforeNode(index,o);
+ }
+ this.size++;
}
+
+
+
+
public Object get(int index){
- return null;
+ checkElementIndex(index);
+ return findIndexNode(index);
}
public Object remove(int index){
- return null;
+ checkElementIndex(index);
+ Object deleteData = null;
+
+ if(index == 0){
+ deleteData = removeFirst();
+ } else if(index == (size() - 1) ){
+ deleteData = removeLast();
+ } else {
+ Node temp = findBeforeInsertNode(index);
+ Node tempNext = temp.next;
+ deleteData = tempNext.data;
+
+ temp.next = tempNext.next;
+ tempNext = null;
+ }
+
+ return deleteData;
}
-
+
+ //6
+ private void checkElementIndex(int index) {
+ if ( !( index >= 0 && index < size ) )
+ throw new IndexOutOfBoundsException("Invalid Index:"+index);
+ }
+
public int size(){
- return -1;
+ return this.size;
}
public void addFirst(Object o){
-
+ Node newNode = new Node();
+ newNode.data = o;
+ newNode.next = null;
+ if ( this.head == null ) {
+ this.head = newNode;
+ } else {
+ newNode.next = this.head;
+ this.head = newNode;
+ }
}
- public void addLast(Object o){
-
+ private void addLast(Object o){
+ Node newNode = new Node();
+ newNode.data = o;
+ newNode.next = null;
+ if ( head == null ) {
+ head = newNode;
+ } else{
+ findBeforeInsertNode(this.size).next = newNode;
+ }
}
public Object removeFirst(){
- return null;
+ Object data;
+ Node newHead = new Node();
+ newHead = this.head;
+ this.head = newHead.next;
+
+ data = newHead.data;
+ newHead = null;
+ return data;
}
public Object removeLast(){
- return null;
+ Object data;
+ Node last = findIndexNode(this.size() -1);
+ data = last.data;
+ last = null;
+
+ return data;
}
- public Iterator iterator(){
- return null;
+ public Iterator iterator()
+ {
+ return new LinkedListIterator();
}
-
+
private static class Node{
Object data;
@@ -49,7 +159,17 @@ private static class Node{
* 例如链表为 3->7->10 , 逆置后变为 10->7->3
*/
public void reverse(){
-
+ Node first ;
+ int currentIndex = 1;
+ this.head = findIndexNode(this.size - 1);
+ if(this.size() <= 1){
+ return;
+ }
+ while(currentIndex < this.size() ){
+ first = findIndexNode(this.size() - currentIndex);
+ first.next = findIndexNode(this.size - currentIndex - 1);
+ currentIndex++;
+ }
}
/**
@@ -59,16 +179,35 @@ public void reverse(){
*/
public void removeFirstHalf(){
-
+ checkElementIndex(this.size());
+
+ int mid = this.size / 2;
+ Node temp = this.head;
+ this.head = findIndexNode(mid);
+ for (int i = 0; i < mid; i++) {
+ Node T = temp.next;
+ temp = null;
+ temp = T;
+ }
+
}
/**
* 从第i个元素开始, 删除length 个元素 , 注意i从0开始
- * @param i
+ * @param index
* @param length
*/
- public void remove(int i, int length){
-
+ public void remove(int index, int length){
+ checkElementIndex(length + index );
+
+ Node before = findBeforeInsertNode(index);
+ Node temp = findIndexNode(index);
+ for (int i= 0; i < length; i++) {
+ Node T = temp.next;
+ temp = null;
+ temp = T;
+ }
+ before.next = temp;
}
/**
* 假定当前链表和listB均包含已升序排列的整数
@@ -79,7 +218,17 @@ public void remove(int i, int length){
* @param list
*/
public int[] getElements(LinkedList list){
- return null;
+ Node listNode = list.head;
+ Node myNode = this.head;
+ int[] data = new int[list.size()];
+ for (int i = 0; i < this.size(); i++) {
+ if(i == (Integer) listNode.data){
+ data[i] = (Integer)myNode.data;
+ }
+ myNode = myNode.next;
+ }
+
+ return data;
}
/**
@@ -90,12 +239,22 @@ public int[] getElements(LinkedList list){
*/
public void subtract(LinkedList list){
-
+
+ int[] data = new int[list.size()];
+ for (int i = 0,j = 0; i < this.size(); i++) {
+ for (; j < list.size(); j++) {
+ if(this.get(i).equals(list.get(j))){
+ this.remove(i);
+ break;
+ }
+ }
+ }
}
/**
* 已知当前链表中的元素以值递增有序排列,并以单链表作存储结构。
* 删除表中所有值相同的多余元素(使得操作后的线性表中所有元素的值均不相同)
+ * (选做)
*/
public void removeDuplicateValues(){
@@ -106,6 +265,7 @@ public void removeDuplicateValues(){
* 试写一高效的算法,删除表中所有值大于min且小于max的元素(若表中存在这样的元素)
* @param min
* @param max
+ * (选做)
*/
public void removeRange(int min, int max){
@@ -117,6 +277,51 @@ public void removeRange(int min, int max){
* @param list
*/
public LinkedList intersection( LinkedList list){
- return null;
+ LinkedList listC = new LinkedList();
+
+ for (int i = 0,j = 0; i < this.size(); i++) {
+ for (; j < list.size(); j++) {
+ if(this.get(i).equals(list.get(j))){
+ listC.add(this.get(i));
+ break;
+ }
+ }
+ }
+
+
+
+ return listC;
+ }
+
+
+
+ /************Iterator**************/
+ private class LinkedListIterator implements Iterator{
+ private Node currentNode;
+ private int currentIndex;
+
+ public LinkedListIterator() {
+ // TODO Auto-generated constructor stub
+ this.currentIndex = 0;
+ this.currentNode = new Node();
+ }
+ @Override
+ public boolean hasNext() {
+ // TODO Auto-generated method stub
+ return currentIndex < size();
+ }
+
+ @Override
+ public Object next() {
+ // TODO Auto-generated method stub
+ checkElementIndex(currentIndex);
+ if ( currentNode.data == null ) {
+ this.currentNode = findIndexNode(currentIndex);
+ }
+ Object value = currentNode.data;
+ currentNode = currentNode.next;
+ currentIndex++;
+ return value;
+ }
}
}
diff --git a/group23/729693763/Third_Homework3/DataStruct/List.java b/group23/729693763/Third_Homework3/DataStruct/List.java
new file mode 100644
index 0000000000..aa8b039453
--- /dev/null
+++ b/group23/729693763/Third_Homework3/DataStruct/List.java
@@ -0,0 +1,10 @@
+package com.zhous.DataStruct;
+
+public interface List {
+ void add(Object o);
+ void add(int index, Object o);
+ Object get(int index);
+ Object remove(int index);
+ int size();
+ Iterator iterator();
+}
From db064f3ad635f5ad51fa8e164232f4f237e35015 Mon Sep 17 00:00:00 2001
From: em14Vito
Date: Sun, 26 Mar 2017 23:36:14 +0800
Subject: [PATCH 009/262] add blog
---
group23/729693763/readme.md | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/group23/729693763/readme.md b/group23/729693763/readme.md
index 7e7fac06ae..89b8633e07 100644
--- a/group23/729693763/readme.md
+++ b/group23/729693763/readme.md
@@ -8,4 +8,5 @@ http://www.cnblogs.com/CodeSaveMe/p/6523745.html
Add Blog link: http://www.cnblogs.com/CodeSaveMe/p/6523745.html
Add week2 Blog link:http://www.cnblogs.com/CodeSaveMe/p/6571621.html
->>>>>>> my
+
+Add week3 Blog link:http://www.cnblogs.com/CodeSaveMe/p/6624431.html
From 24175890636de64823a385af322bd282af466a4a Mon Sep 17 00:00:00 2001
From: Pickacat
Date: Mon, 27 Mar 2017 00:50:27 +0800
Subject: [PATCH 010/262] =?UTF-8?q?LinkedList=E5=AE=8C=E6=88=90=E9=83=A8?=
=?UTF-8?q?=E5=88=86=E6=96=B9=E6=B3=95=EF=BC=8C=E5=A4=9A=E7=BA=BF=E7=A8=8B?=
=?UTF-8?q?=E4=B8=8B=E8=BD=BD=E8=BF=98=E6=B2=A1=E5=81=9A?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../src/com/xiaol/study/LinkedList.java | 24 ++++-
.../com/xiaol/download/DownloadThread.java | 20 ++++
.../com/xiaol/download/FileDownloader.java | 91 +++++++++++++++++++
.../xiaol/download/FileDownloaderTest.java | 60 ++++++++++++
.../com/xiaol/download/api/Connection.java | 23 +++++
.../download/api/ConnectionException.java | 5 +
.../xiaol/download/api/ConnectionManager.java | 10 ++
.../xiaol/download/api/DownloadListener.java | 5 +
.../xiaol/download/impl/ConnectionImpl.java | 27 ++++++
.../download/impl/ConnectionManagerImpl.java | 14 +++
10 files changed, 275 insertions(+), 4 deletions(-)
create mode 100644 group23/381519422/download/src/main/java/com/xiaol/download/DownloadThread.java
create mode 100644 group23/381519422/download/src/main/java/com/xiaol/download/FileDownloader.java
create mode 100644 group23/381519422/download/src/main/java/com/xiaol/download/FileDownloaderTest.java
create mode 100644 group23/381519422/download/src/main/java/com/xiaol/download/api/Connection.java
create mode 100644 group23/381519422/download/src/main/java/com/xiaol/download/api/ConnectionException.java
create mode 100644 group23/381519422/download/src/main/java/com/xiaol/download/api/ConnectionManager.java
create mode 100644 group23/381519422/download/src/main/java/com/xiaol/download/api/DownloadListener.java
create mode 100644 group23/381519422/download/src/main/java/com/xiaol/download/impl/ConnectionImpl.java
create mode 100644 group23/381519422/download/src/main/java/com/xiaol/download/impl/ConnectionManagerImpl.java
diff --git a/group23/381519422/DataStructure/src/com/xiaol/study/LinkedList.java b/group23/381519422/DataStructure/src/com/xiaol/study/LinkedList.java
index d60ede59a1..2b3104756e 100644
--- a/group23/381519422/DataStructure/src/com/xiaol/study/LinkedList.java
+++ b/group23/381519422/DataStructure/src/com/xiaol/study/LinkedList.java
@@ -159,6 +159,7 @@ private Node(Object o) {
}
//---------------下面的方法暂时先不实现
+ // removeDuplicateValues(),removeRange()可以不实现
/**
* 把该链表逆置
@@ -182,8 +183,16 @@ public void removeFirstHalf(){
* @param i
* @param length
*/
- public void remove(int i, int length){
-
+ public void remove(int i, int length) {
+ if (i < 0) {
+ throw new RuntimeException("非法参数");
+ }
+ Node indexNode = getIndexNode(i);
+ Node nextNode = getIndexNode(i);
+ for (int j = 0; j < length; j++) {
+ nextNode = nextNode.next;
+ }
+ indexNode.next = nextNode;
}
/**
@@ -194,8 +203,15 @@ public void remove(int i, int length){
* 返回的结果应该是[101,301,401,601]
* @param list
*/
- public int[] getElements(LinkedList list){
- return null;
+ public int[] getElements(LinkedList list) {
+ int[] retVal = new int[list.size()];
+ for (int i = 0; i < list.size(); i++) {
+ int index = (int) list.get(i);
+ Node indexNode = getIndexNode(index);
+ int data = (int) indexNode.data;
+ retVal[i] = data;
+ }
+ return retVal;
}
/**
diff --git a/group23/381519422/download/src/main/java/com/xiaol/download/DownloadThread.java b/group23/381519422/download/src/main/java/com/xiaol/download/DownloadThread.java
new file mode 100644
index 0000000000..a038d0da37
--- /dev/null
+++ b/group23/381519422/download/src/main/java/com/xiaol/download/DownloadThread.java
@@ -0,0 +1,20 @@
+package com.xiaol.download;
+
+import com.xiaol.download.api.Connection;
+
+public class DownloadThread extends Thread{
+
+ Connection conn;
+ int startPos;
+ int endPos;
+
+ public DownloadThread( Connection conn, int startPos, int endPos){
+
+ this.conn = conn;
+ this.startPos = startPos;
+ this.endPos = endPos;
+ }
+ public void run(){
+
+ }
+}
\ No newline at end of file
diff --git a/group23/381519422/download/src/main/java/com/xiaol/download/FileDownloader.java b/group23/381519422/download/src/main/java/com/xiaol/download/FileDownloader.java
new file mode 100644
index 0000000000..cd0b433843
--- /dev/null
+++ b/group23/381519422/download/src/main/java/com/xiaol/download/FileDownloader.java
@@ -0,0 +1,91 @@
+package com.xiaol.download;
+
+import com.xiaol.download.api.Connection;
+import com.xiaol.download.api.ConnectionException;
+import com.xiaol.download.api.ConnectionManager;
+import com.xiaol.download.api.DownloadListener;
+
+
+public class FileDownloader {
+
+ String url;
+
+ DownloadListener listener;
+
+ ConnectionManager cm;
+
+
+ public FileDownloader(String _url) {
+ this.url = _url;
+
+ }
+
+ public void execute(){
+ // 在这里实现你的代码, 注意: 需要用多线程实现下载
+ // 这个类依赖于其他几个接口, 你需要写这几个接口的实现代码
+ // (1) ConnectionManager , 可以打开一个连接,通过Connection可以读取其中的一段(用startPos, endPos来指定)
+ // (2) DownloadListener, 由于是多线程下载, 调用这个类的客户端不知道什么时候结束,所以你需要实现当所有
+ // 线程都执行完以后, 调用listener的notifiedFinished方法, 这样客户端就能收到通知。
+ // 具体的实现思路:
+ // 1. 需要调用ConnectionManager的open方法打开连接, 然后通过Connection.getContentLength方法获得文件的长度
+ // 2. 至少启动3个线程下载, 注意每个线程需要先调用ConnectionManager的open方法
+ // 然后调用read方法, read方法中有读取文件的开始位置和结束位置的参数, 返回值是byte[]数组
+ // 3. 把byte数组写入到文件中
+ // 4. 所有的线程都下载完成以后, 需要调用listener的notifiedFinished方法
+
+ // 下面的代码是示例代码, 也就是说只有一个线程, 你需要改造成多线程的。
+// Connection conn = null;
+// try {
+//
+// conn = cm.open(this.url);
+//
+// int length = conn.getContentLength();
+//
+// new DownloadThread(conn,0,length-1).start();
+//
+// } catch (ConnectionException e) {
+// e.printStackTrace();
+// }finally{
+// if(conn != null){
+// conn.close();
+// }
+// }
+
+
+ Connection conn = null;
+ try {
+
+ conn = cm.open(this.url);
+
+ int length = conn.getContentLength();
+
+ new DownloadThread(conn,0,length-1).start();
+
+ } catch (ConnectionException e) {
+ e.printStackTrace();
+ }finally{
+ if(conn != null){
+ conn.close();
+ }
+ }
+
+
+
+
+ }
+
+ public void setListener(DownloadListener listener) {
+ this.listener = listener;
+ }
+
+
+
+ public void setConnectionManager(ConnectionManager ucm){
+ this.cm = ucm;
+ }
+
+ public DownloadListener getListener(){
+ return this.listener;
+ }
+
+}
\ No newline at end of file
diff --git a/group23/381519422/download/src/main/java/com/xiaol/download/FileDownloaderTest.java b/group23/381519422/download/src/main/java/com/xiaol/download/FileDownloaderTest.java
new file mode 100644
index 0000000000..f76ba7ff38
--- /dev/null
+++ b/group23/381519422/download/src/main/java/com/xiaol/download/FileDownloaderTest.java
@@ -0,0 +1,60 @@
+package com.xiaol.download;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+import com.xiaol.download.api.ConnectionManager;
+import com.xiaol.download.api.DownloadListener;
+import com.xiaol.download.impl.ConnectionManagerImpl;
+
+public class FileDownloaderTest {
+ boolean downloadFinished = false;
+ @Before
+ public void setUp() throws Exception {
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ }
+
+ @Test
+ public void testDownload() {
+
+// String url = "http://localhost:8080/test.jpg";
+ String url = "http://img4.duitang.com/uploads/item/201411/09/20141109224803_GXSri.jpeg";
+
+ FileDownloader downloader = new FileDownloader(url);
+
+
+ ConnectionManager cm = new ConnectionManagerImpl();
+ downloader.setConnectionManager(cm);
+
+ downloader.setListener(new DownloadListener() {
+ @Override
+ public void notifyFinished() {
+ downloadFinished = true;
+ }
+
+ });
+
+
+ downloader.execute();
+
+ // 等待多线程下载程序执行完毕
+ while (!downloadFinished) {
+ try {
+ System.out.println("还没有下载完成,休眠五秒");
+ //休眠5秒
+ Thread.sleep(5000);
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+ }
+ System.out.println("下载完成!");
+
+
+
+ }
+
+}
\ No newline at end of file
diff --git a/group23/381519422/download/src/main/java/com/xiaol/download/api/Connection.java b/group23/381519422/download/src/main/java/com/xiaol/download/api/Connection.java
new file mode 100644
index 0000000000..425fe784a7
--- /dev/null
+++ b/group23/381519422/download/src/main/java/com/xiaol/download/api/Connection.java
@@ -0,0 +1,23 @@
+package com.xiaol.download.api;
+
+import java.io.IOException;
+
+public interface Connection {
+ /**
+ * 给定开始和结束位置, 读取数据, 返回值是字节数组
+ * @param startPos 开始位置, 从0开始
+ * @param endPos 结束位置
+ * @return
+ */
+ public byte[] read(int startPos,int endPos) throws IOException;
+ /**
+ * 得到数据内容的长度
+ * @return
+ */
+ public int getContentLength();
+
+ /**
+ * 关闭连接
+ */
+ public void close();
+}
\ No newline at end of file
diff --git a/group23/381519422/download/src/main/java/com/xiaol/download/api/ConnectionException.java b/group23/381519422/download/src/main/java/com/xiaol/download/api/ConnectionException.java
new file mode 100644
index 0000000000..83cbd33c7e
--- /dev/null
+++ b/group23/381519422/download/src/main/java/com/xiaol/download/api/ConnectionException.java
@@ -0,0 +1,5 @@
+package com.xiaol.download.api;
+
+public class ConnectionException extends Exception {
+
+}
\ No newline at end of file
diff --git a/group23/381519422/download/src/main/java/com/xiaol/download/api/ConnectionManager.java b/group23/381519422/download/src/main/java/com/xiaol/download/api/ConnectionManager.java
new file mode 100644
index 0000000000..fcd90b77da
--- /dev/null
+++ b/group23/381519422/download/src/main/java/com/xiaol/download/api/ConnectionManager.java
@@ -0,0 +1,10 @@
+package com.xiaol.download.api;
+
+public interface ConnectionManager {
+ /**
+ * 给定一个url , 打开一个连接
+ * @param url
+ * @return
+ */
+ public Connection open(String url) throws ConnectionException;
+}
\ No newline at end of file
diff --git a/group23/381519422/download/src/main/java/com/xiaol/download/api/DownloadListener.java b/group23/381519422/download/src/main/java/com/xiaol/download/api/DownloadListener.java
new file mode 100644
index 0000000000..549a36e478
--- /dev/null
+++ b/group23/381519422/download/src/main/java/com/xiaol/download/api/DownloadListener.java
@@ -0,0 +1,5 @@
+package com.xiaol.download.api;
+
+public interface DownloadListener {
+ public void notifyFinished();
+}
\ No newline at end of file
diff --git a/group23/381519422/download/src/main/java/com/xiaol/download/impl/ConnectionImpl.java b/group23/381519422/download/src/main/java/com/xiaol/download/impl/ConnectionImpl.java
new file mode 100644
index 0000000000..3cc898e626
--- /dev/null
+++ b/group23/381519422/download/src/main/java/com/xiaol/download/impl/ConnectionImpl.java
@@ -0,0 +1,27 @@
+package com.xiaol.download.impl;
+
+import java.io.IOException;
+
+import com.xiaol.download.api.Connection;
+
+public class ConnectionImpl implements Connection{
+
+ @Override
+ public byte[] read(int startPos, int endPos) throws IOException {
+
+ return null;
+ }
+
+ @Override
+ public int getContentLength() {
+
+ return 0;
+ }
+
+ @Override
+ public void close() {
+
+
+ }
+
+}
\ No newline at end of file
diff --git a/group23/381519422/download/src/main/java/com/xiaol/download/impl/ConnectionManagerImpl.java b/group23/381519422/download/src/main/java/com/xiaol/download/impl/ConnectionManagerImpl.java
new file mode 100644
index 0000000000..d8bd4c5a34
--- /dev/null
+++ b/group23/381519422/download/src/main/java/com/xiaol/download/impl/ConnectionManagerImpl.java
@@ -0,0 +1,14 @@
+package com.xiaol.download.impl;
+import com.xiaol.download.api.Connection;
+import com.xiaol.download.api.ConnectionException;
+import com.xiaol.download.api.ConnectionManager;
+
+public class ConnectionManagerImpl implements ConnectionManager {
+
+ @Override
+ public Connection open(String url) throws ConnectionException {
+
+ return null;
+ }
+
+}
\ No newline at end of file
From fa4f699d6fbca186a2affeaf6a2232a903344a7f Mon Sep 17 00:00:00 2001
From: anxinJ <1028361767@qq.com>
Date: Mon, 27 Mar 2017 12:44:14 +0800
Subject: [PATCH 011/262] LinkedList homework
LinkedList homework
---
.../src/com/coding/basic/LinkedList.java | 183 ++++++++++++++++--
1 file changed, 169 insertions(+), 14 deletions(-)
diff --git a/group23/1028361767/Week1DataStructure/src/com/coding/basic/LinkedList.java b/group23/1028361767/Week1DataStructure/src/com/coding/basic/LinkedList.java
index 5e241db172..b88654c9a8 100644
--- a/group23/1028361767/Week1DataStructure/src/com/coding/basic/LinkedList.java
+++ b/group23/1028361767/Week1DataStructure/src/com/coding/basic/LinkedList.java
@@ -67,7 +67,7 @@ public Object get(int index) {
pos++;
} while (pos != index);
}
- return cur;
+ return cur.data;
}
public Object remove(int index) {
@@ -87,7 +87,7 @@ public Object remove(int index) {
prev.next = cur.next;
}
size--;
- return cur;
+ return cur.data;
}
public int size() {
@@ -122,7 +122,7 @@ public Object removeFirst() {
Node ret = head;
head = head.next;
size--;
- return ret;
+ return ret.data;
}
public Object removeLast() {
@@ -143,7 +143,7 @@ public Object removeLast() {
prev.next = null;
}
size--;
- return ret;
+ return ret.data;
}
public Iterator iterator() {
@@ -167,7 +167,20 @@ public Node(Object data, Node next) {
* 例如链表为 3->7->10 , 逆置后变为 10->7->3
*/
public void reverse() {
-
+ if(size == 0 || size == 1){
+ return ;
+ }
+ Node node = head;
+ Node nextNode = head.next;
+ Node tmp;
+ node.next = null;
+ do{
+ tmp = nextNode.next;
+ nextNode.next = node;
+ node = nextNode;
+ nextNode = tmp;
+ }while(nextNode != null);
+ head = node;
}
/**
@@ -176,9 +189,19 @@ public void reverse() {
* 如果list = 2->5->7->8->10 ,删除以后的值为7,8,10
*/
public void removeFirstHalf() {
-
+ if(size == 0 || size == 1){
+ return ;
+ }
+ int num = size / 2;
+ size -= num;
+ Node node = head;
+ while(num > 0){
+ node = node.next;
+ num--;
+ }
+ head = node;
}
-
+
/**
* 从第i个元素开始, 删除length 个元素 , 注意i从0开始
*
@@ -186,7 +209,28 @@ public void removeFirstHalf() {
* @param length
*/
public void remove(int i, int length) {
-
+ checkMinBound(i);
+ checkMaxBound(i + length, size);
+ Node prev = null;
+ Node node = head;
+ int index = 0;
+ while(index < i){
+ prev = node;
+ node = node.next;
+ index++;
+ }
+ Node nextNode = node.next;
+ while(index < (i + length - 1)){
+ nextNode = nextNode.next;
+ index++;
+ }
+ size -= length;
+ if(i == 0){
+ head = nextNode;
+ }else{
+ prev.next = nextNode;
+ head = prev;
+ }
}
/**
@@ -198,8 +242,26 @@ public void remove(int i, int length) {
*
* @param list
*/
- public static int[] getElements(LinkedList list) {
- return null;
+ public int[] getElements(LinkedList list) {
+ int[] ret = new int[list.size()];
+ if(ret.length == 0){
+ return ret;
+ }
+ int index;
+ int j = 0;
+ Node node = head;
+ for(int i=0;i min){
+ foundMin = true;
+ }
+ if((int)node.data > max){
+ break;
+ }
+ if(foundMin == false){
+ prev = node;
+ }else{
+ size -= 1;
+ }
+ node = node.next;
+ }while(node != null);
+ if(prev == null){
+ head = node;
+ }else{
+ prev.next = node;
+ }
}
/**
@@ -239,6 +356,44 @@ public void removeRange(int min, int max) {
* @param list
*/
public LinkedList intersection(LinkedList list) {
- return null;
+ LinkedList ret = new LinkedList();
+ Node node = head;
+ int nodeValue;
+ int elementValue;
+ for(int i=0;i elementValue){
+ break;
+ }
+ node = node.next;
+ }
+ }
+ }
+ return ret;
+ }
+
+ public String toString(){
+ Node node = head;
+ StringBuilder sb = new StringBuilder();
+ if(node == null){
+ return "";
+ }else{
+ sb.append(head.data);
+ while((node = node.next) != null){
+ sb.append(",").append(node.data);
+ }
+ return sb.toString();
+ }
}
}
From 4a36e78d2c1a9c27a3fb2d769974e2b40dc278d8 Mon Sep 17 00:00:00 2001
From: anxinJ <1028361767@qq.com>
Date: Mon, 27 Mar 2017 12:56:39 +0800
Subject: [PATCH 012/262] LinkedList homework update
LinkedList homework update
---
.../src/com/coding/basic/LinkedList.java | 2 +-
.../test/com/coding/basic/TestLinkedList.java | 176 ++++++++++++++++++
2 files changed, 177 insertions(+), 1 deletion(-)
create mode 100644 group23/1028361767/Week1DataStructure/src/test/com/coding/basic/TestLinkedList.java
diff --git a/group23/1028361767/Week1DataStructure/src/com/coding/basic/LinkedList.java b/group23/1028361767/Week1DataStructure/src/com/coding/basic/LinkedList.java
index b88654c9a8..eb41670f82 100644
--- a/group23/1028361767/Week1DataStructure/src/com/coding/basic/LinkedList.java
+++ b/group23/1028361767/Week1DataStructure/src/com/coding/basic/LinkedList.java
@@ -332,7 +332,7 @@ public void removeRange(int min, int max) {
if(!foundMin && (int)node.data > min){
foundMin = true;
}
- if((int)node.data > max){
+ if(foundMin && (int)node.data > max){
break;
}
if(foundMin == false){
diff --git a/group23/1028361767/Week1DataStructure/src/test/com/coding/basic/TestLinkedList.java b/group23/1028361767/Week1DataStructure/src/test/com/coding/basic/TestLinkedList.java
new file mode 100644
index 0000000000..39b41c1317
--- /dev/null
+++ b/group23/1028361767/Week1DataStructure/src/test/com/coding/basic/TestLinkedList.java
@@ -0,0 +1,176 @@
+package test.com.coding.basic;
+
+import static org.junit.Assert.*;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import com.coding.basic.LinkedList;
+
+public class TestLinkedList {
+
+ @Test
+ public void testReverse(){
+ LinkedList list = new LinkedList();
+ list.add(3);
+ list.add(7);
+ list.add(10);
+ list.reverse();
+ Assert.assertEquals("10,7,3", list.toString());
+ Assert.assertEquals("10", list.get(0).toString());
+ }
+
+ @Test
+ public void testRemoveFirstHalf(){
+ LinkedList list = new LinkedList();
+ list.add(3);
+ list.add(7);
+ list.add(10);
+ list.add(12);
+ list.add(15);
+ list.removeFirstHalf();
+ Assert.assertEquals("10", list.get(0).toString());
+ Assert.assertEquals("10,12,15", list.toString());
+ Assert.assertEquals(3, list.size());
+ }
+
+ @Test
+ public void testRemoveByLength(){
+ LinkedList list = new LinkedList();
+ list.add(3);
+ list.add(7);
+ list.add(10);
+ list.add(12);
+ list.add(15);
+ list.remove(0, 2);
+ Assert.assertEquals("10", list.get(0).toString());
+ Assert.assertEquals("10,12,15", list.toString());
+ Assert.assertEquals(3, list.size());
+
+ list.remove(1, 1);
+ Assert.assertEquals("10", list.get(0).toString());
+ Assert.assertEquals("10,15", list.toString());
+ Assert.assertEquals(2, list.size());
+ }
+
+ @Test
+ public void testGetElements(){
+ LinkedList list = new LinkedList();
+ list.add(0);
+ list.add(1);
+ list.add(2);
+ list.add(3);
+ list.add(4);
+ list.add(5);
+ list.add(6);
+
+ LinkedList indices = new LinkedList();
+ indices.add(1);
+ indices.add(3);
+ indices.add(4);
+ indices.add(6);
+ int[] elements = list.getElements(indices);
+ StringBuilder sb = new StringBuilder();
+ for(int i=0;i
Date: Mon, 27 Mar 2017 16:15:32 +0800
Subject: [PATCH 013/262] FileDownload
FileDownload
---
.../coderising/download/DownloadThread.java | 31 ++++++
.../coderising/download/FileDownloader.java | 98 +++++++++++++++++++
.../download/FileDownloaderTest.java | 59 +++++++++++
.../coderising/download/api/Connection.java | 26 +++++
.../download/api/ConnectionException.java | 5 +
.../download/api/ConnectionManager.java | 10 ++
.../download/api/DownloadListener.java | 5 +
.../download/impl/ConnectionImpl.java | 62 ++++++++++++
.../download/impl/ConnectionManagerImpl.java | 26 +++++
9 files changed, 322 insertions(+)
create mode 100644 group23/1028361767/Week1DataStructure/src/com/coderising/download/DownloadThread.java
create mode 100644 group23/1028361767/Week1DataStructure/src/com/coderising/download/FileDownloader.java
create mode 100644 group23/1028361767/Week1DataStructure/src/com/coderising/download/FileDownloaderTest.java
create mode 100644 group23/1028361767/Week1DataStructure/src/com/coderising/download/api/Connection.java
create mode 100644 group23/1028361767/Week1DataStructure/src/com/coderising/download/api/ConnectionException.java
create mode 100644 group23/1028361767/Week1DataStructure/src/com/coderising/download/api/ConnectionManager.java
create mode 100644 group23/1028361767/Week1DataStructure/src/com/coderising/download/api/DownloadListener.java
create mode 100644 group23/1028361767/Week1DataStructure/src/com/coderising/download/impl/ConnectionImpl.java
create mode 100644 group23/1028361767/Week1DataStructure/src/com/coderising/download/impl/ConnectionManagerImpl.java
diff --git a/group23/1028361767/Week1DataStructure/src/com/coderising/download/DownloadThread.java b/group23/1028361767/Week1DataStructure/src/com/coderising/download/DownloadThread.java
new file mode 100644
index 0000000000..8cf0ae1e42
--- /dev/null
+++ b/group23/1028361767/Week1DataStructure/src/com/coderising/download/DownloadThread.java
@@ -0,0 +1,31 @@
+package com.coderising.download;
+
+import java.io.IOException;
+import java.io.RandomAccessFile;
+
+import com.coderising.download.api.Connection;
+
+public class DownloadThread extends Thread{
+
+ Connection conn;
+ int startPos;
+ int endPos;
+
+ public DownloadThread( Connection conn, int startPos, int endPos){
+
+ this.conn = conn;
+ this.startPos = startPos;
+ this.endPos = endPos;
+ }
+ public void run(){
+ try {
+ byte[] bytes = conn.read(startPos, endPos);
+ RandomAccessFile file = new RandomAccessFile("/Users/jie/Desktop/test.png", "rw");
+ file.seek(startPos);
+ file.write(bytes);
+ file.close();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+}
diff --git a/group23/1028361767/Week1DataStructure/src/com/coderising/download/FileDownloader.java b/group23/1028361767/Week1DataStructure/src/com/coderising/download/FileDownloader.java
new file mode 100644
index 0000000000..a5b8aac78e
--- /dev/null
+++ b/group23/1028361767/Week1DataStructure/src/com/coderising/download/FileDownloader.java
@@ -0,0 +1,98 @@
+package com.coderising.download;
+
+import com.coderising.download.api.Connection;
+import com.coderising.download.api.ConnectionException;
+import com.coderising.download.api.ConnectionManager;
+import com.coderising.download.api.DownloadListener;
+
+
+public class FileDownloader {
+
+ String url;
+
+ DownloadListener listener;
+
+ ConnectionManager cm;
+
+
+ public FileDownloader(String _url) {
+ this.url = _url;
+
+ }
+
+ public void execute(){
+ // 在这里实现你的代码, 注意: 需要用多线程实现下载
+ // 这个类依赖于其他几个接口, 你需要写这几个接口的实现代码
+ // (1) ConnectionManager , 可以打开一个连接,通过Connection可以读取其中的一段(用startPos, endPos来指定)
+ // (2) DownloadListener, 由于是多线程下载, 调用这个类的客户端不知道什么时候结束,所以你需要实现当所有
+ // 线程都执行完以后, 调用listener的notifiedFinished方法, 这样客户端就能收到通知。
+ // 具体的实现思路:
+ // 1. 需要调用ConnectionManager的open方法打开连接, 然后通过Connection.getContentLength方法获得文件的长度
+ // 2. 至少启动3个线程下载, 注意每个线程需要先调用ConnectionManager的open方法
+ // 然后调用read方法, read方法中有读取文件的开始位置和结束位置的参数, 返回值是byte[]数组
+ // 3. 把byte数组写入到文件中
+ // 4. 所有的线程都下载完成以后, 需要调用listener的notifiedFinished方法
+
+ // 下面的代码是示例代码, 也就是说只有一个线程, 你需要改造成多线程的。
+ Connection conn = null;
+ try {
+
+ conn = cm.open(this.url);
+
+ int length = conn.getContentLength();
+
+ int size = length / 3;
+ int remain = length - size;
+
+ Thread[] threads = new Thread[3];
+ for(int i=0;i<3;i++){
+ conn = cm.open(this.url);
+ int startPos = i*size;
+ int endPos = (i+1) * size - 1;
+ if(i == 2){
+ endPos = (i+1) * size - 1 + remain;
+ }
+ threads[i] = new DownloadThread(conn,startPos,endPos);
+ threads[i].start();
+ }
+ boolean finish;
+ do{
+ finish = true;
+ for(int i=0;i
Date: Mon, 27 Mar 2017 16:26:24 +0800
Subject: [PATCH 014/262] FileDownloader update
FileDownloader update
---
.../coderising/download/FileDownloader.java | 30 +++++++++++--------
1 file changed, 18 insertions(+), 12 deletions(-)
diff --git a/group23/1028361767/Week1DataStructure/src/com/coderising/download/FileDownloader.java b/group23/1028361767/Week1DataStructure/src/com/coderising/download/FileDownloader.java
index a5b8aac78e..1fe4ebb159 100644
--- a/group23/1028361767/Week1DataStructure/src/com/coderising/download/FileDownloader.java
+++ b/group23/1028361767/Week1DataStructure/src/com/coderising/download/FileDownloader.java
@@ -14,6 +14,8 @@ public class FileDownloader {
ConnectionManager cm;
+ Thread[] threads = new Thread[3];
+
public FileDownloader(String _url) {
this.url = _url;
@@ -44,7 +46,6 @@ public void execute(){
int size = length / 3;
int remain = length - size;
- Thread[] threads = new Thread[3];
for(int i=0;i<3;i++){
conn = cm.open(this.url);
int startPos = i*size;
@@ -55,18 +56,23 @@ public void execute(){
threads[i] = new DownloadThread(conn,startPos,endPos);
threads[i].start();
}
- boolean finish;
- do{
- finish = true;
- for(int i=0;i
Date: Mon, 27 Mar 2017 17:29:27 +0800
Subject: [PATCH 015/262] =?UTF-8?q?=E7=AC=AC=E4=B8=89=E5=91=A8?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../coderising/download/DownloadThread.java | 65 ++++++++
.../coderising/download/FileDownloader.java | 89 +++++++++++
.../download/FileDownloaderTest.java | 58 +++++++
.../coderising/download/api/Connection.java | 24 +++
.../download/api/ConnectionException.java | 5 +
.../download/api/ConnectionManager.java | 10 ++
.../download/api/DownloadListener.java | 5 +
.../download/impl/ConnectionImpl.java | 143 ++++++++++++++++++
.../download/impl/ConnectionManagerImpl.java | 16 ++
.../src/junit/test/ConnectionImplTest.java | 92 +++++++++++
.../junit/test/ConnectionManagerImplTest.java | 31 ++++
.../src/junit/test/DownloadThreadTest.java | 77 ++++++++++
12 files changed, 615 insertions(+)
create mode 100644 group23/1072760797-skomefen/day3-26/src/com/coderising/download/DownloadThread.java
create mode 100644 group23/1072760797-skomefen/day3-26/src/com/coderising/download/FileDownloader.java
create mode 100644 group23/1072760797-skomefen/day3-26/src/com/coderising/download/FileDownloaderTest.java
create mode 100644 group23/1072760797-skomefen/day3-26/src/com/coderising/download/api/Connection.java
create mode 100644 group23/1072760797-skomefen/day3-26/src/com/coderising/download/api/ConnectionException.java
create mode 100644 group23/1072760797-skomefen/day3-26/src/com/coderising/download/api/ConnectionManager.java
create mode 100644 group23/1072760797-skomefen/day3-26/src/com/coderising/download/api/DownloadListener.java
create mode 100644 group23/1072760797-skomefen/day3-26/src/com/coderising/download/impl/ConnectionImpl.java
create mode 100644 group23/1072760797-skomefen/day3-26/src/com/coderising/download/impl/ConnectionManagerImpl.java
create mode 100644 group23/1072760797-skomefen/day3-26/src/junit/test/ConnectionImplTest.java
create mode 100644 group23/1072760797-skomefen/day3-26/src/junit/test/ConnectionManagerImplTest.java
create mode 100644 group23/1072760797-skomefen/day3-26/src/junit/test/DownloadThreadTest.java
diff --git a/group23/1072760797-skomefen/day3-26/src/com/coderising/download/DownloadThread.java b/group23/1072760797-skomefen/day3-26/src/com/coderising/download/DownloadThread.java
new file mode 100644
index 0000000000..66024b0ccf
--- /dev/null
+++ b/group23/1072760797-skomefen/day3-26/src/com/coderising/download/DownloadThread.java
@@ -0,0 +1,65 @@
+package com.coderising.download;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.util.concurrent.locks.Lock;
+import java.util.concurrent.locks.ReentrantLock;
+
+import com.coderising.download.api.Connection;
+
+public class DownloadThread extends Thread{
+
+ private Connection conn;
+ private int startPos;
+ private int endPos;
+ private byte[] b = null;
+ private static Lock lock = new ReentrantLock();
+ private static int index=0;
+
+ static FileOutputStream file = null;
+ static{
+ try {
+ file = new FileOutputStream(new File("e://readme.txt"));
+ } catch (FileNotFoundException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+
+ public DownloadThread( Connection conn, int startPos, int endPos){
+
+ this.conn = conn;
+ this.startPos = startPos;
+ this.endPos = endPos;
+ try {
+ this.b = conn.read(startPos, endPos);
+ } catch (IOException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ throw new RuntimeException();
+ }finally{
+ conn.close();
+ }
+
+ }
+ public void run(){
+ if(lock.tryLock()){
+ if(index==startPos){
+ try {
+ if (file!=null) {
+ file.write(b);
+ }
+ index=endPos+1;
+ } catch (IOException e) {
+ e.printStackTrace();
+ throw new RuntimeException();
+ }
+
+ }else{
+ lock.unlock();
+ }
+ }
+ }
+}
diff --git a/group23/1072760797-skomefen/day3-26/src/com/coderising/download/FileDownloader.java b/group23/1072760797-skomefen/day3-26/src/com/coderising/download/FileDownloader.java
new file mode 100644
index 0000000000..ed4a1cf9a1
--- /dev/null
+++ b/group23/1072760797-skomefen/day3-26/src/com/coderising/download/FileDownloader.java
@@ -0,0 +1,89 @@
+package com.coderising.download;
+
+import com.coderising.download.api.Connection;
+import com.coderising.download.api.ConnectionException;
+import com.coderising.download.api.ConnectionManager;
+import com.coderising.download.api.DownloadListener;
+
+
+public class FileDownloader {
+
+ String url;
+
+ DownloadListener listener;
+
+ ConnectionManager cm;
+
+
+ public FileDownloader(String _url) {
+ this.url = _url;
+
+ }
+
+ public void execute(){
+ // 在这里实现你的代码, 注意: 需要用多线程实现下载
+ // 这个类依赖于其他几个接口, 你需要写这几个接口的实现代码
+ // (1) ConnectionManager , 可以打开一个连接,通过Connection可以读取其中的一段(用startPos, endPos来指定)
+ // (2) DownloadListener, 由于是多线程下载, 调用这个类的客户端不知道什么时候结束,所以你需要实现当所有
+ // 线程都执行完以后, 调用listener的notifiedFinished方法, 这样客户端就能收到通知。
+ // 具体的实现思路:
+ // 1. 需要调用ConnectionManager的open方法打开连接, 然后通过Connection.getContentLength方法获得文件的长度
+ // 2. 至少启动3个线程下载, 注意每个线程需要先调用ConnectionManager的open方法
+ // 然后调用read方法, read方法中有读取文件的开始位置和结束位置的参数, 返回值是byte[]数组
+ // 3. 把byte数组写入到文件中
+ // 4. 所有的线程都下载完成以后, 需要调用listener的notifiedFinished方法
+
+ // 下面的代码是示例代码, 也就是说只有一个线程, 你需要改造成多线程的。
+ Connection conn = null;
+ try {
+
+ conn = cm.open(this.url);
+
+ int length = conn.getContentLength();
+
+ if(length%3==0){
+ for(int i=1;i<=3;i++){
+ int startPos = length/3*i-1;
+ int endPos = length/3*(i-1);
+ new DownloadThread(conn, endPos, startPos).start();
+ }
+ }else{
+ for(int i=1;i<=2;i++){
+
+ int startPos = length/3*(i-1);
+ int endPos = length/3*i-1;
+ new DownloadThread(conn, startPos, endPos).start();
+ }
+ int startPos = length/3*2;
+ new DownloadThread(conn, startPos, length).start();
+ }
+
+ listener.notifyFinished();
+ } catch (ConnectionException e) {
+ e.printStackTrace();
+ }finally{
+ if(conn != null){
+ conn.close();
+ }
+ }
+
+
+
+
+ }
+
+ public void setListener(DownloadListener listener) {
+ this.listener = listener;
+ }
+
+
+
+ public void setConnectionManager(ConnectionManager ucm){
+ this.cm = ucm;
+ }
+
+ public DownloadListener getListener(){
+ return this.listener;
+ }
+
+}
diff --git a/group23/1072760797-skomefen/day3-26/src/com/coderising/download/FileDownloaderTest.java b/group23/1072760797-skomefen/day3-26/src/com/coderising/download/FileDownloaderTest.java
new file mode 100644
index 0000000000..ce99026d2b
--- /dev/null
+++ b/group23/1072760797-skomefen/day3-26/src/com/coderising/download/FileDownloaderTest.java
@@ -0,0 +1,58 @@
+package com.coderising.download;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+import com.coderising.download.api.ConnectionManager;
+import com.coderising.download.api.DownloadListener;
+import com.coderising.download.impl.ConnectionManagerImpl;
+
+public class FileDownloaderTest {
+ boolean downloadFinished = false;
+ @Before
+ public void setUp() throws Exception {
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ }
+
+ @Test
+ public void testDownload() {
+
+ String url = "http://localhost:8080/TimeCapsule/readme.txt";
+
+ FileDownloader downloader = new FileDownloader(url);
+
+
+ ConnectionManager cm = new ConnectionManagerImpl();
+ downloader.setConnectionManager(cm);
+
+ downloader.setListener(new DownloadListener() {
+ public void notifyFinished() {
+ downloadFinished = true;
+ }
+
+ });
+
+
+ downloader.execute();
+
+ // 等待多线程下载程序执行完毕
+ while (!downloadFinished) {
+ try {
+ System.out.println("还没有下载完成,休眠五秒");
+ //休眠5秒
+ Thread.sleep(5000);
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+ }
+ System.out.println("下载完成!");
+
+
+
+ }
+
+}
diff --git a/group23/1072760797-skomefen/day3-26/src/com/coderising/download/api/Connection.java b/group23/1072760797-skomefen/day3-26/src/com/coderising/download/api/Connection.java
new file mode 100644
index 0000000000..3982b8e310
--- /dev/null
+++ b/group23/1072760797-skomefen/day3-26/src/com/coderising/download/api/Connection.java
@@ -0,0 +1,24 @@
+package com.coderising.download.api;
+
+import java.io.IOException;
+
+public interface Connection {
+ /**
+ * 给定开始和结束位置, 读取数据, 返回值是字节数组
+ * @param startPos 开始位置, 从0开始
+ * @param endPos 结束位置
+ * @return
+ */
+ public byte[] read(int startPos,int endPos) throws IOException;
+ /**
+ * 得到数据内容的长度
+ * @return
+ */
+ public int getContentLength();
+
+ /**
+ * 关闭连接
+ *
+ */
+ public void close();
+}
diff --git a/group23/1072760797-skomefen/day3-26/src/com/coderising/download/api/ConnectionException.java b/group23/1072760797-skomefen/day3-26/src/com/coderising/download/api/ConnectionException.java
new file mode 100644
index 0000000000..1551a80b3d
--- /dev/null
+++ b/group23/1072760797-skomefen/day3-26/src/com/coderising/download/api/ConnectionException.java
@@ -0,0 +1,5 @@
+package com.coderising.download.api;
+
+public class ConnectionException extends Exception {
+
+}
diff --git a/group23/1072760797-skomefen/day3-26/src/com/coderising/download/api/ConnectionManager.java b/group23/1072760797-skomefen/day3-26/src/com/coderising/download/api/ConnectionManager.java
new file mode 100644
index 0000000000..ce045393b1
--- /dev/null
+++ b/group23/1072760797-skomefen/day3-26/src/com/coderising/download/api/ConnectionManager.java
@@ -0,0 +1,10 @@
+package com.coderising.download.api;
+
+public interface ConnectionManager {
+ /**
+ * 给定一个url , 打开一个连接
+ * @param url
+ * @return
+ */
+ public Connection open(String url) throws ConnectionException;
+}
diff --git a/group23/1072760797-skomefen/day3-26/src/com/coderising/download/api/DownloadListener.java b/group23/1072760797-skomefen/day3-26/src/com/coderising/download/api/DownloadListener.java
new file mode 100644
index 0000000000..bf9807b307
--- /dev/null
+++ b/group23/1072760797-skomefen/day3-26/src/com/coderising/download/api/DownloadListener.java
@@ -0,0 +1,5 @@
+package com.coderising.download.api;
+
+public interface DownloadListener {
+ public void notifyFinished();
+}
diff --git a/group23/1072760797-skomefen/day3-26/src/com/coderising/download/impl/ConnectionImpl.java b/group23/1072760797-skomefen/day3-26/src/com/coderising/download/impl/ConnectionImpl.java
new file mode 100644
index 0000000000..ae639d2651
--- /dev/null
+++ b/group23/1072760797-skomefen/day3-26/src/com/coderising/download/impl/ConnectionImpl.java
@@ -0,0 +1,143 @@
+package com.coderising.download.impl;
+
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+
+import com.coderising.download.api.Connection;
+
+public class ConnectionImpl implements Connection{
+
+ private String url = null;
+ private InputStream in = null;
+
+
+ public ConnectionImpl(String url) {
+ this.url = url;
+
+
+ }
+
+ public byte[] read(int startPos, int endPos) throws IOException {
+
+ try {
+ if(url==null||url.trim()==""){
+ return null;
+ }
+
+ URL u = new URL(url);
+ in = u.openStream();
+
+
+ } catch (Exception e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+
+ if(in==null){
+ return null;
+ }
+ byte[] read = insert(startPos, endPos);
+
+ return read;
+ }
+
+ private byte[] insert(int startPos, int endPos) throws IOException {
+ byte[] b = new byte[1024];
+ int len = 0;
+ int index = 0;
+ byte[] read = new byte[endPos-startPos+1];
+
+ while((len=in.read(b))>0){
+ if((index+1024)<=startPos){
+ index+=1024;
+ continue;
+ }
+
+ if(index<=startPos&&startPos<(index+1024)){
+
+ if(endPos<(index+1024)){
+ for(int i=0,j=startPos-index;i0){
+ count+=len;
+ }
+ Assert.assertEquals(count, conn.getContentLength());
+
+ }
+
+
+ @Test
+ public void testClose() {
+ conn.close();
+ }
+
+}
diff --git a/group23/1072760797-skomefen/day3-26/src/junit/test/ConnectionManagerImplTest.java b/group23/1072760797-skomefen/day3-26/src/junit/test/ConnectionManagerImplTest.java
new file mode 100644
index 0000000000..589c1bf1d2
--- /dev/null
+++ b/group23/1072760797-skomefen/day3-26/src/junit/test/ConnectionManagerImplTest.java
@@ -0,0 +1,31 @@
+package junit.test;
+
+import static org.junit.Assert.*;
+
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import com.coderising.download.api.Connection;
+import com.coderising.download.api.ConnectionException;
+import com.coderising.download.api.ConnectionManager;
+import com.coderising.download.impl.ConnectionImpl;
+import com.coderising.download.impl.ConnectionManagerImpl;
+
+public class ConnectionManagerImplTest {
+
+ @Before
+ public void setUp() throws Exception {
+ }
+
+
+ @Test
+ public void testOpen() throws ConnectionException {
+ ConnectionManager cm = new ConnectionManagerImpl();
+ String url = "http://localhost:8080/TimeCapsule/readme.txt";
+ Connection conn = cm.open(url);
+ }
+
+}
diff --git a/group23/1072760797-skomefen/day3-26/src/junit/test/DownloadThreadTest.java b/group23/1072760797-skomefen/day3-26/src/junit/test/DownloadThreadTest.java
new file mode 100644
index 0000000000..5ae230e97b
--- /dev/null
+++ b/group23/1072760797-skomefen/day3-26/src/junit/test/DownloadThreadTest.java
@@ -0,0 +1,77 @@
+package junit.test;
+
+import static org.junit.Assert.*;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.util.ArrayList;
+
+
+
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+import com.coderising.download.DownloadThread;
+import com.coderising.download.api.Connection;
+import com.coderising.download.api.ConnectionException;
+import com.coderising.download.api.ConnectionManager;
+import com.coderising.download.impl.ConnectionManagerImpl;
+
+public class DownloadThreadTest {
+
+ @Before
+ public void setUp() throws Exception {
+ }
+
+ @Test
+ public void testRun() throws ConnectionException, IOException {
+ ConnectionManager cm = new ConnectionManagerImpl();
+ String url = "http://localhost:8080/TimeCapsule/readme.txt";
+ Connection conn = cm.open(url);
+ DownloadThread dt = new DownloadThread(conn, 0, conn.getContentLength());
+ dt.start();
+
+ File file = new File("e://readme.txt");
+ FileInputStream in = new FileInputStream(file);
+ byte[] b = new byte[10];
+ int len = 0;
+ ArrayList a = new ArrayList();
+ while((len=in.read(b))>0){
+ a.add(b);
+ }
+
+ int length = conn.getContentLength();
+ if(length%3==0){
+ for(int i=1;i<=3;i++){
+ int startPos = length/3*i-1;
+ int endPos = length/3*(i-1);
+ new DownloadThread(conn, endPos, startPos).start();
+ }
+ }else{
+ for(int i=1;i<=2;i++){
+
+ int startPos = length/3*(i-1);
+ int endPos = length/3*i-1;
+ new DownloadThread(conn, startPos, endPos).start();
+ }
+ int startPos = length/3*2;
+ new DownloadThread(conn, startPos, length).start();
+ }
+
+ file = new File("e://readme.txt");
+ in = new FileInputStream(file);
+ b = new byte[10];
+ len = 0;
+ ArrayList a1 = new ArrayList();
+ while((len=in.read(b))>0){
+ a1.add(b);
+ }
+ for(int i = 0;i
Date: Tue, 28 Mar 2017 09:43:48 +0800
Subject: [PATCH 016/262] =?UTF-8?q?=E9=87=8D=E6=9E=84=E6=95=B0=E6=8D=AE?=
=?UTF-8?q?=E7=BB=93=E6=9E=84=E9=A1=B9=E7=9B=AE?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
重构数据结构项目
---
.../coderising/download/DownloadThread.java | 31 ++
.../coderising/download/FileDownloader.java | 104 +++++
.../download/FileDownloaderTest.java | 59 +++
.../coderising/download/api/Connection.java | 26 ++
.../download/api/ConnectionException.java | 5 +
.../download/api/ConnectionManager.java | 10 +
.../download/api/DownloadListener.java | 5 +
.../download/impl/ConnectionImpl.java | 62 +++
.../download/impl/ConnectionManagerImpl.java | 26 ++
.../coderising/litestruts/LoginAction.java | 39 ++
.../src/com/coderising/litestruts/Struts.java | 181 ++++++++
.../com/coderising/litestruts/StrutsTest.java | 43 ++
.../src/com/coderising/litestruts/View.java | 23 +
.../src/com/coding/basic/BinaryTreeNode.java | 97 +++++
.../src/com/coding/basic/Iterator.java | 8 +
.../src/com/coding/basic/List.java | 13 +
.../src/com/coding/basic/Queue.java | 24 ++
.../src/com/coding/basic/Stack.java | 37 ++
.../src/com/coding/basic/array/ArrayList.java | 83 ++++
.../src/com/coding/basic/array/ArrayUtil.java | 210 +++++++++
.../com/coding/basic/linklist/LinkedList.java | 402 ++++++++++++++++++
21 files changed, 1488 insertions(+)
create mode 100644 group23/1028361767/data-structure/src/com/coderising/download/DownloadThread.java
create mode 100644 group23/1028361767/data-structure/src/com/coderising/download/FileDownloader.java
create mode 100644 group23/1028361767/data-structure/src/com/coderising/download/FileDownloaderTest.java
create mode 100644 group23/1028361767/data-structure/src/com/coderising/download/api/Connection.java
create mode 100644 group23/1028361767/data-structure/src/com/coderising/download/api/ConnectionException.java
create mode 100644 group23/1028361767/data-structure/src/com/coderising/download/api/ConnectionManager.java
create mode 100644 group23/1028361767/data-structure/src/com/coderising/download/api/DownloadListener.java
create mode 100644 group23/1028361767/data-structure/src/com/coderising/download/impl/ConnectionImpl.java
create mode 100644 group23/1028361767/data-structure/src/com/coderising/download/impl/ConnectionManagerImpl.java
create mode 100644 group23/1028361767/data-structure/src/com/coderising/litestruts/LoginAction.java
create mode 100644 group23/1028361767/data-structure/src/com/coderising/litestruts/Struts.java
create mode 100644 group23/1028361767/data-structure/src/com/coderising/litestruts/StrutsTest.java
create mode 100644 group23/1028361767/data-structure/src/com/coderising/litestruts/View.java
create mode 100644 group23/1028361767/data-structure/src/com/coding/basic/BinaryTreeNode.java
create mode 100644 group23/1028361767/data-structure/src/com/coding/basic/Iterator.java
create mode 100644 group23/1028361767/data-structure/src/com/coding/basic/List.java
create mode 100644 group23/1028361767/data-structure/src/com/coding/basic/Queue.java
create mode 100644 group23/1028361767/data-structure/src/com/coding/basic/Stack.java
create mode 100644 group23/1028361767/data-structure/src/com/coding/basic/array/ArrayList.java
create mode 100644 group23/1028361767/data-structure/src/com/coding/basic/array/ArrayUtil.java
create mode 100644 group23/1028361767/data-structure/src/com/coding/basic/linklist/LinkedList.java
diff --git a/group23/1028361767/data-structure/src/com/coderising/download/DownloadThread.java b/group23/1028361767/data-structure/src/com/coderising/download/DownloadThread.java
new file mode 100644
index 0000000000..8cf0ae1e42
--- /dev/null
+++ b/group23/1028361767/data-structure/src/com/coderising/download/DownloadThread.java
@@ -0,0 +1,31 @@
+package com.coderising.download;
+
+import java.io.IOException;
+import java.io.RandomAccessFile;
+
+import com.coderising.download.api.Connection;
+
+public class DownloadThread extends Thread{
+
+ Connection conn;
+ int startPos;
+ int endPos;
+
+ public DownloadThread( Connection conn, int startPos, int endPos){
+
+ this.conn = conn;
+ this.startPos = startPos;
+ this.endPos = endPos;
+ }
+ public void run(){
+ try {
+ byte[] bytes = conn.read(startPos, endPos);
+ RandomAccessFile file = new RandomAccessFile("/Users/jie/Desktop/test.png", "rw");
+ file.seek(startPos);
+ file.write(bytes);
+ file.close();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+}
diff --git a/group23/1028361767/data-structure/src/com/coderising/download/FileDownloader.java b/group23/1028361767/data-structure/src/com/coderising/download/FileDownloader.java
new file mode 100644
index 0000000000..1fe4ebb159
--- /dev/null
+++ b/group23/1028361767/data-structure/src/com/coderising/download/FileDownloader.java
@@ -0,0 +1,104 @@
+package com.coderising.download;
+
+import com.coderising.download.api.Connection;
+import com.coderising.download.api.ConnectionException;
+import com.coderising.download.api.ConnectionManager;
+import com.coderising.download.api.DownloadListener;
+
+
+public class FileDownloader {
+
+ String url;
+
+ DownloadListener listener;
+
+ ConnectionManager cm;
+
+ Thread[] threads = new Thread[3];
+
+
+ public FileDownloader(String _url) {
+ this.url = _url;
+
+ }
+
+ public void execute(){
+ // 在这里实现你的代码, 注意: 需要用多线程实现下载
+ // 这个类依赖于其他几个接口, 你需要写这几个接口的实现代码
+ // (1) ConnectionManager , 可以打开一个连接,通过Connection可以读取其中的一段(用startPos, endPos来指定)
+ // (2) DownloadListener, 由于是多线程下载, 调用这个类的客户端不知道什么时候结束,所以你需要实现当所有
+ // 线程都执行完以后, 调用listener的notifiedFinished方法, 这样客户端就能收到通知。
+ // 具体的实现思路:
+ // 1. 需要调用ConnectionManager的open方法打开连接, 然后通过Connection.getContentLength方法获得文件的长度
+ // 2. 至少启动3个线程下载, 注意每个线程需要先调用ConnectionManager的open方法
+ // 然后调用read方法, read方法中有读取文件的开始位置和结束位置的参数, 返回值是byte[]数组
+ // 3. 把byte数组写入到文件中
+ // 4. 所有的线程都下载完成以后, 需要调用listener的notifiedFinished方法
+
+ // 下面的代码是示例代码, 也就是说只有一个线程, 你需要改造成多线程的。
+ Connection conn = null;
+ try {
+
+ conn = cm.open(this.url);
+
+ int length = conn.getContentLength();
+
+ int size = length / 3;
+ int remain = length - size;
+
+ for(int i=0;i<3;i++){
+ conn = cm.open(this.url);
+ int startPos = i*size;
+ int endPos = (i+1) * size - 1;
+ if(i == 2){
+ endPos = (i+1) * size - 1 + remain;
+ }
+ threads[i] = new DownloadThread(conn,startPos,endPos);
+ threads[i].start();
+ }
+
+ new Thread(new Runnable(){
+ public void run(){
+ boolean finish;
+ do{
+ finish = true;
+ for(int i=0;i actions = new HashMap();
+
+ @SuppressWarnings("rawtypes")
+ public static View runAction(String actionName, Map parameters) throws Exception {
+
+ /*
+
+ 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字段中。
+
+ */
+ //读取xml,把xml信息放到actions
+ readStrutsXML();
+
+ Action action = actions.get(actionName);
+ View view = new View();
+ if(action != null){
+ Class clazz = Class.forName(action.getClassName());
+ Object obj = clazz.newInstance();
+
+ //根据parameters调用set方法
+ initClass(clazz, obj, action, parameters);
+
+ //调用execute方法
+ String result = execute(clazz, obj);
+ //调用所有get方法
+ Map resultParameters = getResultParameters(clazz, obj);
+
+ view.setJsp(action.getResults().get(result));
+ view.setParameters(resultParameters);
+ }
+
+ return view;
+ }
+
+ @SuppressWarnings("rawtypes")
+ private static Map getResultParameters(Class clazz, Object obj) throws Exception {
+ Map resultParameters = new HashMap();
+ Method[] methods = clazz.getMethods();
+ String methodName;
+ String propName;
+ String propValue;
+ for(Method method : methods){
+ methodName = method.getName();
+ if(methodName.startsWith("get") && !"getClass".equals(methodName)){
+ propName = firstLetterLowerCase(methodName.substring(3, methodName.length()));
+ propValue = (String) method.invoke(obj);
+ resultParameters.put(propName, propValue);
+ }
+ }
+ return resultParameters;
+ }
+
+ @SuppressWarnings({ "unchecked", "rawtypes" })
+ private static String execute(Class clazz, Object obj) throws Exception{
+ Method method = clazz.getMethod("execute");
+ return (String)method.invoke(obj);
+ }
+
+ @SuppressWarnings({ "unchecked", "rawtypes" })
+ private static void initClass(Class clazz, Object obj, Action action, Map parameters) throws Exception {
+ String setMethodName;
+ Method method = null;
+ for (String parameter : parameters.keySet()) {
+ setMethodName = "set" + firstLetterUpperCase(parameter);
+ method = clazz.getMethod(setMethodName, String.class);
+ method.invoke(obj, parameters.get(parameter));
+ }
+ }
+
+ private static String firstLetterLowerCase(String string){
+ char[] cs = string.toCharArray();
+ cs[0] += 32;
+ return String.valueOf(cs);
+ }
+
+ private static String firstLetterUpperCase(String string){
+ char[] cs = string.toCharArray();
+ cs[0] -= 32;
+ return String.valueOf(cs);
+ }
+
+ @SuppressWarnings("unchecked")
+ private static void readStrutsXML() {
+ SAXReader saxReader = new SAXReader();
+ Document document;
+ try {
+ document = saxReader.read(new File("src/com/coderising/litestruts/struts.xml"));
+ } catch (DocumentException e) {
+ System.out.println("error:file not found");
+ return ;
+ }
+ Element root = document.getRootElement();
+ Iterator actionItr = root.elementIterator();
+ Element action;
+ Action act;
+ Iterator resultItr;
+ Element result;
+ Map results;
+ while(actionItr.hasNext()){
+ action = actionItr.next();
+
+ resultItr = action.elementIterator();
+ results = new HashMap();
+ while(resultItr.hasNext()){
+ result = resultItr.next();
+ results.put(result.attributeValue("name"), result.getStringValue());
+ }
+
+ act = new Action();
+ act.setName(action.attributeValue("name"));
+ act.setClassName(action.attributeValue("class"));
+ act.setResults(results);
+
+ actions.put(act.getName(), act);
+ }
+ }
+
+ static class Action {
+
+ private String name;
+
+ private String className;
+
+ private Map results = new HashMap<>();
+
+ public Map getResults() {
+ return results;
+ }
+
+ public void setResults(Map results) {
+ this.results = results;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public String getClassName() {
+ return className;
+ }
+
+ public void setClassName(String className) {
+ this.className = className;
+ }
+
+ }
+
+}
diff --git a/group23/1028361767/data-structure/src/com/coderising/litestruts/StrutsTest.java b/group23/1028361767/data-structure/src/com/coderising/litestruts/StrutsTest.java
new file mode 100644
index 0000000000..92a6758a69
--- /dev/null
+++ b/group23/1028361767/data-structure/src/com/coderising/litestruts/StrutsTest.java
@@ -0,0 +1,43 @@
+package com.coderising.litestruts;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+
+
+
+
+public class StrutsTest {
+
+ @Test
+ public void testLoginActionSuccess() throws Exception {
+
+ String actionName = "login";
+
+ Map params = new HashMap();
+ params.put("name","test");
+ params.put("password","1234");
+
+
+ View view = Struts.runAction(actionName,params);
+
+ Assert.assertEquals("/jsp/homepage.jsp", view.getJsp());
+ Assert.assertEquals("login successful", view.getParameters().get("message"));
+ }
+
+ @Test
+ public void testLoginActionFailed() throws Exception {
+ String actionName = "login";
+ Map params = new HashMap();
+ params.put("name","test");
+ params.put("password","123456"); //密码和预设的不一致
+
+ View view = Struts.runAction(actionName,params);
+
+ Assert.assertEquals("/jsp/showLogin.jsp", view.getJsp());
+ Assert.assertEquals("login failed,please check your user/pwd", view.getParameters().get("message"));
+ }
+}
diff --git a/group23/1028361767/data-structure/src/com/coderising/litestruts/View.java b/group23/1028361767/data-structure/src/com/coderising/litestruts/View.java
new file mode 100644
index 0000000000..07df2a5dab
--- /dev/null
+++ b/group23/1028361767/data-structure/src/com/coderising/litestruts/View.java
@@ -0,0 +1,23 @@
+package com.coderising.litestruts;
+
+import java.util.Map;
+
+public class View {
+ private String jsp;
+ private Map parameters;
+
+ public String getJsp() {
+ return jsp;
+ }
+ public View setJsp(String jsp) {
+ this.jsp = jsp;
+ return this;
+ }
+ public Map getParameters() {
+ return parameters;
+ }
+ public View setParameters(Map parameters) {
+ this.parameters = parameters;
+ return this;
+ }
+}
diff --git a/group23/1028361767/data-structure/src/com/coding/basic/BinaryTreeNode.java b/group23/1028361767/data-structure/src/com/coding/basic/BinaryTreeNode.java
new file mode 100644
index 0000000000..dced34e873
--- /dev/null
+++ b/group23/1028361767/data-structure/src/com/coding/basic/BinaryTreeNode.java
@@ -0,0 +1,97 @@
+package com.coding.basic;
+
+public class BinaryTreeNode {
+
+ private Object data;
+ private BinaryTreeNode left;
+ private BinaryTreeNode right;
+ private BinaryTreeNode parent;
+
+ public BinaryTreeNode(Object data) {
+ this.data = data;
+ }
+
+ public Object getData() {
+ return data;
+ }
+
+ public void setData(Object data) {
+ this.data = data;
+ }
+
+ public BinaryTreeNode getLeft() {
+ return left;
+ }
+
+ public void setLeft(BinaryTreeNode left) {
+ this.left = left;
+ }
+
+ public BinaryTreeNode getRight() {
+ return right;
+ }
+
+ public void setRight(BinaryTreeNode right) {
+ this.right = right;
+ }
+
+ public void setParent(BinaryTreeNode parent) {
+ this.parent = parent;
+ }
+
+ public BinaryTreeNode getParent() {
+ return parent;
+ }
+
+ public BinaryTreeNode insert(Object o) {
+ BinaryTreeNode newNode = new BinaryTreeNode(o);
+ BinaryTreeNode root = findRoot(this);
+ if (root.data == null) {
+ root.data = newNode;
+ } else {
+ int newVal = getNodeIntVal(newNode);
+ insert(root, newNode, newVal);
+ }
+ return newNode;
+ }
+
+ private void insert(BinaryTreeNode node, BinaryTreeNode newNode, int newVal) {
+ int nodeVal = getNodeIntVal(node);
+ if (newVal < nodeVal) {
+ if (node.left == null) {
+ newNode.parent = node;
+ node.left = newNode;
+ } else {
+ insert(node.left, newNode, newVal);
+ }
+ } else {
+ if (node.right == null) {
+ newNode.parent = node;
+ node.right = newNode;
+ } else {
+ insert(node.right, newNode, newVal);
+ }
+ }
+ }
+
+ private BinaryTreeNode findRoot(BinaryTreeNode binaryTreeNode) {
+ while (binaryTreeNode.parent != null) {
+ binaryTreeNode = binaryTreeNode.parent;
+ }
+ return binaryTreeNode;
+ }
+
+ private int getNodeIntVal(BinaryTreeNode node) {
+ if (node.data instanceof Integer) {
+ return ((Integer) node.data).intValue();
+ }
+ return 0;
+ }
+
+ public int getDataIntVal() {
+ if (data instanceof Integer) {
+ return ((Integer) data).intValue();
+ }
+ return 0;
+ }
+}
diff --git a/group23/1028361767/data-structure/src/com/coding/basic/Iterator.java b/group23/1028361767/data-structure/src/com/coding/basic/Iterator.java
new file mode 100644
index 0000000000..96adcd6d3a
--- /dev/null
+++ b/group23/1028361767/data-structure/src/com/coding/basic/Iterator.java
@@ -0,0 +1,8 @@
+package com.coding.basic;
+
+public interface Iterator {
+ public boolean hasNext();
+
+ public Object next();
+
+}
diff --git a/group23/1028361767/data-structure/src/com/coding/basic/List.java b/group23/1028361767/data-structure/src/com/coding/basic/List.java
new file mode 100644
index 0000000000..01398944e6
--- /dev/null
+++ b/group23/1028361767/data-structure/src/com/coding/basic/List.java
@@ -0,0 +1,13 @@
+package com.coding.basic;
+
+public interface List {
+ public void add(Object o);
+
+ public void add(int index, Object o);
+
+ public Object get(int index);
+
+ public Object remove(int index);
+
+ public int size();
+}
diff --git a/group23/1028361767/data-structure/src/com/coding/basic/Queue.java b/group23/1028361767/data-structure/src/com/coding/basic/Queue.java
new file mode 100644
index 0000000000..ddd1b74d90
--- /dev/null
+++ b/group23/1028361767/data-structure/src/com/coding/basic/Queue.java
@@ -0,0 +1,24 @@
+package com.coding.basic;
+
+import com.coding.basic.linklist.LinkedList;
+
+public class Queue {
+
+ private LinkedList linkedList = new LinkedList();
+
+ public void enQueue(Object o) {
+ linkedList.add(o);
+ }
+
+ public Object deQueue() {
+ return linkedList.removeFirst();
+ }
+
+ public boolean isEmpty() {
+ return linkedList.size() == 0;
+ }
+
+ public int size() {
+ return linkedList.size();
+ }
+}
diff --git a/group23/1028361767/data-structure/src/com/coding/basic/Stack.java b/group23/1028361767/data-structure/src/com/coding/basic/Stack.java
new file mode 100644
index 0000000000..a98f5d76a5
--- /dev/null
+++ b/group23/1028361767/data-structure/src/com/coding/basic/Stack.java
@@ -0,0 +1,37 @@
+package com.coding.basic;
+
+import java.util.EmptyStackException;
+
+import com.coding.basic.array.ArrayList;
+
+public class Stack {
+ private ArrayList elementData = new ArrayList();
+
+ public void push(Object o) {
+ elementData.add(o);
+ }
+
+ public Object pop() {
+ checkBound();
+ return elementData.get(size() - 1);
+ }
+
+ public Object peek() {
+ checkBound();
+ return elementData.remove(size() - 1);
+ }
+
+ public boolean isEmpty() {
+ return size() == 0;
+ }
+
+ public int size() {
+ return elementData.size();
+ }
+
+ private void checkBound() {
+ if (isEmpty()) {
+ throw new EmptyStackException();
+ }
+ }
+}
diff --git a/group23/1028361767/data-structure/src/com/coding/basic/array/ArrayList.java b/group23/1028361767/data-structure/src/com/coding/basic/array/ArrayList.java
new file mode 100644
index 0000000000..43bdae82fa
--- /dev/null
+++ b/group23/1028361767/data-structure/src/com/coding/basic/array/ArrayList.java
@@ -0,0 +1,83 @@
+package com.coding.basic.array;
+
+import java.util.Arrays;
+
+import com.coding.basic.Iterator;
+import com.coding.basic.List;
+
+public class ArrayList implements List {
+
+ private int size = 0;
+
+ private int HALF_MAX_VALUE = Integer.MAX_VALUE;
+
+ private Object[] elementData = new Object[100];
+
+ public void add(Object o) {
+ if (noSpace()) {
+ elementData = grow();
+ }
+ elementData[size++] = o;
+ }
+
+ public void add(int index, Object o) {
+ if (index < 0) {
+ throw new IllegalArgumentException("index must be positive integer");
+ }
+ if (index > size) {
+ throw new IndexOutOfBoundsException("size is" + size);
+ }
+ if (noSpace()) {
+ elementData = grow();
+ }
+ System.arraycopy(elementData, index, elementData, index + 1, size - index);
+ elementData[size++] = o;
+ }
+
+ public Object get(int index) {
+ if (index < 0) {
+ throw new IllegalArgumentException("index must be positive integer");
+ }
+ if (index > (size - 1)) {
+ throw new IndexOutOfBoundsException("size is" + size);
+ }
+ return elementData[index];
+ }
+
+ public Object remove(int index) {
+ if (index < 0) {
+ throw new IllegalArgumentException("index must be positive integer");
+ }
+ if (index > (size - 1)) {
+ throw new IndexOutOfBoundsException("size is" + size);
+ }
+ Object obj = elementData[index];
+ System.arraycopy(elementData, index + 1, elementData, index, size - index);
+ elementData[size-1] = null;
+ size--;
+ return obj;
+ }
+
+ public int size() {
+ return size;
+ }
+
+ public Iterator iterator() {
+ return null;
+ }
+
+ private boolean noSpace() {
+ return size == elementData.length;
+ }
+
+ private Object[] grow() {
+ int newSize;
+ if (size < HALF_MAX_VALUE) {
+ newSize = size * 2;
+ } else {
+ newSize = Integer.MAX_VALUE;
+ }
+ return Arrays.copyOf(elementData, newSize);
+ }
+
+}
diff --git a/group23/1028361767/data-structure/src/com/coding/basic/array/ArrayUtil.java b/group23/1028361767/data-structure/src/com/coding/basic/array/ArrayUtil.java
new file mode 100644
index 0000000000..8e1b170dc0
--- /dev/null
+++ b/group23/1028361767/data-structure/src/com/coding/basic/array/ArrayUtil.java
@@ -0,0 +1,210 @@
+package com.coding.basic.array;
+
+import java.util.Arrays;
+
+public class ArrayUtil {
+
+ /**
+ * 给定一个整形数组a , 对该数组的值进行置换
+ 例如: a = [7, 9 , 30, 3] , 置换后为 [3, 30, 9,7]
+ 如果 a = [7, 9, 30, 3, 4] , 置换后为 [4,3, 30 , 9,7]
+ * @param origin
+ * @return
+ */
+ public int[] reverseArray(int[] origin){
+ int len = origin.length;
+ int[] ret = new int[len];
+ for(int i=0;i len1 && i2 > len2){
+ break;
+ }else if(i1 > len1){
+ ret[i++] = array2[i2++];
+ }else{
+ ret[i++] = array1[i1++];
+ }
+ }
+
+ }
+ if(sameNum > 0){
+ ret = Arrays.copyOf(ret, ret.length - sameNum);
+ }
+ return ret;
+ }
+
+ /**
+ * 把一个已经存满数据的数组 oldArray的容量进行扩展, 扩展后的新数据大小为oldArray.length + size
+ * 注意,老数组的元素在新数组中需要保持
+ * 例如 oldArray = [2,3,6] , size = 3,则返回的新数组为
+ * [2,3,6,0,0,0]
+ * @param oldArray
+ * @param size
+ * @return
+ */
+ public int[] grow(int [] oldArray, int size){
+ return Arrays.copyOf(oldArray, oldArray.length + size);
+ }
+
+ /**
+ * 斐波那契数列为:1,1,2,3,5,8,13,21...... ,给定一个最大值, 返回小于该值的数列
+ * 例如, max = 15 , 则返回的数组应该为 [1,1,2,3,5,8,13]
+ * max = 1, 则返回空数组 []
+ * @param max
+ * @return
+ */
+ public int[] fibonacci(int max){
+ if(max == 1){
+ return new int[0];
+ }else{
+ int[] tmp = new int[max + 1];
+ int x1 = 1, x2 = 1;
+ int i = 1, j = 0;
+ tmp[j++] = x1;
+ tmp[j++] = x2;
+ while(true){
+ i = x1 + x2;
+ if(i > max){
+ break;
+ }
+ x1 = x2;
+ x2 = i;
+ tmp[j++] = i;
+ }
+ return Arrays.copyOf(tmp, j);
+ }
+ }
+
+ /**
+ * 返回小于给定最大值max的所有素数数组
+ * 例如max = 23, 返回的数组为[2,3,5,7,11,13,17,19]
+ * @param max
+ * @return
+ */
+ public int[] getPrimes(int max){
+ int[] tmp = new int[max/2 + 1];
+ boolean isPrime;
+ int k = 0;
+ for(int i=2;i max) {
+ throw new IndexOutOfBoundsException();
+ }
+ }
+
+
+ public Object get(int index) {
+ checkMinBound(index);
+ checkMaxBound(index, size - 1);
+ Node cur = head;
+ if (index != 0) {
+ int pos = 0;
+ do {
+ cur = cur.next;
+ pos++;
+ } while (pos != index);
+ }
+ return cur.data;
+ }
+
+ public Object remove(int index) {
+ checkMinBound(index);
+ checkMaxBound(index, size - 1);
+ Node cur = head;
+ if (index == 0) {
+ head = cur.next;
+ } else {
+ int pos = 1;
+ Node prev = cur;
+ while (pos != index) {
+ prev = prev.next;
+ pos++;
+ }
+ cur = prev.next;
+ prev.next = cur.next;
+ }
+ size--;
+ return cur.data;
+ }
+
+ public int size() {
+ return size;
+ }
+
+ public void addFirst(Object o) {
+ Node newNode = new Node(o, null);
+ newNode.next = head;
+ head = newNode;
+ size++;
+ }
+
+ public void addLast(Object o) {
+ Node newNode = new Node(o, null);
+ if (head == null) {
+ head = newNode;
+ } else {
+ Node tmp = head;
+ while (tmp.next != null) {
+ tmp = tmp.next;
+ }
+ tmp.next = newNode;
+ }
+ size++;
+ }
+
+ public Object removeFirst() {
+ if (head == null) {
+ throw new NoSuchElementException();
+ }
+ Node ret = head;
+ head = head.next;
+ size--;
+ return ret.data;
+ }
+
+ public Object removeLast() {
+ if (head == null) {
+ throw new NoSuchElementException();
+ }
+ Node ret;
+ if (head.next == null) {
+ ret = head;
+ head = null;
+ } else {
+ Node prev = head;
+ ret = head.next;
+ while (ret.next != null) {
+ prev = ret;
+ ret = ret.next;
+ }
+ prev.next = null;
+ }
+ size--;
+ return ret.data;
+ }
+
+ public Iterator iterator() {
+ return null;
+ }
+
+
+ private static class Node {
+ Object data;
+ Node next;
+
+ public Node(Object data, Node next) {
+ this.data = data;
+ this.next = next;
+ }
+
+ }
+
+ /**
+ * 把该链表逆置
+ * 例如链表为 3->7->10 , 逆置后变为 10->7->3
+ */
+ public void reverse() {
+ if(size == 0 || size == 1){
+ return ;
+ }
+ Node node = head;
+ Node nextNode = head.next;
+ Node tmp;
+ node.next = null;
+ do{
+ tmp = nextNode.next;
+ nextNode.next = node;
+ node = nextNode;
+ nextNode = tmp;
+ }while(nextNode != null);
+ head = node;
+ }
+
+ /**
+ * 删除一个单链表的前半部分
+ * 例如:list = 2->5->7->8 , 删除以后的值为 7->8
+ * 如果list = 2->5->7->8->10 ,删除以后的值为7,8,10
+ */
+ public void removeFirstHalf() {
+ if(size == 0 || size == 1){
+ return ;
+ }
+ int num = size / 2;
+ size -= num;
+ Node node = head;
+ while(num > 0){
+ node = node.next;
+ num--;
+ }
+ head = node;
+ }
+
+ /**
+ * 从第i个元素开始, 删除length 个元素 , 注意i从0开始
+ *
+ * @param i
+ * @param length
+ */
+ public void remove(int i, int length) {
+ checkMinBound(i);
+ checkMaxBound(i + length, size);
+ Node prev = null;
+ Node node = head;
+ int index = 0;
+ while(index < i){
+ prev = node;
+ node = node.next;
+ index++;
+ }
+ Node nextNode = node.next;
+ while(index < (i + length - 1)){
+ nextNode = nextNode.next;
+ index++;
+ }
+ size -= length;
+ if(i == 0){
+ head = nextNode;
+ }else{
+ prev.next = nextNode;
+ head = prev;
+ }
+ }
+
+ /**
+ * 假定当前链表和list均包含已升序排列的整数
+ * 从当前链表中取出那些list所指定的元素
+ * 例如当前链表 = 11->101->201->301->401->501->601->701
+ * listB = 1->3->4->6
+ * 返回的结果应该是[101,301,401,601]
+ *
+ * @param list
+ */
+ public int[] getElements(LinkedList list) {
+ int[] ret = new int[list.size()];
+ if(ret.length == 0){
+ return ret;
+ }
+ int index;
+ int j = 0;
+ Node node = head;
+ for(int i=0;i min){
+ foundMin = true;
+ }
+ if(foundMin && (int)node.data > max){
+ break;
+ }
+ if(foundMin == false){
+ prev = node;
+ }else{
+ size -= 1;
+ }
+ node = node.next;
+ }while(node != null);
+ if(prev == null){
+ head = node;
+ }else{
+ prev.next = node;
+ }
+ }
+
+ /**
+ * 假设当前链表和参数list指定的链表均以元素依值递增有序排列(同一表中的元素值各不相同)
+ * 现要求生成新链表C,其元素为当前链表和list中元素的交集,且表C中的元素有依值递增有序排列
+ *
+ * @param list
+ */
+ public LinkedList intersection(LinkedList list) {
+ LinkedList ret = new LinkedList();
+ Node node = head;
+ int nodeValue;
+ int elementValue;
+ for(int i=0;i elementValue){
+ break;
+ }
+ node = node.next;
+ }
+ }
+ }
+ return ret;
+ }
+
+ public String toString(){
+ Node node = head;
+ StringBuilder sb = new StringBuilder();
+ if(node == null){
+ return "";
+ }else{
+ sb.append(head.data);
+ while((node = node.next) != null){
+ sb.append(",").append(node.data);
+ }
+ return sb.toString();
+ }
+ }
+}
From 54532084198069eaab425ef3b76c48df05310e21 Mon Sep 17 00:00:00 2001
From: anxinJ <1028361767@qq.com>
Date: Tue, 28 Mar 2017 09:49:18 +0800
Subject: [PATCH 017/262] =?UTF-8?q?=E9=A1=B9=E7=9B=AE=E9=87=8D=E6=9E=84?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
项目重构
---
.../bin/com/coderising/litestruts/struts.xml | 11 -
.../src/com/coderising/array/ArrayUtil.java | 210 ---------
.../coderising/download/DownloadThread.java | 31 --
.../coderising/download/FileDownloader.java | 104 -----
.../download/FileDownloaderTest.java | 59 ---
.../coderising/download/api/Connection.java | 26 --
.../download/api/ConnectionException.java | 5 -
.../download/api/ConnectionManager.java | 10 -
.../download/api/DownloadListener.java | 5 -
.../download/impl/ConnectionImpl.java | 62 ---
.../download/impl/ConnectionManagerImpl.java | 26 --
.../coderising/litestruts/LoginAction.java | 39 --
.../src/com/coderising/litestruts/Struts.java | 181 --------
.../com/coderising/litestruts/StrutsTest.java | 43 --
.../src/com/coderising/litestruts/View.java | 23 -
.../src/com/coderising/litestruts/struts.xml | 11 -
.../src/com/coding/basic/ArrayList.java | 80 ----
.../src/com/coding/basic/BinaryTreeNode.java | 97 -----
.../src/com/coding/basic/Iterator.java | 8 -
.../src/com/coding/basic/LinkedList.java | 399 ------------------
.../src/com/coding/basic/List.java | 13 -
.../src/com/coding/basic/Queue.java | 22 -
.../src/com/coding/basic/Stack.java | 35 --
.../src/com/coding/me/Palindrome.java | 82 ++++
.../test/com/coding/basic/TestArrayList.java | 3 +-
.../com/coding/basic/TestBinaryTreeNode.java | 0
.../test/com/coding/basic/TestLinkedList.java | 4 +-
27 files changed, 86 insertions(+), 1503 deletions(-)
delete mode 100644 group23/1028361767/Week1DataStructure/bin/com/coderising/litestruts/struts.xml
delete mode 100644 group23/1028361767/Week1DataStructure/src/com/coderising/array/ArrayUtil.java
delete mode 100644 group23/1028361767/Week1DataStructure/src/com/coderising/download/DownloadThread.java
delete mode 100644 group23/1028361767/Week1DataStructure/src/com/coderising/download/FileDownloader.java
delete mode 100644 group23/1028361767/Week1DataStructure/src/com/coderising/download/FileDownloaderTest.java
delete mode 100644 group23/1028361767/Week1DataStructure/src/com/coderising/download/api/Connection.java
delete mode 100644 group23/1028361767/Week1DataStructure/src/com/coderising/download/api/ConnectionException.java
delete mode 100644 group23/1028361767/Week1DataStructure/src/com/coderising/download/api/ConnectionManager.java
delete mode 100644 group23/1028361767/Week1DataStructure/src/com/coderising/download/api/DownloadListener.java
delete mode 100644 group23/1028361767/Week1DataStructure/src/com/coderising/download/impl/ConnectionImpl.java
delete mode 100644 group23/1028361767/Week1DataStructure/src/com/coderising/download/impl/ConnectionManagerImpl.java
delete mode 100644 group23/1028361767/Week1DataStructure/src/com/coderising/litestruts/LoginAction.java
delete mode 100644 group23/1028361767/Week1DataStructure/src/com/coderising/litestruts/Struts.java
delete mode 100644 group23/1028361767/Week1DataStructure/src/com/coderising/litestruts/StrutsTest.java
delete mode 100644 group23/1028361767/Week1DataStructure/src/com/coderising/litestruts/View.java
delete mode 100644 group23/1028361767/Week1DataStructure/src/com/coderising/litestruts/struts.xml
delete mode 100644 group23/1028361767/Week1DataStructure/src/com/coding/basic/ArrayList.java
delete mode 100644 group23/1028361767/Week1DataStructure/src/com/coding/basic/BinaryTreeNode.java
delete mode 100644 group23/1028361767/Week1DataStructure/src/com/coding/basic/Iterator.java
delete mode 100644 group23/1028361767/Week1DataStructure/src/com/coding/basic/LinkedList.java
delete mode 100644 group23/1028361767/Week1DataStructure/src/com/coding/basic/List.java
delete mode 100644 group23/1028361767/Week1DataStructure/src/com/coding/basic/Queue.java
delete mode 100644 group23/1028361767/Week1DataStructure/src/com/coding/basic/Stack.java
create mode 100644 group23/1028361767/data-structure/src/com/coding/me/Palindrome.java
rename group23/1028361767/{Week1DataStructure => data-structure}/src/test/com/coding/basic/TestArrayList.java (97%)
rename group23/1028361767/{Week1DataStructure => data-structure}/src/test/com/coding/basic/TestBinaryTreeNode.java (100%)
rename group23/1028361767/{Week1DataStructure => data-structure}/src/test/com/coding/basic/TestLinkedList.java (97%)
diff --git a/group23/1028361767/Week1DataStructure/bin/com/coderising/litestruts/struts.xml b/group23/1028361767/Week1DataStructure/bin/com/coderising/litestruts/struts.xml
deleted file mode 100644
index e5d9aebba8..0000000000
--- a/group23/1028361767/Week1DataStructure/bin/com/coderising/litestruts/struts.xml
+++ /dev/null
@@ -1,11 +0,0 @@
-
-
-
- /jsp/homepage.jsp
- /jsp/showLogin.jsp
-
-
- /jsp/welcome.jsp
- /jsp/error.jsp
-
-
\ No newline at end of file
diff --git a/group23/1028361767/Week1DataStructure/src/com/coderising/array/ArrayUtil.java b/group23/1028361767/Week1DataStructure/src/com/coderising/array/ArrayUtil.java
deleted file mode 100644
index e497a8e251..0000000000
--- a/group23/1028361767/Week1DataStructure/src/com/coderising/array/ArrayUtil.java
+++ /dev/null
@@ -1,210 +0,0 @@
-package com.coderising.array;
-
-import java.util.Arrays;
-
-public class ArrayUtil {
-
- /**
- * 给定一个整形数组a , 对该数组的值进行置换
- 例如: a = [7, 9 , 30, 3] , 置换后为 [3, 30, 9,7]
- 如果 a = [7, 9, 30, 3, 4] , 置换后为 [4,3, 30 , 9,7]
- * @param origin
- * @return
- */
- public int[] reverseArray(int[] origin){
- int len = origin.length;
- int[] ret = new int[len];
- for(int i=0;i len1 && i2 > len2){
- break;
- }else if(i1 > len1){
- ret[i++] = array2[i2++];
- }else{
- ret[i++] = array1[i1++];
- }
- }
-
- }
- if(sameNum > 0){
- ret = Arrays.copyOf(ret, ret.length - sameNum);
- }
- return ret;
- }
-
- /**
- * 把一个已经存满数据的数组 oldArray的容量进行扩展, 扩展后的新数据大小为oldArray.length + size
- * 注意,老数组的元素在新数组中需要保持
- * 例如 oldArray = [2,3,6] , size = 3,则返回的新数组为
- * [2,3,6,0,0,0]
- * @param oldArray
- * @param size
- * @return
- */
- public int[] grow(int [] oldArray, int size){
- return Arrays.copyOf(oldArray, oldArray.length + size);
- }
-
- /**
- * 斐波那契数列为:1,1,2,3,5,8,13,21...... ,给定一个最大值, 返回小于该值的数列
- * 例如, max = 15 , 则返回的数组应该为 [1,1,2,3,5,8,13]
- * max = 1, 则返回空数组 []
- * @param max
- * @return
- */
- public int[] fibonacci(int max){
- if(max == 1){
- return new int[0];
- }else{
- int[] tmp = new int[max + 1];
- int x1 = 1, x2 = 1;
- int i = 1, j = 0;
- tmp[j++] = x1;
- tmp[j++] = x2;
- while(true){
- i = x1 + x2;
- if(i > max){
- break;
- }
- x1 = x2;
- x2 = i;
- tmp[j++] = i;
- }
- return Arrays.copyOf(tmp, j);
- }
- }
-
- /**
- * 返回小于给定最大值max的所有素数数组
- * 例如max = 23, 返回的数组为[2,3,5,7,11,13,17,19]
- * @param max
- * @return
- */
- public int[] getPrimes(int max){
- int[] tmp = new int[max/2 + 1];
- boolean isPrime;
- int k = 0;
- for(int i=2;i actions = new HashMap();
-
- @SuppressWarnings("rawtypes")
- public static View runAction(String actionName, Map parameters) throws Exception {
-
- /*
-
- 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字段中。
-
- */
- //读取xml,把xml信息放到actions
- readStrutsXML();
-
- Action action = actions.get(actionName);
- View view = new View();
- if(action != null){
- Class clazz = Class.forName(action.getClassName());
- Object obj = clazz.newInstance();
-
- //根据parameters调用set方法
- initClass(clazz, obj, action, parameters);
-
- //调用execute方法
- String result = execute(clazz, obj);
- //调用所有get方法
- Map resultParameters = getResultParameters(clazz, obj);
-
- view.setJsp(action.getResults().get(result));
- view.setParameters(resultParameters);
- }
-
- return view;
- }
-
- @SuppressWarnings("rawtypes")
- private static Map getResultParameters(Class clazz, Object obj) throws Exception {
- Map resultParameters = new HashMap();
- Method[] methods = clazz.getMethods();
- String methodName;
- String propName;
- String propValue;
- for(Method method : methods){
- methodName = method.getName();
- if(methodName.startsWith("get") && !"getClass".equals(methodName)){
- propName = firstLetterLowerCase(methodName.substring(3, methodName.length()));
- propValue = (String) method.invoke(obj);
- resultParameters.put(propName, propValue);
- }
- }
- return resultParameters;
- }
-
- @SuppressWarnings({ "unchecked", "rawtypes" })
- private static String execute(Class clazz, Object obj) throws Exception{
- Method method = clazz.getMethod("execute");
- return (String)method.invoke(obj);
- }
-
- @SuppressWarnings({ "unchecked", "rawtypes" })
- private static void initClass(Class clazz, Object obj, Action action, Map parameters) throws Exception {
- String setMethodName;
- Method method = null;
- for (String parameter : parameters.keySet()) {
- setMethodName = "set" + firstLetterUpperCase(parameter);
- method = clazz.getMethod(setMethodName, String.class);
- method.invoke(obj, parameters.get(parameter));
- }
- }
-
- private static String firstLetterLowerCase(String string){
- char[] cs = string.toCharArray();
- cs[0] += 32;
- return String.valueOf(cs);
- }
-
- private static String firstLetterUpperCase(String string){
- char[] cs = string.toCharArray();
- cs[0] -= 32;
- return String.valueOf(cs);
- }
-
- @SuppressWarnings("unchecked")
- private static void readStrutsXML() {
- SAXReader saxReader = new SAXReader();
- Document document;
- try {
- document = saxReader.read(new File("src/com/coderising/litestruts/struts.xml"));
- } catch (DocumentException e) {
- System.out.println("error:file not found");
- return ;
- }
- Element root = document.getRootElement();
- Iterator actionItr = root.elementIterator();
- Element action;
- Action act;
- Iterator resultItr;
- Element result;
- Map results;
- while(actionItr.hasNext()){
- action = actionItr.next();
-
- resultItr = action.elementIterator();
- results = new HashMap();
- while(resultItr.hasNext()){
- result = resultItr.next();
- results.put(result.attributeValue("name"), result.getStringValue());
- }
-
- act = new Action();
- act.setName(action.attributeValue("name"));
- act.setClassName(action.attributeValue("class"));
- act.setResults(results);
-
- actions.put(act.getName(), act);
- }
- }
-
- static class Action {
-
- private String name;
-
- private String className;
-
- private Map results = new HashMap<>();
-
- public Map getResults() {
- return results;
- }
-
- public void setResults(Map results) {
- this.results = results;
- }
-
- public String getName() {
- return name;
- }
-
- public void setName(String name) {
- this.name = name;
- }
-
- public String getClassName() {
- return className;
- }
-
- public void setClassName(String className) {
- this.className = className;
- }
-
- }
-
-}
diff --git a/group23/1028361767/Week1DataStructure/src/com/coderising/litestruts/StrutsTest.java b/group23/1028361767/Week1DataStructure/src/com/coderising/litestruts/StrutsTest.java
deleted file mode 100644
index 92a6758a69..0000000000
--- a/group23/1028361767/Week1DataStructure/src/com/coderising/litestruts/StrutsTest.java
+++ /dev/null
@@ -1,43 +0,0 @@
-package com.coderising.litestruts;
-
-import java.util.HashMap;
-import java.util.Map;
-
-import org.junit.Assert;
-import org.junit.Test;
-
-
-
-
-
-public class StrutsTest {
-
- @Test
- public void testLoginActionSuccess() throws Exception {
-
- String actionName = "login";
-
- Map params = new HashMap();
- params.put("name","test");
- params.put("password","1234");
-
-
- View view = Struts.runAction(actionName,params);
-
- Assert.assertEquals("/jsp/homepage.jsp", view.getJsp());
- Assert.assertEquals("login successful", view.getParameters().get("message"));
- }
-
- @Test
- public void testLoginActionFailed() throws Exception {
- String actionName = "login";
- Map params = new HashMap();
- params.put("name","test");
- params.put("password","123456"); //密码和预设的不一致
-
- View view = Struts.runAction(actionName,params);
-
- Assert.assertEquals("/jsp/showLogin.jsp", view.getJsp());
- Assert.assertEquals("login failed,please check your user/pwd", view.getParameters().get("message"));
- }
-}
diff --git a/group23/1028361767/Week1DataStructure/src/com/coderising/litestruts/View.java b/group23/1028361767/Week1DataStructure/src/com/coderising/litestruts/View.java
deleted file mode 100644
index 07df2a5dab..0000000000
--- a/group23/1028361767/Week1DataStructure/src/com/coderising/litestruts/View.java
+++ /dev/null
@@ -1,23 +0,0 @@
-package com.coderising.litestruts;
-
-import java.util.Map;
-
-public class View {
- private String jsp;
- private Map parameters;
-
- public String getJsp() {
- return jsp;
- }
- public View setJsp(String jsp) {
- this.jsp = jsp;
- return this;
- }
- public Map getParameters() {
- return parameters;
- }
- public View setParameters(Map parameters) {
- this.parameters = parameters;
- return this;
- }
-}
diff --git a/group23/1028361767/Week1DataStructure/src/com/coderising/litestruts/struts.xml b/group23/1028361767/Week1DataStructure/src/com/coderising/litestruts/struts.xml
deleted file mode 100644
index e5d9aebba8..0000000000
--- a/group23/1028361767/Week1DataStructure/src/com/coderising/litestruts/struts.xml
+++ /dev/null
@@ -1,11 +0,0 @@
-
-
-
- /jsp/homepage.jsp
- /jsp/showLogin.jsp
-
-
- /jsp/welcome.jsp
- /jsp/error.jsp
-
-
\ No newline at end of file
diff --git a/group23/1028361767/Week1DataStructure/src/com/coding/basic/ArrayList.java b/group23/1028361767/Week1DataStructure/src/com/coding/basic/ArrayList.java
deleted file mode 100644
index da0237bdf7..0000000000
--- a/group23/1028361767/Week1DataStructure/src/com/coding/basic/ArrayList.java
+++ /dev/null
@@ -1,80 +0,0 @@
-package com.coding.basic;
-
-import java.util.Arrays;
-
-public class ArrayList implements List {
-
- private int size = 0;
-
- private int HALF_MAX_VALUE = Integer.MAX_VALUE;
-
- private Object[] elementData = new Object[100];
-
- public void add(Object o) {
- if (noSpace()) {
- elementData = grow();
- }
- elementData[size++] = o;
- }
-
- public void add(int index, Object o) {
- if (index < 0) {
- throw new IllegalArgumentException("index must be positive integer");
- }
- if (index > size) {
- throw new IndexOutOfBoundsException("size is" + size);
- }
- if (noSpace()) {
- elementData = grow();
- }
- System.arraycopy(elementData, index, elementData, index + 1, size - index);
- elementData[size++] = o;
- }
-
- public Object get(int index) {
- if (index < 0) {
- throw new IllegalArgumentException("index must be positive integer");
- }
- if (index > (size - 1)) {
- throw new IndexOutOfBoundsException("size is" + size);
- }
- return elementData[index];
- }
-
- public Object remove(int index) {
- if (index < 0) {
- throw new IllegalArgumentException("index must be positive integer");
- }
- if (index > (size - 1)) {
- throw new IndexOutOfBoundsException("size is" + size);
- }
- Object obj = elementData[index];
- System.arraycopy(elementData, index + 1, elementData, index, size - index);
- elementData[size-1] = null;
- size--;
- return obj;
- }
-
- public int size() {
- return size;
- }
-
- public Iterator iterator() {
- return null;
- }
-
- private boolean noSpace() {
- return size == elementData.length;
- }
-
- private Object[] grow() {
- int newSize;
- if (size < HALF_MAX_VALUE) {
- newSize = size * 2;
- } else {
- newSize = Integer.MAX_VALUE;
- }
- return Arrays.copyOf(elementData, newSize);
- }
-
-}
diff --git a/group23/1028361767/Week1DataStructure/src/com/coding/basic/BinaryTreeNode.java b/group23/1028361767/Week1DataStructure/src/com/coding/basic/BinaryTreeNode.java
deleted file mode 100644
index dced34e873..0000000000
--- a/group23/1028361767/Week1DataStructure/src/com/coding/basic/BinaryTreeNode.java
+++ /dev/null
@@ -1,97 +0,0 @@
-package com.coding.basic;
-
-public class BinaryTreeNode {
-
- private Object data;
- private BinaryTreeNode left;
- private BinaryTreeNode right;
- private BinaryTreeNode parent;
-
- public BinaryTreeNode(Object data) {
- this.data = data;
- }
-
- public Object getData() {
- return data;
- }
-
- public void setData(Object data) {
- this.data = data;
- }
-
- public BinaryTreeNode getLeft() {
- return left;
- }
-
- public void setLeft(BinaryTreeNode left) {
- this.left = left;
- }
-
- public BinaryTreeNode getRight() {
- return right;
- }
-
- public void setRight(BinaryTreeNode right) {
- this.right = right;
- }
-
- public void setParent(BinaryTreeNode parent) {
- this.parent = parent;
- }
-
- public BinaryTreeNode getParent() {
- return parent;
- }
-
- public BinaryTreeNode insert(Object o) {
- BinaryTreeNode newNode = new BinaryTreeNode(o);
- BinaryTreeNode root = findRoot(this);
- if (root.data == null) {
- root.data = newNode;
- } else {
- int newVal = getNodeIntVal(newNode);
- insert(root, newNode, newVal);
- }
- return newNode;
- }
-
- private void insert(BinaryTreeNode node, BinaryTreeNode newNode, int newVal) {
- int nodeVal = getNodeIntVal(node);
- if (newVal < nodeVal) {
- if (node.left == null) {
- newNode.parent = node;
- node.left = newNode;
- } else {
- insert(node.left, newNode, newVal);
- }
- } else {
- if (node.right == null) {
- newNode.parent = node;
- node.right = newNode;
- } else {
- insert(node.right, newNode, newVal);
- }
- }
- }
-
- private BinaryTreeNode findRoot(BinaryTreeNode binaryTreeNode) {
- while (binaryTreeNode.parent != null) {
- binaryTreeNode = binaryTreeNode.parent;
- }
- return binaryTreeNode;
- }
-
- private int getNodeIntVal(BinaryTreeNode node) {
- if (node.data instanceof Integer) {
- return ((Integer) node.data).intValue();
- }
- return 0;
- }
-
- public int getDataIntVal() {
- if (data instanceof Integer) {
- return ((Integer) data).intValue();
- }
- return 0;
- }
-}
diff --git a/group23/1028361767/Week1DataStructure/src/com/coding/basic/Iterator.java b/group23/1028361767/Week1DataStructure/src/com/coding/basic/Iterator.java
deleted file mode 100644
index 96adcd6d3a..0000000000
--- a/group23/1028361767/Week1DataStructure/src/com/coding/basic/Iterator.java
+++ /dev/null
@@ -1,8 +0,0 @@
-package com.coding.basic;
-
-public interface Iterator {
- public boolean hasNext();
-
- public Object next();
-
-}
diff --git a/group23/1028361767/Week1DataStructure/src/com/coding/basic/LinkedList.java b/group23/1028361767/Week1DataStructure/src/com/coding/basic/LinkedList.java
deleted file mode 100644
index eb41670f82..0000000000
--- a/group23/1028361767/Week1DataStructure/src/com/coding/basic/LinkedList.java
+++ /dev/null
@@ -1,399 +0,0 @@
-package com.coding.basic;
-
-
-import java.util.NoSuchElementException;
-
-public class LinkedList implements List {
-
- private Node head;
- private int size;
-
- public void add(Object o) {
- Node newNode = new Node(o, null);
- if (head == null) {
- head = newNode;
- } else {
- Node tmp = head;
- while (tmp.next != null) {
- tmp = tmp.next;
- }
- tmp.next = newNode;
- }
- size++;
- }
-
- public void add(int index, Object o) {
- checkMinBound(index);
- checkMaxBound(index, size);
- Node newNode = new Node(o, null);
- if (index == 0) {
- newNode.next = head;
- head = newNode;
- } else {
- int pos = 1;
- Node tmp = head;
- while (pos != index) {
- tmp = tmp.next;
- pos++;
- }
- newNode.next = tmp.next;
- tmp.next = newNode;
- }
- size++;
-
- }
-
- private void checkMinBound(int index) {
- if (index < 0) {
- throw new IllegalArgumentException();
- }
- }
-
- private void checkMaxBound(int index, int max) {
- if (index > max) {
- throw new IndexOutOfBoundsException();
- }
- }
-
-
- public Object get(int index) {
- checkMinBound(index);
- checkMaxBound(index, size - 1);
- Node cur = head;
- if (index != 0) {
- int pos = 0;
- do {
- cur = cur.next;
- pos++;
- } while (pos != index);
- }
- return cur.data;
- }
-
- public Object remove(int index) {
- checkMinBound(index);
- checkMaxBound(index, size - 1);
- Node cur = head;
- if (index == 0) {
- head = cur.next;
- } else {
- int pos = 1;
- Node prev = cur;
- while (pos != index) {
- prev = prev.next;
- pos++;
- }
- cur = prev.next;
- prev.next = cur.next;
- }
- size--;
- return cur.data;
- }
-
- public int size() {
- return size;
- }
-
- public void addFirst(Object o) {
- Node newNode = new Node(o, null);
- newNode.next = head;
- head = newNode;
- size++;
- }
-
- public void addLast(Object o) {
- Node newNode = new Node(o, null);
- if (head == null) {
- head = newNode;
- } else {
- Node tmp = head;
- while (tmp.next != null) {
- tmp = tmp.next;
- }
- tmp.next = newNode;
- }
- size++;
- }
-
- public Object removeFirst() {
- if (head == null) {
- throw new NoSuchElementException();
- }
- Node ret = head;
- head = head.next;
- size--;
- return ret.data;
- }
-
- public Object removeLast() {
- if (head == null) {
- throw new NoSuchElementException();
- }
- Node ret;
- if (head.next == null) {
- ret = head;
- head = null;
- } else {
- Node prev = head;
- ret = head.next;
- while (ret.next != null) {
- prev = ret;
- ret = ret.next;
- }
- prev.next = null;
- }
- size--;
- return ret.data;
- }
-
- public Iterator iterator() {
- return null;
- }
-
-
- private static class Node {
- Object data;
- Node next;
-
- public Node(Object data, Node next) {
- this.data = data;
- this.next = next;
- }
-
- }
-
- /**
- * 把该链表逆置
- * 例如链表为 3->7->10 , 逆置后变为 10->7->3
- */
- public void reverse() {
- if(size == 0 || size == 1){
- return ;
- }
- Node node = head;
- Node nextNode = head.next;
- Node tmp;
- node.next = null;
- do{
- tmp = nextNode.next;
- nextNode.next = node;
- node = nextNode;
- nextNode = tmp;
- }while(nextNode != null);
- head = node;
- }
-
- /**
- * 删除一个单链表的前半部分
- * 例如:list = 2->5->7->8 , 删除以后的值为 7->8
- * 如果list = 2->5->7->8->10 ,删除以后的值为7,8,10
- */
- public void removeFirstHalf() {
- if(size == 0 || size == 1){
- return ;
- }
- int num = size / 2;
- size -= num;
- Node node = head;
- while(num > 0){
- node = node.next;
- num--;
- }
- head = node;
- }
-
- /**
- * 从第i个元素开始, 删除length 个元素 , 注意i从0开始
- *
- * @param i
- * @param length
- */
- public void remove(int i, int length) {
- checkMinBound(i);
- checkMaxBound(i + length, size);
- Node prev = null;
- Node node = head;
- int index = 0;
- while(index < i){
- prev = node;
- node = node.next;
- index++;
- }
- Node nextNode = node.next;
- while(index < (i + length - 1)){
- nextNode = nextNode.next;
- index++;
- }
- size -= length;
- if(i == 0){
- head = nextNode;
- }else{
- prev.next = nextNode;
- head = prev;
- }
- }
-
- /**
- * 假定当前链表和list均包含已升序排列的整数
- * 从当前链表中取出那些list所指定的元素
- * 例如当前链表 = 11->101->201->301->401->501->601->701
- * listB = 1->3->4->6
- * 返回的结果应该是[101,301,401,601]
- *
- * @param list
- */
- public int[] getElements(LinkedList list) {
- int[] ret = new int[list.size()];
- if(ret.length == 0){
- return ret;
- }
- int index;
- int j = 0;
- Node node = head;
- for(int i=0;i min){
- foundMin = true;
- }
- if(foundMin && (int)node.data > max){
- break;
- }
- if(foundMin == false){
- prev = node;
- }else{
- size -= 1;
- }
- node = node.next;
- }while(node != null);
- if(prev == null){
- head = node;
- }else{
- prev.next = node;
- }
- }
-
- /**
- * 假设当前链表和参数list指定的链表均以元素依值递增有序排列(同一表中的元素值各不相同)
- * 现要求生成新链表C,其元素为当前链表和list中元素的交集,且表C中的元素有依值递增有序排列
- *
- * @param list
- */
- public LinkedList intersection(LinkedList list) {
- LinkedList ret = new LinkedList();
- Node node = head;
- int nodeValue;
- int elementValue;
- for(int i=0;i elementValue){
- break;
- }
- node = node.next;
- }
- }
- }
- return ret;
- }
-
- public String toString(){
- Node node = head;
- StringBuilder sb = new StringBuilder();
- if(node == null){
- return "";
- }else{
- sb.append(head.data);
- while((node = node.next) != null){
- sb.append(",").append(node.data);
- }
- return sb.toString();
- }
- }
-}
diff --git a/group23/1028361767/Week1DataStructure/src/com/coding/basic/List.java b/group23/1028361767/Week1DataStructure/src/com/coding/basic/List.java
deleted file mode 100644
index 01398944e6..0000000000
--- a/group23/1028361767/Week1DataStructure/src/com/coding/basic/List.java
+++ /dev/null
@@ -1,13 +0,0 @@
-package com.coding.basic;
-
-public interface List {
- public void add(Object o);
-
- public void add(int index, Object o);
-
- public Object get(int index);
-
- public Object remove(int index);
-
- public int size();
-}
diff --git a/group23/1028361767/Week1DataStructure/src/com/coding/basic/Queue.java b/group23/1028361767/Week1DataStructure/src/com/coding/basic/Queue.java
deleted file mode 100644
index bb24e2132e..0000000000
--- a/group23/1028361767/Week1DataStructure/src/com/coding/basic/Queue.java
+++ /dev/null
@@ -1,22 +0,0 @@
-package com.coding.basic;
-
-public class Queue {
-
- private LinkedList linkedList = new LinkedList();
-
- public void enQueue(Object o) {
- linkedList.add(o);
- }
-
- public Object deQueue() {
- return linkedList.removeFirst();
- }
-
- public boolean isEmpty() {
- return linkedList.size() == 0;
- }
-
- public int size() {
- return linkedList.size();
- }
-}
diff --git a/group23/1028361767/Week1DataStructure/src/com/coding/basic/Stack.java b/group23/1028361767/Week1DataStructure/src/com/coding/basic/Stack.java
deleted file mode 100644
index 55c96985a9..0000000000
--- a/group23/1028361767/Week1DataStructure/src/com/coding/basic/Stack.java
+++ /dev/null
@@ -1,35 +0,0 @@
-package com.coding.basic;
-
-import java.util.EmptyStackException;
-
-public class Stack {
- private ArrayList elementData = new ArrayList();
-
- public void push(Object o) {
- elementData.add(o);
- }
-
- public Object pop() {
- checkBound();
- return elementData.get(size() - 1);
- }
-
- public Object peek() {
- checkBound();
- return elementData.remove(size() - 1);
- }
-
- public boolean isEmpty() {
- return size() == 0;
- }
-
- public int size() {
- return elementData.size();
- }
-
- private void checkBound() {
- if (isEmpty()) {
- throw new EmptyStackException();
- }
- }
-}
diff --git a/group23/1028361767/data-structure/src/com/coding/me/Palindrome.java b/group23/1028361767/data-structure/src/com/coding/me/Palindrome.java
new file mode 100644
index 0000000000..2de0c4370d
--- /dev/null
+++ b/group23/1028361767/data-structure/src/com/coding/me/Palindrome.java
@@ -0,0 +1,82 @@
+package com.coding.me;
+
+/**
+ * 回文
+ *
+ */
+public class Palindrome {
+
+ private static String oddCase(char[] chars, int index) {
+ int maxLength = 1;
+ int i = 1;
+ while((index - i) >= 0 && (index + i) < chars.length - 1){
+ if(chars[index - i] != chars[index + i]){
+ break;
+ }
+ maxLength += 2;
+ i++;
+ }
+ return String.valueOf(chars, index + 1 - i, maxLength);
+ }
+
+ private static String evenCase(char[] chars, int index) {
+ int maxLength = 0;
+ int i = 0;
+ while((index - i) >= 0 && (index + 1 + i) <= chars.length - 1){
+ if(chars[index - i] != chars[index + 1 + i]){
+ break;
+ }
+ i++;
+ maxLength += 2;
+ }
+ return String.valueOf(chars, index + 1 - i, maxLength);
+ }
+
+ public static String findLongestPalindrome(String s){
+ char[] chars = s.toCharArray();
+ String longestPalindrome = "";
+ String tmp = "";
+ for(int i=0;i
Date: Tue, 28 Mar 2017 10:12:58 +0800
Subject: [PATCH 018/262] gitignore
---
.gitignore | 22 ++
.../src/com/skomefen/list/ArrayList.java | 83 -----
.../com/skomefen/list/ArrayListIterator.java | 25 --
.../src/com/skomefen/list/BinaryTreeNode.java | 32 --
.../src/com/skomefen/list/Iterator.java | 7 -
.../src/com/skomefen/list/LinkedList.java | 252 --------------
.../com/skomefen/list/LinkedListiterator.java | 25 --
.../day3-11/src/com/skomefen/list/List.java | 9 -
.../day3-11/src/com/skomefen/list/Queue.java | 26 --
.../day3-11/src/com/skomefen/list/Stack.java | 28 --
.../day3-11/src/com/skomefen/test/test.java | 109 ------
.../src/com/coderising/array/ArrayUtil.java | 117 -------
.../com/coderising/litestruts/StrutsTest.java | 54 ---
.../src/com/coding/datastructs/ArrayList.java | 98 ------
.../src/com/coding/datastructs/Iterator.java | 7 -
.../com/coding/datastructs/LinkedList.java | 229 ------------
.../src/com/coding/datastructs/List.java | 9 -
.../com/coding/datastructs/MyIterator.java | 35 --
.../src/com/coding/datastructs/Queue.java | 30 --
.../src/com/coding/datastructs/Stack.java | 33 --
.../src/com/coding/test/ArrayListTest.java | 32 --
.../src/com/coding/test/LinkedListTest.java | 28 --
.../src/com/coding/test/QueueTest.java | 22 --
.../src/com/coding/test/StackTest.java | 25 --
.../com/coding/datastructs/ArrayUtil.java" | 141 --------
.../src/com/coding/test/ArrayUtilTest.java" | 86 -----
.../WebContent/WEB-INF/etc/struts.xml" | 11 -
.../coderising/litestruts/LoginAction.java" | 35 --
.../com/coderising/litestruts/Struts.java" | 122 -------
.../coderising/litestruts/StrutsTest.java" | 43 ---
.../src/com/coderising/litestruts/Test.java" | 94 -----
.../src/com/coderising/litestruts/View.java" | 23 --
.../src/com/coderising/array/ArrayUtil.java | 96 -----
.../coderising/download/DownloadThread.java | 20 --
.../coderising/download/FileDownloader.java | 73 ----
.../download/FileDownloaderTest.java | 59 ----
.../coderising/download/api/Connection.java | 23 --
.../download/api/ConnectionException.java | 5 -
.../download/api/ConnectionManager.java | 10 -
.../download/api/DownloadListener.java | 5 -
.../download/impl/ConnectionImpl.java | 27 --
.../download/impl/ConnectionManagerImpl.java | 15 -
.../coderising/litestruts/LoginAction.java | 39 ---
.../src/com/coderising/litestruts/Struts.java | 37 --
.../com/coderising/litestruts/StrutsTest.java | 43 ---
.../src/com/coderising/litestruts/View.java | 23 --
.../src/com/coderising/litestruts/struts.xml | 11 -
.../src/com/coding/basic/ArrayList.java | 32 --
.../src/com/coding/basic/BinaryTreeNode.java | 32 --
.../src/com/coding/basic/Iterator.java | 7 -
.../src/com/coding/basic/LinkedList.java | 122 -------
.../565832157/src/com/coding/basic/List.java | 9 -
.../565832157/src/com/coding/basic/Queue.java | 19 -
.../565832157/src/com/coding/basic/Stack.java | 22 --
group23/601689050/ArrayList.java | 58 ----
group23/601689050/BinaryTreeNode.java | 50 ---
group23/601689050/Iterator.java | 7 -
group23/601689050/LinkedList.java | 117 -------
group23/601689050/List.java | 10 -
group23/601689050/Queue.java | 45 ---
group23/601689050/Stack.java | 39 ---
group23/609041842/.classpath | 10 -
group23/609041842/.gitignore | 1 -
group23/609041842/.project | 17 -
.../.settings/org.eclipse.jdt.ui.prefs | 60 ----
.../src/com/homework01/ArrayList.java | 49 ---
.../src/com/homework01/LinkedList.java | 87 -----
.../609041842/src/com/homework01/Queue.java | 17 -
.../609041842/src/com/homework01/Stack.java | 30 --
group23/609041842/src/test.java | 9 -
.../com/basic/datastructure/ArrayList.java | 64 ----
.../com/basic/datastructure/LinkedList.java | 98 ------
.../com/basic/datastructure/List.java | 9 -
.../com/basic/datastructure/Queue.java | 23 --
.../com/basic/datastructure/Stack.java | 29 --
.../datastructure/TestDataStructure.java | 27 --
.../basic/week2/datastructure/ArrayTest.java | 50 ---
.../basic/week2/datastructure/ArrayUtil.java | 228 ------------
group23/729693763/First_Homework1/.classpath | 7 -
group23/729693763/First_Homework1/.project | 17 -
.../org.eclipse.core.resources.prefs | 2 -
.../.settings/org.eclipse.jdt.core.prefs | 11 -
group23/729693763/First_Homework1/readme.md | 2 -
.../src/com/danny/hw1/ArrayList.java | 117 -------
.../src/com/danny/hw1/BinaryTreeNode.java | 101 ------
.../src/com/danny/hw1/Iterator.java | 6 -
.../src/com/danny/hw1/LinkedList.java | 296 ----------------
.../src/com/danny/hw1/List.java | 10 -
.../src/com/danny/hw1/Queue.java | 25 --
.../src/com/danny/hw1/Stack.java | 40 ---
.../src/com/danny/hw1/test/ArrayListTest.java | 80 -----
.../danny/hw1/test/BinaryTreeNodeTest.java | 48 ---
.../com/danny/hw1/test/LinkedListTest.java | 86 -----
.../src/com/danny/hw1/test/QueueTest.java | 47 ---
.../src/com/danny/hw1/test/StackTest.java | 54 ---
.../src/com/danny/hw1/test/SuitTest.java | 17 -
group23/729693763/Second_Homework2/.classpath | 9 -
group23/729693763/Second_Homework2/.project | 17 -
.../.settings/org.eclipse.jdt.core.prefs | 11 -
.../src/com/danny/hw2/ArrayUtil.java | 221 ------------
.../src/com/danny/hw2/LoginAction.java | 39 ---
.../src/com/danny/hw2/Struts.java | 163 ---------
.../src/com/danny/hw2/View.java | 23 --
.../src/com/danny/hw2/test/ArrayUtilTest.java | 95 -----
.../src/com/danny/hw2/test/StrutsTest.java | 46 ---
.../Second_Homework2/xmlFolder/struts.xml | 11 -
.../729693763/homework1_demo/ArrayList.java | 32 --
.../homework1_demo/BinaryTreeNode.java | 32 --
.../729693763/homework1_demo/Iterator.java | 7 -
.../729693763/homework1_demo/LinkedList.java | 124 -------
group23/729693763/homework1_demo/List.java | 9 -
group23/729693763/homework1_demo/Queue.java | 19 -
group23/729693763/homework1_demo/Stack.java | 22 --
group23/769232552/coding/pom.xml | 47 ---
.../src/main/java/code01/ArrayList.java | 138 --------
.../src/main/java/code01/BinaryTree.java | 97 ------
.../coding/src/main/java/code01/Iterator.java | 7 -
.../src/main/java/code01/LinkedList.java | 327 ------------------
.../coding/src/main/java/code01/List.java | 9 -
.../coding/src/main/java/code01/Queue.java | 24 --
.../coding/src/main/java/code01/Stack.java | 31 --
.../src/main/java/code02/ArrayUtil.java | 257 --------------
.../java/code02/litestruts/ActionConfig.java | 28 --
.../java/code02/litestruts/Configuration.java | 64 ----
.../java/code02/litestruts/LoginAction.java | 39 ---
.../code02/litestruts/ReflectionUtil.java | 119 -------
.../main/java/code02/litestruts/Struts.java | 76 ----
.../src/main/java/code02/litestruts/View.java | 23 --
.../src/main/java/code03/DownloadThread.java | 47 ---
.../src/main/java/code03/FileDownloader.java | 109 ------
.../src/main/java/code03/api/Connection.java | 23 --
.../java/code03/api/ConnectionException.java | 9 -
.../java/code03/api/ConnectionManager.java | 10 -
.../java/code03/api/DownloadListener.java | 5 -
.../main/java/code03/impl/ConnectionImpl.java | 107 ------
.../code03/impl/ConnectionManagerImpl.java | 36 --
.../coding/src/main/resources/struts.xml | 11 -
.../src/test/java/code01/ArrayListTest.java | 67 ----
.../src/test/java/code01/BinaryTreeTest.java | 27 --
.../src/test/java/code01/LinkedListTest.java | 174 ----------
.../src/test/java/code01/QueueTest.java | 24 --
.../src/test/java/code01/StackTest.java | 27 --
.../src/test/java/code02/ArrayUtilTest.java | 73 ----
.../java/code02/litestruts/StrutsTest.java | 43 ---
.../test/java/code03/FileDownloaderTest.java | 59 ----
group23/810181789/.classpath | 6 -
group23/810181789/.gitignore | 1 -
group23/810181789/.project | 17 -
.../810181789/src/firstday/ArrayListt.java | 86 -----
group23/810181789/src/firstday/LinkListt.java | 167 ---------
group23/810181789/src/firstday/Queue.java | 43 ---
group23/810181789/src/firstday/Stack.java | 43 ---
152 files changed, 22 insertions(+), 8079 deletions(-)
delete mode 100644 group23/1072760797-skomefen/day3-11/src/com/skomefen/list/ArrayList.java
delete mode 100644 group23/1072760797-skomefen/day3-11/src/com/skomefen/list/ArrayListIterator.java
delete mode 100644 group23/1072760797-skomefen/day3-11/src/com/skomefen/list/BinaryTreeNode.java
delete mode 100644 group23/1072760797-skomefen/day3-11/src/com/skomefen/list/Iterator.java
delete mode 100644 group23/1072760797-skomefen/day3-11/src/com/skomefen/list/LinkedList.java
delete mode 100644 group23/1072760797-skomefen/day3-11/src/com/skomefen/list/LinkedListiterator.java
delete mode 100644 group23/1072760797-skomefen/day3-11/src/com/skomefen/list/List.java
delete mode 100644 group23/1072760797-skomefen/day3-11/src/com/skomefen/list/Queue.java
delete mode 100644 group23/1072760797-skomefen/day3-11/src/com/skomefen/list/Stack.java
delete mode 100644 group23/1072760797-skomefen/day3-11/src/com/skomefen/test/test.java
delete mode 100644 group23/1072760797-skomefen/day3-19/src/com/coderising/array/ArrayUtil.java
delete mode 100644 group23/1072760797-skomefen/day3-19/src/com/coderising/litestruts/StrutsTest.java
delete mode 100644 group23/1246614258/src/com/coding/datastructs/ArrayList.java
delete mode 100644 group23/1246614258/src/com/coding/datastructs/Iterator.java
delete mode 100644 group23/1246614258/src/com/coding/datastructs/LinkedList.java
delete mode 100644 group23/1246614258/src/com/coding/datastructs/List.java
delete mode 100644 group23/1246614258/src/com/coding/datastructs/MyIterator.java
delete mode 100644 group23/1246614258/src/com/coding/datastructs/Queue.java
delete mode 100644 group23/1246614258/src/com/coding/datastructs/Stack.java
delete mode 100644 group23/1246614258/src/com/coding/test/ArrayListTest.java
delete mode 100644 group23/1246614258/src/com/coding/test/LinkedListTest.java
delete mode 100644 group23/1246614258/src/com/coding/test/QueueTest.java
delete mode 100644 group23/1246614258/src/com/coding/test/StackTest.java
delete mode 100644 "group23/1246614258/\347\254\254\344\272\214\346\254\241\344\275\234\344\270\232/DataStructsTest/src/com/coding/datastructs/ArrayUtil.java"
delete mode 100644 "group23/1246614258/\347\254\254\344\272\214\346\254\241\344\275\234\344\270\232/DataStructsTest/src/com/coding/test/ArrayUtilTest.java"
delete mode 100644 "group23/1246614258/\347\254\254\344\272\214\346\254\241\344\275\234\344\270\232/StrutsDemo/WebContent/WEB-INF/etc/struts.xml"
delete mode 100644 "group23/1246614258/\347\254\254\344\272\214\346\254\241\344\275\234\344\270\232/StrutsDemo/src/com/coderising/litestruts/LoginAction.java"
delete mode 100644 "group23/1246614258/\347\254\254\344\272\214\346\254\241\344\275\234\344\270\232/StrutsDemo/src/com/coderising/litestruts/Struts.java"
delete mode 100644 "group23/1246614258/\347\254\254\344\272\214\346\254\241\344\275\234\344\270\232/StrutsDemo/src/com/coderising/litestruts/StrutsTest.java"
delete mode 100644 "group23/1246614258/\347\254\254\344\272\214\346\254\241\344\275\234\344\270\232/StrutsDemo/src/com/coderising/litestruts/Test.java"
delete mode 100644 "group23/1246614258/\347\254\254\344\272\214\346\254\241\344\275\234\344\270\232/StrutsDemo/src/com/coderising/litestruts/View.java"
delete mode 100644 group23/565832157/src/com/coderising/array/ArrayUtil.java
delete mode 100644 group23/565832157/src/com/coderising/download/DownloadThread.java
delete mode 100644 group23/565832157/src/com/coderising/download/FileDownloader.java
delete mode 100644 group23/565832157/src/com/coderising/download/FileDownloaderTest.java
delete mode 100644 group23/565832157/src/com/coderising/download/api/Connection.java
delete mode 100644 group23/565832157/src/com/coderising/download/api/ConnectionException.java
delete mode 100644 group23/565832157/src/com/coderising/download/api/ConnectionManager.java
delete mode 100644 group23/565832157/src/com/coderising/download/api/DownloadListener.java
delete mode 100644 group23/565832157/src/com/coderising/download/impl/ConnectionImpl.java
delete mode 100644 group23/565832157/src/com/coderising/download/impl/ConnectionManagerImpl.java
delete mode 100644 group23/565832157/src/com/coderising/litestruts/LoginAction.java
delete mode 100644 group23/565832157/src/com/coderising/litestruts/Struts.java
delete mode 100644 group23/565832157/src/com/coderising/litestruts/StrutsTest.java
delete mode 100644 group23/565832157/src/com/coderising/litestruts/View.java
delete mode 100644 group23/565832157/src/com/coderising/litestruts/struts.xml
delete mode 100644 group23/565832157/src/com/coding/basic/ArrayList.java
delete mode 100644 group23/565832157/src/com/coding/basic/BinaryTreeNode.java
delete mode 100644 group23/565832157/src/com/coding/basic/Iterator.java
delete mode 100644 group23/565832157/src/com/coding/basic/LinkedList.java
delete mode 100644 group23/565832157/src/com/coding/basic/List.java
delete mode 100644 group23/565832157/src/com/coding/basic/Queue.java
delete mode 100644 group23/565832157/src/com/coding/basic/Stack.java
delete mode 100644 group23/601689050/ArrayList.java
delete mode 100644 group23/601689050/BinaryTreeNode.java
delete mode 100644 group23/601689050/Iterator.java
delete mode 100644 group23/601689050/LinkedList.java
delete mode 100644 group23/601689050/List.java
delete mode 100644 group23/601689050/Queue.java
delete mode 100644 group23/601689050/Stack.java
delete mode 100644 group23/609041842/.classpath
delete mode 100644 group23/609041842/.gitignore
delete mode 100644 group23/609041842/.project
delete mode 100644 group23/609041842/.settings/org.eclipse.jdt.ui.prefs
delete mode 100644 group23/609041842/src/com/homework01/ArrayList.java
delete mode 100644 group23/609041842/src/com/homework01/LinkedList.java
delete mode 100644 group23/609041842/src/com/homework01/Queue.java
delete mode 100644 group23/609041842/src/com/homework01/Stack.java
delete mode 100644 group23/609041842/src/test.java
delete mode 100644 group23/632678665/com/basic/datastructure/ArrayList.java
delete mode 100644 group23/632678665/com/basic/datastructure/LinkedList.java
delete mode 100644 group23/632678665/com/basic/datastructure/List.java
delete mode 100644 group23/632678665/com/basic/datastructure/Queue.java
delete mode 100644 group23/632678665/com/basic/datastructure/Stack.java
delete mode 100644 group23/632678665/com/basic/datastructure/TestDataStructure.java
delete mode 100644 group23/632678665/com/basic/week2/datastructure/ArrayTest.java
delete mode 100644 group23/632678665/com/basic/week2/datastructure/ArrayUtil.java
delete mode 100644 group23/729693763/First_Homework1/.classpath
delete mode 100644 group23/729693763/First_Homework1/.project
delete mode 100644 group23/729693763/First_Homework1/.settings/org.eclipse.core.resources.prefs
delete mode 100644 group23/729693763/First_Homework1/.settings/org.eclipse.jdt.core.prefs
delete mode 100644 group23/729693763/First_Homework1/readme.md
delete mode 100644 group23/729693763/First_Homework1/src/com/danny/hw1/ArrayList.java
delete mode 100644 group23/729693763/First_Homework1/src/com/danny/hw1/BinaryTreeNode.java
delete mode 100644 group23/729693763/First_Homework1/src/com/danny/hw1/Iterator.java
delete mode 100644 group23/729693763/First_Homework1/src/com/danny/hw1/LinkedList.java
delete mode 100644 group23/729693763/First_Homework1/src/com/danny/hw1/List.java
delete mode 100644 group23/729693763/First_Homework1/src/com/danny/hw1/Queue.java
delete mode 100644 group23/729693763/First_Homework1/src/com/danny/hw1/Stack.java
delete mode 100644 group23/729693763/First_Homework1/src/com/danny/hw1/test/ArrayListTest.java
delete mode 100644 group23/729693763/First_Homework1/src/com/danny/hw1/test/BinaryTreeNodeTest.java
delete mode 100644 group23/729693763/First_Homework1/src/com/danny/hw1/test/LinkedListTest.java
delete mode 100644 group23/729693763/First_Homework1/src/com/danny/hw1/test/QueueTest.java
delete mode 100644 group23/729693763/First_Homework1/src/com/danny/hw1/test/StackTest.java
delete mode 100644 group23/729693763/First_Homework1/src/com/danny/hw1/test/SuitTest.java
delete mode 100644 group23/729693763/Second_Homework2/.classpath
delete mode 100644 group23/729693763/Second_Homework2/.project
delete mode 100644 group23/729693763/Second_Homework2/.settings/org.eclipse.jdt.core.prefs
delete mode 100644 group23/729693763/Second_Homework2/src/com/danny/hw2/ArrayUtil.java
delete mode 100644 group23/729693763/Second_Homework2/src/com/danny/hw2/LoginAction.java
delete mode 100644 group23/729693763/Second_Homework2/src/com/danny/hw2/Struts.java
delete mode 100644 group23/729693763/Second_Homework2/src/com/danny/hw2/View.java
delete mode 100644 group23/729693763/Second_Homework2/src/com/danny/hw2/test/ArrayUtilTest.java
delete mode 100644 group23/729693763/Second_Homework2/src/com/danny/hw2/test/StrutsTest.java
delete mode 100644 group23/729693763/Second_Homework2/xmlFolder/struts.xml
delete mode 100644 group23/729693763/homework1_demo/ArrayList.java
delete mode 100644 group23/729693763/homework1_demo/BinaryTreeNode.java
delete mode 100644 group23/729693763/homework1_demo/Iterator.java
delete mode 100644 group23/729693763/homework1_demo/LinkedList.java
delete mode 100644 group23/729693763/homework1_demo/List.java
delete mode 100644 group23/729693763/homework1_demo/Queue.java
delete mode 100644 group23/729693763/homework1_demo/Stack.java
delete mode 100644 group23/769232552/coding/pom.xml
delete mode 100644 group23/769232552/coding/src/main/java/code01/ArrayList.java
delete mode 100644 group23/769232552/coding/src/main/java/code01/BinaryTree.java
delete mode 100644 group23/769232552/coding/src/main/java/code01/Iterator.java
delete mode 100644 group23/769232552/coding/src/main/java/code01/LinkedList.java
delete mode 100644 group23/769232552/coding/src/main/java/code01/List.java
delete mode 100644 group23/769232552/coding/src/main/java/code01/Queue.java
delete mode 100644 group23/769232552/coding/src/main/java/code01/Stack.java
delete mode 100644 group23/769232552/coding/src/main/java/code02/ArrayUtil.java
delete mode 100644 group23/769232552/coding/src/main/java/code02/litestruts/ActionConfig.java
delete mode 100644 group23/769232552/coding/src/main/java/code02/litestruts/Configuration.java
delete mode 100644 group23/769232552/coding/src/main/java/code02/litestruts/LoginAction.java
delete mode 100644 group23/769232552/coding/src/main/java/code02/litestruts/ReflectionUtil.java
delete mode 100644 group23/769232552/coding/src/main/java/code02/litestruts/Struts.java
delete mode 100644 group23/769232552/coding/src/main/java/code02/litestruts/View.java
delete mode 100644 group23/769232552/coding/src/main/java/code03/DownloadThread.java
delete mode 100644 group23/769232552/coding/src/main/java/code03/FileDownloader.java
delete mode 100644 group23/769232552/coding/src/main/java/code03/api/Connection.java
delete mode 100644 group23/769232552/coding/src/main/java/code03/api/ConnectionException.java
delete mode 100644 group23/769232552/coding/src/main/java/code03/api/ConnectionManager.java
delete mode 100644 group23/769232552/coding/src/main/java/code03/api/DownloadListener.java
delete mode 100644 group23/769232552/coding/src/main/java/code03/impl/ConnectionImpl.java
delete mode 100644 group23/769232552/coding/src/main/java/code03/impl/ConnectionManagerImpl.java
delete mode 100644 group23/769232552/coding/src/main/resources/struts.xml
delete mode 100644 group23/769232552/coding/src/test/java/code01/ArrayListTest.java
delete mode 100644 group23/769232552/coding/src/test/java/code01/BinaryTreeTest.java
delete mode 100644 group23/769232552/coding/src/test/java/code01/LinkedListTest.java
delete mode 100644 group23/769232552/coding/src/test/java/code01/QueueTest.java
delete mode 100644 group23/769232552/coding/src/test/java/code01/StackTest.java
delete mode 100644 group23/769232552/coding/src/test/java/code02/ArrayUtilTest.java
delete mode 100644 group23/769232552/coding/src/test/java/code02/litestruts/StrutsTest.java
delete mode 100644 group23/769232552/coding/src/test/java/code03/FileDownloaderTest.java
delete mode 100644 group23/810181789/.classpath
delete mode 100644 group23/810181789/.gitignore
delete mode 100644 group23/810181789/.project
delete mode 100644 group23/810181789/src/firstday/ArrayListt.java
delete mode 100644 group23/810181789/src/firstday/LinkListt.java
delete mode 100644 group23/810181789/src/firstday/Queue.java
delete mode 100644 group23/810181789/src/firstday/Stack.java
diff --git a/.gitignore b/.gitignore
index 825a471a70..95026b5340 100644
--- a/.gitignore
+++ b/.gitignore
@@ -287,3 +287,25 @@ target
liuxin/.DS_Store
liuxin/src/.DS_Store
+
+group23/729693763/*
+
+group23/1072760797-skomefen/*
+
+group23/609041842/*
+
+group23/810181789/*
+
+group23/1246614258/*
+
+group23/565832157/*
+
+group23/601689050/*
+
+group23/632678665/*
+
+group23/769232552/*
+
+
+
+
diff --git a/group23/1072760797-skomefen/day3-11/src/com/skomefen/list/ArrayList.java b/group23/1072760797-skomefen/day3-11/src/com/skomefen/list/ArrayList.java
deleted file mode 100644
index 2567132d2a..0000000000
--- a/group23/1072760797-skomefen/day3-11/src/com/skomefen/list/ArrayList.java
+++ /dev/null
@@ -1,83 +0,0 @@
-package com.skomefen.list;
-
-public class ArrayList implements List {
-
-
- private int size = 0;
-
- private Object[] elementData = new Object[100];
-
- private Iterator iterator ;
-
- public void add(Object o){
-
- if(sizesize||index<0){
- throw new IndexOutOfBoundsException("index:"+index+"size:"+size);
- }
-
- if(sizesize||index<0){
- throw new IndexOutOfBoundsException("index:"+index+"size:"+size);
- }
-
- return elementData[index];
-
- }
-
- public Object remove(int index){
- if(index>size||index<0){
- throw new IndexOutOfBoundsException("index:"+index+"size:"+size);
- }
- Object revalue = elementData[index];
- Object[] dest = new Object[elementData.length];
- System.arraycopy(elementData, 0, dest, 0, index);
- System.arraycopy(elementData, index+1, dest, index, elementData.length-1-index);
- elementData = dest;
- size--;
- return revalue;
- }
-
- public int size(){
- return size;
- }
-
- public Iterator iterator(){
- iterator = new ArrayListIterator(this);
- return iterator;
- }
-
-}
diff --git a/group23/1072760797-skomefen/day3-11/src/com/skomefen/list/ArrayListIterator.java b/group23/1072760797-skomefen/day3-11/src/com/skomefen/list/ArrayListIterator.java
deleted file mode 100644
index 345d620c0e..0000000000
--- a/group23/1072760797-skomefen/day3-11/src/com/skomefen/list/ArrayListIterator.java
+++ /dev/null
@@ -1,25 +0,0 @@
-package com.skomefen.list;
-
-public class ArrayListIterator implements Iterator {
- private ArrayList array = null;
- private int index = 0;
- public ArrayListIterator(ArrayList array) {
- this.array = array;
- }
- public boolean hasNext() {
- if(array==null){
- return false;
- }
- if(indexsize||index<0){
- throw new IndexOutOfBoundsException("index:"+index+"size:"+size);
- }
- insertoflist(index, o);
-
-
- }
- public Object get(int index){
- if(index>=size||index<0){
- throw new IndexOutOfBoundsException("index:"+index+"size:"+size);
- }
- if(head==null){
- return null;
- }
- if(index==point){
- return node.data;
- }
- this.point=0;
- node = head;
- while(index>=this.point){
-
- if(index==point){
- return node.data;
- }
- point++;
- node = node.next;
- }
- return null;
- }
- public Object remove(int index){
- if(index>=size||index<0){
- throw new IndexOutOfBoundsException("index:"+index+"size:"+size);
- }
- size--;
- if(index==(this.point+1)){
- Object o =node.next.data;
- node.next = node.next.next;
- return o;
- }
- this.point = 0;
- if(index==0){
- head = head.next;
- Object o =head.data;
- node = head;
- return o;
- }
-
- Object o = null;
- while(index<=(this.point+1)){
- if(index==(this.point+1)){
- o =node.next.data;
- node.next = node.next.next;
-
- }
- point++;
- node = node.next;
- }
- return o;
- }
-
- public int size(){
-
- return size;
- }
-
- public void addFirst(Object o){
- add(0,o);
- }
- public void addLast(Object o){
- add(size,o);
- }
- public Object removeFirst(){
- if(head==null){
- return null;
- }
- remove(0);
- return null;
- }
- public Object removeLast(){
- if(head==null){
- return null;
- }
- remove(size-1);
- return null;
- }
- public Iterator iterator(){
- iterator = new LinkedListiterator(this);
- return iterator;
- }
-
-
- private static class Node{
- private Object data;
- private Node next;
-
-
- }
-
- private void insertoflist(int index,Object o){
-
- if(index>size||index<0){
- throw new IndexOutOfBoundsException("index:"+index+"size:"+size);
- }
-
- if(head==null){
- head = new Node();
- head.data=o;
- head.next=new Node();
- size++;
- node = head;
- this.point = 0;
- return;
- }
- if(index==(this.point+1)){
- pointlast(index, o);
- return;
- }
- //head不等于空,先从head顺序往下找
- this.point = 0;
- if(index == this.point){
- Node next = head;
- head = new Node();
- head.next = next;
- head.data = o;
- node = head;//当前节点为head
- this.point = index;
- size++;
- return;
- }
- do{
- if(index==(this.point+1)){
- pointlast(index, o);
- return;
- }
- node = node.next;
- this.point++;
- }while(index>(this.point+1));
-
- }
-
- private void pointlast(int index, Object o) {
- if(index==(this.point+1)){
- if(index==size){//index插入List结尾
- this.point = this.point+1;
- node = node.next;
- node.data=o;
- node.next = new Node();
- size++;
- return;
- }
- this.point = this.point+1;
- Node next = node.next;//从上一个node获取下一个node
- node.next = new Node();//上一个节点指向新建节点
- node = node.next;//获取新建节点
- node.data=o;//新建节点获取值
- node.next = next;//新建节点指向下一个节点
- size++;
- return;
- }
- }
-
- /**
- * 把该链表逆置
- * 例如链表为 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/group23/1072760797-skomefen/day3-11/src/com/skomefen/list/LinkedListiterator.java b/group23/1072760797-skomefen/day3-11/src/com/skomefen/list/LinkedListiterator.java
deleted file mode 100644
index c04de32a93..0000000000
--- a/group23/1072760797-skomefen/day3-11/src/com/skomefen/list/LinkedListiterator.java
+++ /dev/null
@@ -1,25 +0,0 @@
-package com.skomefen.list;
-
-public class LinkedListiterator implements Iterator {
-
- private LinkedList link = null;
- private int index = 0;
- public LinkedListiterator(LinkedList link) {
- this.link = link;
- }
- public boolean hasNext() {
- if(link==null){
- return false;
- }
- if(index 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/group23/1246614258/src/com/coding/datastructs/ArrayList.java b/group23/1246614258/src/com/coding/datastructs/ArrayList.java
deleted file mode 100644
index bf8da9cccc..0000000000
--- a/group23/1246614258/src/com/coding/datastructs/ArrayList.java
+++ /dev/null
@@ -1,98 +0,0 @@
-package com.coding.datastructs;
-
-import java.util.ConcurrentModificationException;
-import java.util.NoSuchElementException;
-
-
-public class ArrayList implements List {
-
- private int size = 0;
-
- private Object[] elementData = null;
-
- public ArrayList(){
- size=0;
- elementData=new Object[10];
- }
-
- public void add(Object o){
- size();
- elementData=grow(elementData,1);
- elementData[size] = o;
- }
- public void add(int index, Object o){
- size();
- if (index >size || index < 0||index == size)
- throw new IndexOutOfBoundsException(
- "Index: "+index+", Size: "+size);
- Object temp = elementData;
- elementData=grow(elementData,1); // Increments modCount!!
- System.arraycopy(temp, index, elementData, index + 1,
- size - index);
- elementData[index] = o;
- }
-
- public Object get(int index){
- size();
- if (index > size || index < 0 ||index == size)
- throw new IndexOutOfBoundsException(
- "Index: "+index+", Size: "+size);
- return elementData[index];
- }
-
- public Object remove(int index){
- size();
- if (index > size || index < 0 ||index == size)
- throw new IndexOutOfBoundsException(
- "Index: "+index+", Size: "+size);
- Object tempData = elementData[index];
- System.arraycopy(elementData, index+1, elementData, index,
- size - index);
- return tempData;
- }
-
- public int size(){
- for(int i=0;i= size)
- throw new NoSuchElementException();
- Object[] elementData = ArrayList.this.elementData;
- if (i >= elementData.length)
- throw new ConcurrentModificationException();
- cursor = i + 1;
- return elementData[lastRet = i];
- }
-
-
-}
-
-
-
-}
diff --git a/group23/1246614258/src/com/coding/datastructs/Iterator.java b/group23/1246614258/src/com/coding/datastructs/Iterator.java
deleted file mode 100644
index 56acec15a3..0000000000
--- a/group23/1246614258/src/com/coding/datastructs/Iterator.java
+++ /dev/null
@@ -1,7 +0,0 @@
-package com.coding.datastructs;
-
-public interface Iterator {
- public boolean hasNext();
- public Object next();
-
-}
diff --git a/group23/1246614258/src/com/coding/datastructs/LinkedList.java b/group23/1246614258/src/com/coding/datastructs/LinkedList.java
deleted file mode 100644
index cd5de44121..0000000000
--- a/group23/1246614258/src/com/coding/datastructs/LinkedList.java
+++ /dev/null
@@ -1,229 +0,0 @@
-package com.coding.datastructs;
-
-public class LinkedList implements List{
-
- private Node head;
- private int size ;
-
- public LinkedList() {
- size = 0;
- head=new Node();
- }
-
- public void add(Object o) {
- Node pnew = new Node();
- pnew.setData(o);
- pnew.next = null;
- if(null==head.getNext()){
- head.setNext(pnew);
- return;
- }
- Node ptr = head.getNext();
- Node ptr1 = new Node();
-
- while (ptr != null) {
- ptr1 = ptr;
- ptr = ptr.getNext();
- }
- ptr1.next = pnew;
-
- }
-
- public void add(int index, Object o) {
- size();
- if (index > size || index < 0)
- throw new IndexOutOfBoundsException("Index: " + index + ", Size: "
- + size);
- Node ptr;
- Node ptemp = new Node();
- ;
- Node pnew;// ʵ�����½ڵ�
- ptr = head.getNext();
- int i = 0;
- if (ptr == null && size == 0) {
- System.out.println("��������ʧ�ܣ�");
- }
- while (ptr != null) {
- ptemp = ptr;
- if (index == 0) {
- pnew = new Node();
- pnew.setData(o);
- pnew.setNext(ptr);
- head.setNext(pnew);
- break;
- }
- if (index == i && index > 0) {
- ptemp = getNode(i-1);
- pnew = new Node();
- pnew.setData(o);
- pnew.setNext(ptr);
- ptemp.setNext(pnew);//
- System.out.println("��������" + o + "�ɹ���");
- break;
- }
- ptr = ptr.getNext();
- i++;
- }
- if (ptr == null && size > 0) {
- pnew = new Node();
- pnew.setData(o);
- pnew.setNext(null);
- ptemp.setNext(pnew);//
- System.out.println("��������" + o + "�ɹ���");
- }
-
- }
-
- public Object get(int index) {
- size();
- if (index > size || index < 0 || index == size)
- throw new IndexOutOfBoundsException("Index: " + index + ", Size: "
- + size);
- Node ptr = head.getNext();
- Object tempData = null;
- int i = 0;
- while (ptr != null) {
- if (index == i) {
- tempData = ptr.getData();
- }
- ptr = ptr.getNext();
- i++;
- }
-
- return tempData;
- }
-
- public Node getNode(int index) {
- size();
- if (index > size || index < 0 || index == size)
- throw new IndexOutOfBoundsException("Index: " + index + ", Size: "
- + size);
- Node ptr = head.getNext();
- Node tempData = null;
- int i = 0;
- while (ptr != null) {
- if (index == i) {
- tempData = ptr;
- }
- ptr = ptr.getNext();
- i++;
- }
-
- return tempData;
- }
-
- public Object remove(int index) {
- size();
- if(size()==0){
- throw new NullPointerException("list�ڲ�Ϊ�գ�����ɾ������");
- }
- if (index > size || index < 0 || index == size)
- throw new IndexOutOfBoundsException("Index: " + index + ", Size: "
- + size);
- Node ptr = head.getNext();
- Node ptrNext = new Node();
- Object tempData = null;
- int i = 0;
- while (ptr != null) {
- if (index == 0) {
- ptrNext = ptr.getNext();
- head.setNext(ptrNext);
- break;
- }
- if (index == i && index > 0) {
- Node ptrprevious = getNode(i - 1);
- tempData = ptr.getData();
- ptrprevious.setNext(ptr.getNext());
- break;
- }
- ptr = ptr.getNext();
- i++;
- }
- return tempData;
- }
-
- public int size() {
- int i = 0;
- Node ptr = head.getNext();
- while (ptr != null) {
- ptr = ptr.getNext();
- i++;
- }
- size = i;
- return size;
- }
-
- public void addFirst(Object o) {
- add(0,o);
-
- }
-
- public void addLast(Object o) {
- /*Node ptr = head.getNext();
- Node pnew = new Node();
- pnew.setData(o);
- Node ptemp = new Node();
- if (ptr == null) {
- head.setNext(pnew);
- } else {
- while (ptr != null) {
- ptemp = ptr;
- ptr = ptr.getNext();
- }
- if (ptr == null) {
- ptemp.setNext(pnew);
- }
- }*/
- add(size(),o);
-
- }
-
- public Object removeFirst() {
- Node ptr = head.getNext();
- Object temp = null;
- if (ptr == null) {
- throw new NullPointerException("LinkedList���������ݣ����ܽ���ɾ������");
- } else {
- temp = ptr.getData();
- remove(0);
- }
-
- return temp;
- }
-
- public Object removeLast() {
- size();
- Node ptr = head.getNext();
- Object temp = null;
- if (ptr == null) {
- throw new NullPointerException("LinkedList���������ݣ����ܽ���ɾ������");
- } else {
- temp = remove(size - 1);
- }
-
- return temp;
- }
-
- private static class Node {
- Object data;
- Node next;
-
- public Object getData() {
- return data;
- }
-
- public void setData(Object data) {
- this.data = data;
- }
-
- public Node getNext() {
- return next;
- }
-
- public void setNext(Node next) {
- this.next = next;
- }
-
- }
-
-}
diff --git a/group23/1246614258/src/com/coding/datastructs/List.java b/group23/1246614258/src/com/coding/datastructs/List.java
deleted file mode 100644
index 35ece31ca6..0000000000
--- a/group23/1246614258/src/com/coding/datastructs/List.java
+++ /dev/null
@@ -1,9 +0,0 @@
-package com.coding.datastructs;
-
-public interface List {
- public void add(Object o);
- public void add(int index, Object o);
- public Object get(int index);
- public Object remove(int index);
- public int size();
-}
diff --git a/group23/1246614258/src/com/coding/datastructs/MyIterator.java b/group23/1246614258/src/com/coding/datastructs/MyIterator.java
deleted file mode 100644
index be827a7875..0000000000
--- a/group23/1246614258/src/com/coding/datastructs/MyIterator.java
+++ /dev/null
@@ -1,35 +0,0 @@
-package com.coding.datastructs;
-
-import java.util.Iterator;
-
-public class MyIterator {
- public Iterator iterator(){
- return null;
- }
- private class Itera implements Iterator
- * @param args
- * @author:Wilson huang
- * @date 2017-3-12����1:45:58
- */
-
- public static void main(String[] args) {
- // TODO Auto-generated method stub
- LinkedList list = new LinkedList();
- list.add("a");
- list.add("b");
- list.add("c");
- list.add("d");
- list.removeLast();
- for(int i=0;iDescription:
- * @param args
- * @author:Wilson huang
- * @date 2017-3-12����2:42:15
- */
- public static void main(String[] args) {
- // TODO Auto-generated method stub
- Queue q = new Queue();
- q.enQueue("a");
- q.enQueue("b");
- System.out.println(q.deQueue());
-
- }
-
-}
diff --git a/group23/1246614258/src/com/coding/test/StackTest.java b/group23/1246614258/src/com/coding/test/StackTest.java
deleted file mode 100644
index 41f2a15b5b..0000000000
--- a/group23/1246614258/src/com/coding/test/StackTest.java
+++ /dev/null
@@ -1,25 +0,0 @@
-package com.coding.test;
-import com.coding.datastructs.Stack;
-
-
-public class StackTest {
-
- /**
- * Description:
- * @param args
- * @author:Wilson huang
- * @date 2017-3-12����2:34:15
- */
- public static void main(String[] args) {
- // TODO Auto-generated method stub
- Stack a = new Stack();
- a.push("a");
- a.push("b");
- a.push("c");
- System.out.println(a.isEmpty());
- System.out.println(a.peek());
- System.out.println(a.pop());
-
- }
-
-}
diff --git "a/group23/1246614258/\347\254\254\344\272\214\346\254\241\344\275\234\344\270\232/DataStructsTest/src/com/coding/datastructs/ArrayUtil.java" "b/group23/1246614258/\347\254\254\344\272\214\346\254\241\344\275\234\344\270\232/DataStructsTest/src/com/coding/datastructs/ArrayUtil.java"
deleted file mode 100644
index ff773dffcc..0000000000
--- "a/group23/1246614258/\347\254\254\344\272\214\346\254\241\344\275\234\344\270\232/DataStructsTest/src/com/coding/datastructs/ArrayUtil.java"
+++ /dev/null
@@ -1,141 +0,0 @@
-/**
- *
- */
-package com.coding.datastructs;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.HashSet;
-import java.util.Set;
-
-
-public class ArrayUtil {
-
-
- public void reverseArray(int[] origin){
- for (int i=0; i temp = new HashSet();
- for(Integer i : newArray)
- temp.add(i);
- for (int i = 0; i < temp.size(); i++) {
- newArray[i]=(int)temp.toArray()[i];
- }
- Arrays.sort(Arrays.copyOfRange(newArray, 0, temp.size()));
- return Arrays.copyOfRange(newArray, 0, temp.size());
- }
-
- public int[] grow(int [] oldArray, int size){
- int[] target = new int[oldArray.length+size];
- System.arraycopy(oldArray, 0, target, 0, oldArray.length);
- return target;
- }
-
-
- public int[] fibonacci(int max){
- ArrayList list = new ArrayList();
- list.add(1);
- list.add(1);
- if(max<=1){
- return new int[0];
- }
- for (int i = 2; i < max; i++) {
- int a = list.get(i-1)+list.get(i-2);
- if(a list = new ArrayList();
- int j=1;
- for(int i=2;i<100;i++){
- j=i;
- while(j>0){
- if(i%j==0&&i!=j&&j!=1){
- break;
- }else{
- j--;
- }
- }
- if(j==0){
- list.add(i);
- }
- }
- int[] newArray = new int[list.size()];
- for(int i=0;i list = new ArrayList();
- for(int i = 1; i < max; i++)
- {
- int sum = 0;
- for(int j = 1; j < i; j++)
- {
- if(i % j == 0)
- {
- sum = sum + j;
- }
- }
- if(sum == i)
- {
- list.add(i);
- }
- }
- int[] newArray = new int[list.size()];
- for(int i=0;i
-
-
- /jsp/homepage.jsp
- /jsp/showLogin.jsp
-
-
- /jsp/welcome.jsp
- /jsp/error.jsp
-
-
\ No newline at end of file
diff --git "a/group23/1246614258/\347\254\254\344\272\214\346\254\241\344\275\234\344\270\232/StrutsDemo/src/com/coderising/litestruts/LoginAction.java" "b/group23/1246614258/\347\254\254\344\272\214\346\254\241\344\275\234\344\270\232/StrutsDemo/src/com/coderising/litestruts/LoginAction.java"
deleted file mode 100644
index 07d16b45d3..0000000000
--- "a/group23/1246614258/\347\254\254\344\272\214\346\254\241\344\275\234\344\270\232/StrutsDemo/src/com/coderising/litestruts/LoginAction.java"
+++ /dev/null
@@ -1,35 +0,0 @@
-package com.coderising.litestruts;
-
-
-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;
- }
-}
\ No newline at end of file
diff --git "a/group23/1246614258/\347\254\254\344\272\214\346\254\241\344\275\234\344\270\232/StrutsDemo/src/com/coderising/litestruts/Struts.java" "b/group23/1246614258/\347\254\254\344\272\214\346\254\241\344\275\234\344\270\232/StrutsDemo/src/com/coderising/litestruts/Struts.java"
deleted file mode 100644
index bdcafdff8a..0000000000
--- "a/group23/1246614258/\347\254\254\344\272\214\346\254\241\344\275\234\344\270\232/StrutsDemo/src/com/coderising/litestruts/Struts.java"
+++ /dev/null
@@ -1,122 +0,0 @@
-package com.coderising.litestruts;
-
-import java.io.File;
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import org.jdom.Document;
-import org.jdom.Element;
-import org.jdom.input.SAXBuilder;
-
-public class Struts {
-
- public static View runAction(String actionName,
- Map parameters) {
-
-
- View view = new View();
- Map> array = new HashMap>();
- Map params = new HashMap();
- Map classData = new HashMap();
- try {
- analysisXml(classData,array);
- Map jspData = array.get(actionName);
- String s = "�Բ��������ݹ�����actionName��û�ж�Ӧ��class�࣬������Ҫ���´�";
- if (!classData.containsKey(actionName)) {
- throw new ClassNotFoundException(s);
- }
-
- Class> class1 = Class.forName(classData.get(actionName));
- LoginAction login = (LoginAction) class1.newInstance();
- for (String ss : parameters.keySet()) {
- Method[] methos1 = class1.getMethods();
- for (int i = 0; i < methos1.length; i++) {
- if (("set" + ss.substring(0, 1).toUpperCase() + ss
- .substring(1)).equals(methos1[i].getName())) {
- methos1[i].invoke(login, parameters.get(ss));
- break;
-
- }
- }
- }
-
- Method method1 = class1.getMethod("execute");
- String result = (String) method1.invoke(login);
- if(null!=result){
- view.setJsp(jspData.get(result));
- }
- Method[] methos2 = class1.getMethods();
- for (int i = 0; i < methos2.length; i++) {
- if(methos2[i].getName().substring(0, 3).equals("get")){
- Object value1 = (Object) (methos2[i].invoke(login));
- String name1 = methos2[i].getName();
- params.put(name1.substring(3, 4).toLowerCase()+name1.substring(4), value1);
- }
- }
- view.setParameters(params);
-
- } catch (Exception e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
-
- return view;
- }
-
-
- public static void analysisXml(Map xmlData,Map> array) {
- try {
-
- String dirpath = System.getProperty("user.dir");
- String xmlFile = dirpath + "/WebContent/WEB-INF/etc/struts.xml";
- SAXBuilder builder = new SAXBuilder();
- Document doc = builder.build(new File(xmlFile));
- Element xRoot = doc.getRootElement();
- List actions = getChildren(xRoot, "action");
- for (int i = 0; i < actions.size(); i++) {
- Element e = (Element) actions.get(i);
- String actionName1 = getAttributeValue(e, "name");
- String className = getAttributeValue(e, "class");
- xmlData.put(actionName1, className);
- List results = getChildren(e, "result");
- Map jspData = new HashMap();
- for (int j = 0; j < results.size(); j++) {
- Element result = (Element) results.get(j);
- String jspUrl = getValue(result);
- String resultName = getAttributeValue(result, "name");
- jspData.put(resultName, jspUrl);
- array.put(actionName1, jspData);
- }
- }
-
- // /StrutsDemo/WebContent/WEB-INF/etc/struts.xml
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
-
-
- public static Element getChild(Element element, String sonMark) {
- return element == null ? null : element.getChild(sonMark);
- }
-
-
- public static List getChildren(Element element, String sonMark) {
- return element == null ? null : element.getChildren(sonMark);
- }
-
-
- public static String getValue(Element element) {
- return element == null ? "" : element.getValue();
- }
-
-
- public static String getAttributeValue(Element element, String attribute) {
- return element == null ? null : element.getAttributeValue(attribute);
- }
-
-}
\ No newline at end of file
diff --git "a/group23/1246614258/\347\254\254\344\272\214\346\254\241\344\275\234\344\270\232/StrutsDemo/src/com/coderising/litestruts/StrutsTest.java" "b/group23/1246614258/\347\254\254\344\272\214\346\254\241\344\275\234\344\270\232/StrutsDemo/src/com/coderising/litestruts/StrutsTest.java"
deleted file mode 100644
index 52f08f3652..0000000000
--- "a/group23/1246614258/\347\254\254\344\272\214\346\254\241\344\275\234\344\270\232/StrutsDemo/src/com/coderising/litestruts/StrutsTest.java"
+++ /dev/null
@@ -1,43 +0,0 @@
-package com.coderising.litestruts;
-
-import java.util.HashMap;
-import java.util.Map;
-
-import org.junit.Assert;
-import org.junit.Test;
-
-
-
-
-
-public class StrutsTest {
-
- @Test
- public void testLoginActionSuccess() {
-
- String actionName = "login";
-
- Map params = new HashMap();
- params.put("name","test");
- params.put("password","1234");
-
-
- View view = Struts.runAction(actionName,params);
-
- Assert.assertEquals("/jsp/homepage.jsp", view.getJsp());
- Assert.assertEquals("login successful", view.getParameters().get("message"));
- }
-
- @Test
- public void testLoginActionFailed() {
- String actionName = "login";
- Map params = new HashMap();
- params.put("name","test");
- params.put("password","123456"); //�����Ԥ��IJ�һ��
-
- View view = Struts.runAction(actionName,params);
-
- Assert.assertEquals("/jsp/showLogin.jsp", view.getJsp());
- Assert.assertEquals("login failed,please check your user/pwd", view.getParameters().get("message"));
- }
-}
\ No newline at end of file
diff --git "a/group23/1246614258/\347\254\254\344\272\214\346\254\241\344\275\234\344\270\232/StrutsDemo/src/com/coderising/litestruts/Test.java" "b/group23/1246614258/\347\254\254\344\272\214\346\254\241\344\275\234\344\270\232/StrutsDemo/src/com/coderising/litestruts/Test.java"
deleted file mode 100644
index d7bcd36d42..0000000000
--- "a/group23/1246614258/\347\254\254\344\272\214\346\254\241\344\275\234\344\270\232/StrutsDemo/src/com/coderising/litestruts/Test.java"
+++ /dev/null
@@ -1,94 +0,0 @@
-/**
- *
- */
-package com.coderising.litestruts;
-
-import java.io.BufferedReader;
-import java.io.File;
-import java.io.StringReader;
-import java.lang.reflect.Method;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import org.jdom.Document;
-import org.jdom.Element;
-import org.jdom.input.SAXBuilder;
-
-/**
- * Title:
- * Description:
- * @author HuangLiang
- * @2017��3��17������10:55:39
- *
- */
-public class Test {
-
- /**Description:
- * @param args
- * @author HuangLiang 2017��3��17�� ����10:55:39
- */
- public static void main(String[] args) {
- // TODO Auto-generated method stub
- String name1 = "getName";
- System.out.println(name1.substring(3, 4).toLowerCase()+name1.substring(4));
- try {
- Class> class1 = Class.forName("com.coderising.litestruts.LoginAction");
- Method[] methos1 = class1.getMethods();
- for(int i=0;i para[] = methos1[i].getParameterTypes();
- throw new ClassNotFoundException();
- }
- System.out.println("���");
- } catch (ClassNotFoundException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
-
- }
- /**
- * ��ȡXML�ӱ�ǩ
- *
- * @param element
- * ��ǩ�ڵ�
- * @param sonMark
- * �ӱ�ǩ
- * @return
- */
- public static Element getChild(Element element, String sonMark) {
- return element == null ? null : element.getChild(sonMark);
- }
-
- /**
- * ��ȡXML�ӱ�ǩ��
- *
- * @param element
- * ��ǩ�ڵ�
- * @param sonMark
- * �ӱ�ǩ
- * @return
- */
- public static List getChildren(Element element, String sonMark) {
- return element == null ? null : element.getChildren(sonMark);
- }
-
- /**
- * s ��ȡXML��ǩֵ
- *
- * @param element
- * @return
- */
- public static String getValue(Element element) {
- return element == null ? "" : element.getValue();
- }
- /**
- * s ��ȡXML����ֵ
- *
- * @param element
- * @return
- */
- public static String getAttributeValue(Element element, String attribute) {
- return element == null ? null : element.getAttributeValue(attribute);
- }
-
-}
diff --git "a/group23/1246614258/\347\254\254\344\272\214\346\254\241\344\275\234\344\270\232/StrutsDemo/src/com/coderising/litestruts/View.java" "b/group23/1246614258/\347\254\254\344\272\214\346\254\241\344\275\234\344\270\232/StrutsDemo/src/com/coderising/litestruts/View.java"
deleted file mode 100644
index f68a8c438b..0000000000
--- "a/group23/1246614258/\347\254\254\344\272\214\346\254\241\344\275\234\344\270\232/StrutsDemo/src/com/coderising/litestruts/View.java"
+++ /dev/null
@@ -1,23 +0,0 @@
-package com.coderising.litestruts;
-
-import java.util.Map;
-
-public class View {
- private String jsp;
- private Map parameters;
-
- public String getJsp() {
- return jsp;
- }
- public View setJsp(String jsp) {
- this.jsp = jsp;
- return this;
- }
- public Map getParameters() {
- return parameters;
- }
- public View setParameters(Map parameters) {
- this.parameters = parameters;
- return this;
- }
-}
\ No newline at end of file
diff --git a/group23/565832157/src/com/coderising/array/ArrayUtil.java b/group23/565832157/src/com/coderising/array/ArrayUtil.java
deleted file mode 100644
index e5ddb476a6..0000000000
--- a/group23/565832157/src/com/coderising/array/ArrayUtil.java
+++ /dev/null
@@ -1,96 +0,0 @@
-package com.coderising.array;
-
-public class ArrayUtil {
-
- /**
- * 给定一个整形数组a , 对该数组的值进行置换
- 例如: a = [7, 9 , 30, 3] , 置换后为 [3, 30, 9,7]
- 如果 a = [7, 9, 30, 3, 4] , 置换后为 [4,3, 30 , 9,7]
- * @param origin
- * @return
- */
- public void reverseArray(int[] origin){
-
- }
-
- /**
- * 现在有如下的一个数组: int oldArr[]={1,3,4,5,0,0,6,6,0,5,4,7,6,7,0,5}
- * 要求将以上数组中值为0的项去掉,将不为0的值存入一个新的数组,生成的新数组为:
- * {1,3,4,5,6,6,5,4,7,6,7,5}
- * @param oldArray
- * @return
- */
-
- public int[] removeZero(int[] oldArray){
- return null;
- }
-
- /**
- * 给定两个已经排序好的整形数组, a1和a2 , 创建一个新的数组a3, 使得a3 包含a1和a2 的所有元素, 并且仍然是有序的
- * 例如 a1 = [3, 5, 7,8] a2 = [4, 5, 6,7] 则 a3 为[3,4,5,6,7,8] , 注意: 已经消除了重复
- * @param array1
- * @param array2
- * @return
- */
-
- public int[] merge(int[] array1, int[] array2){
- return null;
- }
- /**
- * 把一个已经存满数据的数组 oldArray的容量进行扩展, 扩展后的新数据大小为oldArray.length + size
- * 注意,老数组的元素在新数组中需要保持
- * 例如 oldArray = [2,3,6] , size = 3,则返回的新数组为
- * [2,3,6,0,0,0]
- * @param oldArray
- * @param size
- * @return
- */
- public int[] grow(int [] oldArray, int size){
- return null;
- }
-
- /**
- * 斐波那契数列为:1,1,2,3,5,8,13,21...... ,给定一个最大值, 返回小于该值的数列
- * 例如, max = 15 , 则返回的数组应该为 [1,1,2,3,5,8,13]
- * max = 1, 则返回空数组 []
- * @param max
- * @return
- */
- public int[] fibonacci(int max){
- return null;
- }
-
- /**
- * 返回小于给定最大值max的所有素数数组
- * 例如max = 23, 返回的数组为[2,3,5,7,11,13,17,19]
- * @param max
- * @return
- */
- public int[] getPrimes(int max){
- return null;
- }
-
- /**
- * 所谓“完数”, 是指这个数恰好等于它的因子之和,例如6=1+2+3
- * 给定一个最大值max, 返回一个数组, 数组中是小于max 的所有完数
- * @param max
- * @return
- */
- public int[] getPerfectNumbers(int max){
- return null;
- }
-
- /**
- * 用seperator 把数组 array给连接起来
- * 例如array= [3,8,9], seperator = "-"
- * 则返回值为"3-8-9"
- * @param array
- * @param s
- * @return
- */
- public String join(int[] array, String seperator){
- return null;
- }
-
-
-}
diff --git a/group23/565832157/src/com/coderising/download/DownloadThread.java b/group23/565832157/src/com/coderising/download/DownloadThread.java
deleted file mode 100644
index 900a3ad358..0000000000
--- a/group23/565832157/src/com/coderising/download/DownloadThread.java
+++ /dev/null
@@ -1,20 +0,0 @@
-package com.coderising.download;
-
-import com.coderising.download.api.Connection;
-
-public class DownloadThread extends Thread{
-
- Connection conn;
- int startPos;
- int endPos;
-
- public DownloadThread( Connection conn, int startPos, int endPos){
-
- this.conn = conn;
- this.startPos = startPos;
- this.endPos = endPos;
- }
- public void run(){
-
- }
-}
diff --git a/group23/565832157/src/com/coderising/download/FileDownloader.java b/group23/565832157/src/com/coderising/download/FileDownloader.java
deleted file mode 100644
index c3c8a3f27d..0000000000
--- a/group23/565832157/src/com/coderising/download/FileDownloader.java
+++ /dev/null
@@ -1,73 +0,0 @@
-package com.coderising.download;
-
-import com.coderising.download.api.Connection;
-import com.coderising.download.api.ConnectionException;
-import com.coderising.download.api.ConnectionManager;
-import com.coderising.download.api.DownloadListener;
-
-
-public class FileDownloader {
-
- String url;
-
- DownloadListener listener;
-
- ConnectionManager cm;
-
-
- public FileDownloader(String _url) {
- this.url = _url;
-
- }
-
- public void execute(){
- // 在这里实现你的代码, 注意: 需要用多线程实现下载
- // 这个类依赖于其他几个接口, 你需要写这几个接口的实现代码
- // (1) ConnectionManager , 可以打开一个连接,通过Connection可以读取其中的一段(用startPos, endPos来指定)
- // (2) DownloadListener, 由于是多线程下载, 调用这个类的客户端不知道什么时候结束,所以你需要实现当所有
- // 线程都执行完以后, 调用listener的notifiedFinished方法, 这样客户端就能收到通知。
- // 具体的实现思路:
- // 1. 需要调用ConnectionManager的open方法打开连接, 然后通过Connection.getContentLength方法获得文件的长度
- // 2. 至少启动3个线程下载, 注意每个线程需要先调用ConnectionManager的open方法
- // 然后调用read方法, read方法中有读取文件的开始位置和结束位置的参数, 返回值是byte[]数组
- // 3. 把byte数组写入到文件中
- // 4. 所有的线程都下载完成以后, 需要调用listener的notifiedFinished方法
-
- // 下面的代码是示例代码, 也就是说只有一个线程, 你需要改造成多线程的。
- Connection conn = null;
- try {
-
- conn = cm.open(this.url);
-
- int length = conn.getContentLength();
-
- new DownloadThread(conn,0,length-1).start();
-
- } catch (ConnectionException e) {
- e.printStackTrace();
- }finally{
- if(conn != null){
- conn.close();
- }
- }
-
-
-
-
- }
-
- public void setListener(DownloadListener listener) {
- this.listener = listener;
- }
-
-
-
- public void setConnectionManager(ConnectionManager ucm){
- this.cm = ucm;
- }
-
- public DownloadListener getListener(){
- return this.listener;
- }
-
-}
diff --git a/group23/565832157/src/com/coderising/download/FileDownloaderTest.java b/group23/565832157/src/com/coderising/download/FileDownloaderTest.java
deleted file mode 100644
index 4ff7f46ae0..0000000000
--- a/group23/565832157/src/com/coderising/download/FileDownloaderTest.java
+++ /dev/null
@@ -1,59 +0,0 @@
-package com.coderising.download;
-
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-
-import com.coderising.download.api.ConnectionManager;
-import com.coderising.download.api.DownloadListener;
-import com.coderising.download.impl.ConnectionManagerImpl;
-
-public class FileDownloaderTest {
- boolean downloadFinished = false;
- @Before
- public void setUp() throws Exception {
- }
-
- @After
- public void tearDown() throws Exception {
- }
-
- @Test
- public void testDownload() {
-
- String url = "http://localhost:8080/test.jpg";
-
- FileDownloader downloader = new FileDownloader(url);
-
-
- ConnectionManager cm = new ConnectionManagerImpl();
- downloader.setConnectionManager(cm);
-
- downloader.setListener(new DownloadListener() {
- @Override
- public void notifyFinished() {
- downloadFinished = true;
- }
-
- });
-
-
- downloader.execute();
-
- // 等待多线程下载程序执行完毕
- while (!downloadFinished) {
- try {
- System.out.println("还没有下载完成,休眠五秒");
- //休眠5秒
- Thread.sleep(5000);
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- }
- System.out.println("下载完成!");
-
-
-
- }
-
-}
diff --git a/group23/565832157/src/com/coderising/download/api/Connection.java b/group23/565832157/src/com/coderising/download/api/Connection.java
deleted file mode 100644
index 0957eaf7f4..0000000000
--- a/group23/565832157/src/com/coderising/download/api/Connection.java
+++ /dev/null
@@ -1,23 +0,0 @@
-package com.coderising.download.api;
-
-import java.io.IOException;
-
-public interface Connection {
- /**
- * 给定开始和结束位置, 读取数据, 返回值是字节数组
- * @param startPos 开始位置, 从0开始
- * @param endPos 结束位置
- * @return
- */
- public byte[] read(int startPos,int endPos) throws IOException;
- /**
- * 得到数据内容的长度
- * @return
- */
- public int getContentLength();
-
- /**
- * 关闭连接
- */
- public void close();
-}
diff --git a/group23/565832157/src/com/coderising/download/api/ConnectionException.java b/group23/565832157/src/com/coderising/download/api/ConnectionException.java
deleted file mode 100644
index 1551a80b3d..0000000000
--- a/group23/565832157/src/com/coderising/download/api/ConnectionException.java
+++ /dev/null
@@ -1,5 +0,0 @@
-package com.coderising.download.api;
-
-public class ConnectionException extends Exception {
-
-}
diff --git a/group23/565832157/src/com/coderising/download/api/ConnectionManager.java b/group23/565832157/src/com/coderising/download/api/ConnectionManager.java
deleted file mode 100644
index ce045393b1..0000000000
--- a/group23/565832157/src/com/coderising/download/api/ConnectionManager.java
+++ /dev/null
@@ -1,10 +0,0 @@
-package com.coderising.download.api;
-
-public interface ConnectionManager {
- /**
- * 给定一个url , 打开一个连接
- * @param url
- * @return
- */
- public Connection open(String url) throws ConnectionException;
-}
diff --git a/group23/565832157/src/com/coderising/download/api/DownloadListener.java b/group23/565832157/src/com/coderising/download/api/DownloadListener.java
deleted file mode 100644
index bf9807b307..0000000000
--- a/group23/565832157/src/com/coderising/download/api/DownloadListener.java
+++ /dev/null
@@ -1,5 +0,0 @@
-package com.coderising.download.api;
-
-public interface DownloadListener {
- public void notifyFinished();
-}
diff --git a/group23/565832157/src/com/coderising/download/impl/ConnectionImpl.java b/group23/565832157/src/com/coderising/download/impl/ConnectionImpl.java
deleted file mode 100644
index 36a9d2ce15..0000000000
--- a/group23/565832157/src/com/coderising/download/impl/ConnectionImpl.java
+++ /dev/null
@@ -1,27 +0,0 @@
-package com.coderising.download.impl;
-
-import java.io.IOException;
-
-import com.coderising.download.api.Connection;
-
-public class ConnectionImpl implements Connection{
-
- @Override
- public byte[] read(int startPos, int endPos) throws IOException {
-
- return null;
- }
-
- @Override
- public int getContentLength() {
-
- return 0;
- }
-
- @Override
- public void close() {
-
-
- }
-
-}
diff --git a/group23/565832157/src/com/coderising/download/impl/ConnectionManagerImpl.java b/group23/565832157/src/com/coderising/download/impl/ConnectionManagerImpl.java
deleted file mode 100644
index 172371dd55..0000000000
--- a/group23/565832157/src/com/coderising/download/impl/ConnectionManagerImpl.java
+++ /dev/null
@@ -1,15 +0,0 @@
-package com.coderising.download.impl;
-
-import com.coderising.download.api.Connection;
-import com.coderising.download.api.ConnectionException;
-import com.coderising.download.api.ConnectionManager;
-
-public class ConnectionManagerImpl implements ConnectionManager {
-
- @Override
- public Connection open(String url) throws ConnectionException {
-
- return null;
- }
-
-}
diff --git a/group23/565832157/src/com/coderising/litestruts/LoginAction.java b/group23/565832157/src/com/coderising/litestruts/LoginAction.java
deleted file mode 100644
index dcdbe226ed..0000000000
--- a/group23/565832157/src/com/coderising/litestruts/LoginAction.java
+++ /dev/null
@@ -1,39 +0,0 @@
-package com.coderising.litestruts;
-
-/**
- * 这是一个用来展示登录的业务类, 其中的用户名和密码都是硬编码的。
- * @author liuxin
- *
- */
-public class LoginAction{
- private String name ;
- private String password;
- private String message;
-
- public String getName() {
- return name;
- }
-
- public String getPassword() {
- return password;
- }
-
- public String execute(){
- if("test".equals(name) && "1234".equals(password)){
- this.message = "login successful";
- return "success";
- }
- this.message = "login failed,please check your user/pwd";
- return "fail";
- }
-
- public void setName(String name){
- this.name = name;
- }
- public void setPassword(String password){
- this.password = password;
- }
- public String getMessage(){
- return this.message;
- }
-}
diff --git a/group23/565832157/src/com/coderising/litestruts/Struts.java b/group23/565832157/src/com/coderising/litestruts/Struts.java
deleted file mode 100644
index 6df190d484..0000000000
--- a/group23/565832157/src/com/coderising/litestruts/Struts.java
+++ /dev/null
@@ -1,37 +0,0 @@
-package com.coderising.litestruts;
-
-import java.lang.reflect.Method;
-import java.util.Map;
-
-
-
-public class Struts {
-
-
- public static View runAction(String actionName, Map parameters) {
-
- /*
-
- 0. 读取配置文件struts.xml
-
- 1. 根据actionName找到相对应的class , 例如LoginAction, 通过反射实例化(创建对象)
- 据parameters中的数据,调用对象的setter方法, 例如parameters中的数据是
- ("name"="test" , "password"="1234") ,
- 那就应该调用 setName和setPassword方法
-
- 2. 通过反射调用对象的exectue 方法, 并获得返回值,例如"success"
-
- 3. 通过反射找到对象的所有getter方法(例如 getMessage),
- 通过反射来调用, 把值和属性形成一个HashMap , 例如 {"message": "登录成功"} ,
- 放到View对象的parameters
-
- 4. 根据struts.xml中的 配置,以及execute的返回值, 确定哪一个jsp,
- 放到View对象的jsp字段中。
-
- */
-
-
- return null;
- }
-
-}
diff --git a/group23/565832157/src/com/coderising/litestruts/StrutsTest.java b/group23/565832157/src/com/coderising/litestruts/StrutsTest.java
deleted file mode 100644
index b8c81faf3c..0000000000
--- a/group23/565832157/src/com/coderising/litestruts/StrutsTest.java
+++ /dev/null
@@ -1,43 +0,0 @@
-package com.coderising.litestruts;
-
-import java.util.HashMap;
-import java.util.Map;
-
-import org.junit.Assert;
-import org.junit.Test;
-
-
-
-
-
-public class StrutsTest {
-
- @Test
- public void testLoginActionSuccess() {
-
- String actionName = "login";
-
- Map params = new HashMap();
- params.put("name","test");
- params.put("password","1234");
-
-
- View view = Struts.runAction(actionName,params);
-
- Assert.assertEquals("/jsp/homepage.jsp", view.getJsp());
- Assert.assertEquals("login successful", view.getParameters().get("message"));
- }
-
- @Test
- public void testLoginActionFailed() {
- String actionName = "login";
- Map params = new HashMap();
- params.put("name","test");
- params.put("password","123456"); //密码和预设的不一致
-
- View view = Struts.runAction(actionName,params);
-
- Assert.assertEquals("/jsp/showLogin.jsp", view.getJsp());
- Assert.assertEquals("login failed,please check your user/pwd", view.getParameters().get("message"));
- }
-}
diff --git a/group23/565832157/src/com/coderising/litestruts/View.java b/group23/565832157/src/com/coderising/litestruts/View.java
deleted file mode 100644
index 07df2a5dab..0000000000
--- a/group23/565832157/src/com/coderising/litestruts/View.java
+++ /dev/null
@@ -1,23 +0,0 @@
-package com.coderising.litestruts;
-
-import java.util.Map;
-
-public class View {
- private String jsp;
- private Map parameters;
-
- public String getJsp() {
- return jsp;
- }
- public View setJsp(String jsp) {
- this.jsp = jsp;
- return this;
- }
- public Map getParameters() {
- return parameters;
- }
- public View setParameters(Map parameters) {
- this.parameters = parameters;
- return this;
- }
-}
diff --git a/group23/565832157/src/com/coderising/litestruts/struts.xml b/group23/565832157/src/com/coderising/litestruts/struts.xml
deleted file mode 100644
index e5d9aebba8..0000000000
--- a/group23/565832157/src/com/coderising/litestruts/struts.xml
+++ /dev/null
@@ -1,11 +0,0 @@
-
-
-
- /jsp/homepage.jsp
- /jsp/showLogin.jsp
-
-
- /jsp/welcome.jsp
- /jsp/error.jsp
-
-
\ No newline at end of file
diff --git a/group23/565832157/src/com/coding/basic/ArrayList.java b/group23/565832157/src/com/coding/basic/ArrayList.java
deleted file mode 100644
index 1f185736f9..0000000000
--- a/group23/565832157/src/com/coding/basic/ArrayList.java
+++ /dev/null
@@ -1,32 +0,0 @@
-package com.coding.basic;
-
-public class ArrayList implements List {
-
- private int size = 0;
-
- private Object[] elementData = new Object[100];
-
- 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 Iterator iterator(){
- return null;
- }
-
-}
diff --git a/group23/565832157/src/com/coding/basic/BinaryTreeNode.java b/group23/565832157/src/com/coding/basic/BinaryTreeNode.java
deleted file mode 100644
index d7ac820192..0000000000
--- a/group23/565832157/src/com/coding/basic/BinaryTreeNode.java
+++ /dev/null
@@ -1,32 +0,0 @@
-package com.coding.basic;
-
-public class BinaryTreeNode {
-
- private Object data;
- private BinaryTreeNode left;
- private BinaryTreeNode right;
-
- public Object getData() {
- return data;
- }
- public void setData(Object data) {
- this.data = data;
- }
- public BinaryTreeNode getLeft() {
- return left;
- }
- public void setLeft(BinaryTreeNode left) {
- this.left = left;
- }
- public BinaryTreeNode getRight() {
- return right;
- }
- public void setRight(BinaryTreeNode right) {
- this.right = right;
- }
-
- public BinaryTreeNode insert(Object o){
- return null;
- }
-
-}
diff --git a/group23/565832157/src/com/coding/basic/Iterator.java b/group23/565832157/src/com/coding/basic/Iterator.java
deleted file mode 100644
index 06ef6311b2..0000000000
--- a/group23/565832157/src/com/coding/basic/Iterator.java
+++ /dev/null
@@ -1,7 +0,0 @@
-package com.coding.basic;
-
-public interface Iterator {
- public boolean hasNext();
- public Object next();
-
-}
diff --git a/group23/565832157/src/com/coding/basic/LinkedList.java b/group23/565832157/src/com/coding/basic/LinkedList.java
deleted file mode 100644
index 09fe0a8ff3..0000000000
--- a/group23/565832157/src/com/coding/basic/LinkedList.java
+++ /dev/null
@@ -1,122 +0,0 @@
-package com.coding.basic;
-
-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/group23/565832157/src/com/coding/basic/List.java b/group23/565832157/src/com/coding/basic/List.java
deleted file mode 100644
index 10d13b5832..0000000000
--- a/group23/565832157/src/com/coding/basic/List.java
+++ /dev/null
@@ -1,9 +0,0 @@
-package com.coding.basic;
-
-public interface List {
- public void add(Object o);
- public void add(int index, Object o);
- public Object get(int index);
- public Object remove(int index);
- public int size();
-}
diff --git a/group23/565832157/src/com/coding/basic/Queue.java b/group23/565832157/src/com/coding/basic/Queue.java
deleted file mode 100644
index 36e516e266..0000000000
--- a/group23/565832157/src/com/coding/basic/Queue.java
+++ /dev/null
@@ -1,19 +0,0 @@
-package com.coding.basic;
-
-public class Queue {
-
- public void enQueue(Object o){
- }
-
- public Object deQueue(){
- return null;
- }
-
- public boolean isEmpty(){
- return false;
- }
-
- public int size(){
- return -1;
- }
-}
diff --git a/group23/565832157/src/com/coding/basic/Stack.java b/group23/565832157/src/com/coding/basic/Stack.java
deleted file mode 100644
index a5a04de76d..0000000000
--- a/group23/565832157/src/com/coding/basic/Stack.java
+++ /dev/null
@@ -1,22 +0,0 @@
-package com.coding.basic;
-
-public class Stack {
- private ArrayList elementData = new ArrayList();
-
- public void push(Object o){
- }
-
- public Object pop(){
- return null;
- }
-
- public Object peek(){
- return null;
- }
- public boolean isEmpty(){
- return false;
- }
- public int size(){
- return -1;
- }
-}
diff --git a/group23/601689050/ArrayList.java b/group23/601689050/ArrayList.java
deleted file mode 100644
index 5a4169dc9b..0000000000
--- a/group23/601689050/ArrayList.java
+++ /dev/null
@@ -1,58 +0,0 @@
-package com.bjsxd.test;
-
-public class ArrayList implements List {
- private Object[] elementData = new Object[100];
- private int size = 0;
- Object[] temp = null;
-
- public void add(Object o) {
- if (size < elementData.length) {
- size++;
- Object[] target = new Object[elementData.length + size];
- System.arraycopy(elementData, 0, target, 0, elementData.length);
- elementData[size] = o;
- }
- }
-
- public void add(int index, Object o) {
- if (index < 0 || o == null) {
- throw new IllegalArgumentException("��Ӷ������");
- } else if (index <= elementData.length) {
- add(o);
- } else if (index > elementData.length) {
- throw new IllegalArgumentException("��Ӷ���Խ��");
- }
-
- if (size <= elementData.length) {
- this.size++;
- }
- Object[] target = new Object[this.size];
- System.arraycopy(elementData, 0, target, 0, index);
- target[index] = o;
- System.arraycopy(elementData, index, target, index + 1, elementData.length - index);
- }
-
- public Object get(int index) {
- if (index < 0 || index >= elementData.length) {
- return false;
- } else {
- return elementData[index];
- }
- }
-
- public Object remove(int index) {
- if (index < 0 || index >= elementData.length) {
- throw new IllegalArgumentException("ɾ��������");
- } else {
- for (int i = index; i < elementData.length; i++) {
- elementData[i] = elementData[i + 1];
- }
- return elementData[index];
- }
- }
-
- public int size() {
- return this.size;
- }
-
-}
diff --git a/group23/601689050/BinaryTreeNode.java b/group23/601689050/BinaryTreeNode.java
deleted file mode 100644
index 3687306f5e..0000000000
--- a/group23/601689050/BinaryTreeNode.java
+++ /dev/null
@@ -1,50 +0,0 @@
-package com.bjsxd.test;
-
-public class BinaryTreeNode {
- private Object data;
- private BinaryTreeNode left;
- private BinaryTreeNode right;
- private BinaryTreeNode root;
-
- public BinaryTreeNode(BinaryTreeNode root){
- this.root = root;
-
- }
-
- public BinaryTreeNode(BinaryTreeNode left,BinaryTreeNode right,Object data){
- this.left = left;
- this.right = right;
- this.data = data;
- }
-
- public void buildTree(){
-
- }
-
- public BinaryTreeNode(Object data){
- this(null,null,data);
- }
- public Object getData(){
- return data;
- }
- public void setData(Object data){
- this.data = data;
- }
- public BinaryTreeNode getLeft(){
- return left;
- }
- public void setLeft(BinaryTreeNode left){
- this.left = left;
-
- }
- public BinaryTreeNode getRight(){
- return right;
- }
- public void setRight(BinaryTreeNode right){
- this.right = right;
- }
- public BinaryTreeNode insert(Object o){
- return null;
- }
-
-}
diff --git a/group23/601689050/Iterator.java b/group23/601689050/Iterator.java
deleted file mode 100644
index 06ef6311b2..0000000000
--- a/group23/601689050/Iterator.java
+++ /dev/null
@@ -1,7 +0,0 @@
-package com.coding.basic;
-
-public interface Iterator {
- public boolean hasNext();
- public Object next();
-
-}
diff --git a/group23/601689050/LinkedList.java b/group23/601689050/LinkedList.java
deleted file mode 100644
index ee173bec67..0000000000
--- a/group23/601689050/LinkedList.java
+++ /dev/null
@@ -1,117 +0,0 @@
-package com.bjsxd.test;
-
-public class LinkedList implements List{
- private static class Node{
- Object data;
- Node next;
- }
- private Node head;
- private Node last;
- public void add (Object o){
- if (head == null){
- head = new Node();
- head.data = o;
- head.next = null;
- }else{
- Node MyNode = new Node();
- MyNode = head;
- while (MyNode.next != null){
- MyNode = MyNode.next;
- }
- Node AddNode = new Node();
- MyNode.next = AddNode;
- AddNode.data = o;
- }
- }
- public void add(int index,Object o){
- if(index<0 || o ==null){
- throw new IllegalArgumentException("���Ӷ���λ�ó����Ҳ���Ϊ��");
- }else if (index == 0 && head == null){
- head = new Node();
- head.data = o;
- head.next = null;
- }else if (index > 0 && head == null){
- throw new IllegalArgumentException("���Ӷ���λ�ó���");
- }else{
- Node SrcNode = new Node();
- Node AddNode = new Node();
- Node SrcNode2 = new Node();
- SrcNode = head;
- for(int i=0;i<=index;i++){
- SrcNode = SrcNode.next;
- }
- AddNode.next = SrcNode;
- AddNode.data = o;
- for (int i=0;i size){
- throw new IllegalArgumentException("ɾ������λ�ó���");
- }else{
- for (int i=0;i front){
- return rear - front;
- }else
- return Q.length-1;
- }
-
-}
diff --git a/group23/601689050/Stack.java b/group23/601689050/Stack.java
deleted file mode 100644
index 106d2ecc7d..0000000000
--- a/group23/601689050/Stack.java
+++ /dev/null
@@ -1,39 +0,0 @@
-package com.bjsxd.test;
-
-public class Stack {
- private int top = -1;
- private Object[] elements;
- private int size = 0;
- public Stack(){
- elements = new Object[100];
- }
- public void push (Object o){
- elements[this.size] = o;
- this.size++;
- }
- public Object pop(){
- if (this.size != 0){
- Object temp = elements[size-1];
- elements[size-1]=0;
- size--;
- return temp;
- }else{
- System.out.println("ջ��");
- return 0;
- }
- }
- public Object peek(){
- if(!this.isEmpty()){
- Object temp = elements[this.size-1];
- elements[this.size-1] = 0;
- this.size--;
- return temp;
- }else{
- System.out.println("ջ��");
- return 0;
- }
- }
- public boolean isEmpty(){
- return this.size == 0;
- }
-}
diff --git a/group23/609041842/.classpath b/group23/609041842/.classpath
deleted file mode 100644
index 4449a3dae9..0000000000
--- a/group23/609041842/.classpath
+++ /dev/null
@@ -1,10 +0,0 @@
-
-
-
-
-
-
-
-
-
-
diff --git a/group23/609041842/.gitignore b/group23/609041842/.gitignore
deleted file mode 100644
index ae3c172604..0000000000
--- a/group23/609041842/.gitignore
+++ /dev/null
@@ -1 +0,0 @@
-/bin/
diff --git a/group23/609041842/.project b/group23/609041842/.project
deleted file mode 100644
index b2b4094e01..0000000000
--- a/group23/609041842/.project
+++ /dev/null
@@ -1,17 +0,0 @@
-
-
- 609041842coding
-
-
-
-
-
- org.eclipse.jdt.core.javabuilder
-
-
-
-
-
- org.eclipse.jdt.core.javanature
-
-
diff --git a/group23/609041842/.settings/org.eclipse.jdt.ui.prefs b/group23/609041842/.settings/org.eclipse.jdt.ui.prefs
deleted file mode 100644
index b6ec1a71fb..0000000000
--- a/group23/609041842/.settings/org.eclipse.jdt.ui.prefs
+++ /dev/null
@@ -1,60 +0,0 @@
-eclipse.preferences.version=1
-editor_save_participant_org.eclipse.jdt.ui.postsavelistener.cleanup=true
-sp_cleanup.add_default_serial_version_id=true
-sp_cleanup.add_generated_serial_version_id=false
-sp_cleanup.add_missing_annotations=true
-sp_cleanup.add_missing_deprecated_annotations=true
-sp_cleanup.add_missing_methods=false
-sp_cleanup.add_missing_nls_tags=false
-sp_cleanup.add_missing_override_annotations=true
-sp_cleanup.add_missing_override_annotations_interface_methods=true
-sp_cleanup.add_serial_version_id=false
-sp_cleanup.always_use_blocks=true
-sp_cleanup.always_use_parentheses_in_expressions=false
-sp_cleanup.always_use_this_for_non_static_field_access=false
-sp_cleanup.always_use_this_for_non_static_method_access=false
-sp_cleanup.convert_functional_interfaces=false
-sp_cleanup.convert_to_enhanced_for_loop=false
-sp_cleanup.correct_indentation=false
-sp_cleanup.format_source_code=true
-sp_cleanup.format_source_code_changes_only=false
-sp_cleanup.insert_inferred_type_arguments=false
-sp_cleanup.make_local_variable_final=true
-sp_cleanup.make_parameters_final=false
-sp_cleanup.make_private_fields_final=true
-sp_cleanup.make_type_abstract_if_missing_method=false
-sp_cleanup.make_variable_declarations_final=false
-sp_cleanup.never_use_blocks=false
-sp_cleanup.never_use_parentheses_in_expressions=true
-sp_cleanup.on_save_use_additional_actions=false
-sp_cleanup.organize_imports=true
-sp_cleanup.qualify_static_field_accesses_with_declaring_class=false
-sp_cleanup.qualify_static_member_accesses_through_instances_with_declaring_class=true
-sp_cleanup.qualify_static_member_accesses_through_subtypes_with_declaring_class=true
-sp_cleanup.qualify_static_member_accesses_with_declaring_class=false
-sp_cleanup.qualify_static_method_accesses_with_declaring_class=false
-sp_cleanup.remove_private_constructors=true
-sp_cleanup.remove_redundant_type_arguments=true
-sp_cleanup.remove_trailing_whitespaces=false
-sp_cleanup.remove_trailing_whitespaces_all=true
-sp_cleanup.remove_trailing_whitespaces_ignore_empty=false
-sp_cleanup.remove_unnecessary_casts=true
-sp_cleanup.remove_unnecessary_nls_tags=false
-sp_cleanup.remove_unused_imports=false
-sp_cleanup.remove_unused_local_variables=false
-sp_cleanup.remove_unused_private_fields=true
-sp_cleanup.remove_unused_private_members=false
-sp_cleanup.remove_unused_private_methods=true
-sp_cleanup.remove_unused_private_types=true
-sp_cleanup.sort_members=false
-sp_cleanup.sort_members_all=false
-sp_cleanup.use_anonymous_class_creation=false
-sp_cleanup.use_blocks=false
-sp_cleanup.use_blocks_only_for_return_and_throw=false
-sp_cleanup.use_lambda=true
-sp_cleanup.use_parentheses_in_expressions=false
-sp_cleanup.use_this_for_non_static_field_access=false
-sp_cleanup.use_this_for_non_static_field_access_only_if_necessary=true
-sp_cleanup.use_this_for_non_static_method_access=false
-sp_cleanup.use_this_for_non_static_method_access_only_if_necessary=true
-sp_cleanup.use_type_arguments=false
diff --git a/group23/609041842/src/com/homework01/ArrayList.java b/group23/609041842/src/com/homework01/ArrayList.java
deleted file mode 100644
index 1feb6162ad..0000000000
--- a/group23/609041842/src/com/homework01/ArrayList.java
+++ /dev/null
@@ -1,49 +0,0 @@
-package com.homework01;
-
-import java.util.Arrays;
-
-public class ArrayList {
-
- private Object[] obj = new Object[0];
-
- public void add(Object o) {
- Object[] tar = new Object[obj.length + 1];
- System.arraycopy(obj, 0, tar, 0, obj.length);
- tar[tar.length - 1] = o;
- obj = tar;
- System.out.println(Arrays.toString(obj));
- }
-
- public void add(int index, Object o) {
- Object[] tar = new Object[obj.length + 1];
- System.arraycopy(obj, 0, tar, 0, index);
- tar[index] = o;
- System.arraycopy(obj, index, tar, index + 1, obj.length - index);
- obj = tar;
- }
-
- public Object get(int index) {
- return obj[index];
- }
-
- public int size(){
- return obj.length;
- }
-
- public Object remove(int index){
- Object[] tar = new Object[obj.length-1];
- System.arraycopy(obj, 0, tar, 0, index);
- System.arraycopy(obj, index+1, tar, index, obj.length-index-1);
- Object o = obj[index];
- obj = tar;
- return o;//���ر�ɾԪ��
- }
- public static void main(String[] args) {
- ArrayList al = new ArrayList();
- al.add("hello");
- al.add("java");
- al.add(2, "addm");
- System.out.println(al.remove(1));
- }
-
-}
diff --git a/group23/609041842/src/com/homework01/LinkedList.java b/group23/609041842/src/com/homework01/LinkedList.java
deleted file mode 100644
index f18c110c7c..0000000000
--- a/group23/609041842/src/com/homework01/LinkedList.java
+++ /dev/null
@@ -1,87 +0,0 @@
-package com.homework01;
-
-public class LinkedList {
- private static Node head;
- private Node last;
- public int size;
-
- public void add(Object o) {
- Node l = last;
- Node newNode = new Node(l, o, null);
- last = newNode;
- if (head == null) {
- head = newNode;
- size = 1;
- } else {
- l.next = newNode;
- size++;
- }
- }
-
- public void add(int index, Object o) {
- Node n = node(index);
- System.out.println(n.data);
- Node pred = n.prev;
- Node newNode = new Node(pred, o, n);
- if (pred == null) {
- head = newNode;
- } else {
- pred.next = newNode;
- }
- size++;
- }
-
-
- public Node get(int index){
- return node(index);
- }
- public Node node(int index) {
- Node n = head;
- for (int i = 0; i < index; i++) {
- n = n.next;
- }
- return n;
- }
-
- public Node remove(int index){
- Node del = node(index);
- Node after = del.next;
- Node before = del.prev;
- before.next = after;
- after.prev = before;
- size--;
- return del;
- }
- private static class Node {
- Node next;
- Object data;
- Node prev;
-
- private Node(Node prev, Object data, Node next) {
- this.data = data;
- this.next = next;
- this.prev = prev;
- }
- }
-
- public static void main(String[] arg) {
- LinkedList ll = new LinkedList();
- ll.add("hello");
- ll.add("java");
- ll.add("jvm");
- ll.add("jvmd");
- // System.out.println(ll.get(2));
-// ll.add(1, "ds");
- System.out.println(ll.get(0).data);
- System.out.println(ll.get(1).data);
- System.out.println(ll.get(2).data);
- System.out.println(ll.get(3).data);
- System.out.println(ll.size);
- System.out.println(ll.remove(1).data);
- System.out.println(ll.get(0).data);
- System.out.println(ll.get(1).data);
- System.out.println(ll.get(2).data);
- System.out.println(ll.size);
- }
-
-}
diff --git a/group23/609041842/src/com/homework01/Queue.java b/group23/609041842/src/com/homework01/Queue.java
deleted file mode 100644
index afc54a2dda..0000000000
--- a/group23/609041842/src/com/homework01/Queue.java
+++ /dev/null
@@ -1,17 +0,0 @@
-package com.homework01;
-
-public class Queue {
-
- private LinkedList lk = new LinkedList();
- public void enQueue(Object o){
- lk.add(o);
- }
- public void deQueue(){
- lk.remove(lk.size-1);
- }
- public boolean isEmpty(){
- if(lk.size == 0)
- return true;
- return false;
- }
-}
diff --git a/group23/609041842/src/com/homework01/Stack.java b/group23/609041842/src/com/homework01/Stack.java
deleted file mode 100644
index a5bc4488af..0000000000
--- a/group23/609041842/src/com/homework01/Stack.java
+++ /dev/null
@@ -1,30 +0,0 @@
-package com.homework01;
-
-public class Stack {
-
- private ArrayList array = new ArrayList();
-
- public void push(Object o){
- array.add(o);
- }
- public Object pop(){
- return array.remove(array.size()-1);
- }
-
- public boolean isEmpty(){
- if(array.size()<=0)
- return true;
- return false;
- }
-
- public int size(){
- return array.size();
- }
- public static void main(String[] args) {
- Stack sc = new Stack();
- sc.push("hello world");
- sc.push("java");
- sc.push("jvm");
- }
-
-}
diff --git a/group23/609041842/src/test.java b/group23/609041842/src/test.java
deleted file mode 100644
index 931a307711..0000000000
--- a/group23/609041842/src/test.java
+++ /dev/null
@@ -1,9 +0,0 @@
-import org.junit.Test;
-
-public class test {
-
- @Test
- public void test(){
- System.out.println("Heool");
- }
-}
diff --git a/group23/632678665/com/basic/datastructure/ArrayList.java b/group23/632678665/com/basic/datastructure/ArrayList.java
deleted file mode 100644
index 35fb185737..0000000000
--- a/group23/632678665/com/basic/datastructure/ArrayList.java
+++ /dev/null
@@ -1,64 +0,0 @@
-package com.basic.datastructure;
-
-import java.util.Arrays;
-
-import org.junit.Test;
-
-public class ArrayList implements List{
- private Object [] array =new Object [15];
- private int size=0;
- private int aindex=0;
- @Override
- public void add(Object o) {
- if(aindex>(int)(array.length/3*2)){
- array=autoGrew(array);
- }
- array[aindex]=o;
- size++;
- aindex++;
- }
-
- @Override
- public void add(int index, Object o) {
- if(index>=array.length){
- throw new IndexOutOfBoundsException();
- }
- array[index]=o;
- size++;
- aindex=index;
- }
-
- @Override
- public Object get(int index) {
- if(index>=array.length){
- throw new IndexOutOfBoundsException();
- }
- return array[index];
- }
-
- @Override
- public Object remove(int index) {
- if(index>=array.length){
- throw new IndexOutOfBoundsException();
- }
- Object o=array[index];
- for(int i=index;iarray=new ArrayList ();
- int from;
- int to;
- for(int i=0;i list=new ArrayList();
- for(int i=0;i set=new HashSet();
- set.addAll(list);
- Object[] array=set.toArray();
- int [] arrayInt=new int [array.length];
- for(int i=0;ilist=new ArrayList();
- list.add(front);
- list.add(behind);
- while(true){
- result=front+behind;
- if(max list=new ArrayList();
- int num=3;
- list.add(2);
- boolean flag=true;
- while(true){
- flag=true;
- for(int i=2;i list=new ArrayList();
- Set temp=new HashSet();
- int num=1;
- int result=0;
- while(true){
- for(int i=1;imax){
- break;
- }
- if(num==result){
- list.add(num);
- }
- temp.clear();
- result=0;
- num++;
- }
- int [] array=new int [list.size()];
- for(int i=0;i list=new ArrayList();
- for(int i=0;i
-
-
-
-
-
-
diff --git a/group23/729693763/First_Homework1/.project b/group23/729693763/First_Homework1/.project
deleted file mode 100644
index 5022bfb83c..0000000000
--- a/group23/729693763/First_Homework1/.project
+++ /dev/null
@@ -1,17 +0,0 @@
-
-
- First_Homework1
-
-
-
-
-
- org.eclipse.jdt.core.javabuilder
-
-
-
-
-
- org.eclipse.jdt.core.javanature
-
-
diff --git a/group23/729693763/First_Homework1/.settings/org.eclipse.core.resources.prefs b/group23/729693763/First_Homework1/.settings/org.eclipse.core.resources.prefs
deleted file mode 100644
index 99f26c0203..0000000000
--- a/group23/729693763/First_Homework1/.settings/org.eclipse.core.resources.prefs
+++ /dev/null
@@ -1,2 +0,0 @@
-eclipse.preferences.version=1
-encoding/=UTF-8
diff --git a/group23/729693763/First_Homework1/.settings/org.eclipse.jdt.core.prefs b/group23/729693763/First_Homework1/.settings/org.eclipse.jdt.core.prefs
deleted file mode 100644
index 3a21537071..0000000000
--- a/group23/729693763/First_Homework1/.settings/org.eclipse.jdt.core.prefs
+++ /dev/null
@@ -1,11 +0,0 @@
-eclipse.preferences.version=1
-org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
-org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
-org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
-org.eclipse.jdt.core.compiler.compliance=1.8
-org.eclipse.jdt.core.compiler.debug.lineNumber=generate
-org.eclipse.jdt.core.compiler.debug.localVariable=generate
-org.eclipse.jdt.core.compiler.debug.sourceFile=generate
-org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
-org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
-org.eclipse.jdt.core.compiler.source=1.8
diff --git a/group23/729693763/First_Homework1/readme.md b/group23/729693763/First_Homework1/readme.md
deleted file mode 100644
index 219dee010b..0000000000
--- a/group23/729693763/First_Homework1/readme.md
+++ /dev/null
@@ -1,2 +0,0 @@
-It contain source code and Test file by JUnit,
-you can run SuitTest for testing whole file.
diff --git a/group23/729693763/First_Homework1/src/com/danny/hw1/ArrayList.java b/group23/729693763/First_Homework1/src/com/danny/hw1/ArrayList.java
deleted file mode 100644
index ccb3bcb12c..0000000000
--- a/group23/729693763/First_Homework1/src/com/danny/hw1/ArrayList.java
+++ /dev/null
@@ -1,117 +0,0 @@
-package com.danny.hw1;
-
-import java.lang.reflect.Array;
-import java.util.Arrays;
-
-import javax.print.attribute.Size2DSyntax;
-
-public class ArrayList implements List{
- //ArrayList Size
- private int size=0;
- private int array_len=2;
-
- //total element in here
- private Object[] elementData = new Object[array_len];
-
- @Override
- public void add(Object o) {
- // TODO Auto-generated method stub
- adjustCapacity();
- this.elementData[size++] = o;
- }
-
- @Override
- public void add(int index, Object o) {
- // TODO Auto-generated method stub
- //Check range. if index is invalid,then would not add anythings
- rangeCheckForAdd(index);
-
- adjustCapacity();
- System.arraycopy(elementData, index, elementData,
- index + 1,size - index);
- this.elementData[index] = o;
- this.size++;
-
- }
-
- @Override
- public Object get(int index) {
- // TODO Auto-generated method stub
- rangeCheckExist(index);
-
- return elementData[index];
-
- }
-
- @Override
- public Object remove(int index) {
- // TODO Auto-generated method stub
- rangeCheckExist(index);
-
- Object oldValue = elementData[index];
- //deal with copy operation
- int moveStep = size - index - 1;
- if ( moveStep > 0 )
- System.arraycopy(elementData, index+1, elementData, index,moveStep);
- elementData[--size] = null; // clear to let GC do its work
-
- return oldValue;
-
- }
-
- @Override
- public int size() {
- // TODO Auto-generated method stub
- return this.size;
- }
-
- //Get Iterator
- public Iterator iterator() {
- return new ArrayListIterator();
- }
-
- /******* Iterator *******/
- private class ArrayListIterator implements Iterator{
-
- private int currentIndex = 0;
-
- @Override
- public boolean hasNext() {
- return currentIndex < size();
- }
-
- @Override
- public Object next() {
- rangeCheckExist(currentIndex);
-
- return elementData[currentIndex++];
- }
- }
-
-
- /*******Inner function*******/
- //Increase arraylist size
- private void adjustCapacity(){
- //array length can not satisfy data size;
- if ( this.array_len < size() + 1 ) {
- this.array_len *= 2;
- this.elementData = Arrays.copyOf(elementData, array_len);
- } else {
- return ;
- }
- }
-
- private void rangeCheckForAdd(int index) {
- //Add operation is allow to add value in [ size() ] even if [ size() ] has not data
- if ( index > size() || index < 0 )
- throw new IndexOutOfBoundsException("Invalid Adding Index:"+index);
- }
- private void rangeCheckExist(int index) {
- if ( index >= size() || index < 0 )
- throw new IndexOutOfBoundsException("Invalid Index:"+index);
- }
-
-
-
-
-}
diff --git a/group23/729693763/First_Homework1/src/com/danny/hw1/BinaryTreeNode.java b/group23/729693763/First_Homework1/src/com/danny/hw1/BinaryTreeNode.java
deleted file mode 100644
index 8e3178b50b..0000000000
--- a/group23/729693763/First_Homework1/src/com/danny/hw1/BinaryTreeNode.java
+++ /dev/null
@@ -1,101 +0,0 @@
-package com.danny.hw1;
-
-import java.util.Map;
-import java.util.TreeMap;
-
-public class BinaryTreeNode {
- private Object data;
- private BinaryTreeNode left;
- private BinaryTreeNode right;
-
- public BinaryTreeNode insert(Object o){
- if ( this.data == null && left == null && right == null ) {
- this.data = o;
- return this;
- } else {
- BinaryTreeNode temp = findNode(this, o);
-
- BinaryTreeNode newNode = new BinaryTreeNode();
- newNode.data = o;
- //assert more than one null node in the temp(left,right,or both);
- if ( temp.compareTo(o) >= 0 ) {
- temp.left = newNode;
- } else {
- temp.right = newNode;
- }
- return newNode;
- }
- }
-
- public BinaryTreeNode() {
- // TODO Auto-generated constructor stub
- data=null;
- left =null;
- right = null;
-
- }
-
- public Object getData() {
- return data;
- }
- public void setData(Object data) {
- this.data = data;
- }
- public BinaryTreeNode getLeft() {
- return left;
- }
- public void setLeft(BinaryTreeNode left) {
- this.left = left;
- }
- public BinaryTreeNode getRight() {
- return right;
- }
- public void setRight(BinaryTreeNode right) {
- this.right = right;
- }
-
- private int compareTo(Object o){
- // o1 > o2 == 1; o1 = o2 == 0 ; o1 < o2 == -1
- //假设这个比较现在只用在数字上
- return Integer.parseInt(this.data.toString()) - Integer.parseInt(o.toString());
- }
-
- private static BinaryTreeNode findNode(BinaryTreeNode root,Object o){
- if ( root.left == null && root.right == null ||
- ( root.compareTo(o) < 0 && root.right == null) ||
- ( root.compareTo(o) >= 0 && root.left == null) ){
- return root;
- } else if ( root.compareTo(o) >= 0 ) {
- //root data is bigger than object
- return findNode(root.left, o);
- } else {
- return findNode(root.right, o);
- }
-// else if(root.compareTo(o) < 0 ){
-// return findNode(root.right, o);
-// }
-//
- }
-
- //For Test value
- private Map