From 608ff37635d551bf70ab2f542ae305782f74dd88 Mon Sep 17 00:00:00 2001 From: xdx54321 <20409287@qq.com> Date: Tue, 14 Mar 2017 21:08:42 +0800 Subject: [PATCH] =?UTF-8?q?=E7=AC=AC=E4=B8=89=E6=AC=A1=E4=BD=9C=E4=B8=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../first => com/basic}/ArrayList.java | 2 +- .../src/com/basic/BinaryTreeNode.java | 32 ++ .../homework/first => com/basic}/Hello.java | 4 +- .../first => com/basic}/Iterator.java | 2 +- .../20409287/src/com/basic/LinkedList.java | 405 ++++++++++++++++++ .../homework/first => com/basic}/List.java | 2 +- .../homework/first => com/basic}/Queue.java | 2 +- .../homework/first => com/basic}/Stack.java | 2 +- .../basic/test}/ArrayListTest.java | 2 +- .../basic/test}/LinkedListTest.java | 119 ++++- .../first => com/basic/test}/QueueTest.java | 6 +- .../first => com/basic/test}/StackTest.java | 6 +- .../com/coderising/array/ArrayListTest.java | 182 ++++++++ .../coderising}/array/ArrayUtil.java | 5 +- .../coderising/download/DownloadThread.java | 60 +++ .../coderising/download/FileDownloader.java | 86 ++++ .../download/FileDownloaderTest.java | 54 +++ .../coderising/download/api/Connection.java | 23 + .../download/api/ConnectionException.java | 8 + .../download/api/ConnectionManager.java | 10 + .../download/api/DownloadListener.java | 5 + .../download/impl/ConnectionImpl.java | 51 +++ .../download/impl/ConnectionManagerImpl.java | 24 ++ .../coderising}/litestruts/LoginAction.java | 2 +- .../coderising}/litestruts/Struts.java | 7 +- .../coderising}/litestruts/StrutsTest.java | 8 +- .../coderising}/litestruts/View.java | 2 +- .../coderising}/litestruts/struts.xml | 0 .../java/xdx/homework/first/LinkedList.java | 246 ----------- .../xdx/homework/second/ArrayUtilTest.java | 157 ------- 30 files changed, 1078 insertions(+), 436 deletions(-) rename group07/20409287/src/{main/java/xdx/homework/first => com/basic}/ArrayList.java (99%) create mode 100644 group07/20409287/src/com/basic/BinaryTreeNode.java rename group07/20409287/src/{main/java/xdx/homework/first => com/basic}/Hello.java (80%) rename group07/20409287/src/{main/java/xdx/homework/first => com/basic}/Iterator.java (75%) create mode 100644 group07/20409287/src/com/basic/LinkedList.java rename group07/20409287/src/{main/java/xdx/homework/first => com/basic}/List.java (97%) rename group07/20409287/src/{main/java/xdx/homework/first => com/basic}/Queue.java (98%) rename group07/20409287/src/{main/java/xdx/homework/first => com/basic}/Stack.java (98%) rename group07/20409287/src/{test/xdx/homework/first => com/basic/test}/ArrayListTest.java (99%) rename group07/20409287/src/{test/xdx/homework/first => com/basic/test}/LinkedListTest.java (62%) rename group07/20409287/src/{test/xdx/homework/first => com/basic/test}/QueueTest.java (99%) rename group07/20409287/src/{test/xdx/homework/first => com/basic/test}/StackTest.java (98%) create mode 100644 group07/20409287/src/com/coderising/array/ArrayListTest.java rename group07/20409287/src/{main/java/xdx/homework/second => com/coderising}/array/ArrayUtil.java (98%) create mode 100644 group07/20409287/src/com/coderising/download/DownloadThread.java create mode 100644 group07/20409287/src/com/coderising/download/FileDownloader.java create mode 100644 group07/20409287/src/com/coderising/download/FileDownloaderTest.java create mode 100644 group07/20409287/src/com/coderising/download/api/Connection.java create mode 100644 group07/20409287/src/com/coderising/download/api/ConnectionException.java create mode 100644 group07/20409287/src/com/coderising/download/api/ConnectionManager.java create mode 100644 group07/20409287/src/com/coderising/download/api/DownloadListener.java create mode 100644 group07/20409287/src/com/coderising/download/impl/ConnectionImpl.java create mode 100644 group07/20409287/src/com/coderising/download/impl/ConnectionManagerImpl.java rename group07/20409287/src/{main/java/xdx/homework/second => com/coderising}/litestruts/LoginAction.java (95%) rename group07/20409287/src/{main/java/xdx/homework/second => com/coderising}/litestruts/Struts.java (96%) rename group07/20409287/src/{main/java/xdx/homework/second => com/coderising}/litestruts/StrutsTest.java (91%) rename group07/20409287/src/{main/java/xdx/homework/second => com/coderising}/litestruts/View.java (89%) rename group07/20409287/src/{main/java/xdx/homework/second => com/coderising}/litestruts/struts.xml (100%) delete mode 100644 group07/20409287/src/main/java/xdx/homework/first/LinkedList.java delete mode 100644 group07/20409287/src/test/xdx/homework/second/ArrayUtilTest.java diff --git a/group07/20409287/src/main/java/xdx/homework/first/ArrayList.java b/group07/20409287/src/com/basic/ArrayList.java similarity index 99% rename from group07/20409287/src/main/java/xdx/homework/first/ArrayList.java rename to group07/20409287/src/com/basic/ArrayList.java index f8757c9a68..40fdc22d18 100644 --- a/group07/20409287/src/main/java/xdx/homework/first/ArrayList.java +++ b/group07/20409287/src/com/basic/ArrayList.java @@ -1,4 +1,4 @@ -package xdx.homework.first; +package com.basic; public class ArrayList implements List { diff --git a/group07/20409287/src/com/basic/BinaryTreeNode.java b/group07/20409287/src/com/basic/BinaryTreeNode.java new file mode 100644 index 0000000000..48ad6e0ef3 --- /dev/null +++ b/group07/20409287/src/com/basic/BinaryTreeNode.java @@ -0,0 +1,32 @@ +package com.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/group07/20409287/src/main/java/xdx/homework/first/Hello.java b/group07/20409287/src/com/basic/Hello.java similarity index 80% rename from group07/20409287/src/main/java/xdx/homework/first/Hello.java rename to group07/20409287/src/com/basic/Hello.java index 1abb23045e..ca0b713827 100644 --- a/group07/20409287/src/main/java/xdx/homework/first/Hello.java +++ b/group07/20409287/src/com/basic/Hello.java @@ -1,6 +1,4 @@ -package xdx.homework.first; - -import java.util.List; +package com.basic; /** * @Description: Hello World! diff --git a/group07/20409287/src/main/java/xdx/homework/first/Iterator.java b/group07/20409287/src/com/basic/Iterator.java similarity index 75% rename from group07/20409287/src/main/java/xdx/homework/first/Iterator.java rename to group07/20409287/src/com/basic/Iterator.java index b90db66d5d..146e8329f7 100644 --- a/group07/20409287/src/main/java/xdx/homework/first/Iterator.java +++ b/group07/20409287/src/com/basic/Iterator.java @@ -1,4 +1,4 @@ -package xdx.homework.first; +package com.basic; public interface Iterator { diff --git a/group07/20409287/src/com/basic/LinkedList.java b/group07/20409287/src/com/basic/LinkedList.java new file mode 100644 index 0000000000..5b24307b63 --- /dev/null +++ b/group07/20409287/src/com/basic/LinkedList.java @@ -0,0 +1,405 @@ +package com.basic; + +import java.util.Stack; + +/** + * @Description: 链式列表 + */ +public class LinkedList implements List { + + private class Node { + + private E data; // 数据域 + + private Node next; // 指针域 + + public Node() { + } + + private Node(E data) { + this.data = data; + this.next = null; + } + + } + + // 链表大小 + private int size = 0; + + private Node head; + + private Node tail; + + /** + * 添加元素 + * + * @param data + * @return + */ + @Override + public boolean add(E data) { + + if (this.head != null) { + Node newNode = new Node(data); + this.tail.next = newNode; + this.tail = newNode; + } else { + this.head = new Node(data); + this.tail = this.head; + } + size++; + return true; + } + + /** + * 删除指定索引的元素 + * + * @param index@return + */ + @Override + public E remove(int index) { + + if (index < 0 || index > size) { + throw new IndexOutOfBoundsException("索引不正确!"); + } + if (isEmpty()) { + throw new RuntimeException("链表为空!"); + } + Node currentNode = this.head; + Node preNode = currentNode; + for (int i = 0; i < index; i++) { + preNode = currentNode; + currentNode = currentNode.next; + } + // 如果是头结点 + if (currentNode == preNode) { + head = head.next; + } else if (currentNode.next == null) { + // 如果是尾结点 + tail = preNode; + tail.next = null; + } else { + preNode.next = currentNode.next; + } + size--; + return currentNode.data; + } + + /** + * 删除指定的元素 + * + * @param e + * @return + */ + @Override + public boolean remove(E e) { + + if (!this.contains(e)) return false; + + if (this.head.data.equals(e)) { + this.head = this.head.next; + size--; + return true; + } + Node currentNode = this.head; + Node preNode = currentNode; + boolean isFind = false; + for (int i = 0; i < size; i++) { + if (currentNode.data.equals(e)) { + isFind = true; + break; + } + preNode = currentNode; + currentNode = currentNode.next; + } + if (!isFind) return false; + preNode.next = currentNode.next; + size--; + return true; + } + + /** + * 返回列表长度 + * + * @return + */ + @Override + public int size() { + return size; + } + + /** + * 判断列表是否为空 + * + * @return + */ + @Override + public boolean isEmpty() { + return size == 0; + } + + /** + * 获取指定索引的元素 + * + * @param index + * @return + */ + @Override + public E get(int index) { + + if (index < 0 || index > size || isEmpty()) { + throw new IndexOutOfBoundsException("索引不正确!"); + } + Node currentNode = this.head; + for (int i = 0; i < index; i++) { + currentNode = currentNode.next; + } + return currentNode.data; + } + + /** + * 重置某个索引的元素 + * + * @param index + * @param e + * @return + */ + @Override + public boolean set(int index, E e) { + + if (index < 0 || index > size || isEmpty()) { + throw new IndexOutOfBoundsException("索引不正确!"); + } + Node currentNode = this.head; + for (int i = 0; i < index; i++) { + currentNode = currentNode.next; + } + currentNode.data = e; + return false; + } + + /** + * 判断是否包含某个元素 + * + * @param e + * @return + */ + @Override + public boolean contains(E e) { + + if (isEmpty()) return false; + Node currentNode = this.head; + boolean isFind = false; + for (int i = 0; i < size(); i++) { + if (currentNode.data.equals(e)) { + isFind = true; + } + currentNode = currentNode.next; + } + return isFind; + } + + /** + * 清空列表 + */ + @Override + public void clear() { + this.head = this.tail = null; + size = 0; + } + + @Override + public String toString() { + + if (isEmpty()) return "[]"; + StringBuilder strLinkedList = new StringBuilder("["); + Node currentNode = this.head; + while (currentNode.next != null) { + strLinkedList.append(currentNode.data.toString()).append(","); + currentNode = currentNode.next; + } + strLinkedList.append(currentNode.data.toString()).append("]"); + return strLinkedList.toString(); + } + + /** + * 把该链表逆置 + * 例如链表为 3->7->10 , 逆置后变为 10->7->3 + */ + public void reverse() { + + if (this.isEmpty()) return; + Stack stack = new Stack<>(); + for (int i = 0; i < this.size(); i++) { + stack.push(this.get(i)); + } + int i = 0; + while (!stack.isEmpty()) { + this.set(i++, stack.pop()); + } + } + + /** + * 删除一个单链表的前半部分 + * 例如:list = 2->5->7->8 , 删除以后的值为 7->8 + * 如果list = 2->5->7->8->10 ,删除以后的值为7,8,10 + */ + public void removeFirstHalf() { + + int begin = size / 2; + while (begin-- > 0) { + this.remove(0); + } + } + + /** + * 从第i个元素开始, 删除length 个元素 , 注意i从0开始 + * + * @param i + * @param length + */ + public void remove(int i, int length) { + + if (i < 0 || i > size) { + throw new IndexOutOfBoundsException("索引不正确: " + i); + } + while (length-- > 0 && size() > i) { + remove(i); + } + } + + /** + * 假定当前链表和list均包含已升序排列的整数 + * 从当前链表中取出那些list所指定的元素 + * 例如当前链表 = 11->101->201->301->401->501->601->701 + * listB = 1->3->4->6 + * 返回的结果应该是[101,301,401,601] + * + * @param list + */ + public Object[] getElements(LinkedList list) { + + Object[] data = new Object[list.size()]; + for (int i = 0; i < list.size(); i++) { + data[i] = this.get(list.get(i)).toString(); + } + return data; + } + + /** + * 已知链表中的元素以值递增有序排列,并以单链表作存储结构。 + * 从当前链表中中删除在list中出现的元素 + * + * @param list + */ + @SuppressWarnings("unchecked") + public void subtract(LinkedList list) { + + Object[] removeDatas = getElements(list); + for (Object removeData : removeDatas) { + remove((E) removeData); + } + } + + /** + * 已知当前链表中的元素以值递增有序排列,并以单链表作存储结构。 + * 删除表中所有值相同的多余元素(使得操作后的线性表中所有元素的值均不相同) + */ + public void removeDuplicateValues() { + + Node node = head; // 哨兵 + while (node.next != null) { + if (node.data.equals(node.next.data)) { + Node delNode = node.next; + node.next = node.next.next; + delNode = null; + } else { + node = node.next; + } + } + } + + /** + * 已知链表中的元素以值递增有序排列,并以单链表作存储结构。 + * 试写一高效的算法,删除表中所有值大于min且小于max的元素(若表中存在这样的元素) + * + * @param min + * @param max + */ + public void removeRange(int min, int max) { + + if (max < min) throw new RuntimeException("max大于min!"); + + if (Integer.parseInt(head.data.toString()) > min) return; + if (Integer.parseInt(tail.data.toString()) < max) return; + Node begin = head; // 要删除的开始结点 + Node end = tail; // 要删除的结束结点 + Node currentNode = head; + boolean beginFound = false; // 已找到开始结点标志 + Node preNode = head; + while (currentNode.next != null) { + if (!beginFound && min < Integer.parseInt(currentNode.data.toString())) { + begin = preNode; + beginFound = true; + } + if (max > Integer.parseInt(currentNode.data.toString())) { + end = currentNode; + } + preNode = currentNode; + currentNode = currentNode.next; + } + begin.next = end.next; + } + + /** + * 假设当前链表和参数list指定的链表均以元素依值递增有序排列(同一表中的元素值各不相同) + * 现要求生成新链表C,其元素为当前链表和list中元素的交集,且表C中的元素有依值递增有序排列 + * + * @param list + */ + @SuppressWarnings("unchecked") + public LinkedList intersection(LinkedList list) { + + LinkedList linkedListC = new LinkedList(); + for (int i = 0; i < list.size(); i++) { + Object element = list.get(i); + if (this.contains((E) element)) { + linkedListC.add(list.get(i)); + } + } + return linkedListC; + } + + /** + * 取得迭代器 + * + * @return + */ + @Override + public Iterator iterator() { + return new Itr(); + } + + private class Itr implements Iterator { + + Node curNode = LinkedList.this.head; + + @Override + public boolean hasNext() { + return curNode != null; + } + + @Override + public E next() { + Node thisNode = curNode; + curNode = curNode.next; + return thisNode.data; + } + + @Override + public void remove() { + LinkedList.this.remove(curNode.data); + curNode = curNode.next; + } + } +} diff --git a/group07/20409287/src/main/java/xdx/homework/first/List.java b/group07/20409287/src/com/basic/List.java similarity index 97% rename from group07/20409287/src/main/java/xdx/homework/first/List.java rename to group07/20409287/src/com/basic/List.java index 7c6f1c4e52..acfa85a87a 100644 --- a/group07/20409287/src/main/java/xdx/homework/first/List.java +++ b/group07/20409287/src/com/basic/List.java @@ -1,4 +1,4 @@ -package xdx.homework.first; +package com.basic; /** * @param diff --git a/group07/20409287/src/main/java/xdx/homework/first/Queue.java b/group07/20409287/src/com/basic/Queue.java similarity index 98% rename from group07/20409287/src/main/java/xdx/homework/first/Queue.java rename to group07/20409287/src/com/basic/Queue.java index 5d98cff312..e57db19b18 100644 --- a/group07/20409287/src/main/java/xdx/homework/first/Queue.java +++ b/group07/20409287/src/com/basic/Queue.java @@ -1,4 +1,4 @@ -package xdx.homework.first; +package com.basic; /** * @Description: 链式队列 diff --git a/group07/20409287/src/main/java/xdx/homework/first/Stack.java b/group07/20409287/src/com/basic/Stack.java similarity index 98% rename from group07/20409287/src/main/java/xdx/homework/first/Stack.java rename to group07/20409287/src/com/basic/Stack.java index d898ffeb6e..d916591fcf 100644 --- a/group07/20409287/src/main/java/xdx/homework/first/Stack.java +++ b/group07/20409287/src/com/basic/Stack.java @@ -1,4 +1,4 @@ -package xdx.homework.first; +package com.basic; /** * @Description: diff --git a/group07/20409287/src/test/xdx/homework/first/ArrayListTest.java b/group07/20409287/src/com/basic/test/ArrayListTest.java similarity index 99% rename from group07/20409287/src/test/xdx/homework/first/ArrayListTest.java rename to group07/20409287/src/com/basic/test/ArrayListTest.java index d19cdb3dec..9dd117ec07 100644 --- a/group07/20409287/src/test/xdx/homework/first/ArrayListTest.java +++ b/group07/20409287/src/com/basic/test/ArrayListTest.java @@ -1,4 +1,4 @@ -package xdx.homework.first; +package com.basic.test; import org.junit.After; diff --git a/group07/20409287/src/test/xdx/homework/first/LinkedListTest.java b/group07/20409287/src/com/basic/test/LinkedListTest.java similarity index 62% rename from group07/20409287/src/test/xdx/homework/first/LinkedListTest.java rename to group07/20409287/src/com/basic/test/LinkedListTest.java index dabbc04a96..d27ee61553 100644 --- a/group07/20409287/src/test/xdx/homework/first/LinkedListTest.java +++ b/group07/20409287/src/com/basic/test/LinkedListTest.java @@ -1,9 +1,12 @@ -package xdx.homework.first; +package com.basic.test; +import org.junit.After; import org.junit.Assert; -import org.junit.Test; import org.junit.Before; -import org.junit.After; +import org.junit.Test; + +import java.util.Arrays; +import java.util.Random; /** * LinkedList Tester. @@ -218,5 +221,115 @@ public void testRemove() throws Exception { } + @Test + public void testReverse() { + + LinkedList testLinkedList = new LinkedList<>(); + for (int i = 0; i < 10; i++) { + testLinkedList.add(i + "号"); + } + System.out.println("原链表:" + testLinkedList); + testLinkedList.reverse(); + System.out.println("转置后:" + testLinkedList); + } + + @Test + public void testRemoveFirstHalf() { + + LinkedList testLinkedList = new LinkedList<>(); + for (int i = 0; i < 10; i++) { + testLinkedList.add(i + "号"); + } + System.out.println("原链表:" + testLinkedList); + testLinkedList.removeFirstHalf(); + System.out.println("删除前面一半后:" + testLinkedList); + } + + @Test + public void testRemoveLength() { + + LinkedList testLinkedList = new LinkedList<>(); + for (int i = 0; i < 10; i++) { + testLinkedList.add(i + "号"); + } + System.out.println("原链表:" + testLinkedList); + testLinkedList.remove(5, 3); + System.out.println("删除后:" + testLinkedList); + } + + @Test + public void testGetElement() { + + LinkedList testLinkedList = new LinkedList<>(); + for (int i = 0; i < 10; i++) { + testLinkedList.add(i + "号"); + } + LinkedList indexLinkedList = new LinkedList<>(); + indexLinkedList.add(1); + indexLinkedList.add(3); + indexLinkedList.add(5); + System.out.println("原链表:" + testLinkedList); + System.out.println("取的索引:" + indexLinkedList); + System.out.println("取的值:" + Arrays.toString(testLinkedList.getElements(indexLinkedList))); + } + + @Test + public void testSubstract() { + + LinkedList testLinkedList = new LinkedList<>(); + for (int i = 0; i < 10; i++) { + testLinkedList.add(i + "号"); + } + LinkedList indexLinkedList = new LinkedList<>(); + indexLinkedList.add(1); + indexLinkedList.add(3); + indexLinkedList.add(5); + System.out.println("原链表:" + testLinkedList); + System.out.println("要删除的索引:" + indexLinkedList); + testLinkedList.subtract(indexLinkedList); + System.out.println("删除后的链表:" + testLinkedList); + } + + @Test + public void testRemoveDuplicateValues() { + + LinkedList testLinkedList = new LinkedList<>(); + for (int i = 0; i < 10; i++) { + testLinkedList.add(i); + testLinkedList.add(i); + } + System.out.println("原链表:" + testLinkedList); + testLinkedList.removeDuplicateValues(); + System.out.println("去重后:" + testLinkedList); + } + + @Test + public void testRemoveRange() { + + LinkedList testLinkedList = new LinkedList<>(); + for (int i = 0; i < 10000; i++) { + testLinkedList.add(i); + } + System.out.println("原链表:" + testLinkedList); + testLinkedList.removeRange(0, 8000); + System.out.println("删除指定区间后:" + testLinkedList); + } + + @Test + public void testIntersection() { + + LinkedList testLinkedList1 = new LinkedList<>(); + for (int i = 0; i < 50; i += 3) { + testLinkedList1.add(i); + } + System.out.println("链表1: " + testLinkedList1); + LinkedList testLinkedList2 = new LinkedList<>(); + Random random = new Random(); + for (int i = 0; i < 100; i += 5) { + testLinkedList2.add(i); + } + System.out.println("链表2: " + testLinkedList2); + System.out.println("交 集: " + testLinkedList1.intersection(testLinkedList2)); + } } diff --git a/group07/20409287/src/test/xdx/homework/first/QueueTest.java b/group07/20409287/src/com/basic/test/QueueTest.java similarity index 99% rename from group07/20409287/src/test/xdx/homework/first/QueueTest.java rename to group07/20409287/src/com/basic/test/QueueTest.java index 6e56e3b8b1..eca3e266bd 100644 --- a/group07/20409287/src/test/xdx/homework/first/QueueTest.java +++ b/group07/20409287/src/com/basic/test/QueueTest.java @@ -1,9 +1,9 @@ -package xdx.homework.first; +package com.basic.test; +import org.junit.After; import org.junit.Assert; -import org.junit.Test; import org.junit.Before; -import org.junit.After; +import org.junit.Test; import xdx.homework.first.Queue; /** diff --git a/group07/20409287/src/test/xdx/homework/first/StackTest.java b/group07/20409287/src/com/basic/test/StackTest.java similarity index 98% rename from group07/20409287/src/test/xdx/homework/first/StackTest.java rename to group07/20409287/src/com/basic/test/StackTest.java index bfc6b2c8f7..3440e39310 100644 --- a/group07/20409287/src/test/xdx/homework/first/StackTest.java +++ b/group07/20409287/src/com/basic/test/StackTest.java @@ -1,9 +1,9 @@ -package test.xdx.homework.first; +package com.basic.test; +import org.junit.After; import org.junit.Assert; -import org.junit.Test; import org.junit.Before; -import org.junit.After; +import org.junit.Test; import xdx.homework.first.Stack; /** diff --git a/group07/20409287/src/com/coderising/array/ArrayListTest.java b/group07/20409287/src/com/coderising/array/ArrayListTest.java new file mode 100644 index 0000000000..868e326eba --- /dev/null +++ b/group07/20409287/src/com/coderising/array/ArrayListTest.java @@ -0,0 +1,182 @@ +package com.coderising.array; + + +import org.junit.After; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +/** + * ArrayList Tester. + * + * @author xdx + * @version 1.0 + * @since
2月25日, 2017
+ */ +public class ArrayListTest { + + private List defaultTestList; + + @Before + public void before() throws Exception { + + defaultTestList = new ArrayList<>(); + Assert.assertTrue(defaultTestList.add("《三国演义》")); + Assert.assertTrue(defaultTestList.add("《红楼梦》")); + Assert.assertTrue(defaultTestList.add("《西游记》")); + Assert.assertTrue(defaultTestList.add("《水浒传》")); + } + + @After + public void after() throws Exception { + } + + /** + * Method: add(E e) + */ + @Test + public void testAdd() throws Exception { + + List testList = new ArrayList<>(); + final int NUM = 1000000; + for (Integer i = 0; i < NUM; i++) { + testList.add(i); + } + for (Integer i = 0; i < NUM; i++) { + Assert.assertEquals(i, testList.get(i)); + } + Assert.assertEquals(NUM, testList.size()); + System.out.println(testList.toString()); + } + + /** + * Method: remove(int index) + */ + @Test + public void testRemoveIndex() throws Exception { + + List testReomoveList = new ArrayList<>(); + Assert.assertTrue(testReomoveList.add(4)); + Assert.assertTrue(testReomoveList.add(5)); + Assert.assertTrue(testReomoveList.add(6)); + System.out.println("删除前: " + testReomoveList); + Integer delElement = testReomoveList.get(0); + Assert.assertTrue(testReomoveList.remove(0).equals(delElement)); + System.out.println("删除后: " + testReomoveList); + } + + /** + * Method: remove(E e) + */ + @Test + public void testRemoveE() throws Exception { + + List testReomoveList = new ArrayList<>(); + Assert.assertTrue(testReomoveList.add(7)); + Assert.assertTrue(testReomoveList.add(8)); + Assert.assertTrue(testReomoveList.add(9)); + System.out.println("删除前: " + testReomoveList); + Assert.assertTrue(testReomoveList.remove(new Integer(8))); + System.out.println("删除后: " + testReomoveList); + } + + /** + * Method: size() + */ + @Test + public void testSize() throws Exception { + int size = defaultTestList.size(); + Assert.assertEquals(4, size); + System.out.println("defaultTest内容:" + defaultTestList); + System.out.println("defaultTest长度:" + size); + } + + /** + * Method: isEmpty() + */ + @Test + public void testIsEmpty() throws Exception { + Assert.assertFalse(defaultTestList.isEmpty()); + List testReomoveList = new ArrayList<>(); + Assert.assertTrue(testReomoveList.isEmpty()); + } + + /** + * Method: get(int index) + */ + @Test + public void testGet() throws Exception { + Assert.assertTrue("《三国演义》".equals(defaultTestList.get(0))); + Assert.assertFalse("《西游记》".equals(defaultTestList.get(0))); + } + + /** + * Method: set(int index, Object o) + */ + @Test + public void testSet() throws Exception { + + List testList = new ArrayList<>(); + Assert.assertTrue(testList.add(7)); + Assert.assertTrue(testList.add(8)); + Assert.assertTrue(testList.add(9)); + System.out.println("设置前: " + testList); + Assert.assertTrue(testList.set(0, 10)); + System.out.println("设置后: " + testList); + } + + /** + * Method: contains(Object o) + */ + @Test + public void testContains() throws Exception { + Assert.assertTrue(defaultTestList.contains("《红楼梦》")); + Assert.assertFalse(defaultTestList.contains("《聊斋》")); + } + + /** + * Method: clear() + */ + @Test + public void testClear() throws Exception { + + List testList = new ArrayList<>(); + Assert.assertTrue(testList.add(7)); + Assert.assertTrue(testList.add(8)); + Assert.assertTrue(testList.add(9)); + System.out.println("清除前: " + testList); + testList.clear(); + Assert.assertTrue(testList.isEmpty()); + System.out.println("清除后: " + testList); + } + + /** + * Method: iterator() + */ + @Test + public void testIterator() throws Exception { + + List testList = new ArrayList<>(); + Assert.assertTrue(testList.add(7)); + Assert.assertTrue(testList.add(8)); + Assert.assertTrue(testList.add(9)); + Iterator iterator = testList.iterator(); + Assert.assertNotNull(iterator); + while(iterator.hasNext()) { + System.out.println(iterator.next()); + } + List testListByDel = new ArrayList<>(); + Assert.assertTrue(testListByDel.add("张三")); + Assert.assertTrue(testListByDel.add("李四")); + Assert.assertTrue(testListByDel.add("王五")); + Iterator iteratorByDel = testListByDel.iterator(); + while(iteratorByDel.hasNext()) { + iteratorByDel.remove(); + } + Assert.assertTrue(testListByDel.isEmpty()); + + } + + + +} diff --git a/group07/20409287/src/main/java/xdx/homework/second/array/ArrayUtil.java b/group07/20409287/src/com/coderising/array/ArrayUtil.java similarity index 98% rename from group07/20409287/src/main/java/xdx/homework/second/array/ArrayUtil.java rename to group07/20409287/src/com/coderising/array/ArrayUtil.java index 2fa1237dbb..2d6677baaf 100644 --- a/group07/20409287/src/main/java/xdx/homework/second/array/ArrayUtil.java +++ b/group07/20409287/src/com/coderising/array/ArrayUtil.java @@ -1,14 +1,11 @@ -package xdx.homework.second.array; +package com.coderising.array; import xdx.homework.first.ArrayList; import xdx.homework.first.List; import xdx.homework.first.Queue; -import xdx.homework.first.Stack; import java.util.Arrays; -import static java.lang.StrictMath.sqrt; - public class ArrayUtil { /** diff --git a/group07/20409287/src/com/coderising/download/DownloadThread.java b/group07/20409287/src/com/coderising/download/DownloadThread.java new file mode 100644 index 0000000000..4a1bc99672 --- /dev/null +++ b/group07/20409287/src/com/coderising/download/DownloadThread.java @@ -0,0 +1,60 @@ +package com.coderising.download; + + +import xdx.homework.third.download.api.Connection; + +import java.io.*; + +public class DownloadThread extends Thread { + + Connection conn; + int startPos; + int endPos; + + private RandomAccessFile downFile; + + private RandomAccessFile recordFile; + + public DownloadThread(Connection conn, int startPos, int endPos, String fileName) throws FileNotFoundException { + + this.conn = conn; + this.startPos = startPos; + this.endPos = endPos; + downFile = new RandomAccessFile(fileName, "rwd"); + } + + public void run() { + + System.out.println("线程" + Thread.currentThread().getName() + "开始下载"); + try { + byte[] data = conn.read(startPos, endPos); + File file = new File("record.dat"); + if (file.exists() && file.length() > 0) { + BufferedReader br = new BufferedReader( + new InputStreamReader(new FileInputStream(file))); + String saveStartPos = br.readLine(); + if (saveStartPos != null && saveStartPos.length() > 0) { + startPos = Integer.parseInt(saveStartPos); + } + } + // 将数据写入文件并记录位置 + recordFile = new RandomAccessFile("record.dat", "rwd");// 存储下载标记的文件 + downFile.write(data, 0, data.length); + // 将下载标记存入指定文档 + String savaPoint = String.valueOf(data.length + 1); + recordFile.write(savaPoint.getBytes()); + } catch (IOException e) { + System.out.println("读取失败: " + e.getMessage()); + } finally { + try { + recordFile.close(); + conn.close(); + } catch (IOException e) { + } + } + + } + + + +} diff --git a/group07/20409287/src/com/coderising/download/FileDownloader.java b/group07/20409287/src/com/coderising/download/FileDownloader.java new file mode 100644 index 0000000000..e318cc7941 --- /dev/null +++ b/group07/20409287/src/com/coderising/download/FileDownloader.java @@ -0,0 +1,86 @@ +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; + +import java.io.FileNotFoundException; + +public class FileDownloader { + + private String url; + + private DownloadListener listener; + + private ConnectionManager cm; + + private int threadCount = 3; //线程数量 + + public FileDownloader(String _url) { + this.url = _url; + + } + + public void execute() throws FileNotFoundException, ConnectionException { + // 在这里实现你的代码, 注意: 需要用多线程实现下载 + // 这个类依赖于其他几个接口, 你需要写这几个接口的实现代码 + // (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 blockSize = length / threadCount;//计算每个线程理论上下载的数量. + for (int threadId = 0; threadId < threadCount; threadId++) {//为每个线程分配任务 + int startIndex = threadId * blockSize; //线程开始下载的位置 + int endIndex = (threadId + 1) * blockSize - 1; //线程结束下载的位置 + if (threadId == (threadCount - 1)) { //如果是最后一个线程,将剩下的文件全部交给这个线程完成 + endIndex = length - 1; + } + new DownloadThread(conn, startIndex, endIndex, "xdx.rar").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/group07/20409287/src/com/coderising/download/FileDownloaderTest.java b/group07/20409287/src/com/coderising/download/FileDownloaderTest.java new file mode 100644 index 0000000000..e4aee5f687 --- /dev/null +++ b/group07/20409287/src/com/coderising/download/FileDownloaderTest.java @@ -0,0 +1,54 @@ +package com.coderising.download; + + + +import com.coderising.download.api.ConnectionManager; +import com.coderising.download.api.DownloadListener; +import com.coderising.download.impl.ConnectionManagerImpl; + +import java.io.FileNotFoundException; + +public class FileDownloaderTest { + + private static boolean downloadFinished = false; + + public static void main(String[] args) { + + String url = "http://qunying.jb51.net:8080/201702/books/Wiresharkshjb.rar"; + + FileDownloader downloader = new FileDownloader(url); + + + ConnectionManager cm = new ConnectionManagerImpl(); + downloader.setConnectionManager(cm); + + downloader.setListener(new DownloadListener() { + @Override + public void notifyFinished() { + downloadFinished = true; + } + + }); + + try { + downloader.execute(); + } catch (FileNotFoundException e) { + e.printStackTrace(); + } + + // 等待多线程下载程序执行完毕 + while (!downloadFinished) { + try { + System.out.println("还没有下载完成,休眠五秒"); + //休眠5秒 + Thread.sleep(5000); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + System.out.println("下载完成!"); + + + } + +} diff --git a/group07/20409287/src/com/coderising/download/api/Connection.java b/group07/20409287/src/com/coderising/download/api/Connection.java new file mode 100644 index 0000000000..494c713b27 --- /dev/null +++ b/group07/20409287/src/com/coderising/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/group07/20409287/src/com/coderising/download/api/ConnectionException.java b/group07/20409287/src/com/coderising/download/api/ConnectionException.java new file mode 100644 index 0000000000..0efcfbb420 --- /dev/null +++ b/group07/20409287/src/com/coderising/download/api/ConnectionException.java @@ -0,0 +1,8 @@ +package com.coderising.download.api; + +public class ConnectionException extends Exception { + + public ConnectionException(String message) { + super(message); + } +} diff --git a/group07/20409287/src/com/coderising/download/api/ConnectionManager.java b/group07/20409287/src/com/coderising/download/api/ConnectionManager.java new file mode 100644 index 0000000000..3bb82cc2e5 --- /dev/null +++ b/group07/20409287/src/com/coderising/download/api/ConnectionManager.java @@ -0,0 +1,10 @@ +package com.coderising.download.api; + +public interface ConnectionManager { + /** + * 给定一个url , 打开一个连接 + * @param url + * @return + */ + public com.coderising.download.api.Connection open(String url) throws com.coderising.download.api.ConnectionException; +} diff --git a/group07/20409287/src/com/coderising/download/api/DownloadListener.java b/group07/20409287/src/com/coderising/download/api/DownloadListener.java new file mode 100644 index 0000000000..bf9807b307 --- /dev/null +++ b/group07/20409287/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/group07/20409287/src/com/coderising/download/impl/ConnectionImpl.java b/group07/20409287/src/com/coderising/download/impl/ConnectionImpl.java new file mode 100644 index 0000000000..0ebbfb330c --- /dev/null +++ b/group07/20409287/src/com/coderising/download/impl/ConnectionImpl.java @@ -0,0 +1,51 @@ +package com.coderising.download.impl; + +import xdx.homework.third.download.api.Connection; + +import java.io.IOException; +import java.io.InputStream; +import java.net.HttpURLConnection; +import java.net.URL; + +public class ConnectionImpl implements Connection { + + private HttpURLConnection conn; + + private URL url; + + public ConnectionImpl(String strUrl) throws IOException { + url = new URL(strUrl); + conn = (HttpURLConnection) url.openConnection(); + conn.setConnectTimeout(5000); + } + + @Override + public byte[] read(int startPos, int endPos) throws IOException { + + conn.setRequestProperty("Range", "bytes=" + startPos + "-" + endPos); + System.out.println("线程_" + Thread.currentThread().getName() + + "的下载起点是: " + startPos + " 下载终点是: " + endPos); + byte[] data = new byte[endPos - startPos]; + if (conn.getResponseCode() == 206) { + InputStream inputStream = conn.getInputStream(); + byte[] buffer = new byte[1024]; + int count = 1; + while(inputStream.read(buffer) > 0){ + System.arraycopy(buffer, 0, data, count * 1024, 1024); + count++; + } + } + return data; + } + + @Override + public int getContentLength() { + return conn.getContentLength(); + } + + @Override + public void close() { + conn.disconnect(); + } + +} diff --git a/group07/20409287/src/com/coderising/download/impl/ConnectionManagerImpl.java b/group07/20409287/src/com/coderising/download/impl/ConnectionManagerImpl.java new file mode 100644 index 0000000000..e0a67fa741 --- /dev/null +++ b/group07/20409287/src/com/coderising/download/impl/ConnectionManagerImpl.java @@ -0,0 +1,24 @@ +package com.coderising.download.impl; + + +import com.coderising.download.api.Connection; +import com.coderising.download.api.ConnectionException; +import com.coderising.download.api.ConnectionManager; + +import java.io.IOException; + +public class ConnectionManagerImpl implements ConnectionManager { + + @Override + public Connection open(String url) throws ConnectionException { + + Connection conn; + try { + conn = new ConnectionImpl(url); + } catch (IOException e) { + throw new ConnectionException("获取连接失败:" + e.getMessage()); + } + return conn; + } + +} diff --git a/group07/20409287/src/main/java/xdx/homework/second/litestruts/LoginAction.java b/group07/20409287/src/com/coderising/litestruts/LoginAction.java similarity index 95% rename from group07/20409287/src/main/java/xdx/homework/second/litestruts/LoginAction.java rename to group07/20409287/src/com/coderising/litestruts/LoginAction.java index f59067088b..bf31612b74 100644 --- a/group07/20409287/src/main/java/xdx/homework/second/litestruts/LoginAction.java +++ b/group07/20409287/src/com/coderising/litestruts/LoginAction.java @@ -1,4 +1,4 @@ -package xdx.homework.second.litestruts; +package com.coderising.litestruts; /** * 这是一个用来展示登录的业务类, 其中的用户名和密码都是硬编码的。 diff --git a/group07/20409287/src/main/java/xdx/homework/second/litestruts/Struts.java b/group07/20409287/src/com/coderising/litestruts/Struts.java similarity index 96% rename from group07/20409287/src/main/java/xdx/homework/second/litestruts/Struts.java rename to group07/20409287/src/com/coderising/litestruts/Struts.java index 0ba4f85313..6885c2b94d 100644 --- a/group07/20409287/src/main/java/xdx/homework/second/litestruts/Struts.java +++ b/group07/20409287/src/com/coderising/litestruts/Struts.java @@ -1,23 +1,18 @@ -package xdx.homework.second.litestruts; +package com.coderising.litestruts; -import org.jcp.xml.dsig.internal.dom.DOMEnvelopedTransform; import org.w3c.dom.Document; import org.w3c.dom.Element; -import org.w3c.dom.Node; import org.w3c.dom.NodeList; import org.xml.sax.SAXException; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; -import java.beans.BeanInfo; import java.beans.IntrospectionException; import java.beans.Introspector; import java.beans.PropertyDescriptor; import java.io.File; import java.io.IOException; -import java.lang.reflect.Executable; -import java.lang.reflect.Method; import java.net.URL; import java.util.HashMap; import java.util.Map; diff --git a/group07/20409287/src/main/java/xdx/homework/second/litestruts/StrutsTest.java b/group07/20409287/src/com/coderising/litestruts/StrutsTest.java similarity index 91% rename from group07/20409287/src/main/java/xdx/homework/second/litestruts/StrutsTest.java rename to group07/20409287/src/com/coderising/litestruts/StrutsTest.java index a56eec5e28..64aff57eaa 100644 --- a/group07/20409287/src/main/java/xdx/homework/second/litestruts/StrutsTest.java +++ b/group07/20409287/src/com/coderising/litestruts/StrutsTest.java @@ -1,7 +1,9 @@ -package xdx.homework.second.litestruts; +package com.coderising.litestruts; -import org.testng.Assert; -import org.testng.annotations.Test; + + +import org.junit.Assert; +import org.junit.Test; import java.util.HashMap; import java.util.Map; diff --git a/group07/20409287/src/main/java/xdx/homework/second/litestruts/View.java b/group07/20409287/src/com/coderising/litestruts/View.java similarity index 89% rename from group07/20409287/src/main/java/xdx/homework/second/litestruts/View.java rename to group07/20409287/src/com/coderising/litestruts/View.java index 0d7f02f86b..07df2a5dab 100644 --- a/group07/20409287/src/main/java/xdx/homework/second/litestruts/View.java +++ b/group07/20409287/src/com/coderising/litestruts/View.java @@ -1,4 +1,4 @@ -package xdx.homework.second.litestruts; +package com.coderising.litestruts; import java.util.Map; diff --git a/group07/20409287/src/main/java/xdx/homework/second/litestruts/struts.xml b/group07/20409287/src/com/coderising/litestruts/struts.xml similarity index 100% rename from group07/20409287/src/main/java/xdx/homework/second/litestruts/struts.xml rename to group07/20409287/src/com/coderising/litestruts/struts.xml diff --git a/group07/20409287/src/main/java/xdx/homework/first/LinkedList.java b/group07/20409287/src/main/java/xdx/homework/first/LinkedList.java deleted file mode 100644 index 1c31589204..0000000000 --- a/group07/20409287/src/main/java/xdx/homework/first/LinkedList.java +++ /dev/null @@ -1,246 +0,0 @@ -package xdx.homework.first; - -/** - * @Description: 链式列表 - */ -public class LinkedList implements List { - - private class Node { - - private E data; // 数据域 - - private Node next; // 指针域 - - public Node() { - } - - private Node(E data) { - this.data = data; - this.next = null; - } - - } - - // 链表大小 - private int size = 0; - - private Node head; - - private Node tail; - - /** - * 添加元素 - * - * @param data - * @return - */ - @Override - public boolean add(E data) { - - if(this.head != null) { - Node newNode = new Node(data); - this.tail.next = newNode; - this.tail = newNode; - } else { - this.head = new Node(data); - this.tail = this.head; - } - size++; - return true; - } - - /** - * 删除指定索引的元素 - * - * @param index@return - */ - @Override - public E remove(int index) { - - if (index < 0 || index > size) { - throw new IndexOutOfBoundsException("索引不正确!"); - } - if (isEmpty()) { - throw new RuntimeException("链表为空!"); - } - Node currentNode = this.head; - Node preNode = currentNode; - for (int i = 0; i < index; i++) { - preNode = currentNode; - currentNode = currentNode.next; - } - preNode.next = currentNode.next; - size--; - return currentNode.data; - } - - /** - * 删除指定的元素 - * - * @param e - * @return - */ - @Override - public boolean remove(E e) { - - if (!this.contains(e)) return false; - - if (this.head.data.equals(e)) { - this.head = this.head.next; - size--; - return true; - } - Node currentNode = this.head; - Node preNode = currentNode; - boolean isFind = false; - for (int i = 0; i < size; i++) { - if(currentNode.data.equals(e)) { - isFind = true; - break; - } - preNode = currentNode; - currentNode = currentNode.next; - } - if (!isFind) return false; - preNode.next = currentNode.next; - size--; - return true; - } - - /** - * 返回列表长度 - * - * @return - */ - @Override - public int size() { - return size; - } - - /** - * 判断列表是否为空 - * - * @return - */ - @Override - public boolean isEmpty() { - return size == 0; - } - - /** - * 获取指定索引的元素 - * - * @param index - * @return - */ - @Override - public E get(int index) { - - if (index < 0 || index > size || isEmpty()) { - throw new IndexOutOfBoundsException("索引不正确!"); - } - Node currentNode = this.head; - for (int i = 0; i < index; i++) { - currentNode = currentNode.next; - } - return currentNode.data; - } - - /** - * 重置某个索引的元素 - * - * @param index - * @param e - * @return - */ - @Override - public boolean set(int index, E e) { - - if (index < 0 || index > size || isEmpty()) { - throw new IndexOutOfBoundsException("索引不正确!"); - } - Node currentNode = this.head; - for (int i = 0; i < index; i++) { - currentNode = currentNode.next; - } - currentNode.data = e; - return false; - } - - /** - * 判断是否包含某个元素 - * - * @param e - * @return - */ - @Override - public boolean contains(E e) { - - if (isEmpty()) return false; - Node currentNode = this.head; - boolean isFind = false; - for (int i = 0; i < size(); i++) { - if(currentNode.data.equals(e)) { - isFind = true; - } - currentNode = currentNode.next; - } - return isFind; - } - - /** - * 清空列表 - */ - @Override - public void clear() { - this.head = this.tail = null; - size = 0; - } - - @Override - public String toString() { - - if (isEmpty()) return "[]"; - StringBuilder strLinkedList = new StringBuilder("["); - Node currentNode = this.head; - while (currentNode.next != null) { - strLinkedList.append(currentNode.data.toString()).append(","); - currentNode = currentNode.next; - } - strLinkedList.append(currentNode.data.toString()).append("]"); - return strLinkedList.toString(); - } - - /** - * 取得迭代器 - * - * @return - */ - @Override - public Iterator iterator() { - return new Itr(); - } - - private class Itr implements Iterator { - - Node curNode = LinkedList.this.head; - - @Override - public boolean hasNext() { - return curNode != null; - } - - @Override - public E next() { - Node thisNode = curNode; - curNode = curNode.next; - return thisNode.data; - } - - @Override - public void remove() { - LinkedList.this.remove(curNode.data); - curNode = curNode.next; - } - } -} diff --git a/group07/20409287/src/test/xdx/homework/second/ArrayUtilTest.java b/group07/20409287/src/test/xdx/homework/second/ArrayUtilTest.java deleted file mode 100644 index ffafc94f7d..0000000000 --- a/group07/20409287/src/test/xdx/homework/second/ArrayUtilTest.java +++ /dev/null @@ -1,157 +0,0 @@ -package xdx.homework.second; - -import org.junit.Test; -import org.junit.Before; -import org.junit.After; -import org.testng.Assert; -import xdx.homework.second.array.ArrayUtil; - -import java.util.Arrays; - -/** - * ArrayUtil Tester. - * - * @author - * @since
���� 4, 2017
- * @version 1.0 - */ -public class ArrayUtilTest { - - ArrayUtil arrayUtil = new ArrayUtil(); - - @Before - public void before() throws Exception { - } - - @After - public void after() throws Exception { - } - - /** - * - * Method: reverseArray(int[] origin) - * - */ - @Test - public void testReverseArray() throws Exception { - - int[] array = {1,2,3,4,5,6,7,8,9}; - System.out.println("===================数组反转开始==================="); - System.out.println("原数组: " + Arrays.toString(array)); - arrayUtil.reverseArray(array); - System.out.println("反转后的数组: " + Arrays.toString(array)); - System.out.println("===================数组反转结束===================" + "\n"); - } - - /** - * - * Method: removeZero(int[] oldArray) - * - */ - @Test - public void testRemoveZero() throws Exception { - - System.out.println("===================数组清零开始==================="); - int oldArr[]={1,3,4,5,0,0,6,6,0,5,4,7,6,7,0,5}; - System.out.println("原数组: " + Arrays.toString(oldArr)); - System.out.println("清零后的数组: " + Arrays.toString(arrayUtil.removeZero(oldArr))); - System.out.println("===================数组清零结束===================" + "\n"); - } - - /** - * - * Method: merge(int[] array1, int[] array2) - * - */ - @Test - public void testMerge() throws Exception { - - System.out.println("===================数组合并开始==================="); - int[] array1 = {1,2,4,5}; - int[] array2 = {3,4,5,6,7,8,9}; - System.out.println("原数组1: " + Arrays.toString(array1)); - System.out.println("原数组2: " + Arrays.toString(array2)); - int[] mergedArray = arrayUtil.merge(array1, array2); - System.out.println("合并后的数组: " + Arrays.toString(mergedArray)); - System.out.println("===================数组合并结束===================" + "\n"); - } - - /** - * - * Method: grow(int [] oldArray, int size) - * - */ - @Test - public void testGrow() throws Exception { - - System.out.println("===================数组增长开始==================="); - int[] array2 = {3,4,5,6,7,8,9}; - final int GROW_SIZE = 5; - int[] growArray = arrayUtil.grow(array2, GROW_SIZE); - Assert.assertEquals(array2.length + GROW_SIZE, growArray.length); - System.out.println("原数组: " + Arrays.toString(array2)); - System.out.println("增长" + GROW_SIZE + "个单位后的数组: " + Arrays.toString(growArray)); - System.out.println("===================数组增长结束===================" + "\n"); - } - - /** - * - * Method: fibonacci(int max) - * - */ - @Test - public void testFibonacci() throws Exception { - - System.out.println("===================斐波那契数列开始==================="); - final int MAX = 10000000; - System.out.println(MAX + "以内的斐波那契数列: " + Arrays.toString(arrayUtil.fibonacci(MAX))); - System.out.println("===================斐波那契数列结束===================" + "\n"); - } - - /** - * - * Method: getPrimes(int max) - * - */ - @Test - public void testGetPrimes() throws Exception { - - System.out.println("===================素数计算开始==================="); - final int MAX = 10000; - System.out.println(MAX + "以内的素数: " + Arrays.toString(arrayUtil.getPrimes(MAX))); - System.out.println("===================素数计算结束===================" + "\n"); - } - - /** - * - * Method: getPerfectNumbers(int max) - * - */ - @Test - public void testGetPerfectNumbers() throws Exception { - - System.out.println("===================计算完美数列结束==================="); - final int MAX = 10000; - System.out.println(MAX + "以内的完数分别是: " + Arrays.toString(arrayUtil.getPerfectNumbers(MAX))); - System.out.println("===================计算完美数列结束===================" + "\n"); - } - - /** - * - * Method: join(int[] array, String seperator) - * - */ - @Test - public void testJoin() throws Exception { - - System.out.println("===================数组分隔开始==================="); - int[] array2 = {3,4,5,6,7,8,9}; - final String SEP = "-"; - System.out.println("原数组: " + Arrays.toString(array2)); - System.out.println("分隔符: " + SEP); - System.out.println("分隔后的数组: " + arrayUtil.join(array2, SEP)); - System.out.println("===================数组分隔结束===================" + "\n"); - } - - -}