diff --git a/group06/1454385822/copy.jpg b/group06/1454385822/copy.jpg new file mode 100644 index 0000000000..8cca8d6a63 Binary files /dev/null and b/group06/1454385822/copy.jpg differ diff --git a/group06/1454385822/src/com/coding/basic/homework_02/litestruts/Struts.java b/group06/1454385822/src/com/coding/basic/homework_02/litestruts/Struts.java index 5c6c57cf73..ba9cc5922b 100644 --- a/group06/1454385822/src/com/coding/basic/homework_02/litestruts/Struts.java +++ b/group06/1454385822/src/com/coding/basic/homework_02/litestruts/Struts.java @@ -42,11 +42,10 @@ public static View runAction(String actionName, Map params) thro 放到View对象的jsp字段中。 */ - - View view = new View(); Element root = getRoot(); Class clazz = getClazz(actionName, root); Object obj = clazz.newInstance(); + View view = new View(); methodInvoke(clazz, obj, params); String result = getExecuteInfo(clazz, obj); diff --git a/group06/1454385822/src/com/coding/basic/homework_03/download/DownloadThread.java b/group06/1454385822/src/com/coding/basic/homework_03/download/DownloadThread.java new file mode 100644 index 0000000000..73fe0a42ef --- /dev/null +++ b/group06/1454385822/src/com/coding/basic/homework_03/download/DownloadThread.java @@ -0,0 +1,50 @@ +package com.coding.basic.homework_03.download; + +import java.io.File; +import java.io.IOException; +import java.io.RandomAccessFile; + +import com.coding.basic.homework_03.download.api.Connection; + +public class DownloadThread extends Thread{ + + Connection conn; + int startPos; + int endPos; + boolean downOver = false; + + public DownloadThread( Connection conn, int startPos, int endPos){ + + this.conn = conn; + this.startPos = startPos; + this.endPos = endPos; + } + public void run(){ + RandomAccessFile raf = null; + try { +// System.out.println(Thread.currentThread().getName() + "开始下载..."); + byte[] bytes = conn.read(startPos, endPos); + +// if(!file.exists()){ +// file.createNewFile(); +// } + synchronized(this){ + File file = new File("copy.jpg"); + raf = new RandomAccessFile(file,"rw"); + raf.seek(startPos); + raf.write(bytes); + } + } catch (IOException e) { + e.printStackTrace(); + }finally{ + if(raf != null){ + try { + raf.close(); + downOver = true; + } catch (IOException e) { + e.printStackTrace(); + } + } + } + } +} \ No newline at end of file diff --git a/group06/1454385822/src/com/coding/basic/homework_03/download/FileDownloader.java b/group06/1454385822/src/com/coding/basic/homework_03/download/FileDownloader.java new file mode 100644 index 0000000000..06a6644c7b --- /dev/null +++ b/group06/1454385822/src/com/coding/basic/homework_03/download/FileDownloader.java @@ -0,0 +1,130 @@ +package com.coding.basic.homework_03.download; + +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.nio.ByteBuffer; +import java.nio.channels.FileChannel; + +import com.coding.basic.homework_03.download.api.Connection; +import com.coding.basic.homework_03.download.api.ConnectionManager; +import com.coding.basic.homework_03.download.api.DownloadListener; + +public class FileDownloader { + + String url; + + DownloadListener listener; + + ConnectionManager cm; + private static final long KBSIZE = 1024; + private static final long MBSIZE = 1024 * 1024; + + public FileDownloader(String _url) { + this.url = _url; + + } + + public void execute() throws IOException { + // 在这里实现你的代码, 注意: 需要用多线程实现下载 + // 这个类依赖于其他几个接口, 你需要写这几个接口的实现代码 + // (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(); + createFile(new File("copy.jpg"), length); +// System.out.println(length); + int len = length / 5; + DownloadThread t1 = new DownloadThread(cm.open(this.url), 0, len - 1); + DownloadThread t2 = new DownloadThread(cm.open(this.url), len, len * 2 - 1); + DownloadThread t3 = new DownloadThread(cm.open(this.url), len * 2, len * 3 - 1); + DownloadThread t4 = new DownloadThread(cm.open(this.url), len * 3, len * 4 - 1); + DownloadThread t5 = new DownloadThread(cm.open(this.url), len * 4, len * 5 - 1); + DownloadThread t6 = new DownloadThread(cm.open(this.url), len * 5, length - 1); + t1.start(); + t2.start(); + t3.start(); + t4.start(); + t5.start(); + t6.start(); + + while (!(t1.downOver && t2.downOver && t3.downOver && t4.downOver && t5.downOver && t6.downOver)) { + try { + System.out.println("还有线程没有下载完成,等待五秒..."); + // 休眠5秒 + Thread.sleep(5000); + } catch (Exception e) { + e.printStackTrace(); + } + } + + } catch (Exception e) { + e.printStackTrace(); + } finally { + if (conn != null) { + conn.close(); + } + } + + } + + /** + * 创建一个临时文件 + * + * @param file + * @param length + * @throws IOException + */ + private void createFile(File file, int length) throws IOException { + long batchSize = 0; + FileOutputStream fos = null; + if (!file.exists()) { + file.createNewFile(); + } + + if (length > KBSIZE) { + batchSize = KBSIZE; + } + if (length > MBSIZE) { + batchSize = MBSIZE; + } + fos = new FileOutputStream(file); + int times = length / (int) batchSize; + int last = length % (int) batchSize; + FileChannel channel = fos.getChannel(); + for (int i = 0; i < times; i++) { + ByteBuffer buffer = ByteBuffer.allocate((int) batchSize); + channel.write(buffer); + } + ByteBuffer buffer = ByteBuffer.allocate(last); + channel.write(buffer); + fos.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/group06/1454385822/src/com/coding/basic/homework_03/download/FileDownloaderTest.java b/group06/1454385822/src/com/coding/basic/homework_03/download/FileDownloaderTest.java new file mode 100644 index 0000000000..cc02371dfa --- /dev/null +++ b/group06/1454385822/src/com/coding/basic/homework_03/download/FileDownloaderTest.java @@ -0,0 +1,57 @@ +package com.coding.basic.homework_03.download; + +import java.io.IOException; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import com.coding.basic.homework_03.download.api.ConnectionManager; +import com.coding.basic.homework_03.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() throws IOException { + + String url = "http://bpic.588ku.com/element_origin_min_pic/16/12/01/b4365c64e8a567afd0ab63285515de55.jpg"; + + FileDownloader downloader = new FileDownloader(url); + ConnectionManager cm = new ConnectionManagerImpl(); + downloader.setConnectionManager(cm); + downloader.execute(); + +// downloader.setListener(new DownloadListener() { +// @Override +// public void notifyFinished() { +// downloadFinished = true; +// } +// }); + + + // 等待多线程下载程序执行完毕 +// while (!downloadFinished) { +// try { +//// System.out.println(Thread.currentThread().getName()); +// System.out.println("还没有下载完成,休眠五秒"); +// //休眠5秒 +//// Thread.sleep(1000); +// } catch (Exception e) { +// e.printStackTrace(); +// } +// } + System.out.println("下载完成!文件存放在此项目根目录下"); + + + + } + +} \ No newline at end of file diff --git a/group06/1454385822/src/com/coding/basic/homework_03/download/api/Connection.java b/group06/1454385822/src/com/coding/basic/homework_03/download/api/Connection.java new file mode 100644 index 0000000000..dbebed39d3 --- /dev/null +++ b/group06/1454385822/src/com/coding/basic/homework_03/download/api/Connection.java @@ -0,0 +1,26 @@ +package com.coding.basic.homework_03.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 + * @throws IOException + */ + public int getContentLength() throws IOException; + + /** + * 关闭连接 + * @throws IOException + */ + public void close() throws IOException; +} \ No newline at end of file diff --git a/group06/1454385822/src/com/coding/basic/homework_03/download/api/ConnectionException.java b/group06/1454385822/src/com/coding/basic/homework_03/download/api/ConnectionException.java new file mode 100644 index 0000000000..0d68b040a8 --- /dev/null +++ b/group06/1454385822/src/com/coding/basic/homework_03/download/api/ConnectionException.java @@ -0,0 +1,5 @@ +package com.coding.basic.homework_03.download.api; + +public class ConnectionException extends Exception { + +} diff --git a/group06/1454385822/src/com/coding/basic/homework_03/download/api/ConnectionManager.java b/group06/1454385822/src/com/coding/basic/homework_03/download/api/ConnectionManager.java new file mode 100644 index 0000000000..15759b05e8 --- /dev/null +++ b/group06/1454385822/src/com/coding/basic/homework_03/download/api/ConnectionManager.java @@ -0,0 +1,16 @@ +package com.coding.basic.homework_03.download.api; + +import java.io.FileNotFoundException; +import java.io.IOException; + +public interface ConnectionManager { + /** + * 给定一个url , 打开一个连接 + * @param url + * @return + * @throws FileNotFoundException + * @throws IOException + */ + public Connection open(String url) throws IOException; +} + diff --git a/group06/1454385822/src/com/coding/basic/homework_03/download/api/DownloadListener.java b/group06/1454385822/src/com/coding/basic/homework_03/download/api/DownloadListener.java new file mode 100644 index 0000000000..732c8dc806 --- /dev/null +++ b/group06/1454385822/src/com/coding/basic/homework_03/download/api/DownloadListener.java @@ -0,0 +1,5 @@ +package com.coding.basic.homework_03.download.api; + +public interface DownloadListener { + public void notifyFinished(); +} diff --git a/group06/1454385822/src/com/coding/basic/homework_03/download/impl/ConnectionImpl.java b/group06/1454385822/src/com/coding/basic/homework_03/download/impl/ConnectionImpl.java new file mode 100644 index 0000000000..d6874ae76f --- /dev/null +++ b/group06/1454385822/src/com/coding/basic/homework_03/download/impl/ConnectionImpl.java @@ -0,0 +1,75 @@ +package com.coding.basic.homework_03.download.impl; + +import java.io.IOException; +import java.io.InputStream; +import java.net.HttpURLConnection; +import java.net.URL; + +import com.coding.basic.homework_03.download.api.Connection; + +public class ConnectionImpl implements Connection{ +// public RandomAccessFile raf = null; + public HttpURLConnection httpUrl = null; + public URL Url = null; +// public BufferedInputStream bis = null; +// FileInputStream fis = null; + InputStream is = null; + public ConnectionImpl(String url) throws IOException{ + + Url = new URL(url); + httpUrl = (HttpURLConnection) Url.openConnection(); + httpUrl.connect(); + is = httpUrl.getInputStream(); + +// fis = (FileInputStream) httpUrl.getInputStream(); +// bis = new BufferedInputStream(httpUrl.getInputStream()); +// raf = new RandomAccessFile(url, "r"); + } + + @Override + public byte[] read(int startPos, int endPos) throws IOException { + int length = endPos - startPos + 1; + byte[] result = new byte[length]; + int num = 0; + if(startPos != 0){ + is.skip(startPos); + } + num = (int)is.read(result); +// System.out.println("length : " + length); +// System.out.println("num : " + num); + +// System.out.println(startPos +"....读到了...."+endPos); +// +// System.out.println(Integer.MAX_VALUE); +// System.out.println("num:" + num); +// fis.skip(startPos); +// fis.read(result, startPos, length); +// bis.read(result, startPos, length); + +// raf.seek(startPos); +// raf.read(result); + return result; + } + + @Override + public int getContentLength() throws IOException { + int num = 0; + return httpUrl.getContentLength(); +// return (int) raf.length(); + } + + @Override + public void close() throws IOException { +// if(raf != null){ +// raf.close(); +// } +// if(bis != null){ +// bis.close(); +// } + if(is != null){ + is.close(); + } + + } + +} \ No newline at end of file diff --git a/group06/1454385822/src/com/coding/basic/homework_03/download/impl/ConnectionManagerImpl.java b/group06/1454385822/src/com/coding/basic/homework_03/download/impl/ConnectionManagerImpl.java new file mode 100644 index 0000000000..e81398ac7b --- /dev/null +++ b/group06/1454385822/src/com/coding/basic/homework_03/download/impl/ConnectionManagerImpl.java @@ -0,0 +1,16 @@ +package com.coding.basic.homework_03.download.impl; + +import java.io.IOException; + +import com.coding.basic.homework_03.download.api.Connection; +import com.coding.basic.homework_03.download.api.ConnectionManager; + +public class ConnectionManagerImpl implements ConnectionManager { + + @Override + public Connection open(String url) throws IOException { + Connection conn = new ConnectionImpl(url); + return conn; + } + +} diff --git a/group06/1454385822/src/com/coding/basic/homework_03/linkedListImpl/LinkedList.java b/group06/1454385822/src/com/coding/basic/homework_03/linkedListImpl/LinkedList.java new file mode 100644 index 0000000000..a617f003fc --- /dev/null +++ b/group06/1454385822/src/com/coding/basic/homework_03/linkedListImpl/LinkedList.java @@ -0,0 +1,365 @@ +package com.coding.basic.homework_03.linkedListImpl; + +import com.coding.basic.homework_01.Iterator; +import com.coding.basic.homework_01.List; + +/** + * 重新实现的LinkedList + * @author yanght + * + */ +public class LinkedList implements List { + + private Node head; //头节点 + private Node end; //当前链表的末尾结点 + private int num = 0; //链表中元素的个数 + + /** + * 直接从链表的尾部添加节点 + */ + public void add(Object o){ + Node node = new Node(o); + if(head == null){ //当前List为空,从第一个节点开始添加 + head = end = node; + }else{ + end.next = node; + end = node; + } + num++; + } + + /** + * 将结点添加到index处(从0开始) + */ + public void add(int index , Object o){ + if(index == num){ + add(o); + }else if(index < num && index >= 0){ + addNode(index, o); + } + } + + /** + * 在链表头部和中间添加节点 + * @param index + * @param node + */ + private void addNode(int index,Object o){ + if(index == 0){ + addFirst(o); + }else{ + Node node = new Node(o); + Node tem = getNode(index - 1); + Node pos = tem.next; + tem.next = node; + node.next = pos; + num++; + } + } + + /** + * 根据索引获取节点 + * @param index + * @return + */ + private Node getNode(int index){ + Node node = head; + if(index < num){ + for(int i = 1; i<= index; i++){ + node = node.next; + } + return node; + } + return node; + } + + public Object get(int index){ + if(index < 0 && index >= num){ + throw new IndexOutOfBoundsException(); + } + return getNode(index).data; + } + + public Object remove(int index){ + if(index < 0 && index >= num){ + throw new IndexOutOfBoundsException(); + } + Object result = null; + if(index == 0){ + removeFirst(); + }else if(index == num -1){ + removeLast(); + }else{ + Node pre = getNode(index - 1); + result = pre.next.data; + pre.next = pre.next.next; + num--; + } + return result; + } + + public int size(){ + return num; + } + + public void addFirst(Object o){ + if(o != null){ + Node node = new Node(o); + node.next = head; + head = node; + num++; + } + } + + public void addLast(Object o){ + add(o); + } + + public Object removeFirst(){ + Object result = null; + if(size() > 1){ + result = head.data; + head = head.next; + num--; + }else if(size() == 1){ + result = head.data; + head = end = null; + num-- ; + } + return result; + } + + public Object removeLast(){ + Object result = null; + if(size() > 1){ + Node pre = getNode(num - 2); + result = end.data; + pre.next = null; + end = pre; + num--; + }else if(size() == 1){ + result = head.data; + head = end = null; + num-- ; + } + return result; + } + + + public Iterator iterator(){ + return new Iterator(){ + private int cur = 0; + private Node node = null; + @Override + public boolean hasNext() { + + return num - cur > 0; + } + + @Override + public Object next() { + if(node == null){ + node = head; + }else{ + node = node.next; + } + cur++; + return node.data; + } + }; + } + + + private static class Node{ + Object data; + Node next; + @SuppressWarnings("unused") + public Node(){} + public Node(Object data){ + this.data = data; + } + } + + /** + * 把该链表逆置 + * 例如链表为 3->7->10 , 逆置后变为 10->7->3 + */ + public void reverse(){ + Object[] obj = new Object[num]; + Node node = head; + for(int i = obj.length-1; i >= 0; i--){ + obj[i] = node.data; + node = node.next; + } + node = head; + for(int i = 0; i < obj.length; i++){ + node.data = obj[i]; + node = node.next; + } + } + + /** + * 删除一个单链表的前半部分 + * 例如:list = 2->5->7->8 , 删除以后的值为 7->8 + * 如果list = 2->5->7->8->10 ,删除以后的值为7,8,10 + + */ + public void removeFirstHalf(){ + Node node = getNode(num / 2); + head = node; + if(num % 2 == 0){ + num = num / 2; + }else{ + num = num / 2 + 1; + } + } + + /** + * 从第i个元素开始, 删除length 个元素 , 注意i从0开始 + * @param i + * @param length + */ + public void remove(int i, int length){ + if(num - length < i + 1){ + throw new IndexOutOfBoundsException(); + } + if(num - length == i){ //i后面的全部删除 + Node node = getNode(i - 1); + end = node; + num = i; + }else{ + Node pre = getNode(i - 1); + Node pos = getNode(i + length); + pre.next = pos; + num = num - length; + } + } + /** + * 假定当前链表和list均包含已升序排列的整数 + * 从当前链表中取出那些list所指定的元素 + * 例如当前链表 = 11->101->201->301->401->501->601->701 + * listB = 1->3->4->6 + * 返回的结果应该是[101,301,401,601] + * @param list + */ + public static int[] getElements(LinkedList list, LinkedList listB){ + int[] result = new int[listB.size()]; + for(int i = 0; i < result.length; i++){ + result[i] =(int) list.getNode((Integer)listB.get(i)).data; + } + return result; + } + + /** + * 已知链表中的元素以值递增有序排列,并以单链表作存储结构。 + * 从当前链表中中删除在list中出现的元素 + + * @param list + */ + + public void subtract(LinkedList list){ + for(int i = 0; i < list.size(); i++){ + findPos(list.get(i), this); + } + } + + /** + * 在原数组中找相同的元素 + * @param pos 起始位置 + * @param obj 要找的元素 + * @param list 原数组 + * @return 下一次要传入的位置 + */ + private void findPos(Object obj, LinkedList list){ + for(int i = 0; i < list.size(); i++){ + if(compare(list.get(i), obj) == 0){ + list.remove(i); + break; + } + if(compare(list.get(i), obj) > 0){ + break; + } + } + } + + /** + * 已知当前链表中的元素以值递增有序排列,并以单链表作存储结构。 + * 删除表中所有值相同的多余元素(使得操作后的线性表中所有元素的值均不相同) + */ + public void removeDuplicateValues(){ + int pos = 0; + while(pos < this.size() - 1){ + if(compare(this.get(pos), this.get(pos + 1)) == 0){ + this.remove(pos); + continue; + } + pos++; + } + } + + /** + *比较大小 + * @param o1 + * @param o2 + * @return + */ + private int compare(Object o1, Object o2){ + int i1 = (Integer)o1; + int i2 = (Integer)o2; + return i1 > i2 ? 1 : (i1 < i2 ? -1 : 0); + } + /** + * 已知链表中的元素以值递增有序排列,并以单链表作存储结构。 + * 试写一高效的算法,删除表中所有值大于min且小于max的元素(若表中存在这样的元素) + * @param min + * @param max + */ + public void removeRange(int min, int max){ + Integer start = null; + Integer end = null; + for(int i = 0; i < this.size(); i++){ + if(compare(this.get(i), min) > 0 && compare(this.get(i), max) < 0){ + if(start == null){ + start = end = i; + }else{ + end = i; + } + } + } + remove(start, end - start); + } + + /** + * 假设当前链表和参数list指定的链表均以元素依值递增有序排列(同一表中的元素值各不相同) + * 现要求生成新链表C,其元素为当前链表和list中元素的交集,且表C中的元素有依值递增有序排列 + * @param list + */ + public LinkedList intersection( LinkedList list){ + int point1 = 0; + int point2 = 0; + LinkedList result = new LinkedList(); + while(point1 < this.size() && point2 < list.size()){ + if(compare(this.get(point1), list.get(point2)) < 0){ + point1++; + }else if(compare(this.get(point1), list.get(point2)) > 0){ + point2++; + }else{ + result.add(list.get(point2)); + point1++; + point2++; + } + } + return result; + } +} + + + + + + + + + + + diff --git a/group06/1454385822/src/com/coding/basic/homework_03/linkedListImpl/TestLinkedList.java b/group06/1454385822/src/com/coding/basic/homework_03/linkedListImpl/TestLinkedList.java new file mode 100644 index 0000000000..6c8c4fd50b --- /dev/null +++ b/group06/1454385822/src/com/coding/basic/homework_03/linkedListImpl/TestLinkedList.java @@ -0,0 +1,192 @@ +package com.coding.basic.homework_03.linkedListImpl; + +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +import com.coding.basic.homework_01.Iterator; + +public class TestLinkedList { + LinkedList list; + @Before + public void before(){ + list = new LinkedList(); + } + +// @Test + public void test1(){ + list.add(1); + list.add(2); + list.add(3); + list.remove(2); + list.add(4); + list.add(0, 0); + list.addFirst(-1); + Iterator it = list.iterator(); + while(it.hasNext()){ + System.out.println(it.next()); + } + System.out.println("size:" + list.size()); + } + + @Test + public void testReverse(){ + list.add(3); + list.add(7); + list.add(10); + list.reverse(); + String str = ""; + Iterator it = list.iterator(); + while(it.hasNext()){ + str = str + it.next() + " "; + } + Assert.assertEquals("10 7 3 ", str); + } + + @Test + public void testRemoveFirstHalf(){ + list.add(2); + list.add(5); + list.add(7); + list.add(8); + list.add(10); +// Object[] obj = new Object[list.size() / 2]; + Object[] obj = new Object[list.size() / 2 + 1]; + list.removeFirstHalf(); + for(int i = 0; i < obj.length; i++){ + obj[i] = list.get(i); + } +// Assert.assertArrayEquals(new Object[]{7, 8}, obj); + Assert.assertArrayEquals(new Object[]{7, 8, 10}, obj); + } + + @Test + public void testRemove(){ + list.add(0); + list.add(1); + list.add(2); + list.add(3); + list.add(4); + list.add(5); + list.add(6); + list.add(7); + list.remove(3, 4); + Object[] obj = new Object[4]; + for (int i = 0; i < obj.length; i++) { + obj[i] = list.get(i); + } + Assert.assertArrayEquals(new Object[]{0, 1, 2, 7}, obj); + } + + @Test + public void testGetElements(){ + list.add(11); + list.add(101); + list.add(201); + list.add(301); + list.add(401); + list.add(501); + list.add(601); + list.add(701); + LinkedList listB = new LinkedList(); + listB.add(1); + listB.add(3); + listB.add(4); + listB.add(6); + int[] result = LinkedList.getElements(list, listB); + Assert.assertArrayEquals(new int[]{101, 301, 401, 601}, result); + } + + @Test + public void testSubtract(){ + list.add(11); + list.add(101); + list.add(201); + list.add(301); + list.add(401); + list.add(501); + list.add(601); + list.add(701); + LinkedList listB = new LinkedList(); + listB.add(11); + listB.add(201); + listB.add(601); + list.subtract(listB); + Object[] obj = new Object[list.size()]; + for(int i = 0; i < list.size(); i++){ + System.out.println(list.get(i)); + obj[i] = list.get(i); + } + Assert.assertArrayEquals(new Object[]{101, 301, 401, 501, 701}, obj); + } + + @Test + public void testRemoveDuplicateValues(){ + list.add(11); + list.add(11); + list.add(11); + list.add(11); + list.add(101); + list.add(201); + list.add(201); + list.add(201); + list.add(301); + list.removeDuplicateValues(); + Object[] obj = new Object[list.size()]; + for(int i = 0; i < list.size(); i++){ + obj[i] = list.get(i); + } + Assert.assertArrayEquals(new Object[]{11, 101, 201, 301}, obj); + } + + @Test + public void testRemoveRange(){ + list.add(1); + list.add(5); + list.add(7); + list.add(9); + list.add(11); + list.add(12); + list.add(13); + list.add(14); + list.add(15); + list.add(20); + list.add(30); + list.removeRange(8, 17); + Object[] obj = new Object[list.size()]; + for(int i = 0; i < list.size(); i++){ + obj[i] = list.get(i); + } + Assert.assertArrayEquals(new Object[]{1, 5, 7, 15, 20, 30}, obj); + } + + @Test + public void testIntersection(){ + list.add(1); + list.add(2); + list.add(4); + list.add(7); + list.add(9); + list.add(11); + list.add(15); + list.add(20); + LinkedList list1 = new LinkedList(); + list1.add(2); + list1.add(3); + list1.add(5); + list1.add(6); + list1.add(7); + list1.add(8); + list1.add(11); + LinkedList result = list.intersection(list1); + Object[] obj = new Object[result.size()]; + for(int i = 0; i < result.size(); i++){ + obj[i] = result.get(i); + } + Assert.assertArrayEquals(new Object[]{2, 7, 11}, obj); + } + +} + + + diff --git "a/group06/1454385822/\346\226\207\347\253\240\344\275\234\344\270\232" "b/group06/1454385822/\346\226\207\347\253\240\344\275\234\344\270\232" new file mode 100644 index 0000000000..f20bf62bc4 --- /dev/null +++ "b/group06/1454385822/\346\226\207\347\253\240\344\275\234\344\270\232" @@ -0,0 +1,5 @@ +http://blog.csdn.net/water_baby/article/details/60583333 操作系统学习之进程 +http://blog.csdn.net/water_baby/article/details/60583333 操作系统学习——进程中的线程 +http://blog.csdn.net/water_baby/article/details/60959970 计算机组成的学习 +http://blog.csdn.net/water_baby/article/details/60962650 计算机语言学习 +http://blog.csdn.net/water_baby/article/details/61196521 基础学习之程序的机器级表示