From 72afa19846e68183c54729517359a9867094e391 Mon Sep 17 00:00:00 2001 From: GordenChow <513274874@qq.com> Date: Thu, 16 Mar 2017 20:54:23 +0800 Subject: [PATCH 1/5] =?UTF-8?q?=E6=8F=90=E4=BA=A4=E7=AC=AC=E4=BA=8C?= =?UTF-8?q?=E5=91=A8=E4=BD=9C=E4=B8=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 提交第二周作业,test尚未完成 --- .../coding/coderising/array/ArrayUtil.java | 249 +++++++++++++++++ .../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 +++ .../coding/coderising/litestruts/Struts.java | 254 ++++++++++++++++++ .../coderising/litestruts/StrutsTest.java | 43 +++ .../coding/coderising/litestruts/View.java | 23 ++ .../coding/coderising/litestruts/struts.xml | 11 + 15 files changed, 856 insertions(+) create mode 100644 group27/513274874/homework/src/com/coding/coderising/array/ArrayUtil.java create mode 100644 group27/513274874/homework/src/com/coding/coderising/download/DownloadThread.java create mode 100644 group27/513274874/homework/src/com/coding/coderising/download/FileDownloader.java create mode 100644 group27/513274874/homework/src/com/coding/coderising/download/FileDownloaderTest.java create mode 100644 group27/513274874/homework/src/com/coding/coderising/download/api/Connection.java create mode 100644 group27/513274874/homework/src/com/coding/coderising/download/api/ConnectionException.java create mode 100644 group27/513274874/homework/src/com/coding/coderising/download/api/ConnectionManager.java create mode 100644 group27/513274874/homework/src/com/coding/coderising/download/api/DownloadListener.java create mode 100644 group27/513274874/homework/src/com/coding/coderising/download/impl/ConnectionImpl.java create mode 100644 group27/513274874/homework/src/com/coding/coderising/download/impl/ConnectionManagerImpl.java create mode 100644 group27/513274874/homework/src/com/coding/coderising/litestruts/LoginAction.java create mode 100644 group27/513274874/homework/src/com/coding/coderising/litestruts/Struts.java create mode 100644 group27/513274874/homework/src/com/coding/coderising/litestruts/StrutsTest.java create mode 100644 group27/513274874/homework/src/com/coding/coderising/litestruts/View.java create mode 100644 group27/513274874/homework/src/com/coding/coderising/litestruts/struts.xml diff --git a/group27/513274874/homework/src/com/coding/coderising/array/ArrayUtil.java b/group27/513274874/homework/src/com/coding/coderising/array/ArrayUtil.java new file mode 100644 index 0000000000..2c0856829e --- /dev/null +++ b/group27/513274874/homework/src/com/coding/coderising/array/ArrayUtil.java @@ -0,0 +1,249 @@ +package com.coding.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(final int[] origin) { + int size = origin.length; + if (size <= 0) return; + + int[] newArray = this.copyOf(origin); + + for (int i = 0; i < size; i++) { + origin[i] = newArray[size - i]; + } + } + + /** + * 现在有如下的一个数组: int oldArr[]={1,3,4,5,0,0,6,6,0,5,4,7,6,7,0,5} + * 要求将以上数组中值为0的项去掉,将不为0的值存入一个新的数组,生成的新数组为: + * {1,3,4,5,6,6,5,4,7,6,7,5} + * + * @param oldArray + * @return + */ + + public int[] removeZero(int[] oldArray) { + int size = oldArray.length; + int countZero = 0; + //首先判断数组中0的个数 + for (int i : oldArray) { + if (i == 0) countZero++; + } + int[] newArray = new int[size - countZero]; + //cur 命名newArray的游标 + int cur = 0; + for (int i = 0; i < size; i++) { + if (oldArray[i] == 0) continue; + newArray[cur++] = oldArray[i]; + //cur++; + } + + return newArray; + } + + /** + * 给定两个已经排序好的整形数组, a1和a2 , 创建一个新的数组a3, 使得a3 包含a1和a2 的所有元素, 并且仍然是有序的 + * 例如 a1 = [3, 5, 7,8] a2 = [4, 5, 6,7] 则 a3 为[3,4,5,6,7,8] , 注意: 已经消除了重复 + * + * @param array1 + * @param array2 + * @return + */ + + public int[] merge(int[] array1, int[] array2) { + //判断数组是否为空 + int size1 = array1.length; + int size2 = array2.length; + if (size1 <= 0 || size2 <= 0) + return size1 <= 0 ? array2 : array1; + + //先将两个数组合并成一个数组 + int[] newArray = new int[size1 + size2]; + System.arraycopy(array1, 0, newArray, 0, size1); + System.arraycopy(array2, 0, newArray, size1, size2); + + + //对数组进行插入排序(假定array1已经是有序数组) + int in, out; + for (out = size1; out < newArray.length; out++) { + in = out; + int temp = newArray[out]; + + while (in > 0 && newArray[in - 1] >= temp) { + //右移 + newArray[in] = newArray[in - 1]; + --in; + } + newArray[in] = temp; + } + return newArray; + } + + /** + * 把一个已经存满数据的数组 oldArray的容量进行扩展, 扩展后的新数据大小为oldArray.length + size + * 注意,老数组的元素在新数组中需要保持 + * 例如 oldArray = [2,3,6] , size = 3,则返回的新数组为 + * [2,3,6,0,0,0] + * + * @param oldArray + * @param size + * @return + */ + public int[] grow(int[] oldArray, int size) { + int oldSize = oldArray.length; + if (oldSize == 0) return new int[size]; + + if (size <= 0) return oldArray; + + int[] newArray = new int[oldSize + size]; + System.arraycopy(oldArray, 0, newArray, 0, oldSize); + + return newArray; + } + + /** + * 斐波那契数列为:1,1,2,3,5,8,13,21...... ,给定一个最大值, 返回小于该值的数列 + * 例如, max = 15 , 则返回的数组应该为 [1,1,2,3,5,8,13] + * max = 1, 则返回空数组 [] + * + * @param max + * @return + */ + public int[] fibonacci(int max) { + //先确定数组长度 + if (max == 1) return new int[]{}; + //这里的cur指的是数组的下标,从0开始,而不是数学函数1开始 + int cur = 1; + while (cur * 2 - 1 <= max) { + ++cur; + } + + int[] newArray = new int[cur + 1]; + for (int i = 0; i <= cur + 1; i++) { + if (i == 0 || i == 1) { + newArray[i] = 1; + } + newArray[i] = newArray[i - 1] + newArray[i - 2]; + + } + return newArray; + } + + /** + * 返回小于给定最大值max的所有素数数组 + * 例如max = 23, 返回的数组为[2,3,5,7,11,13,17,19] + * + * @param max + * @return + */ + public int[] getPrimes(int max) { + //先确定数组长度 + //判断质数循环 + int count = 0; + for (int i = 1; i <= max; i++) { + //去掉偶数 + if (i == 1 || (i % 2 == 0 && i != 2)) continue; + //判断到开根号即可 + for (int j = 3; j <= Math.sqrt(i); j += 2) { + if (i % j == 0) { + ++count; + break; + } + } + } + int[] newArray = new int[count]; + int cur = 0; + for (int i = 1; i <= max; i++) { + //去掉偶数 + if (i == 1 || (i % 2 == 0 && i != 2)) continue; + //判断到开根号即可 + for (int j = 3; j <= Math.sqrt(i); j += 2) { + if (i % j == 0) { + newArray[cur] = i; + ++cur; + } + } + } + return newArray; + } + + /** + * 所谓“完数”, 是指这个数恰好等于它的因子之和,例如6=1+2+3 + * 给定一个最大值max, 返回一个数组, 数组中是小于max 的所有完数 + * + * @param max + * @return + */ + public int[] getPerfectNumbers(int max) { + //求数组长度 + int count = 0; + for(int a=1;a<=max;a++){ + int sum=0; + for(int i=1;i<=a/2;i++) + if(a%i==0) + sum+=i; + if(a==sum) + ++count; + } + + int[] newArray = new int[count]; + int cur = 0; + for(int a=1;a<=max;a++){ + int sum=0; + for(int i=1;i<=a/2;i++) + if(a%i==0) + sum+=i; + if(a==sum) + { + newArray[cur] = a; + ++cur; + } + } + + return newArray; + } + + /** + * 用seperator 把数组 array给连接起来 + * 例如array= [3,8,9], seperator = "-" + * 则返回值为"3-8-9" + * + * @param array + * @param seperator + * @return + */ + public String join(int[] array, String seperator) { + int size = array.length; + if (size == 0) return ""; + StringBuffer sb = new StringBuffer(""); + for (int i = 0; i < size - 1; i++) { + sb.append(array[i]).append(seperator); + } + sb.append(array[size - 1]); + return sb.toString(); + } + + + /** + * 类私有函数,复制返回一个新的数组 + */ + private int[] copyOf(int[] source) { + int size = source.length; + if (size <= 0) return null; + + int[] newArray = new int[size]; + //int[] ints = Arrays.copyOf(origin, size); + System.arraycopy(source, 0, newArray, 0, size); + return newArray; + } + + +} diff --git a/group27/513274874/homework/src/com/coding/coderising/download/DownloadThread.java b/group27/513274874/homework/src/com/coding/coderising/download/DownloadThread.java new file mode 100644 index 0000000000..1456314140 --- /dev/null +++ b/group27/513274874/homework/src/com/coding/coderising/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/group27/513274874/homework/src/com/coding/coderising/download/FileDownloader.java b/group27/513274874/homework/src/com/coding/coderising/download/FileDownloader.java new file mode 100644 index 0000000000..f5d7999eb4 --- /dev/null +++ b/group27/513274874/homework/src/com/coding/coderising/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/group27/513274874/homework/src/com/coding/coderising/download/FileDownloaderTest.java b/group27/513274874/homework/src/com/coding/coderising/download/FileDownloaderTest.java new file mode 100644 index 0000000000..8171ee5763 --- /dev/null +++ b/group27/513274874/homework/src/com/coding/coderising/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/group27/513274874/homework/src/com/coding/coderising/download/api/Connection.java b/group27/513274874/homework/src/com/coding/coderising/download/api/Connection.java new file mode 100644 index 0000000000..9710e270e1 --- /dev/null +++ b/group27/513274874/homework/src/com/coding/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/group27/513274874/homework/src/com/coding/coderising/download/api/ConnectionException.java b/group27/513274874/homework/src/com/coding/coderising/download/api/ConnectionException.java new file mode 100644 index 0000000000..8dbfe95dda --- /dev/null +++ b/group27/513274874/homework/src/com/coding/coderising/download/api/ConnectionException.java @@ -0,0 +1,5 @@ +package com.coderising.download.api; + +public class ConnectionException extends Exception { + +} diff --git a/group27/513274874/homework/src/com/coding/coderising/download/api/ConnectionManager.java b/group27/513274874/homework/src/com/coding/coderising/download/api/ConnectionManager.java new file mode 100644 index 0000000000..fb44ede457 --- /dev/null +++ b/group27/513274874/homework/src/com/coding/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/group27/513274874/homework/src/com/coding/coderising/download/api/DownloadListener.java b/group27/513274874/homework/src/com/coding/coderising/download/api/DownloadListener.java new file mode 100644 index 0000000000..4cd0b3eab1 --- /dev/null +++ b/group27/513274874/homework/src/com/coding/coderising/download/api/DownloadListener.java @@ -0,0 +1,5 @@ +package com.coderising.download.api; + +public interface DownloadListener { + public void notifyFinished(); +} diff --git a/group27/513274874/homework/src/com/coding/coderising/download/impl/ConnectionImpl.java b/group27/513274874/homework/src/com/coding/coderising/download/impl/ConnectionImpl.java new file mode 100644 index 0000000000..32f03efdc7 --- /dev/null +++ b/group27/513274874/homework/src/com/coding/coderising/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/group27/513274874/homework/src/com/coding/coderising/download/impl/ConnectionManagerImpl.java b/group27/513274874/homework/src/com/coding/coderising/download/impl/ConnectionManagerImpl.java new file mode 100644 index 0000000000..046f7c49a4 --- /dev/null +++ b/group27/513274874/homework/src/com/coding/coderising/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; + } + +} diff --git a/group27/513274874/homework/src/com/coding/coderising/litestruts/LoginAction.java b/group27/513274874/homework/src/com/coding/coderising/litestruts/LoginAction.java new file mode 100644 index 0000000000..689678f3ad --- /dev/null +++ b/group27/513274874/homework/src/com/coding/coderising/litestruts/LoginAction.java @@ -0,0 +1,39 @@ +package com.coding.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/group27/513274874/homework/src/com/coding/coderising/litestruts/Struts.java b/group27/513274874/homework/src/com/coding/coderising/litestruts/Struts.java new file mode 100644 index 0000000000..7aa7dacb4a --- /dev/null +++ b/group27/513274874/homework/src/com/coding/coderising/litestruts/Struts.java @@ -0,0 +1,254 @@ +package com.coding.coderising.litestruts; + +import org.dom4j.Attribute; +import org.dom4j.Document; +import org.dom4j.DocumentException; +import org.dom4j.Element; +import org.dom4j.io.SAXReader; + +import java.beans.IntrospectionException; +import java.beans.PropertyDescriptor; +import java.io.File; +import java.io.FileNotFoundException; +import java.lang.reflect.Field; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; + + +public class Struts { + + private static Struts instance = null; + private static Map strutsXml; + + private Struts() { + } + + /** + * 单例模式初始化struts.xml,而不是每次跑runAction的时候都要初始化一次 + * + * @return + */ + public static Struts init() throws FileNotFoundException { + + if (instance == null) { + /** + * 0. 读取配置文件struts.xml + */ + //创建SAXReader对象 + SAXReader reader = new SAXReader(); + //读取文件 转换成Document + Document document = null; + try { + document = reader.read(new File("src/com/coding/coderising/litestruts/struts.xml")); + } catch (DocumentException e) { + e.printStackTrace(); + } + //获取根节点元素对象 + Element root = document.getRootElement(); + if ("struts".equals(root.getName())) { + strutsXml = new HashMap(); + + Iterator actions = root.elementIterator(); + while (actions.hasNext()) { + Element action = actions.next(); + List attrList = action.attributes(); + + String actionName = null; + StrutsXml xml = null; + if (!"action".equals(action.getName())) { + continue; + } + //遍历属性节点 + for (Attribute attribute : attrList) { + xml = new StrutsXml(); + if ("name".equals(attribute.getName())) { + actionName = attribute.getValue(); + } + if ("class".equals(attribute.getName())) { + xml.setClazz(attribute.getValue()); + //获取result信息 + Iterator results = action.elementIterator(); + while (results.hasNext()) { + Element result = results.next(); + List resultList = result.attributes(); + for (Attribute resultAttr : resultList) { + //System.out.println(resultAttr.getValue() + " ,"+result.getText()); + xml.getResult().put(resultAttr.getValue(), result.getText()); + } + } + + } + //System.out.println("属性"+attribute.getName() +":" + attribute.getValue()); + } + + strutsXml.put(actionName, xml); + } + } else { + throw new FileNotFoundException("not a struts XML file !"); + } + + + instance = new Struts(); + } + return instance; + } + + public static View runAction(String actionName, Map parameters) { + + if (instance == null) return null; + if (actionName == null || "".equals(actionName.trim())) return null; + View view = new View(); + StrutsXml struts = strutsXml.get(actionName); + + Class clazz = null; + /** + * 1. 根据actionName找到相对应的class , 例如LoginAction, 通过反射实例化(创建对象) + * 据parameters中的数据,调用对象的setter方法, 例如parameters中的数据是 + * ("name"="test" , "password"="1234") ,那就应该调用 setName和setPassword方法 + */ + //获取相应处理的action + if (struts != null) { + String className = struts.getClazz(); + try { + clazz = Class.forName(className); + } catch (ClassNotFoundException e) { + e.printStackTrace(); + } + } else { + throw new NullPointerException("action not found in struts file !"); + } + + if (clazz != null) { + Object action = null; + try { + action = clazz.newInstance(); + + //反射调用设置参数 + for (Map.Entry entry : parameters.entrySet()) { + String para = entry.getKey(); + if (!checkField(clazz, para)) continue; + //根据习惯,类的属性首字母在调用时大写,例如属性名是 age,则类方法为getAge + PropertyDescriptor pd = new PropertyDescriptor(para, clazz); + + Method setMethod = pd.getWriteMethod();//获得set方法 + + setMethod.invoke(action, entry.getValue()); + + } + /** + * 2. 通过反射调用对象的exectue 方法, 并获得返回值,例如"success" + */ + //执行execute() + Method excuteMethod = clazz.getDeclaredMethod("execute"); + String result = (String) excuteMethod.invoke(action); + //通过xml文件获取返回值 + String jsp = struts.getResult().get(result); + + if (jsp == null || jsp.trim().equals("")) { + throw new NullPointerException("the requested file is not found !"); + } + /** + * 3. 通过反射找到对象的所有getter方法(例如 getMessage), + * 通过反射来调用, 把值和属性形成一个HashMap , 例如 {"message": "登录成功"} , + * 放到View对象的parameters + */ + //执行get方法 + Map viewMap = new HashMap<>(); + Field[] fields = clazz.getDeclaredFields();//获得属性 + + for (Field field : fields) { + String getMethodName = "get" + field.getName().substring(0, 1).toUpperCase() + field.getName().substring(1); + Method getMethod = clazz.getDeclaredMethod(getMethodName); + String returnVal = (String) getMethod.invoke(action); + viewMap.put(field.getName(), returnVal); + } + /** + * 4. 根据struts.xml中的 配置,以及execute的返回值, 确定哪一个jsp, + * 放到View对象的jsp字段中。 + */ + view.setJsp(jsp); + view.setParameters(viewMap); + + } catch (IntrospectionException e) { + e.printStackTrace(); + } catch (InvocationTargetException e) { + e.printStackTrace(); + } catch (NoSuchMethodException e) { + e.printStackTrace(); + } catch (IllegalAccessException e) { + e.printStackTrace(); + } catch (InstantiationException e) { + e.printStackTrace(); + } + } + + return view; + + + } + + private static boolean checkField(Class clazz, String fieldName) { + if (fieldName == null || fieldName.trim().equals("")) return false; + Field[] fields = clazz.getDeclaredFields(); + for (Field field : fields) { + if (fieldName.equals(field.getName())) return true; + } + return false; + } + + + public static void main(String args[]) { + try { + Struts.init(); + } catch (FileNotFoundException e) { + e.printStackTrace(); + } + Map paras = new HashMap<>(); + paras.put("name", "test"); + paras.put("password", "1234"); + View view = Struts.runAction("login", paras); + } +} + +class StrutsXml { + private String actionName; + private String clazz; + private Map result = new HashMap<>(); + + public StrutsXml(String actionName, String clazz, Map result) { + this.actionName = actionName; + this.clazz = clazz; + this.result = result; + } + + public StrutsXml() { + } + + public String getActionName() { + return actionName; + } + + public void setActionName(String actionName) { + this.actionName = actionName; + } + + public String getClazz() { + return clazz; + } + + public void setClazz(String clazz) { + this.clazz = clazz; + } + + public Map getResult() { + return result; + } + + public void setResult(Map result) { + this.result = result; + } +} \ No newline at end of file diff --git a/group27/513274874/homework/src/com/coding/coderising/litestruts/StrutsTest.java b/group27/513274874/homework/src/com/coding/coderising/litestruts/StrutsTest.java new file mode 100644 index 0000000000..2cf94955f6 --- /dev/null +++ b/group27/513274874/homework/src/com/coding/coderising/litestruts/StrutsTest.java @@ -0,0 +1,43 @@ +package com.coding.coderising.litestruts; + +import org.junit.Assert; +import org.junit.Test; + +import java.util.HashMap; +import java.util.Map; + + + + + +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/group27/513274874/homework/src/com/coding/coderising/litestruts/View.java b/group27/513274874/homework/src/com/coding/coderising/litestruts/View.java new file mode 100644 index 0000000000..ab1297a4a0 --- /dev/null +++ b/group27/513274874/homework/src/com/coding/coderising/litestruts/View.java @@ -0,0 +1,23 @@ +package com.coding.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/group27/513274874/homework/src/com/coding/coderising/litestruts/struts.xml b/group27/513274874/homework/src/com/coding/coderising/litestruts/struts.xml new file mode 100644 index 0000000000..92cb2bcb23 --- /dev/null +++ b/group27/513274874/homework/src/com/coding/coderising/litestruts/struts.xml @@ -0,0 +1,11 @@ + + + + /jsp/homepage.jsp + /jsp/showLogin.jsp + + + /jsp/welcome.jsp + /jsp/error.jsp + + From bea509a4d39adeb09f14f72cac6675a46549f3cc Mon Sep 17 00:00:00 2001 From: GordenChow <513274874@qq.com> Date: Thu, 16 Mar 2017 21:01:10 +0800 Subject: [PATCH 2/5] Revert "Merge branch 'wizardzhang2017/master'" This reverts commit 393ded9ae1f85278fab1c621ec9692375751c282, reversing changes made to 2f5a03f209f73445de5ec8896d7ce6afa96d852c. --- .../src/com/coding/basic/ArrayList.java | 123 ------ .../src/com/coding/basic/BinaryTreeNode.java | 32 -- .../src/com/coding/basic/Iterator.java | 8 - .../src/com/coding/basic/LinkedList.java | 212 ---------- .../guoqixuan/src/com/coding/basic/List.java | 9 - .../guoqixuan/src/com/coding/basic/Queue.java | 21 - .../guoqixuan/src/com/coding/basic/Stack.java | 41 -- group27/1016908591/week01/.classpath | 6 - group27/1016908591/week01/.gitignore | 1 - group27/1016908591/week01/.project | 17 - .../.settings/org.eclipse.jdt.core.prefs | 11 - .../src/com/coding/basic/ArrayList.java | 123 ------ .../src/com/coding/basic/BinaryTreeNode.java | 32 -- .../week01/src/com/coding/basic/Iterator.java | 8 - .../src/com/coding/basic/LinkedList.java | 212 ---------- .../week01/src/com/coding/basic/List.java | 9 - .../week01/src/com/coding/basic/Queue.java | 21 - .../week01/src/com/coding/basic/Stack.java | 41 -- .../src/\346\265\205\350\260\210CPU.txt" | 1 - .../RemoteSystemsTempFiles/.project | 12 - group27/1067041567/TestColleaction/.classpath | 6 - group27/1067041567/TestColleaction/.gitignore | 1 - group27/1067041567/TestColleaction/.project | 17 - .../.settings/org.eclipse.jdt.core.prefs | 11 - .../src/cn/task1/ArrayList.java | 100 ----- .../src/cn/task1/LinkedList.java | 146 ------- .../TestColleaction/src/cn/task1/List.java | 14 - .../TestColleaction/src/cn/task1/Queue.java | 115 ------ .../TestColleaction/src/cn/task1/Stack.java | 68 ---- .../TestColleaction/src/cn/task1/Test.java | 20 - group27/1252327158/task1_20170312/.classpath | 7 - group27/1252327158/task1_20170312/.project | 17 - .../org.eclipse.core.resources.prefs | 3 - .../src/com/coding/ArrayList.java | 111 ----- .../src/com/coding/ArrayListTest.java | 64 --- .../src/com/coding/BinaryTreeNode.java | 52 --- .../src/com/coding/BinaryTreeNodeTest.java | 58 --- .../src/com/coding/Iterator.java | 6 - .../src/com/coding/LinkedList.java | 256 ------------ .../src/com/coding/LinkedListTest.java | 95 ----- .../task1_20170312/src/com/coding/List.java | 9 - .../task1_20170312/src/com/coding/Queue.java | 22 - .../src/com/coding/QueueTest.java | 46 --- .../task1_20170312/src/com/coding/Stack.java | 24 -- .../src/com/coding/StackTest.java | 45 --- group27/2567012201/.DS_Store | Bin 6148 -> 0 bytes .../2567012201/2567012201learning/.DS_Store | Bin 6148 -> 0 bytes .../2567012201/2567012201learning/.classpath | 6 - .../2567012201/2567012201learning/.gitignore | 1 - .../2567012201/2567012201learning/.project | 17 - .../.settings/org.eclipse.jdt.core.prefs | 11 - .../2567012201learning/src/.DS_Store | Bin 6148 -> 0 bytes .../2567012201learning/src/com/.DS_Store | Bin 6148 -> 0 bytes .../src/com/coding/.DS_Store | Bin 6148 -> 0 bytes .../src/com/coding/DataStructure/.DS_Store | Bin 6148 -> 0 bytes .../com/coding/DataStructure/ArrayList.java | 54 --- .../com/coding/DataStructure/LinkedList.java | 10 - .../src/com/coding/DataStructure/Queue.java | 36 -- .../src/com/coding/DataStructure/Stack.java | 41 -- .../src/com/coding/DataStructure/Tree.java | 51 --- .../RemoteSystemsTempFiles/.project | 12 - group27/276961139/src/learn/ArrayList.java | 93 ----- .../276961139/src/learn/BinaryTreeNode.java | 46 --- group27/276961139/src/learn/Iterator.java | 7 - group27/276961139/src/learn/LinkedList.java | 255 ------------ group27/276961139/src/learn/List.java | 9 - group27/276961139/src/learn/Queue.java | 32 -- group27/276961139/src/learn/Stack.java | 23 -- group27/383117348/.classpath | 9 - group27/383117348/.gitignore | 21 - group27/383117348/.project | 17 - .../src/com/coding/basic/ArrayList.java | 213 ---------- .../src/com/coding/basic/BinaryTreeNode.java | 115 ------ .../src/com/coding/basic/Iterator.java | 7 - .../src/com/coding/basic/LinkedList.java | 382 ------------------ .../383117348/src/com/coding/basic/List.java | 9 - .../383117348/src/com/coding/basic/Queue.java | 74 ---- .../383117348/src/com/coding/basic/Stack.java | 99 ----- .../src/com/coding/basic/ArrayList.java | 97 ----- .../src/com/coding/basic/BinaryTreeNode.java | 41 -- .../src/com/coding/basic/Iterator.java | 6 - .../src/com/coding/basic/LinkedList.java | 274 ------------- .../425044891/src/com/coding/basic/List.java | 9 - .../425044891/src/com/coding/basic/Queue.java | 37 -- .../425044891/src/com/coding/basic/Stack.java | 29 -- group27/772642286/basic/ArrayList.java | 80 ---- group27/772642286/basic/BinaryTreeNode.java | 55 --- group27/772642286/basic/Iterator.java | 7 - group27/772642286/basic/LinkedList.java | 208 ---------- group27/772642286/basic/List.java | 9 - group27/772642286/basic/Queue.java | 21 - group27/772642286/basic/Stack.java | 23 -- group27/772642286/test/ArrayListTest.java | 55 --- .../772642286/test/BinaryTreeNodeTest.java | 6 - group27/772642286/test/LinkedListTest.java | 52 --- group27/772642286/test/QueueTest.java | 45 --- group27/772642286/test/StackTest.java | 58 --- group27/815591664/2017Learning/.classpath | 7 - group27/815591664/2017Learning/.gitignore | 1 - group27/815591664/2017Learning/.project | 17 - .../org.eclipse.core.resources.prefs | 2 - .../src/com/coderising/array/ArrayUtil.java | 348 ---------------- .../coderising/litestruts/LoginAction.java | 39 -- .../src/com/coderising/litestruts/Struts.java | 34 -- .../com/coderising/litestruts/StrutsTest.java | 43 -- .../src/com/coderising/litestruts/View.java | 23 -- .../src/com/coderising/litestruts/struts.xml | 11 - .../src/com/coding/basic/ArrayList.java | 146 ------- .../src/com/coding/basic/BinaryTree.java | 35 -- .../src/com/coding/basic/BinaryTreeNode.java | 43 -- .../src/com/coding/basic/Iterator.java | 9 - .../src/com/coding/basic/LinkedList.java | 236 ----------- .../src/com/coding/basic/List.java | 9 - .../src/com/coding/basic/Queue.java | 27 -- .../src/com/coding/basic/Stack.java | 29 -- 115 files changed, 6074 deletions(-) delete mode 100644 group27/1016908591/guoqixuan/src/com/coding/basic/ArrayList.java delete mode 100644 group27/1016908591/guoqixuan/src/com/coding/basic/BinaryTreeNode.java delete mode 100644 group27/1016908591/guoqixuan/src/com/coding/basic/Iterator.java delete mode 100644 group27/1016908591/guoqixuan/src/com/coding/basic/LinkedList.java delete mode 100644 group27/1016908591/guoqixuan/src/com/coding/basic/List.java delete mode 100644 group27/1016908591/guoqixuan/src/com/coding/basic/Queue.java delete mode 100644 group27/1016908591/guoqixuan/src/com/coding/basic/Stack.java delete mode 100644 group27/1016908591/week01/.classpath delete mode 100644 group27/1016908591/week01/.gitignore delete mode 100644 group27/1016908591/week01/.project delete mode 100644 group27/1016908591/week01/.settings/org.eclipse.jdt.core.prefs delete mode 100644 group27/1016908591/week01/src/com/coding/basic/ArrayList.java delete mode 100644 group27/1016908591/week01/src/com/coding/basic/BinaryTreeNode.java delete mode 100644 group27/1016908591/week01/src/com/coding/basic/Iterator.java delete mode 100644 group27/1016908591/week01/src/com/coding/basic/LinkedList.java delete mode 100644 group27/1016908591/week01/src/com/coding/basic/List.java delete mode 100644 group27/1016908591/week01/src/com/coding/basic/Queue.java delete mode 100644 group27/1016908591/week01/src/com/coding/basic/Stack.java delete mode 100644 "group27/1016908591/week01/src/\346\265\205\350\260\210CPU.txt" delete mode 100644 group27/1067041567/RemoteSystemsTempFiles/.project delete mode 100644 group27/1067041567/TestColleaction/.classpath delete mode 100644 group27/1067041567/TestColleaction/.gitignore delete mode 100644 group27/1067041567/TestColleaction/.project delete mode 100644 group27/1067041567/TestColleaction/.settings/org.eclipse.jdt.core.prefs delete mode 100644 group27/1067041567/TestColleaction/src/cn/task1/ArrayList.java delete mode 100644 group27/1067041567/TestColleaction/src/cn/task1/LinkedList.java delete mode 100644 group27/1067041567/TestColleaction/src/cn/task1/List.java delete mode 100644 group27/1067041567/TestColleaction/src/cn/task1/Queue.java delete mode 100644 group27/1067041567/TestColleaction/src/cn/task1/Stack.java delete mode 100644 group27/1067041567/TestColleaction/src/cn/task1/Test.java delete mode 100644 group27/1252327158/task1_20170312/.classpath delete mode 100644 group27/1252327158/task1_20170312/.project delete mode 100644 group27/1252327158/task1_20170312/.settings/org.eclipse.core.resources.prefs delete mode 100644 group27/1252327158/task1_20170312/src/com/coding/ArrayList.java delete mode 100644 group27/1252327158/task1_20170312/src/com/coding/ArrayListTest.java delete mode 100644 group27/1252327158/task1_20170312/src/com/coding/BinaryTreeNode.java delete mode 100644 group27/1252327158/task1_20170312/src/com/coding/BinaryTreeNodeTest.java delete mode 100644 group27/1252327158/task1_20170312/src/com/coding/Iterator.java delete mode 100644 group27/1252327158/task1_20170312/src/com/coding/LinkedList.java delete mode 100644 group27/1252327158/task1_20170312/src/com/coding/LinkedListTest.java delete mode 100644 group27/1252327158/task1_20170312/src/com/coding/List.java delete mode 100644 group27/1252327158/task1_20170312/src/com/coding/Queue.java delete mode 100644 group27/1252327158/task1_20170312/src/com/coding/QueueTest.java delete mode 100644 group27/1252327158/task1_20170312/src/com/coding/Stack.java delete mode 100644 group27/1252327158/task1_20170312/src/com/coding/StackTest.java delete mode 100644 group27/2567012201/.DS_Store delete mode 100644 group27/2567012201/2567012201learning/.DS_Store delete mode 100644 group27/2567012201/2567012201learning/.classpath delete mode 100644 group27/2567012201/2567012201learning/.gitignore delete mode 100644 group27/2567012201/2567012201learning/.project delete mode 100644 group27/2567012201/2567012201learning/.settings/org.eclipse.jdt.core.prefs delete mode 100644 group27/2567012201/2567012201learning/src/.DS_Store delete mode 100644 group27/2567012201/2567012201learning/src/com/.DS_Store delete mode 100644 group27/2567012201/2567012201learning/src/com/coding/.DS_Store delete mode 100644 group27/2567012201/2567012201learning/src/com/coding/DataStructure/.DS_Store delete mode 100644 group27/2567012201/2567012201learning/src/com/coding/DataStructure/ArrayList.java delete mode 100644 group27/2567012201/2567012201learning/src/com/coding/DataStructure/LinkedList.java delete mode 100644 group27/2567012201/2567012201learning/src/com/coding/DataStructure/Queue.java delete mode 100644 group27/2567012201/2567012201learning/src/com/coding/DataStructure/Stack.java delete mode 100644 group27/2567012201/2567012201learning/src/com/coding/DataStructure/Tree.java delete mode 100644 group27/2567012201/RemoteSystemsTempFiles/.project delete mode 100644 group27/276961139/src/learn/ArrayList.java delete mode 100644 group27/276961139/src/learn/BinaryTreeNode.java delete mode 100644 group27/276961139/src/learn/Iterator.java delete mode 100644 group27/276961139/src/learn/LinkedList.java delete mode 100644 group27/276961139/src/learn/List.java delete mode 100644 group27/276961139/src/learn/Queue.java delete mode 100644 group27/276961139/src/learn/Stack.java delete mode 100644 group27/383117348/.classpath delete mode 100644 group27/383117348/.gitignore delete mode 100644 group27/383117348/.project delete mode 100644 group27/383117348/src/com/coding/basic/ArrayList.java delete mode 100644 group27/383117348/src/com/coding/basic/BinaryTreeNode.java delete mode 100644 group27/383117348/src/com/coding/basic/Iterator.java delete mode 100644 group27/383117348/src/com/coding/basic/LinkedList.java delete mode 100644 group27/383117348/src/com/coding/basic/List.java delete mode 100644 group27/383117348/src/com/coding/basic/Queue.java delete mode 100644 group27/383117348/src/com/coding/basic/Stack.java delete mode 100644 group27/425044891/src/com/coding/basic/ArrayList.java delete mode 100644 group27/425044891/src/com/coding/basic/BinaryTreeNode.java delete mode 100644 group27/425044891/src/com/coding/basic/Iterator.java delete mode 100644 group27/425044891/src/com/coding/basic/LinkedList.java delete mode 100644 group27/425044891/src/com/coding/basic/List.java delete mode 100644 group27/425044891/src/com/coding/basic/Queue.java delete mode 100644 group27/425044891/src/com/coding/basic/Stack.java delete mode 100644 group27/772642286/basic/ArrayList.java delete mode 100644 group27/772642286/basic/BinaryTreeNode.java delete mode 100644 group27/772642286/basic/Iterator.java delete mode 100644 group27/772642286/basic/LinkedList.java delete mode 100644 group27/772642286/basic/List.java delete mode 100644 group27/772642286/basic/Queue.java delete mode 100644 group27/772642286/basic/Stack.java delete mode 100644 group27/772642286/test/ArrayListTest.java delete mode 100644 group27/772642286/test/BinaryTreeNodeTest.java delete mode 100644 group27/772642286/test/LinkedListTest.java delete mode 100644 group27/772642286/test/QueueTest.java delete mode 100644 group27/772642286/test/StackTest.java delete mode 100644 group27/815591664/2017Learning/.classpath delete mode 100644 group27/815591664/2017Learning/.gitignore delete mode 100644 group27/815591664/2017Learning/.project delete mode 100644 group27/815591664/2017Learning/.settings/org.eclipse.core.resources.prefs delete mode 100644 group27/815591664/2017Learning/src/com/coderising/array/ArrayUtil.java delete mode 100644 group27/815591664/2017Learning/src/com/coderising/litestruts/LoginAction.java delete mode 100644 group27/815591664/2017Learning/src/com/coderising/litestruts/Struts.java delete mode 100644 group27/815591664/2017Learning/src/com/coderising/litestruts/StrutsTest.java delete mode 100644 group27/815591664/2017Learning/src/com/coderising/litestruts/View.java delete mode 100644 group27/815591664/2017Learning/src/com/coderising/litestruts/struts.xml delete mode 100644 group27/815591664/2017Learning/src/com/coding/basic/ArrayList.java delete mode 100644 group27/815591664/2017Learning/src/com/coding/basic/BinaryTree.java delete mode 100644 group27/815591664/2017Learning/src/com/coding/basic/BinaryTreeNode.java delete mode 100644 group27/815591664/2017Learning/src/com/coding/basic/Iterator.java delete mode 100644 group27/815591664/2017Learning/src/com/coding/basic/LinkedList.java delete mode 100644 group27/815591664/2017Learning/src/com/coding/basic/List.java delete mode 100644 group27/815591664/2017Learning/src/com/coding/basic/Queue.java delete mode 100644 group27/815591664/2017Learning/src/com/coding/basic/Stack.java diff --git a/group27/1016908591/guoqixuan/src/com/coding/basic/ArrayList.java b/group27/1016908591/guoqixuan/src/com/coding/basic/ArrayList.java deleted file mode 100644 index 2eab2cd640..0000000000 --- a/group27/1016908591/guoqixuan/src/com/coding/basic/ArrayList.java +++ /dev/null @@ -1,123 +0,0 @@ -package com.coding.basic; - -import java.util.Arrays; - - -public class ArrayList implements List{ - - private int size = 0; - - private Object[] elementData = new Object[100]; - - private int length; - private static final int MAX_SIZE = 50; - - public ArrayList(){ - this(MAX_SIZE); - } - public ArrayList(int maxSize){ - length = 0; - elementData = new Object[maxSize]; - } - - public void add(Object o){ - if(! isFull()){ - elementData[size] =o; - size++; - } - else - elementData = Arrays.copyOf(elementData, elementData.length*2); - - - } - public void add(int index, Object o){ - - makeRoom(index); - elementData[size-1] =o; - size++; - - - - } - - public Object get(int index){ - if(index>0 && indexsize){ - System.out.println("����Խ��"); - return null; - } - Object o = elementData[size]; - System.arraycopy(elementData,index+1,elementData,index,size-index-1); - elementData[size--] = null; - return o; - - - } - - public int size(){ - return elementData.length; - } - - public Iterator iterator(){ - return null; - } - - public boolean isFull(){ - return size == elementData.length; - } - - - private void makeRoom(int index){ - for(int i = size;i>=index;i--){ - elementData[i] =elementData[i-1]; - - } - } - - public Iterator getiterator(){ - return new ArrayListIterator(this); - } - - private class ArrayListIterator implements Iterator{ - ArrayList l = null; - private int nextIndex; - ArrayListIterator(ArrayList l){ - nextIndex = 0; - this.l = l; - - } - @Override - public boolean hasNext() { - - return nextIndex7->10 , 逆置后变为 10->7->3 - */ - public void reverse(){ - - } - - /** - * 删除一个单链表的前半部分 - * 例如:list = 2->5->7->8 , 删除以后的值为 7->8 - * 如果list = 2->5->7->8->10 ,删除以后的值为7,8,10 - - */ - public void removeFirstHalf(){ - - } - - /** - * 从第i个元素开始, 删除length 个元素 , 注意i从0开始 - * @param i - * @param length - */ - public void remove(int i, int length){ - - } - /** - * 假定当前链表和list均包含已升序排列的整数 - * 从当前链表中取出那些list所指定的元素 - * 例如当前链表 = 11->101->201->301->401->501->601->701 - * listB = 1->3->4->6 - * 返回的结果应该是[101,301,401,601] - * @param list - */ - public static int[] getElements(LinkedList list){ - return null; - } - - /** - * 已知链表中的元素以值递增有序排列,并以单链表作存储结构。 - * 从当前链表中中删除在list中出现的元素 - - * @param list - */ - - public void subtract(LinkedList list){ - - } - - /** - * 已知当前链表中的元素以值递增有序排列,并以单链表作存储结构。 - * 删除表中所有值相同的多余元素(使得操作后的线性表中所有元素的值均不相同) - */ - public void removeDuplicateValues(){ - - } - - /** - * 已知链表中的元素以值递增有序排列,并以单链表作存储结构。 - * 试写一高效的算法,删除表中所有值大于min且小于max的元素(若表中存在这样的元素) - * @param min - * @param max - */ - public void removeRange(int min, int max){ - - } - - /** - * 假设当前链表和参数list指定的链表均以元素依值递增有序排列(同一表中的元素值各不相同) - * 现要求生成新链表C,其元素为当前链表和list中元素的交集,且表C中的元素有依值递增有序排列 - * @param list - */ - public LinkedList intersection( LinkedList list){ - return null; - } -} diff --git a/group27/1016908591/guoqixuan/src/com/coding/basic/List.java b/group27/1016908591/guoqixuan/src/com/coding/basic/List.java deleted file mode 100644 index 10d13b5832..0000000000 --- a/group27/1016908591/guoqixuan/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/group27/1016908591/guoqixuan/src/com/coding/basic/Queue.java b/group27/1016908591/guoqixuan/src/com/coding/basic/Queue.java deleted file mode 100644 index b31c1625b4..0000000000 --- a/group27/1016908591/guoqixuan/src/com/coding/basic/Queue.java +++ /dev/null @@ -1,21 +0,0 @@ -package com.coding.basic; - -public class Queue { - private LinkedList List = new LinkedList(); - - public void enQueue(Object o){ - List.addLast(o); - } - - public Object deQueue(){ - return List.removeFirst(); - } - - public boolean isEmpty(){ - return List.size()==0; - } - - public int size(){ - return List.size(); - } -} diff --git a/group27/1016908591/guoqixuan/src/com/coding/basic/Stack.java b/group27/1016908591/guoqixuan/src/com/coding/basic/Stack.java deleted file mode 100644 index 060fd1862d..0000000000 --- a/group27/1016908591/guoqixuan/src/com/coding/basic/Stack.java +++ /dev/null @@ -1,41 +0,0 @@ -package com.coding.basic; -import java.util.Arrays; -import java.util.EmptyStackException; - -public class Stack { - private ArrayList elementData = new ArrayList(); - private int topIndex =-1;//栈顶元素索引 - private static final int DEFAULT_MAX_SIZE = 50; - private int length; - - //压入一个元素 - public void push(Object o){ - topIndex++; - elementData.add(o); - - - - } - - public Object pop(){ - if(elementData.size() ==0 ){ - throw new EmptyStackException(); - } - topIndex--; - return elementData.remove(elementData.size()-1); - - } - - public Object peek(){ - if(elementData.size()!=1){ - return elementData.get(elementData.size()-1); - } - return null; - } - public boolean isEmpty(){ - return topIndex>0; - } - public int size(){ - return topIndex; - } -} diff --git a/group27/1016908591/week01/.classpath b/group27/1016908591/week01/.classpath deleted file mode 100644 index fb565a588d..0000000000 --- a/group27/1016908591/week01/.classpath +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - diff --git a/group27/1016908591/week01/.gitignore b/group27/1016908591/week01/.gitignore deleted file mode 100644 index 5e56e040ec..0000000000 --- a/group27/1016908591/week01/.gitignore +++ /dev/null @@ -1 +0,0 @@ -/bin diff --git a/group27/1016908591/week01/.project b/group27/1016908591/week01/.project deleted file mode 100644 index 3b3c4fa7ee..0000000000 --- a/group27/1016908591/week01/.project +++ /dev/null @@ -1,17 +0,0 @@ - - - week01 - - - - - - org.eclipse.jdt.core.javabuilder - - - - - - org.eclipse.jdt.core.javanature - - diff --git a/group27/1016908591/week01/.settings/org.eclipse.jdt.core.prefs b/group27/1016908591/week01/.settings/org.eclipse.jdt.core.prefs deleted file mode 100644 index 7341ab1683..0000000000 --- a/group27/1016908591/week01/.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.7 -org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve -org.eclipse.jdt.core.compiler.compliance=1.7 -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.7 diff --git a/group27/1016908591/week01/src/com/coding/basic/ArrayList.java b/group27/1016908591/week01/src/com/coding/basic/ArrayList.java deleted file mode 100644 index 2eab2cd640..0000000000 --- a/group27/1016908591/week01/src/com/coding/basic/ArrayList.java +++ /dev/null @@ -1,123 +0,0 @@ -package com.coding.basic; - -import java.util.Arrays; - - -public class ArrayList implements List{ - - private int size = 0; - - private Object[] elementData = new Object[100]; - - private int length; - private static final int MAX_SIZE = 50; - - public ArrayList(){ - this(MAX_SIZE); - } - public ArrayList(int maxSize){ - length = 0; - elementData = new Object[maxSize]; - } - - public void add(Object o){ - if(! isFull()){ - elementData[size] =o; - size++; - } - else - elementData = Arrays.copyOf(elementData, elementData.length*2); - - - } - public void add(int index, Object o){ - - makeRoom(index); - elementData[size-1] =o; - size++; - - - - } - - public Object get(int index){ - if(index>0 && indexsize){ - System.out.println("����Խ��"); - return null; - } - Object o = elementData[size]; - System.arraycopy(elementData,index+1,elementData,index,size-index-1); - elementData[size--] = null; - return o; - - - } - - public int size(){ - return elementData.length; - } - - public Iterator iterator(){ - return null; - } - - public boolean isFull(){ - return size == elementData.length; - } - - - private void makeRoom(int index){ - for(int i = size;i>=index;i--){ - elementData[i] =elementData[i-1]; - - } - } - - public Iterator getiterator(){ - return new ArrayListIterator(this); - } - - private class ArrayListIterator implements Iterator{ - ArrayList l = null; - private int nextIndex; - ArrayListIterator(ArrayList l){ - nextIndex = 0; - this.l = l; - - } - @Override - public boolean hasNext() { - - return nextIndex7->10 , 逆置后变为 10->7->3 - */ - public void reverse(){ - - } - - /** - * 删除一个单链表的前半部分 - * 例如:list = 2->5->7->8 , 删除以后的值为 7->8 - * 如果list = 2->5->7->8->10 ,删除以后的值为7,8,10 - - */ - public void removeFirstHalf(){ - - } - - /** - * 从第i个元素开始, 删除length 个元素 , 注意i从0开始 - * @param i - * @param length - */ - public void remove(int i, int length){ - - } - /** - * 假定当前链表和list均包含已升序排列的整数 - * 从当前链表中取出那些list所指定的元素 - * 例如当前链表 = 11->101->201->301->401->501->601->701 - * listB = 1->3->4->6 - * 返回的结果应该是[101,301,401,601] - * @param list - */ - public static int[] getElements(LinkedList list){ - return null; - } - - /** - * 已知链表中的元素以值递增有序排列,并以单链表作存储结构。 - * 从当前链表中中删除在list中出现的元素 - - * @param list - */ - - public void subtract(LinkedList list){ - - } - - /** - * 已知当前链表中的元素以值递增有序排列,并以单链表作存储结构。 - * 删除表中所有值相同的多余元素(使得操作后的线性表中所有元素的值均不相同) - */ - public void removeDuplicateValues(){ - - } - - /** - * 已知链表中的元素以值递增有序排列,并以单链表作存储结构。 - * 试写一高效的算法,删除表中所有值大于min且小于max的元素(若表中存在这样的元素) - * @param min - * @param max - */ - public void removeRange(int min, int max){ - - } - - /** - * 假设当前链表和参数list指定的链表均以元素依值递增有序排列(同一表中的元素值各不相同) - * 现要求生成新链表C,其元素为当前链表和list中元素的交集,且表C中的元素有依值递增有序排列 - * @param list - */ - public LinkedList intersection( LinkedList list){ - return null; - } -} diff --git a/group27/1016908591/week01/src/com/coding/basic/List.java b/group27/1016908591/week01/src/com/coding/basic/List.java deleted file mode 100644 index 10d13b5832..0000000000 --- a/group27/1016908591/week01/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/group27/1016908591/week01/src/com/coding/basic/Queue.java b/group27/1016908591/week01/src/com/coding/basic/Queue.java deleted file mode 100644 index b31c1625b4..0000000000 --- a/group27/1016908591/week01/src/com/coding/basic/Queue.java +++ /dev/null @@ -1,21 +0,0 @@ -package com.coding.basic; - -public class Queue { - private LinkedList List = new LinkedList(); - - public void enQueue(Object o){ - List.addLast(o); - } - - public Object deQueue(){ - return List.removeFirst(); - } - - public boolean isEmpty(){ - return List.size()==0; - } - - public int size(){ - return List.size(); - } -} diff --git a/group27/1016908591/week01/src/com/coding/basic/Stack.java b/group27/1016908591/week01/src/com/coding/basic/Stack.java deleted file mode 100644 index 060fd1862d..0000000000 --- a/group27/1016908591/week01/src/com/coding/basic/Stack.java +++ /dev/null @@ -1,41 +0,0 @@ -package com.coding.basic; -import java.util.Arrays; -import java.util.EmptyStackException; - -public class Stack { - private ArrayList elementData = new ArrayList(); - private int topIndex =-1;//栈顶元素索引 - private static final int DEFAULT_MAX_SIZE = 50; - private int length; - - //压入一个元素 - public void push(Object o){ - topIndex++; - elementData.add(o); - - - - } - - public Object pop(){ - if(elementData.size() ==0 ){ - throw new EmptyStackException(); - } - topIndex--; - return elementData.remove(elementData.size()-1); - - } - - public Object peek(){ - if(elementData.size()!=1){ - return elementData.get(elementData.size()-1); - } - return null; - } - public boolean isEmpty(){ - return topIndex>0; - } - public int size(){ - return topIndex; - } -} diff --git "a/group27/1016908591/week01/src/\346\265\205\350\260\210CPU.txt" "b/group27/1016908591/week01/src/\346\265\205\350\260\210CPU.txt" deleted file mode 100644 index ae0478214c..0000000000 --- "a/group27/1016908591/week01/src/\346\265\205\350\260\210CPU.txt" +++ /dev/null @@ -1 +0,0 @@ -http://blog.csdn.net/weixin_37604160/article/details/61195314 \ No newline at end of file diff --git a/group27/1067041567/RemoteSystemsTempFiles/.project b/group27/1067041567/RemoteSystemsTempFiles/.project deleted file mode 100644 index 5447a64fa9..0000000000 --- a/group27/1067041567/RemoteSystemsTempFiles/.project +++ /dev/null @@ -1,12 +0,0 @@ - - - RemoteSystemsTempFiles - - - - - - - org.eclipse.rse.ui.remoteSystemsTempNature - - diff --git a/group27/1067041567/TestColleaction/.classpath b/group27/1067041567/TestColleaction/.classpath deleted file mode 100644 index fb565a588d..0000000000 --- a/group27/1067041567/TestColleaction/.classpath +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - diff --git a/group27/1067041567/TestColleaction/.gitignore b/group27/1067041567/TestColleaction/.gitignore deleted file mode 100644 index ae3c172604..0000000000 --- a/group27/1067041567/TestColleaction/.gitignore +++ /dev/null @@ -1 +0,0 @@ -/bin/ diff --git a/group27/1067041567/TestColleaction/.project b/group27/1067041567/TestColleaction/.project deleted file mode 100644 index 955a5e1e5d..0000000000 --- a/group27/1067041567/TestColleaction/.project +++ /dev/null @@ -1,17 +0,0 @@ - - - TestColleaction - - - - - - org.eclipse.jdt.core.javabuilder - - - - - - org.eclipse.jdt.core.javanature - - diff --git a/group27/1067041567/TestColleaction/.settings/org.eclipse.jdt.core.prefs b/group27/1067041567/TestColleaction/.settings/org.eclipse.jdt.core.prefs deleted file mode 100644 index 7341ab1683..0000000000 --- a/group27/1067041567/TestColleaction/.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.7 -org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve -org.eclipse.jdt.core.compiler.compliance=1.7 -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.7 diff --git a/group27/1067041567/TestColleaction/src/cn/task1/ArrayList.java b/group27/1067041567/TestColleaction/src/cn/task1/ArrayList.java deleted file mode 100644 index b1f4e43e1d..0000000000 --- a/group27/1067041567/TestColleaction/src/cn/task1/ArrayList.java +++ /dev/null @@ -1,100 +0,0 @@ -package cn.task1; - -import java.util.LinkedList; - -public class ArrayList implements List { - - int size; - Object[] obj; - - public ArrayList(){ - size = 0; - obj = new Object[size]; - } - - @Override - public void add(Object object) { - if(size==0){ - obj = new Object[1]; - obj[0] = object; - size = 1; - }else{ - Object[] temp = new Object[size+1]; -// for(int k =0;kindex){ - temp[k-1] = obj[k]; - } - } - obj = temp; - size--; - } - - @Override - public int size() { - return size; - } - - @Override - public boolean isEmpty() { - if(size>0){ - return true; - } - return false; - } - - public void set(int index,Object object){ - Object[] temp = new Object[size+1]; - for(int k=0;kindex){ - temp[k] = obj[k-1]; - } - } - obj = temp; - size++; - } - - - public static void main(String[] args) { - ArrayList list = new ArrayList(); - - list.add("d"); - list.add("dd"); - list.add("cc"); - list.remove(2); - list.set(1, "dwe"); - - System.out.println(list.get(0)); - System.out.println(list.get(1)); - System.out.println(list.get(2)); - System.out.println(list.size()); - System.out.println(list.isEmpty()); - - } - -} diff --git a/group27/1067041567/TestColleaction/src/cn/task1/LinkedList.java b/group27/1067041567/TestColleaction/src/cn/task1/LinkedList.java deleted file mode 100644 index 283129ddd8..0000000000 --- a/group27/1067041567/TestColleaction/src/cn/task1/LinkedList.java +++ /dev/null @@ -1,146 +0,0 @@ -package cn.task1; - -public class LinkedList{ - - Node head; - int size; - - public LinkedList(){ - head = new Node(); - this.size = 0; - } - - public void add(Object data) { - Node temp = head; - while(temp.next != null){ - temp = temp.next; - } - temp.next = new Node(data); - size++; - } - - public void set(int index,Object obj){ - try { - Node temp = new Node(obj); - Node pre = null; - if (index > 0) { - pre = getNode(index - 1); - } else { - pre = head; - } - Node last = getNode(index); - pre.next = temp; - temp.next = last; - size++; - } catch (Exception e) { - // TODO: handle exception - try { - throw new Exception("存在异常错误!"); - } catch (Exception e1) { - // TODO Auto-generated catch block - e1.printStackTrace(); - } - } - } - - - public Object get(int index) { - Node temp = head; - if(index>=size){ - throw new ArrayIndexOutOfBoundsException("超出范围!"); - } - for(int k=0;k=size){ - throw new ArrayIndexOutOfBoundsException("超出范围!"); - } - for(int k=0;k=size){ - throw new ArrayIndexOutOfBoundsException("超出范围!"); - } - for(int k=0;k0){ - return true; - }else{ - return false; - } - } - - public void clear(){ - head.next = null; - size=0; - } - - public static void main(String[] args) { - LinkedList list = new LinkedList(); - list.add("aa"); - list.add("bb"); - list.add("cc"); - list.add("dd"); - list.add("ff"); - list.set(4, "4546"); -// list.remove(2);list.remove(2); - System.out.println(list.size()); - System.out.println(list.get(0)); - System.out.println(list.get(1)); - System.out.println(list.get(2)); - System.out.println(list.get(3)); - System.out.println(list.get(4)); - System.out.println(list.get(5)); - System.out.println(list.isEmpty()); - list.clear(); - System.out.println(list.isEmpty()); - } - -} - - -class Node{ - - Object obj; - Node next; - - public Node(){ - this.obj = null; - this.next = null; - } - - public Node(Object obj){ - this.obj = obj; - this.next = null; - } - -} diff --git a/group27/1067041567/TestColleaction/src/cn/task1/List.java b/group27/1067041567/TestColleaction/src/cn/task1/List.java deleted file mode 100644 index d75d579c80..0000000000 --- a/group27/1067041567/TestColleaction/src/cn/task1/List.java +++ /dev/null @@ -1,14 +0,0 @@ -package cn.task1; - -public interface List { - - public void add(Object obj); - - public Object get(int index); - - public void remove(int index); - - public int size(); - - public boolean isEmpty(); -} diff --git a/group27/1067041567/TestColleaction/src/cn/task1/Queue.java b/group27/1067041567/TestColleaction/src/cn/task1/Queue.java deleted file mode 100644 index 30a5743ae4..0000000000 --- a/group27/1067041567/TestColleaction/src/cn/task1/Queue.java +++ /dev/null @@ -1,115 +0,0 @@ -package cn.task1; - -import java.util.Arrays; - -public class Queue { - - private static final int CAPACITY = 1024; - private static int capacity; - private static int front; - private static int tail; - private static Object[] array; - - public Queue() { - this.capacity = CAPACITY; - array = new Object[capacity]; - front = tail = 0; - } - - public static int getSize() { - if (isEmpty()){ - return 0; - }else{ - return (capacity + tail - front) % capacity; - } - } - - - public static boolean isEmpty() { - return (front == tail); - } - - //进栈 - public static void enqueue(Object element) throws ExceptionQueueFull { - if (getSize() == capacity - 1){ - throw new ExceptionQueueFull("Queue is full"); - } - array[tail] = element; - tail = (tail + 1) % capacity; - } - - //出栈 - public static Object dequeue() throws ExceptionQueueEmpty { - Object element; - if(isEmpty()){ - throw new ExceptionQueueEmpty("Queue is empty"); - } - element = array[front]; - front = (front + 1) % capacity; - return element; - } - - - public static Object frontElement() throws ExceptionQueueEmpty { - if(isEmpty()){ - throw new ExceptionQueueEmpty("Queue is empty"); - } - return array[front]; - } - - public static void getAllElements() { - Object[] arrayList = new Object[getSize()]; - for(int i=front,j=0;j-1); - } - - public int search(Object obj){ - - return -1; - } - - public static void main(String[] args) { - - Stack s = new Stack(); - - s.push("1"); - s.push("2"); - s.push("12"); - s.push("3"); - s.push("34"); - - System.out.println(s.pop()+" "+s.isEmpty()); - - System.out.println(s.size()+" "+s.peek()); - - } -} diff --git a/group27/1067041567/TestColleaction/src/cn/task1/Test.java b/group27/1067041567/TestColleaction/src/cn/task1/Test.java deleted file mode 100644 index 1487409c0e..0000000000 --- a/group27/1067041567/TestColleaction/src/cn/task1/Test.java +++ /dev/null @@ -1,20 +0,0 @@ -package cn.task1; - -import java.util.Queue; -import java.util.Stack; - -public class Test { - public static void main(String[] args) { - - Stack obj = new Stack<>(); - //Queue queue = new - - obj.push("a"); - obj.push("b"); - obj.push("c"); - obj.push("d"); - obj.peek(); - System.out.println(obj.peek()); - System.out.println(obj.size()); - } -} diff --git a/group27/1252327158/task1_20170312/.classpath b/group27/1252327158/task1_20170312/.classpath deleted file mode 100644 index 3e0fb272a8..0000000000 --- a/group27/1252327158/task1_20170312/.classpath +++ /dev/null @@ -1,7 +0,0 @@ - - - - - - - diff --git a/group27/1252327158/task1_20170312/.project b/group27/1252327158/task1_20170312/.project deleted file mode 100644 index 1e6bc81917..0000000000 --- a/group27/1252327158/task1_20170312/.project +++ /dev/null @@ -1,17 +0,0 @@ - - - task1 - - - - - - org.eclipse.jdt.core.javabuilder - - - - - - org.eclipse.jdt.core.javanature - - diff --git a/group27/1252327158/task1_20170312/.settings/org.eclipse.core.resources.prefs b/group27/1252327158/task1_20170312/.settings/org.eclipse.core.resources.prefs deleted file mode 100644 index 3e64772097..0000000000 --- a/group27/1252327158/task1_20170312/.settings/org.eclipse.core.resources.prefs +++ /dev/null @@ -1,3 +0,0 @@ -#Thu Mar 09 21:30:26 CST 2017 -eclipse.preferences.version=1 -encoding/=UTF-8 diff --git a/group27/1252327158/task1_20170312/src/com/coding/ArrayList.java b/group27/1252327158/task1_20170312/src/com/coding/ArrayList.java deleted file mode 100644 index cce789d3b3..0000000000 --- a/group27/1252327158/task1_20170312/src/com/coding/ArrayList.java +++ /dev/null @@ -1,111 +0,0 @@ -package com.coding; - -import java.util.ConcurrentModificationException; -import java.util.NoSuchElementException; - -public class ArrayList implements List { - - private final static int INIT_CAPACITY = 3; - - private final static int INCREASE_CAPACITY = 1; - - private int size = 0; //列表使用长度 - - private int modCount = 0; //列表结构修改次数 - - private int mCurrentCapacity = INIT_CAPACITY; //列表容量 - - private Object[] elementData = new Object[INIT_CAPACITY]; - - private void expansion() { - Object[] newElementData = new Object[mCurrentCapacity + INCREASE_CAPACITY]; - System.arraycopy(elementData, 0, newElementData, 0, elementData.length); - elementData = newElementData; - mCurrentCapacity += INCREASE_CAPACITY; - } - - @Override - public void add(T o) { - if (size >= mCurrentCapacity) { - expansion(); - } - elementData[size] = o; - size++; - modCount++; - } - - @Override - public void add(int index, T o){ - if (index > size || index < 0) { - throw new IndexOutOfBoundsException(); - } - if (size >= mCurrentCapacity) { - expansion(); - } - for (int i = size; i > index; i--) { - elementData[i] = elementData[i-1]; - } - elementData[index] = o; - size++; - modCount++; - } - - @Override - public T get(int index){ - if (index >= size || index < 0) { - throw new IndexOutOfBoundsException(); - } - return (T)elementData[index]; - } - - @Override - public T remove(int index){ - if (index >= size || index < 0) { - throw new IndexOutOfBoundsException(); - } - Object item = elementData[index]; - for (int i = index; i < size - 1; i++) { - elementData[i] = elementData[i+1]; - } - size--; - modCount++; - return (T)item; - } - - @Override - public int size(){ - return size; - } - - public Iterator iterator(){ - return new Iter(); - } - - private class Iter implements Iterator { - int cursor; - int expectedModCount = modCount; - - @Override - public boolean hasNext() { - return cursor != size; - } - - @Override - public T next() { - checkForComodification(); - if (cursor >= size) { - throw new NoSuchElementException(); - } - Object item = elementData[cursor]; - cursor++; - return (T)item; - } - - final void checkForComodification() - { - if (modCount != expectedModCount) - throw new ConcurrentModificationException(); - } - } - -} diff --git a/group27/1252327158/task1_20170312/src/com/coding/ArrayListTest.java b/group27/1252327158/task1_20170312/src/com/coding/ArrayListTest.java deleted file mode 100644 index a96d7287fb..0000000000 --- a/group27/1252327158/task1_20170312/src/com/coding/ArrayListTest.java +++ /dev/null @@ -1,64 +0,0 @@ -package com.coding; - -import static org.junit.Assert.*; - -import org.junit.After; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Ignore; -import org.junit.Test; - -public class ArrayListTest { - - ArrayList list; - - @Before - public void setUp() throws Exception { - list = new ArrayList(); - list.add(new String("first")); - list.add(new String("second")); - list.add(new String("third")); - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void testAddObject() { - list.add(new String("forth")); - Assert.assertEquals("forth", (String)list.get(3)); - } - - @Test - public void testAddIntObject() { - list.add(1, new String("add")); - Assert.assertEquals("add", (String)list.get(1)); - Assert.assertEquals("second", (String)list.get(2)); - } - - @Test - public void testGet() { - Assert.assertEquals("third", list.get(2)); - } - - @Test - public void testRemove() { - list.remove(0); - Assert.assertEquals("second", list.get(0)); - } - - @Test - public void testSize() { - Assert.assertEquals(3, list.size()); - } - - @Test - public void testIterator() { - Iterator it = list.iterator(); - if (it.hasNext()) { - Assert.assertEquals("first", it.next()); - } - } - -} diff --git a/group27/1252327158/task1_20170312/src/com/coding/BinaryTreeNode.java b/group27/1252327158/task1_20170312/src/com/coding/BinaryTreeNode.java deleted file mode 100644 index ce35adcdfe..0000000000 --- a/group27/1252327158/task1_20170312/src/com/coding/BinaryTreeNode.java +++ /dev/null @@ -1,52 +0,0 @@ -package com.coding; - -public class BinaryTreeNode { - - private int data; - private BinaryTreeNode left; - private BinaryTreeNode right; - - public BinaryTreeNode(int data, BinaryTreeNode left, BinaryTreeNode right) { - this.data = data; - this.left = left; - this.right = right; - } - - public int getData() { - return data; - } - public void setData(int data) { - this.data = data; - } - public BinaryTreeNode getLeft() { - return left; - } - public void setLeft(BinaryTreeNode left) { - if (data >= left.data) { - this.left = left; - } - } - public BinaryTreeNode getRight() { - return right; - } - public void setRight(BinaryTreeNode right) { - if (data < right.data) { - this.right = right; - } - } - - public BinaryTreeNode insert(int o) { - return insert(this, o); - } - - private BinaryTreeNode insert(BinaryTreeNode tree,int o){ - if (null == tree) { - tree = new BinaryTreeNode(o, null, null); - } else if (o > tree.data) { - tree.right =insert(tree.right,o); - } else { - tree.left = insert(tree.left,o); - } - return tree; - } -} diff --git a/group27/1252327158/task1_20170312/src/com/coding/BinaryTreeNodeTest.java b/group27/1252327158/task1_20170312/src/com/coding/BinaryTreeNodeTest.java deleted file mode 100644 index b6d56815c7..0000000000 --- a/group27/1252327158/task1_20170312/src/com/coding/BinaryTreeNodeTest.java +++ /dev/null @@ -1,58 +0,0 @@ -package com.coding; - -import static org.junit.Assert.*; - -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; - -public class BinaryTreeNodeTest { - - public BinaryTreeNode node; - - @Before - public void setUp() throws Exception { - node = new BinaryTreeNode(12, null, null); - node = node.insert(10); - } - - @Test - public void testGetData() { - Assert.assertEquals(12, node.getData()); - } - - @Test - public void testSetData() { - node.setData(15); - Assert.assertEquals(15, node.getData()); - } - - @Test - public void testGetLeft() { - Assert.assertEquals(10, node.getLeft().getData()); - } - - @Test - public void testSetLeft() { - node.setLeft(new BinaryTreeNode(8, null, null)); - Assert.assertEquals(8, node.getLeft().getData()); - } - - @Test - public void testGetRight() { - Assert.assertEquals(null, node.getRight()); - } - - @Test - public void testSetRight() { - node.setRight(new BinaryTreeNode(16, null, null)); - Assert.assertEquals(16, node.getRight().getData()); - } - - @Test - public void testInsert() { - node = node.insert(11); - Assert.assertEquals(11, node.getLeft().getRight().getData()); - } - -} diff --git a/group27/1252327158/task1_20170312/src/com/coding/Iterator.java b/group27/1252327158/task1_20170312/src/com/coding/Iterator.java deleted file mode 100644 index 7d5b1e3b63..0000000000 --- a/group27/1252327158/task1_20170312/src/com/coding/Iterator.java +++ /dev/null @@ -1,6 +0,0 @@ -package com.coding; - -public interface Iterator { - public boolean hasNext(); - public T next(); -} diff --git a/group27/1252327158/task1_20170312/src/com/coding/LinkedList.java b/group27/1252327158/task1_20170312/src/com/coding/LinkedList.java deleted file mode 100644 index 168bb07592..0000000000 --- a/group27/1252327158/task1_20170312/src/com/coding/LinkedList.java +++ /dev/null @@ -1,256 +0,0 @@ -package com.coding; - -import java.util.ConcurrentModificationException; -import java.util.NoSuchElementException; - -public class LinkedList implements List { - - private int size; - - private Node head; - - private int modCount; - - public LinkedList(){ - size = 0; - head = null; - } - - @Override - public void add(T o){ - addFirst(o); - } - - @Override - public void add(int index , T o){ - if (index > size || index < 0) { - throw new IndexOutOfBoundsException(); - } - Node item = new Node(o, null); - if (index == 0) { - item.next = head; - head = item; - } else { - Node temp = head; - for (int i = 1; i < index; i++) { - temp = temp.next; - } - item.next = temp.next; - temp.next = item; - } - size++; - modCount++; - } - - @Override - public T get(int index){ - if (index >= size || index < 0) { - throw new IndexOutOfBoundsException(); - } - Node result = head; - for (int i = 0; i < index; i++) { - result = result.next; - } - return result.data; - } - - @Override - public T remove(int index){ - if (index >= size || index < 0) { - throw new IndexOutOfBoundsException(); - } - Node result = head; - if (index == 0) { - head = head.next; - } else { - Node temp = head; - for (int i = 1; i < index; i++) { - temp = temp.next; - } - result = temp.next; - temp.next = temp.next.next; - } - size--; - modCount++; - return result.data; - } - - @Override - public int size(){ - return size; - } - - public void addFirst(T o){ - Node item = new Node(o, null); - if (head == null) { - head = item; - } else { - item.next = head; - head = item; - } - size++; - modCount++; - } - - public void addLast(T o){ - Node item = new Node(o, null); - if(head == null) { - head = item; - } else { - Node tag = head; - while (tag.next != null) { - tag = tag.next; - } - tag.next = item; - } - size++; - modCount++; - } - - public T removeFirst(){ - if (size == 0) { - throw new IndexOutOfBoundsException(); - } - Node result = head; - head = head.next; - size--; - modCount++; - return result.data; - } - - public T removeLast(){ - if (size == 0) { - throw new IndexOutOfBoundsException(); - } - Node result = head; - if (size == 1) { - head = null; - } else { - Node temp = head; - while (result.next != null) { - temp = result; - result = result.next; - } - temp.next = null; - } - size--; - modCount++; - return result.data; - } - - public Iterator iterator(){ - return new Iter(); - } - - private class Iter implements Iterator { - int cursor; - int expectedModCount = modCount; - - @Override - public boolean hasNext() { - return cursor != size; - } - - @Override - public T next() { - checkForComodification(); - if (cursor >= size) { - throw new NoSuchElementException(); - } - T item = get(cursor); - cursor++; - return item; - } - - final void checkForComodification() - { - if (modCount != expectedModCount) - throw new ConcurrentModificationException(); - } - } - - private static class Node{ - T data; - Node next; - public Node(T data, Node node) { - this.data = data; - this.next = node; - } - } - - /** - * 把该链表逆置 - * 例如链表为 3->7->10 , 逆置后变为 10->7->3 - */ - public void reverse(){ - - } - - /** - * 删除一个单链表的前半部分 - * 例如:list = 2->5->7->8 , 删除以后的值为 7->8 - * 如果list = 2->5->7->8->10 ,删除以后的值为7,8,10 - - */ - public void removeFirstHalf(){ - - } - - /** - * 从第i个元素开始, 删除length 个元素 , 注意i从0开始 - * @param i - * @param length - */ - public void remove(int i, int length){ - - } - /** - * 假定当前链表和list均包含已升序排列的整数 - * 从当前链表中取出那些list所指定的元素 - * 例如当前链表 = 11->101->201->301->401->501->601->701 - * listB = 1->3->4->6 - * 返回的结果应该是[101,301,401,601] - * @param list - */ - public static int[] getElements(LinkedList list){ - return null; - } - - /** - * 已知链表中的元素以值递增有序排列,并以单链表作存储结构。 - * 从当前链表中中删除在list中出现的元素 - - * @param list - */ - - public void subtract(LinkedList list){ - - } - - /** - * 已知当前链表中的元素以值递增有序排列,并以单链表作存储结构。 - * 删除表中所有值相同的多余元素(使得操作后的线性表中所有元素的值均不相同) - */ - public void removeDuplicateValues(){ - - } - - /** - * 已知链表中的元素以值递增有序排列,并以单链表作存储结构。 - * 试写一高效的算法,删除表中所有值大于min且小于max的元素(若表中存在这样的元素) - * @param min - * @param max - */ - public void removeRange(int min, int max){ - - } - - /** - * 假设当前链表和参数list指定的链表均以元素依值递增有序排列(同一表中的元素值各不相同) - * 现要求生成新链表C,其元素为当前链表和list中元素的交集,且表C中的元素有依值递增有序排列 - * @param list - */ - public LinkedList intersection( LinkedList list){ - return null; - } -} diff --git a/group27/1252327158/task1_20170312/src/com/coding/LinkedListTest.java b/group27/1252327158/task1_20170312/src/com/coding/LinkedListTest.java deleted file mode 100644 index 03f7198998..0000000000 --- a/group27/1252327158/task1_20170312/src/com/coding/LinkedListTest.java +++ /dev/null @@ -1,95 +0,0 @@ -package com.coding; - -import static org.junit.Assert.*; - -import org.junit.After; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; - -public class LinkedListTest { - LinkedList list; - - @Before - public void setUp() throws Exception { - list = new LinkedList(); - list.add("first"); - list.add("second"); - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void testAddT() { - list.add("third"); - Assert.assertEquals("second", list.get(1)); - Assert.assertEquals("first", list.get(2)); - } - - @Test - public void testAddIntT() { - list.add(1,"third"); - Assert.assertEquals("third", list.get(1)); - Assert.assertEquals("first", list.get(2)); - } - - @Test - public void testGet() { - Assert.assertEquals("second", list.get(0)); - } - - @Test - public void testRemoveInt() { - list.remove(0); - list.add("third"); - list.add("forth"); - list.remove(1); - Assert.assertEquals("forth", list.get(0)); - Assert.assertEquals("first", list.get(1)); - } - - @Test - public void testSize() { - list.remove(0); - list.add("third"); - list.add("forth"); - list.remove(1); - Assert.assertEquals(2, list.size()); - } - - @Test - public void testAddFirst() { - list.addFirst("third"); - Assert.assertEquals("third", list.get(0)); - Assert.assertEquals("second", list.get(1)); - } - - @Test - public void testAddLast() { - list.addLast("third"); - Assert.assertEquals("third", list.get(2)); - } - - @Test - public void testRemoveFirst() { - list.removeFirst(); - Assert.assertEquals("first", list.get(0)); - } - - @Test - public void testRemoveLast() { - list.removeLast(); - Assert.assertEquals(1, list.size()); - } - - @Test - public void testIterator() { - Iterator iter = list.iterator(); - if (iter.hasNext()) { - Assert.assertEquals("second", iter.next()); - } - } - -} diff --git a/group27/1252327158/task1_20170312/src/com/coding/List.java b/group27/1252327158/task1_20170312/src/com/coding/List.java deleted file mode 100644 index 0cd05a3bae..0000000000 --- a/group27/1252327158/task1_20170312/src/com/coding/List.java +++ /dev/null @@ -1,9 +0,0 @@ -package com.coding; - -public interface List { - public void add(T o); - public void add(int index, T o); - public T get(int index); - public T remove(int index); - public int size(); -} diff --git a/group27/1252327158/task1_20170312/src/com/coding/Queue.java b/group27/1252327158/task1_20170312/src/com/coding/Queue.java deleted file mode 100644 index 38b769237c..0000000000 --- a/group27/1252327158/task1_20170312/src/com/coding/Queue.java +++ /dev/null @@ -1,22 +0,0 @@ -package com.coding; - -public class Queue { - - private LinkedList elementData = new LinkedList(); - - public void enQueue(T o){ - elementData.addFirst(o); - } - - public T deQueue(){ - return elementData.removeLast(); - } - - public boolean isEmpty(){ - return elementData.size() == 0; - } - - public int size(){ - return elementData.size(); - } -} diff --git a/group27/1252327158/task1_20170312/src/com/coding/QueueTest.java b/group27/1252327158/task1_20170312/src/com/coding/QueueTest.java deleted file mode 100644 index cc761cac8c..0000000000 --- a/group27/1252327158/task1_20170312/src/com/coding/QueueTest.java +++ /dev/null @@ -1,46 +0,0 @@ -package com.coding; - -import static org.junit.Assert.*; - -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; - -public class QueueTest { - - private Queue queue; - - @Before - public void setUp() throws Exception { - queue = new Queue(); - queue.enQueue("first"); - queue.enQueue("second"); - } - - @Test - public void testEnQueue() { - Assert.assertEquals(2, queue.size()); - queue.enQueue("third"); - Assert.assertEquals(3, queue.size()); - } - - @Test - public void testDeQueue() { - Assert.assertEquals("first", queue.deQueue()); - Assert.assertEquals("second", queue.deQueue()); - } - - @Test - public void testIsEmpty() { - Assert.assertEquals(false, queue.isEmpty()); - queue.deQueue(); - queue.deQueue(); - Assert.assertEquals(true, queue.isEmpty()); - } - - @Test - public void testSize() { - Assert.assertEquals(2, queue.size()); - } - -} diff --git a/group27/1252327158/task1_20170312/src/com/coding/Stack.java b/group27/1252327158/task1_20170312/src/com/coding/Stack.java deleted file mode 100644 index 17dc2f1bf6..0000000000 --- a/group27/1252327158/task1_20170312/src/com/coding/Stack.java +++ /dev/null @@ -1,24 +0,0 @@ -package com.coding; - -public class Stack { - - private ArrayList elementData = new ArrayList(); - - public void push(T o){ - elementData.add(o); - } - - public T pop(){ - return elementData.remove(elementData.size() - 1); - } - - public T peek(){ - return elementData.get(elementData.size() - 1); - } - public boolean isEmpty(){ - return elementData.size() == 0; - } - public int size(){ - return elementData.size(); - } -} diff --git a/group27/1252327158/task1_20170312/src/com/coding/StackTest.java b/group27/1252327158/task1_20170312/src/com/coding/StackTest.java deleted file mode 100644 index 442b13310a..0000000000 --- a/group27/1252327158/task1_20170312/src/com/coding/StackTest.java +++ /dev/null @@ -1,45 +0,0 @@ -package com.coding; - -import static org.junit.Assert.*; -import junit.framework.Assert; - -import org.junit.Before; -import org.junit.Test; - -public class StackTest { - - Stack stack; - - @Before - public void setUp() throws Exception { - stack = new Stack(); - stack.push("first"); - stack.push("second"); - } - - @Test - public void testPush() { - stack.push("third"); - Assert.assertEquals("third", stack.peek()); - } - - @Test - public void testPop() { - Assert.assertEquals("second", stack.pop()); - } - - @Test - public void testPeek() { - Assert.assertEquals("second", stack.peek()); - } - - @Test - public void testIsEmpty() { - Assert.assertEquals(false, stack.isEmpty()); - } - - @Test - public void testSize() { - Assert.assertEquals(2, stack.size()); - } -} diff --git a/group27/2567012201/.DS_Store b/group27/2567012201/.DS_Store deleted file mode 100644 index 28934e70a8cd7c4fd8b0f4e2e265983a5c62cc3e..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 6148 zcmeHK-EPw`6h7|CNXG>Q@q3p$xF}Lfw{~|#WgsDLDl%;sfJ#E6%~FV*5DtcWOH(BGDTUTSRpta-fXW6_}q0x3iv* zim6!!3N=QPT67nM(TZijGVrf6z-#w1R_q#esH@iPeEr50Q9v0bB%wQx;`C)0ry=_D zX7Lbu8(KL$ggxaL;UpiKF}{YQSms5u`9)Ngs^^x^JGB)q7i-V`-E`s?K{3vILH1NV z$zc>4zaJF4bAK~U7|q zB-)a>3}q~f1Eb`U1+r{Ys501jZc4%HgB<22=^!Ty}t-!BQh?AofE*(O`{b;IA_94b?o>8vpy!gV0zq$kgF}!~1=8NILP4r}i4@cxpbB?fH?ut&G^;u-J^EII?UcI%LU0=<>Zt>0HT@)%W|pW8`rR5B?Jd6oZ2 z4l`Ah?e>|d)f=~#mV@RBU3Z#$g99@elyNyOdU5{7_S7g%*zU*W!G-5eK?qB2!}2%2;a!w1u8=UKNU zH@dTyoUX68Tk>hAJDUZ;>Z8u{?Oi=R{`l$hm#^Qx+sT2z4a~}2#tS$>gQtEp$aQA) zd-PCr9SX={{|arVI6}15E@`t-{}64RmVC0daU-Y-|aD*g&@xwC&G7q9g}m#8^2*4~lT9h%Qxdi6OXl5H20Z zBaW{ex^xis$#@@rvfv6uaOokW4F?f9^sQ&WGceCU-E~7c|6l&O{-00sJz%Xi diff --git a/group27/2567012201/2567012201learning/.classpath b/group27/2567012201/2567012201learning/.classpath deleted file mode 100644 index fceb4801b5..0000000000 --- a/group27/2567012201/2567012201learning/.classpath +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - diff --git a/group27/2567012201/2567012201learning/.gitignore b/group27/2567012201/2567012201learning/.gitignore deleted file mode 100644 index ae3c172604..0000000000 --- a/group27/2567012201/2567012201learning/.gitignore +++ /dev/null @@ -1 +0,0 @@ -/bin/ diff --git a/group27/2567012201/2567012201learning/.project b/group27/2567012201/2567012201learning/.project deleted file mode 100644 index eb67d06bb5..0000000000 --- a/group27/2567012201/2567012201learning/.project +++ /dev/null @@ -1,17 +0,0 @@ - - - 2567012201learning - - - - - - org.eclipse.jdt.core.javabuilder - - - - - - org.eclipse.jdt.core.javanature - - diff --git a/group27/2567012201/2567012201learning/.settings/org.eclipse.jdt.core.prefs b/group27/2567012201/2567012201learning/.settings/org.eclipse.jdt.core.prefs deleted file mode 100644 index 3a21537071..0000000000 --- a/group27/2567012201/2567012201learning/.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/group27/2567012201/2567012201learning/src/.DS_Store b/group27/2567012201/2567012201learning/src/.DS_Store deleted file mode 100644 index 72a20b04fb095584bc31a620a77d090a2b0a5643..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 6148 zcmeHK&2G~`5Z+A!IB>v7pu)|!atKnYAj%CZ6eQG3q*UzzP_P?|u4KGb>@-4AB)Xqh@B)2~_M6>FMOC;~3YxKIzwzwM+WW1w>rqPS{&c*dRH&2+poEP!n!gD3lU|Vq zdzwH^W7z#Pw<+#uIFVIgfYz?5_LWti-sG3o?=^ZJL-pC2n+Qjxv+|Hv`7}MuO<8rj zzjdS8x^eSX(7sLA-S+$8ft?Mjq?(rfWb)SCnQ@k~JxHp9rM+Wqeqkr+uE}Pj@cv6% zREa6F$seij_DnIhv%Z}c<8l-}7)-JwL=Tc8+cl+0O>U~sL7T2oxHg~ndY$OW#`8rd zns07)JJHkLv&A9^9l13O12L4Y5bZcw4)yLfUY`ro|I%^~72Pg@})gCWWV7Q|gv2+wa bggSvgA_EvR)*j)3$d7=dK^kG;S{XP8pVXcAY2BGVub5iq> zB}8HGq2c6BZjO`OBy-suSVRVB?v~*g45Xl7cK+z2c#XP_Dz2{3{*#-GiZeggzmv0E z6=kb+DQZjg2g?tG#tI#e8XtS7X4EU=a#(cY!FzkA(k$_QH!e@7{ySsxYd=m7R5t2| zk6#*H#!6>{ze+zGDxI29#|(8^^us6JL3WPW-B@P_s!)l_Rrx7s(9sW{j>qkGQ*LbT zPMUJOv(swIt@ie05(Lj*wD;Z~>hb3k@SAR*bo{ e6+c6@f^kU>V&t)Mh!GV25wJ9{VFvyy1AhRA>18nh diff --git a/group27/2567012201/2567012201learning/src/com/coding/.DS_Store b/group27/2567012201/2567012201learning/src/com/coding/.DS_Store deleted file mode 100644 index 5a44c340ce302c6d18b065b5aa3e3fb28a4d7a3f..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 6148 zcmeHK&59H;5U$LQZjU0iu%g~_)58d}jJV!x#!(P211-A;m9cxLaRW_f>7N~B80dHK z|2gzwd;y z=rVt#hqrym>*5WfRz0jTJ$eQ_1D=7kGvE%Q;PTo>_5*qbJOh6_1AIP6C}ZTXwP=nG7*hfO zyJ$87pMMlNM>>ogwifXPB5W$qrV3YL2%C;}>Ea@Xtwozo!WAFFjVxS+BFyOMUz%_d zkwtGk1D=6j8Q|Iv67v23_|Nsf3G&7>;2HQo84%rZJRV_g?ruFZOTKF*^fi=)<64U+ kDR9hHj99*kZ$gcrU9tm=9JUtG0`Wfrh6Zmu18ZgAC*d4yRR910 diff --git a/group27/2567012201/2567012201learning/src/com/coding/DataStructure/.DS_Store b/group27/2567012201/2567012201learning/src/com/coding/DataStructure/.DS_Store deleted file mode 100644 index 602ec50de12b2c0f8b0f6a6dd353f481ef74d5c9..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 6148 zcmeHK%}T>S5dNlCXce?ak9+K?;2XqJ1;LBf2Qd9PsKtU>!CM}~hw=e@oBGY{Qc{y# zi}V2cSb&Y;_rGOs}g~td)8WiDLKo#0?(thIb4q+1~LV z70|Ui!3AD<^ZtLE= 100) { - throw new RuntimeException("数组越界异常"); - } - elementData[size] = 0; - size++; - } - - public void add(int index, Object o){ - growLength(); - System.arraycopy(elementData, index, elementData, index+1, size-index); - elementData[index] = o; - size++; - } - - public Object get(int index){ - return elementData[index]; - } - - public Object remove(int index){ - if (index > size) throw new IndexOutOfBoundsException("index: "+index+", size: "+size); - Object retVal = elementData[index]; - System.arraycopy(elementData, index+1, elementData, index, size-(index+1)); - elementData[--size] = null; - return retVal; - } - - public int size(){ - return this.size; - } - - public Iterator iterator(){ - return null; - } - private void growLength() { - if (this.size == elementData.length) { - elementData = Arrays.copyOf(elementData, elementData.length+INCREMENT); - } - } -} diff --git a/group27/2567012201/2567012201learning/src/com/coding/DataStructure/LinkedList.java b/group27/2567012201/2567012201learning/src/com/coding/DataStructure/LinkedList.java deleted file mode 100644 index 641998a2ad..0000000000 --- a/group27/2567012201/2567012201learning/src/com/coding/DataStructure/LinkedList.java +++ /dev/null @@ -1,10 +0,0 @@ -package com.coding.DataStructure; - -public class LinkedList { - - public void addLast(E o) { - // TODO Auto-generated method stub - - } - -} diff --git a/group27/2567012201/2567012201learning/src/com/coding/DataStructure/Queue.java b/group27/2567012201/2567012201learning/src/com/coding/DataStructure/Queue.java deleted file mode 100644 index 07e3fcc700..0000000000 --- a/group27/2567012201/2567012201learning/src/com/coding/DataStructure/Queue.java +++ /dev/null @@ -1,36 +0,0 @@ -package com.coding.DataStructure; - -import java.util.NoSuchElementException; - -public class Queue { - private int size; - private LinkedList list = new LinkedList(); - - public void enQueue(Object o){ - list.addLast(o);; - size++; - } - - public Object deQueue(){ - if(size<=0){ - throw new NoSuchElementException(); - } - Object val = list.removeFirst(); - size--; - return val; - } - - public boolean isEmpty(){ - boolean flag = false; - if(size >= 0){ - flag = true; - } - return flag; - } - - public int size(){ - return size; - } - -} - diff --git a/group27/2567012201/2567012201learning/src/com/coding/DataStructure/Stack.java b/group27/2567012201/2567012201learning/src/com/coding/DataStructure/Stack.java deleted file mode 100644 index ef20d5c4e8..0000000000 --- a/group27/2567012201/2567012201learning/src/com/coding/DataStructure/Stack.java +++ /dev/null @@ -1,41 +0,0 @@ -package com.coding.DataStructure; - -import java.util.NoSuchElementException; - -public class Stack { - 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 NoSuchElementException(); - } - int len = size-1; - Object val = elementData.remove(len); - size--; - return val; - } - - public Object peek(){ - if(size<=0){ - throw new NoSuchElementException(); - } - int len = size-1; - return elementData.get(len); - } - public boolean isEmpty(){ - boolean flag = false; - if(size >= 0){ - flag = true; - } - return flag; - } - public int size(){ - return size; - } -} diff --git a/group27/2567012201/2567012201learning/src/com/coding/DataStructure/Tree.java b/group27/2567012201/2567012201learning/src/com/coding/DataStructure/Tree.java deleted file mode 100644 index d3e4c84488..0000000000 --- a/group27/2567012201/2567012201learning/src/com/coding/DataStructure/Tree.java +++ /dev/null @@ -1,51 +0,0 @@ -package com.coding.DataStructure; - -public class Tree { - private Object data; - private Tree left; - private Tree right; - - public Object getData() { - return data; - } - - public void setData(Object data) { - this.data = data; - } - - public Tree getLeft() { - return left; - } - - public void setLeft(Tree left) { - this.left = left; - } - - public Tree getRight() { - return right; - } - - public void setRight(Tree right) { - this.right = right; - } - - public Tree insert(Object o) { - if (data == null) { - setData(o); - } else { - Integer i = (Integer) o; - if (i.compareTo((Integer) data) == -1) { - if(right == null) - right = new Tree(); - return right.insert(i); - } else if (i.compareTo((Integer) data) == 1) { - if(left == null) - left = new Tree(); - return left.insert(i); - } - return null; - } - return null; - } - -} diff --git a/group27/2567012201/RemoteSystemsTempFiles/.project b/group27/2567012201/RemoteSystemsTempFiles/.project deleted file mode 100644 index 5447a64fa9..0000000000 --- a/group27/2567012201/RemoteSystemsTempFiles/.project +++ /dev/null @@ -1,12 +0,0 @@ - - - RemoteSystemsTempFiles - - - - - - - org.eclipse.rse.ui.remoteSystemsTempNature - - diff --git a/group27/276961139/src/learn/ArrayList.java b/group27/276961139/src/learn/ArrayList.java deleted file mode 100644 index c0993491d1..0000000000 --- a/group27/276961139/src/learn/ArrayList.java +++ /dev/null @@ -1,93 +0,0 @@ -package com.liam.learn.code2017; - -import java.lang.reflect.Array; -import java.util.Arrays; - -public class ArrayList implements List { - - private int capacity = 10; - private int size = 0; - - private Object[] elementData = null; //new Object[100]; - - public ArrayList(){ - this.capacity = capacity; - elementData = new Object[capacity]; - } - - public ArrayList(int custCapacity) { - if(custCapacity <= 0){ - throw new IllegalArgumentException("Arraylist 长度不能为负数或0"); - } - this.capacity = custCapacity; - elementData = new Object[capacity]; - } - - public void add(Object o){ - if (size >= capacity){ - enlargeCapacity(); - } - elementData[size] = o; - size++; - } - public void add(int index, Object o){ - if(index <0 || index >= size){ - throw new IllegalArgumentException("数组越界"); - } - if (size >= capacity){ - enlargeCapacity(); - } - System.arraycopy(elementData, index, elementData, index+1, size - index); - elementData[index] = o; - size++; - } - - public Object get(int index){ - if(index <0 || index >= size){ - throw new IllegalArgumentException("数组越界"); - } - return elementData[index]; - } - - public Object remove(int index){ - Object removedObj = get(index); - - int movedSize = size - (index + 1); - if (movedSize > 0) { - System.arraycopy(elementData, index+1, elementData, index, movedSize); - } - elementData[--size] = null; - - return removedObj; - } - - public int size(){ - return size; - } - - public Iterator iterator(){ - return null; - } - - - @Override - public String toString() { - if (size < capacity){ - //int needRemove = capacity - size; - Object[] toStringObj = new Object[size]; - System.arraycopy(elementData, 0, toStringObj, 0, size); - return Arrays.toString(toStringObj); - } - return Arrays.toString(elementData); - } - - private void enlargeCapacity(){ - capacity = capacity * 2; - Object[] temp = new Object[capacity]; - System.arraycopy(elementData, 0, temp, 0, size); - elementData = temp; - } - - - -} diff --git a/group27/276961139/src/learn/BinaryTreeNode.java b/group27/276961139/src/learn/BinaryTreeNode.java deleted file mode 100644 index 86e8d5ce7b..0000000000 --- a/group27/276961139/src/learn/BinaryTreeNode.java +++ /dev/null @@ -1,46 +0,0 @@ -package com.liam.learn.code2017; - -public class BinaryTreeNode { - - private Object data; - private BinaryTreeNode left; - private BinaryTreeNode right; - - public BinaryTreeNode(Object data) { - this.data = data; - } - - public BinaryTreeNode() { - } - - public Object getData() { - return data; - } - public void setData(Object data) { - this.data = data; - } - public BinaryTreeNode getLeft() { - return left; - } - public void setLeft(BinaryTreeNode left) { - this.left = left; - } - public BinaryTreeNode getRight() { - return right; - } - public void setRight(BinaryTreeNode right) { - this.right = right; - } - - public BinaryTreeNode insert(Object o){ - - if (left != null){ - return left = new BinaryTreeNode(o); - } - if (right !=null){ - return right = new BinaryTreeNode(o); - } - throw new RuntimeException("左右子树已经都有值了"); - } - -} diff --git a/group27/276961139/src/learn/Iterator.java b/group27/276961139/src/learn/Iterator.java deleted file mode 100644 index 0f85a64dfd..0000000000 --- a/group27/276961139/src/learn/Iterator.java +++ /dev/null @@ -1,7 +0,0 @@ -package com.liam.learn.code2017; - -public interface Iterator { - public boolean hasNext(); - public Object next(); - -} diff --git a/group27/276961139/src/learn/LinkedList.java b/group27/276961139/src/learn/LinkedList.java deleted file mode 100644 index 79924fa07f..0000000000 --- a/group27/276961139/src/learn/LinkedList.java +++ /dev/null @@ -1,255 +0,0 @@ -package com.liam.learn.code2017; - - - -public class LinkedList implements List { - private int size; - - private Node head; - - private Node tail; - - public void add(Object o){ - Node node = new Node(o, null); - if(head == null){ - head = node; - tail = node; - }else{ - tail.setNext(node); - tail = node; - } - size++; - } - public void add(int index , Object o){ - if (index < 0 || index >= size){ - throw new IllegalArgumentException("链表越界"); - } - if (index == 0){ - addFirst(o); - }else if(index == size-1){ - addLast(o); - }else{ - Node indexNode = getNode(index); - Node newNode = new Node(o, indexNode); - Node previousNode = getNode(index-1); - previousNode.setNext(newNode); - } - size++; - } - public Object get(int index){ - Node node = getNode(index); - return node.getData(); - } - - private Node getNode(int index){ - if (index < 0 || index >= size){ - throw new IllegalArgumentException("链表越界"); - } - if(index == 0){ - return head; - } - if(index == size-1){ - return tail; - } - Node temp = head; - for(int i=0; i= size){ - throw new IllegalArgumentException("链表越界"); - } - - if (index == 0){ - return removeFirst(); - }else if(index == size-1){ - return removeLast(); - }else{ - Node previousNode = getNode(index-1); - Node nextNode = getNode(index+1); - previousNode.setNext(nextNode); - size--; - } - return get(index); - } - - public int size(){ - return size; - } - - public void addFirst(Object o){ - Node node = new Node(o, null); - if(head == null){ - head = node; - tail = node; - }else{ - node.setNext(head); - head = node; - } - size++; - } - public void addLast(Object o){ - Node node = new Node(o, null); - if(head == null){ - head = node; - tail = node; - }else{ - tail.setNext(node); - tail = node; - } - size++; - } - public Object removeFirst(){ - if (head == null){ - throw new RuntimeException("链表为空"); - } - if (size ==1){ - Object ret = head.getData(); - head = null; - tail = null; - return ret; - } - Object headData = head.getData(); - head = getNode(1); - size--; - return headData; - } - public Object removeLast(){ - if (head == null){ - throw new RuntimeException("链表为空"); - } - Object tailData = tail.getData(); - tail = getNode(size-2); - size--; - return tailData; - } - public Iterator iterator(){ - return null; - } - - - private static class Node{ - private Object data; - private Node next; - - public Node(Object data, Node next) { - this.data = data; - this.next = 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; - } - } - - /** - * 把该链表逆置 - * 例如链表为 3->7->10 , 逆置后变为 10->7->3 - */ - public void reverse(){ - if(size == 0 || size ==1){ - return; - } - /*LinkedList linkedList = new LinkedList(); - for(int i=size-1; i>=0; i--){ - linkedList.add(getNode(i)); - }*/ - - Node temp = head; - head = tail; - tail = temp; - for(int i=size-2; i>=1; i--){ - getNode(i+1).setNext(getNode(i)); - } - getNode(1).setNext(tail); - } - - - /** - * 删除一个单链表的前半部分 - * 例如:list = 2->5->7->8 , 删除以后的值为 7->8 - * 如果list = 2->5->7->8->10 ,删除以后的值为7,8,10 - - */ - public void removeFirstHalf(){ - int pre = size/2; - for (int i=0; i101->201->301->401->501->601->701 - * listB = 1->3->4->6 - * 返回的结果应该是[101,301,401,601] - * @param list - */ - public static int[] getElements(LinkedList list){ - return null; - } - - /** - * 已知链表中的元素以值递增有序排列,并以单链表作存储结构。 - * 从当前链表中中删除在list中出现的元素 - - * @param list - */ - - public void subtract(LinkedList list){ - - } - - /** - * 已知当前链表中的元素以值递增有序排列,并以单链表作存储结构。 - * 删除表中所有值相同的多余元素(使得操作后的线性表中所有元素的值均不相同) - */ - public void removeDuplicateValues(){ - - } - - /** - * 已知链表中的元素以值递增有序排列,并以单链表作存储结构。 - * 试写一高效的算法,删除表中所有值大于min且小于max的元素(若表中存在这样的元素) - * @param min - * @param max - */ - public void removeRange(int min, int max){ - - } - - /** - * 假设当前链表和参数list指定的链表均以元素依值递增有序排列(同一表中的元素值各不相同) - * 现要求生成新链表C,其元素为当前链表和list中元素的交集,且表C中的元素有依值递增有序排列 - * @param list - */ - public LinkedList intersection( LinkedList list){ - return null; - } -} diff --git a/group27/276961139/src/learn/List.java b/group27/276961139/src/learn/List.java deleted file mode 100644 index 9b5fc82f83..0000000000 --- a/group27/276961139/src/learn/List.java +++ /dev/null @@ -1,9 +0,0 @@ -package com.liam.learn.code2017; - -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/group27/276961139/src/learn/Queue.java b/group27/276961139/src/learn/Queue.java deleted file mode 100644 index dd6ed22559..0000000000 --- a/group27/276961139/src/learn/Queue.java +++ /dev/null @@ -1,32 +0,0 @@ -package com.liam.learn.code2017; - -public class Queue { - - private LinkedList linkedList; - - public Queue() { - this.linkedList = new LinkedList(); - } - - public void enQueue(Object o){ - linkedList.add(o); - } - - public Object deQueue(){ - if (linkedList == null || isEmpty()){ - return null; - } - return linkedList.removeFirst(); - } - - public boolean isEmpty(){ - return linkedList.size()==0; - } - - public int size(){ - if (linkedList == null || isEmpty()){ - return 0; - } - return linkedList.size(); - } -} diff --git a/group27/276961139/src/learn/Stack.java b/group27/276961139/src/learn/Stack.java deleted file mode 100644 index 1fc79645f1..0000000000 --- a/group27/276961139/src/learn/Stack.java +++ /dev/null @@ -1,23 +0,0 @@ -package com.liam.learn.code2017; - -public class Stack { - private ArrayList elementData = new ArrayList(); - - public void push(Object o){ - elementData.add(o); - } - - public Object pop(){ - return elementData.remove(elementData.size()-1); - } - - public Object peek(){ - return elementData.get(elementData.size()-1); - } - public boolean isEmpty(){ - return elementData.size()==0; - } - public int size(){ - return elementData.size(); - } -} diff --git a/group27/383117348/.classpath b/group27/383117348/.classpath deleted file mode 100644 index d98690584e..0000000000 --- a/group27/383117348/.classpath +++ /dev/null @@ -1,9 +0,0 @@ - - - - - - - - - diff --git a/group27/383117348/.gitignore b/group27/383117348/.gitignore deleted file mode 100644 index 9ded3b51b7..0000000000 --- a/group27/383117348/.gitignore +++ /dev/null @@ -1,21 +0,0 @@ -*.class -# Mobile Tools for Java (J2ME) -.mtj.tmp/ - -# Package Files # -*.jar -*.war -*.ear - -# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml -hs_err_pid* - -#ide config -.metadata -.recommenders -.idea/ -*.iml -rebel.* -.rebel.* - -target \ No newline at end of file diff --git a/group27/383117348/.project b/group27/383117348/.project deleted file mode 100644 index ccad29da35..0000000000 --- a/group27/383117348/.project +++ /dev/null @@ -1,17 +0,0 @@ - - - 383117348Learning - - - - - - org.eclipse.jdt.core.javabuilder - - - - - - org.eclipse.jdt.core.javanature - - diff --git a/group27/383117348/src/com/coding/basic/ArrayList.java b/group27/383117348/src/com/coding/basic/ArrayList.java deleted file mode 100644 index 773d8f6c6b..0000000000 --- a/group27/383117348/src/com/coding/basic/ArrayList.java +++ /dev/null @@ -1,213 +0,0 @@ -package com.coding.basic; - -import java.util.Arrays; - -import org.junit.Test; - -public class ArrayList implements List { - - private int size = 0; - - private Object[] elementData = new Object[100]; - - /** - * 自动增长值 - */ - private static final int GROW_UP_SIZE = 100; - - /** - * 在数组最末尾添加对象 - */ - public void add(Object o) { - growUp(size); - elementData[size] = o; - size++; - } - - /** - * 向指定下标处添加对象 - */ - public void add(int index, Object o) { - checkIndex(index); - growUp(size + 1); - System.arraycopy(elementData, index, elementData, index + 1, size - index); - elementData[index] = o; - size++; - - } - - /** - * 根据index获取对象 - */ - public Object get(int index) { - checkIndex(index); - return elementData[index]; - } - - /** - * 移除指定下标对象 - */ - public Object remove(int index) { - checkIndex(index); - Object obj = elementData[index]; - int afterRemove = size - index - 1; - // System.out.println("@@@@"+afterRemove+"---"+index); - if (afterRemove > 0) - System.arraycopy(elementData, index + 1, elementData, index, afterRemove); - elementData = Arrays.copyOf(elementData, --size); - return obj; - } - - /** - * 获取数组大小 - */ - public int size() { - return size; - } - - /** - * 迭代器 - * - * @return - */ - public Iterator iterator() { - return new Iter(); - } - - /** - * 迭代器内部类 - * - * @author Adminstater - * - */ - private class Iter implements Iterator { - private int nextIndex = 0; - - @Override - public boolean hasNext() { - // TODO Auto-generated method stub - return nextIndex != size; - } - - @Override - public Object next() { - // TODO Auto-generated method stub - int i = nextIndex++; - if (i > size - 1) - throw new IndexOutOfBoundsException(); - - return elementData[i]; - } - - } - - /** - * 检查数组长度是否越界,越界就自动增长100 - */ - private void growUp(int size) { - if (size > elementData.length - 1) { - Object[] elementGrow = new Object[elementData.length + GROW_UP_SIZE]; - System.arraycopy(elementData, 0, elementGrow, 0, elementData.length); - elementData = elementGrow; - // System.out.println(elementData.length); - } - } - - /** - * 检查下标是否越界,越界抛出异常 - */ - private void checkIndex(int index) { - if (index < 0 || index > size) { - throw new IndexOutOfBoundsException("下标越界"); - } - } - - /*------------------------------------------------------单元测试----------------------------------------------------*/ - /** - * 测试自增长数组长度变化及增加功能 - */ - @Test - public void TestAddFunction() { - ArrayList list = new ArrayList(); - for (int x = 0; x < 300; x++) { - list.add(x); - } - } - - /** - * 测试add(int index,Object obj)方法 - */ - @Test - public void TestAddIndexFunction() { - ArrayList list = new ArrayList(); - // System.out.println(list.size()); - list.add(0, 20); - list.add(1, 30); - System.out.println(list.get(1)); - - } - - /** - * 测试get方法 - */ - @Test - public void TestGetFunction() { - ArrayList list = new ArrayList(); - for (int x = 0; x < 300; x++) { - list.add(x); - } - for (int x = 0; x < list.size; x++) { - System.out.println(list.get(x)); - } - } - - /** - * 测试size方法 - */ - @Test - public void TestSizeFunction() { - ArrayList list = new ArrayList(); - for (int x = 0; x < 259; x++) { - list.add(x); - } - /* - * for(int x=0;x list = null; - } - -} diff --git a/group27/383117348/src/com/coding/basic/BinaryTreeNode.java b/group27/383117348/src/com/coding/basic/BinaryTreeNode.java deleted file mode 100644 index bd2ad5effb..0000000000 --- a/group27/383117348/src/com/coding/basic/BinaryTreeNode.java +++ /dev/null @@ -1,115 +0,0 @@ -package com.coding.basic; - -public class BinaryTreeNode { - - private Comparable data; - private BinaryTreeNode root; - private BinaryTreeNode left; - private BinaryTreeNode right; - - public Comparable getData() { - return data; - } - - public void setData(Comparable 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 getRoot() { - return root; - } - - public void setRoot(BinaryTreeNode root) { - this.root = root; - } - - /** - * 插入节点方法 - * - * @param o - * @return - */ - public BinaryTreeNode insert(Comparable o) { - if (o != null) { - root = insert(root, o); - //System.out.println("@@@@@@"+root.getData()); - } - return root; - } - - /** - * 递归比较插入平衡树 - * - * @param node - * @param o - * @return - */ - private BinaryTreeNode insert(BinaryTreeNode node, Comparable o) { - if (node == null) { - node = new BinaryTreeNode(); - node.setData(o); - } else if (compare(node, o) >= 0) { - node.left = insert(node.left, o); - //System.out.println(o+":insert into left"); - //System.out.println("left:"+node.getData()+":"+o); - } else if (compare(node, o) < 0) { - node.right = insert(node.right, o); - //System.out.println(o+":insert into right"); - //System.out.println("right:"+node.getData()+":"+o); - } - return node; - } - - /** - * 比较内容大小 - * - * @param node - * @param o - * @return - */ - private int compare(BinaryTreeNode node, Comparable o) { - // TODO Auto-generated method stub - return node.data.compareTo(o); - } - - /*-----------------------------------------------------单元测试-----------------------------------------------------*/ - - private void printTree() { - printTree(root); - } - - private void printTree(BinaryTreeNode node) { - if (node == null) - return; - printTree(node.left); - System.out.println("---"+node.data + ""); - printTree(node.right); - } - - public static void main(String[] args) { - BinaryTreeNode tree = new BinaryTreeNode(); - for (int x = 0; x < 100; x++) { - Double i = new Double(Math.random() * 100); - //System.out.println(i); - tree.insert(i); - } - System.out.println("@@@@@@" + tree.getRoot().getData()); - tree.printTree(); - } -} diff --git a/group27/383117348/src/com/coding/basic/Iterator.java b/group27/383117348/src/com/coding/basic/Iterator.java deleted file mode 100644 index dbe8b9afb2..0000000000 --- a/group27/383117348/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/group27/383117348/src/com/coding/basic/LinkedList.java b/group27/383117348/src/com/coding/basic/LinkedList.java deleted file mode 100644 index faeafffca6..0000000000 --- a/group27/383117348/src/com/coding/basic/LinkedList.java +++ /dev/null @@ -1,382 +0,0 @@ -package com.coding.basic; - -import java.util.NoSuchElementException; - -import org.junit.Test; - -public class LinkedList implements List { - - private Node first; - - private Node last; - - private int size; - - /** - * 头部添加节点方法 - */ - private void linkFirst(Object o) { - final Node node = first; - final Node firstNode = new Node(o, node, null); - this.first = firstNode; - if (node == null) { - last = firstNode; - } else { - node.prev = firstNode; - } - size++; - } - - /** - * 末端添加节点方法 - * - * @param o - */ - private void linkLast(Object o) { - final Node node = last; - final Node lastNode = new Node(o, null, node); - last = lastNode; - if (node == null) { - first = lastNode; - } else { - node.next = lastNode; - } - size++; - } - - /** - * 在链表末端添加节点 - */ - public void add(Object o) { - if (o != null) - linkLast(o); - } - - /** - * 在指定下标处添加节点 - */ - public void add(int index, Object o) { - checkIndex(index); - Node befo = getNodeByIndex(index); - linkBefore(o, befo); - } - - /** - * 根据下标获取节点 - */ - public Object get(int index) { - checkIndex(index); - return getNodeByIndex(index).data; - } - - /** - * 根据下标移除节点 - */ - public Object remove(int index) { - checkIndex(index); - Node current = getNodeByIndex(index); - final Node node = current; - final Node prev = node.prev; - final Node next = node.next; - if (prev == null) { - first = next; - } else { - prev.next = next; - next.prev = prev; - current = null; - } - if (next == null) { - last = prev; - } else { - prev.next = next; - next.prev = prev; - current = null; - } - size--; - return node.data; - } - - /** - * 返回链表长度 - */ - public int size() { - return size; - } - - /** - * 在链表头添加节点 - * - * @param o - */ - public void addFirst(Object o) { - linkFirst(o); - } - - /** - * 在链表最后添加节点 - * - * @param o - */ - public void addLast(Object o) { - linkLast(o); - } - - /** - * 移除链表首个元素 - * - * @return - */ - public Object removeFirst() { - Node node = first; - if (node == null) - throw new NoSuchElementException(); - else { - Node next = node.next; - if (next == null) - first = null; - else { - first = next; - first.prev = null; - } - } - size--; - return node.data; - } - - /** - * 移除链表最后一个元素 - * - * @return - */ - public Object removeLast() { - Node node = last; - if (last == null) - throw new NoSuchElementException(); - else { - Node prev = node.prev; - if (prev == null) - last = null; - else { - last = prev; - last.next = null; - } - } - size--; - return node.data; - } - - /** - * 迭代方法 - * - * @return - */ - public Iterator iterator() { - return new Iter(); - } - - /** - * 在节点之前插入一个新的节点 - * - * @param data - * @param befo - */ - private void linkBefore(Object data, Node befo) { - final Node prev = befo.prev; - final Node node = new Node(data, befo, prev); - befo.prev = node; - if (prev == null) - first = node; - else - prev.next = node; - size++; - } - - /** - * 根据下标获取节点 - * - * @param index - * @return - */ - private Node getNodeByIndex(int index) { - checkIndex(index); - - Node node = first; - for (int x = 0; x < index; x++) { - node = node.next; - } - return node; - } - - /** - * 检查下标是否越界 - * - * @param index - */ - private void checkIndex(int index) { - // TODO Auto-generated method stub - if (index < 0 || index > size) { - throw new IndexOutOfBoundsException("链表下标越界"); - } - } - - /** - * 迭代器内部类 - * - * @author Adminstater - * - */ - private class Iter implements Iterator { - private int nextIndex = 0; - - @Override - public boolean hasNext() { - // TODO Auto-generated method stub - return nextIndex != size; - } - - @Override - public Object next() { - // TODO Auto-generated method stub - int i = nextIndex++; - if (i > size - 1) - throw new IndexOutOfBoundsException(); - return getNodeByIndex(i).data; - } - - } - - /** - * 节点内部类 - * - * @author Adminstater - * - */ - private static class Node { - Object data; - Node next; - Node prev; - - private Node(Object data, Node next, Node prev) { - this.data = data; - this.next = next; - this.prev = prev; - } - - private Node() { - - } - } - - /*------------------------------------------------------单元测试----------------------------------------------------*/ - - /** - * 测试添加方法功能 - */ - // add(Object o) - @Test - public void TestAddFunction() { - - LinkedList list = new LinkedList(); - for (int i = 0; i < 100; i++) { - list.add(i); - } - System.out.println("添加完毕"); - - } - - // add(int index,Object o) - @Test - public void TestAddIndexFunction() { - LinkedList list = new LinkedList(); - for (int i = 0; i < 100; i++) { - list.add(i); - } - for (int x = 0; x < list.size(); x++) { - System.out.println(list.get(x)); - } - list.add(3, 111); - System.out.println(list.get(3)); - } - - // addFirst(Object o) - @Test - public void TestAddFirstFunction() { - LinkedList list = new LinkedList(); - for (int i = 0; i < 100; i++) { - list.add(i); - } - System.out.println(list.get(0)); - list.addFirst(20); - System.out.println(list.get(0)); - } - - // addLast(Object o) - @Test - public void TestAddLastFunction() { - LinkedList list = new LinkedList(); - for (int i = 0; i < 100; i++) { - list.add(i); - } - System.out.println(list.get(list.size() - 1)); - list.addLast(111); - System.out.println(list.get(list.size() - 1)); - } - - /** - * remove方法测试 - */ - // removeFirst() - @Test - public void TestRemoveFirst() { - LinkedList list = new LinkedList(); - for (int i = 0; i < 100; i++) { - list.add(i); - } - System.out.println(list.get(0)); - list.removeFirst(); - System.out.println(list.get(0)); - } - - // removeLast() - @Test - public void TestRemoveLast() { - LinkedList list = new LinkedList(); - for (int i = 0; i < 100; i++) { - list.add(i); - } - System.out.println(list.get(list.size() - 1)); - list.removeLast(); - System.out.println(list.get(list.size() - 1)); - } - - // remove(int index) - @Test - public void TestRemoveFunction() { - LinkedList list = new LinkedList(); - for (int i = 0; i < 100; i++) { - list.add(i); - } - System.out.println(list.get(50)); - list.remove(50); - System.out.println(list.get(50)); - } - - /** - * Iterator测试 - */ - @Test - public void TestIterator() { - LinkedList list = new LinkedList(); - for (int i = 0; i < 100; i++) { - list.add(i); - } - Iterator ite = list.iterator(); - while (ite.hasNext()) { - System.out.println(ite.next()); - } - } - - public static void main(String[] args) { - java.util.LinkedList list = null; - } -} diff --git a/group27/383117348/src/com/coding/basic/List.java b/group27/383117348/src/com/coding/basic/List.java deleted file mode 100644 index 396b1f6416..0000000000 --- a/group27/383117348/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/group27/383117348/src/com/coding/basic/Queue.java b/group27/383117348/src/com/coding/basic/Queue.java deleted file mode 100644 index 84cb43e3db..0000000000 --- a/group27/383117348/src/com/coding/basic/Queue.java +++ /dev/null @@ -1,74 +0,0 @@ -package com.coding.basic; - -import org.junit.Test; - -public class Queue { - private int size = 0; - private LinkedList linkedList = new LinkedList(); - - /** - * 入队方法 - * - * @param o - */ - public void enQueue(Object o) { - linkedList.add(o); - size++; - } - - /** - * 出队方法 - * - * @return - */ - public Object deQueue() { - Object result = linkedList.removeFirst(); - size--; - return result; - } - - /** - * 判断队列是否为空 - * - * @return - */ - public boolean isEmpty() { - return size == 0; - } - - /** - * 获取队列的长度 - * - * @return - */ - public int size() { - return size; - } - - /*------------------------------------------------------单元测试----------------------------------------------------*/ - /** - * 入队测试 - */ - @Test - public void enQueueTest() { - Queue queue = new Queue(); - queue.enQueue(1); - } - - /** - * 出队测试 - */ - @Test - public void deQueueTest() { - Queue queue = new Queue(); - for (int x = 0; x < 100; x++) { - queue.enQueue(x); - } - for (int x = 0; x < queue.size();) { - System.out.println(queue.deQueue()); - } - } - - public static void main(String[] args) { - } -} diff --git a/group27/383117348/src/com/coding/basic/Stack.java b/group27/383117348/src/com/coding/basic/Stack.java deleted file mode 100644 index 1b12b63b0f..0000000000 --- a/group27/383117348/src/com/coding/basic/Stack.java +++ /dev/null @@ -1,99 +0,0 @@ -package com.coding.basic; - -import org.junit.Test; - -public class Stack { - - private ArrayList elementData = new ArrayList(); - - /** - * 压栈方法 - * - * @param o - */ - public void push(Object o) { - if (o != null) - elementData.add(o); - } - - /** - * 弹栈方法 - * - * @return - */ - public Object pop() { - Object result = elementData.remove(elementData.size() - 1); - return result; - } - - /** - * 查看栈顶对象 - * - * @return - */ - public Object peek() { - Object result = elementData.get(elementData.size() - 1); - return result; - } - - /** - * 判断是否为空 - * - * @return - */ - public boolean isEmpty() { - return elementData.size() == 0; - } - - /** - * 获取栈的长度 - * - * @return - */ - public int size() { - return elementData.size(); - } - - /*------------------------------------------------------单元测试----------------------------------------------------*/ - /** - * push(Object obj)方法测试 - */ - @Test - public void TestPushFunction() { - Stack stack = new Stack(); - for (int x = 0; x < 100; x++) { - stack.push(x); - } - } - - /** - * peek()方法测试 - */ - @Test - public void TestPeekFunction() { - Stack stack = new Stack(); - for (int x = 0; x < 100; x++) { - stack.push(x); - } - for (int x = 0; x < stack.size(); x++) { - System.out.println(x + ":" + stack.peek()); - } - } - - /** - * pop()方法测试 - */ - @Test - public void TestPopFunction() { - Stack stack = new Stack(); - for (int x = 0; x < 100; x++) { - stack.push(x); - } - System.out.println("before:" + stack.size()); - for (int x = 0; x < stack.size();) { - System.out.println(stack.pop()); - } - System.out.println("after:" + stack.size()); - } - -} diff --git a/group27/425044891/src/com/coding/basic/ArrayList.java b/group27/425044891/src/com/coding/basic/ArrayList.java deleted file mode 100644 index 929a41661c..0000000000 --- a/group27/425044891/src/com/coding/basic/ArrayList.java +++ /dev/null @@ -1,97 +0,0 @@ -package com.coding.basic; - -/** - * ArrayList - * - * @author Guang - * @date 2017年3月12日 下午1:55:47 - */ -public class ArrayList implements List { - - /** - * 数组中元素个数 - */ - private int size = 0; - - /** - * 数组 - */ - private Object[] elementData = new Object[100]; - - public void add(Object o) { - if (size >= 100 || size < 0) { - throw new IndexOutOfBoundsException("越界."); - } - if (null == o) { - return; - } - elementData[size] = o; - size++; - } - - public void add(int index, Object o) { - checkRangeForAdd(index); - if (null == o) { - return; - } - for (int i = size; i > index; i--) { - elementData[i] = elementData[i - 1]; - } - elementData[index] = o; - size++; - } - - private void checkRangeForAdd(int index) { - if (index < 0 || index > size) { - throw new IndexOutOfBoundsException("越界."); - } - } - - private void checkRangeForGet(int index) { - if (index < 0 || index >= size) { - throw new IndexOutOfBoundsException("越界."); - } - } - - public Object get(int index) { - checkRangeForGet(index); - return elementData[index]; - } - - /** - * 移除第index位置的元素,后续元素前移 - */ - public Object remove(int index) { - checkRangeForGet(index); - int i = index; - Object o = elementData[index]; - for (; i < size - 1; i++) { - elementData[i] = elementData[i + 1]; - } - elementData[i] = null; - size--; - return o; - } - - public int size() { - return size; - } - - public Iterator iterator() { - return new Iterator() { - int index = 0; - @Override - public Object next() { - checkRangeForGet(index); - Object o = elementData[index]; - index++; - return o; - } - - @Override - public boolean hasNext() { - return index < size && index >= 0; - } - }; - } -} \ No newline at end of file diff --git a/group27/425044891/src/com/coding/basic/BinaryTreeNode.java b/group27/425044891/src/com/coding/basic/BinaryTreeNode.java deleted file mode 100644 index c702b191e4..0000000000 --- a/group27/425044891/src/com/coding/basic/BinaryTreeNode.java +++ /dev/null @@ -1,41 +0,0 @@ -package com.coding.basic; - -public class BinaryTreeNode> { - - private T data; - private BinaryTreeNode left; - private BinaryTreeNode right; - - public T getData() { - return data; - } - - public void setData(T 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(T o) { - if (o.compareTo(data) <= 0) { - return getLeft().insert(o); - } else { - return getRight().insert(o); - } - } - -} \ No newline at end of file diff --git a/group27/425044891/src/com/coding/basic/Iterator.java b/group27/425044891/src/com/coding/basic/Iterator.java deleted file mode 100644 index de308cef25..0000000000 --- a/group27/425044891/src/com/coding/basic/Iterator.java +++ /dev/null @@ -1,6 +0,0 @@ -package com.coding.basic; -public interface Iterator { - public boolean hasNext(); - public Object next(); - -} \ No newline at end of file diff --git a/group27/425044891/src/com/coding/basic/LinkedList.java b/group27/425044891/src/com/coding/basic/LinkedList.java deleted file mode 100644 index 0c8520c62e..0000000000 --- a/group27/425044891/src/com/coding/basic/LinkedList.java +++ /dev/null @@ -1,274 +0,0 @@ -package com.coding.basic; - -public class LinkedList implements List { - - private Node head = null; - - private int size = 0; - - public LinkedList() { - this.head = new Node(); - this.head.next = null; - this.head.data = null; - this.size = 0; - } - - public void add(Object o) { - if (null == o) { - return; - } - Node next = new Node(); - next.data = o; - next.next = null; - - /** - * 寻找尾部节点 - */ - Node p = head; - while (p.next != null) { - p = p.next; - } - p.next = next; - size++; - } - - public void add(int index, Object o) { - if (index < 0 || index > size) { - throw new IndexOutOfBoundsException(); - } - if (null == o) { - return; - } - Node next = new Node(); - next.data = o; - next.next = null; - - Node p = head.next; - Node pre = head; - int pos = 0; - while (p != null && pos < index) { - pre = p; - p = p.next; - pos++; - } - next.next = p; - pre.next = next; - size++; - } - - public Object get(int index) { - if (index < 0 || index >= size) { - throw new IndexOutOfBoundsException(); - } - Node p = head.next; - int pos = 0; - while (p != null && pos < index) { - p = p.next; - pos++; - } - return p == null ? null : p.data; - } - - public Object remove(int index) { - if (index < 0 || index >= size) { - throw new IndexOutOfBoundsException(); - } - Node p = head.next; - Node pre = p; - int pos = 0; - while (p != null && pos < index) { - pre = p; - p = p.next; - pos++; - } - Object o = p.data; - pre.next = p.next; - size--; - return o; - } - - public int size() { - return size; - } - - public void addFirst(Object o) { - if (null == o) { - return; - } - Node next = new Node(); - next.next = null; - next.data = o; - - next.next = head.next; - head.next = next; - size++; - } - - public void addLast(Object o) { - if (null == o) { - return; - } - Node p = head; - while (p.next != null) { - p = p.next; - } - - Node next = new Node(); - next.data = o; - next.next = null; - - p.next = next; - size++; - } - - public Object removeFirst() { - if (size <= 0) { - throw new IndexOutOfBoundsException(); - } - Node p = head.next; - Object o = p.data; - - head.next = p.next; - size--; - return o; - } - - public Object removeLast() { - if (size <= 0) { - throw new IndexOutOfBoundsException(); - } - Node p = head.next; - Node pre = head; - while (p.next != null) { - pre = p; - p = p.next; - } - Object o = p.data; - pre.next = p.next; - size--; - return o; - } - - public Iterator iterator() { - return new Iterator() { - Node current = head; - - @Override - public Object next() { - Object o = current.next.data; - current = current.next; - return o; - } - - @Override - public boolean hasNext() { - return current.next != null; - } - }; - } - - private static class Node { - Object data; - Node next; - } - - /** - * 把该链表逆置 例如链表为 3->7->10 , 逆置后变为 10->7->3 - */ - public void reverse() { - Node p = head.next.next; - Node pre = head.next; - pre.next = null; - while (p != null) { - Node pp = p.next; - p.next = pre; - pre = p; - p = pp; - } - head.next = pre; - // --- --- --- - } - - /** - * 删除一个单链表的前半部分 例如: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; - } - - public static void main(String[] args) { - - LinkedList list = new LinkedList(); - list.add("A"); - list.add("B"); - list.add("C"); - list.add("D"); - list.reverse(); - Iterator it = list.iterator(); - while (it.hasNext()) { - Object o = it.next(); - System.out.println(o); - } - - } -} \ No newline at end of file diff --git a/group27/425044891/src/com/coding/basic/List.java b/group27/425044891/src/com/coding/basic/List.java deleted file mode 100644 index c86b745572..0000000000 --- a/group27/425044891/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(); -} \ No newline at end of file diff --git a/group27/425044891/src/com/coding/basic/Queue.java b/group27/425044891/src/com/coding/basic/Queue.java deleted file mode 100644 index fcec6ac57c..0000000000 --- a/group27/425044891/src/com/coding/basic/Queue.java +++ /dev/null @@ -1,37 +0,0 @@ -package com.coding.basic; - -public class Queue { - - private Object[] elementData = new Object[100]; - - int size = 0; - - public void enQueue(Object o) { - if (size < 0 || size >= 100) { - throw new IndexOutOfBoundsException(); - } - elementData[size++] = o; - } - - public Object deQueue() { - if (size <= 0) { - throw new IndexOutOfBoundsException(); - } - Object o = elementData[0]; - int i = 0; - for (; i < size - 1; i++) { - elementData[i] = elementData[i + 1]; - } - elementData[i] = null; - size--; - return o; - } - - public boolean isEmpty() { - return elementData.length != 0; - } - - public int size() { - return elementData.length; - } -} \ No newline at end of file diff --git a/group27/425044891/src/com/coding/basic/Stack.java b/group27/425044891/src/com/coding/basic/Stack.java deleted file mode 100644 index 1217d25fbe..0000000000 --- a/group27/425044891/src/com/coding/basic/Stack.java +++ /dev/null @@ -1,29 +0,0 @@ -package com.coding.basic; - -public class Stack { - - private ArrayList elementData = new ArrayList(); - - public void push(Object o) { - int size = elementData.size(); - elementData.add(size, o); - } - - public Object pop() { - int size = elementData.size(); - return elementData.remove(size - 1); - } - - public Object peek() { - int size = elementData.size(); - return elementData.get(size - 1); - } - - public boolean isEmpty() { - return elementData.size() != 0; - } - - public int size() { - return elementData.size(); - } -} \ No newline at end of file diff --git a/group27/772642286/basic/ArrayList.java b/group27/772642286/basic/ArrayList.java deleted file mode 100644 index 108eb02ff4..0000000000 --- a/group27/772642286/basic/ArrayList.java +++ /dev/null @@ -1,80 +0,0 @@ -package week01.basic; - -import java.util.Arrays; - -public class ArrayList implements List { - - private int size = 0; - - private Object[] elementData = new Object[100]; - - public void add(Object o){ - add(size , o); - } - public void add(int index, Object o){ - if(index<0||index > size){ - throw new ArrayIndexOutOfBoundsException(index); - } - size++; - if(size>=elementData.length){ - expand(); - } - for(int i = size -1 ;i> index; i--){ - elementData[i] = elementData[i-1]; - } - elementData[index] = o; - } - - public Object get(int index){ - if(index<0||index>=size){ - throw new ArrayIndexOutOfBoundsException(index); - } - return elementData[index]; - } - - public Object remove(int index){ - if(index<0||index>=size){ - throw new ArrayIndexOutOfBoundsException(index); - } - Object o = elementData[index]; - for(int i = index ;i< size - 1; i++){ - elementData[i] = elementData[i+1]; - } - elementData[size - 1] = null; - size--; - return o; - } - - public int size(){ - return size; - } - - public Iterator iterator(){ - return new ArrayListIterator(); - } - - class ArrayListIterator implements Iterator{ - - int count = 0; - @Override - public boolean hasNext() { - count++; - if(size<= count){ - return false; - } - return true; - } - - @Override - public Object next() { - return elementData[count]; - } - - } - - - private void expand(){ - elementData = Arrays.copyOf(elementData, elementData.length*2); - } - -} diff --git a/group27/772642286/basic/BinaryTreeNode.java b/group27/772642286/basic/BinaryTreeNode.java deleted file mode 100644 index 75a9327421..0000000000 --- a/group27/772642286/basic/BinaryTreeNode.java +++ /dev/null @@ -1,55 +0,0 @@ -package week01.basic; - -public class BinaryTreeNode { - - private T data; - private BinaryTreeNode left; - private BinaryTreeNode right; - - public Object getData() { - return data; - } - public void setData(T 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(T o){ - return insert(this,o); - } - - - public BinaryTreeNode insert(BinaryTreeNode root,T o){ - if(o.compareTo(root) >= 0){ - if(root.left == null){ - BinaryTreeNode binaryTreeNode = new BinaryTreeNode(); - root.left = binaryTreeNode; - binaryTreeNode.data = o; - return binaryTreeNode; - } - return insert(root.left, o); - } - else{ - if (root.right == null) { - BinaryTreeNode binaryTreeNode = new BinaryTreeNode(); - root.right = binaryTreeNode; - binaryTreeNode.data = o; - return binaryTreeNode; - } - return insert(root.right, o); - } - } - - -} diff --git a/group27/772642286/basic/Iterator.java b/group27/772642286/basic/Iterator.java deleted file mode 100644 index 305ed43120..0000000000 --- a/group27/772642286/basic/Iterator.java +++ /dev/null @@ -1,7 +0,0 @@ -package week01.basic; - -public interface Iterator { - public boolean hasNext(); - public Object next(); - -} diff --git a/group27/772642286/basic/LinkedList.java b/group27/772642286/basic/LinkedList.java deleted file mode 100644 index 98cf2d651b..0000000000 --- a/group27/772642286/basic/LinkedList.java +++ /dev/null @@ -1,208 +0,0 @@ -package week01.basic; - -import java.util.Objects; - -public class LinkedList implements List { - - private Node head; - - private Node tail; - - private int size; - - public void add(Object o){ - Node node = new Node(); - node.data = o; - if(Objects.isNull(head)){ - head = node; - tail = head; - size++; - return ; - } - tail.next = node; - tail = node; - size++; - } - - public void add(int index , Object o){ - if(index<0 || index >size){ - throw new ArrayIndexOutOfBoundsException(index); - } - if(Objects.isNull(head)||index==size){ - add(o); - return; - } - - Node headNode = getNode(index - 1); - Node temp = headNode.next; - Node node = new Node(); - node.data = o; - node.next = temp; - headNode.next = node; - size++; - } - - - public Object get(int index){ - if(index< 0 || index >= size){ - throw new ArrayIndexOutOfBoundsException(index); - } - - return getNode(index).data; - } - - private Node getNode(int index){ - - - int count = 0; - Node headNode = head; - while(count< index){ - headNode = headNode.next; - count++; - } - return headNode; - } - - public Object remove(int index){ - if(index< 0 || index >= size){ - throw new ArrayIndexOutOfBoundsException(index); - } - - if(index==0){ - Node node = head; - head = head.next; - size --; - return node.data; - } - - Node headNode = getNode(index - 1); - Node node = headNode.next; - head.next = node.next; - size --; - return node.data; - } - - public int size(){ - return size; - } - - public void addFirst(Object o){ - add(0, o); - } - public void addLast(Object o){ - add(size,o); - } - public Object removeFirst(){ - return remove(0); - } - public Object removeLast(){ - return remove(size); - } - public Iterator iterator(){ - return new LinkedListIterator(); - } - - class LinkedListIterator implements Iterator{ - - private Node currentNode; - - @Override - public boolean hasNext() { - if(currentNode==null){ - currentNode = head; - }else{ - currentNode = currentNode.next; - } - return Objects.nonNull(currentNode); - } - - @Override - public Object next() { - return currentNode.data; - } - - } - - - 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){ - - } - /** - * 假定当前链表和list均包含已升序排列的整数 - * 从当前链表中取出那些list所指定的元素 - * 例如当前链表 = 11->101->201->301->401->501->601->701 - * listB = 1->3->4->6 - * 返回的结果应该是[101,301,401,601] - * @param list - */ - public static int[] getElements(LinkedList list){ - return null; - } - - /** - * 已知链表中的元素以值递增有序排列,并以单链表作存储结构。 - * 从当前链表中中删除在list中出现的元素 - - * @param list - */ - - public void subtract(LinkedList list){ - - } - - /** - * 已知当前链表中的元素以值递增有序排列,并以单链表作存储结构。 - * 删除表中所有值相同的多余元素(使得操作后的线性表中所有元素的值均不相同) - */ - public void removeDuplicateValues(){ - - } - - /** - * 已知链表中的元素以值递增有序排列,并以单链表作存储结构。 - * 试写一高效的算法,删除表中所有值大于min且小于max的元素(若表中存在这样的元素) - * @param min - * @param max - */ - public void removeRange(int min, int max){ - - } - - /** - * 假设当前链表和参数list指定的链表均以元素依值递增有序排列(同一表中的元素值各不相同) - * 现要求生成新链表C,其元素为当前链表和list中元素的交集,且表C中的元素有依值递增有序排列 - * @param list - */ - public LinkedList intersection( LinkedList list){ - return null; - } -} diff --git a/group27/772642286/basic/List.java b/group27/772642286/basic/List.java deleted file mode 100644 index 912285e171..0000000000 --- a/group27/772642286/basic/List.java +++ /dev/null @@ -1,9 +0,0 @@ -package week01.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/group27/772642286/basic/Queue.java b/group27/772642286/basic/Queue.java deleted file mode 100644 index 320280635f..0000000000 --- a/group27/772642286/basic/Queue.java +++ /dev/null @@ -1,21 +0,0 @@ -package week01.basic; - -public class Queue { - private LinkedList elementData = new LinkedList(); - - public void enQueue(Object o){ - elementData.add(o); - } - - public Object deQueue(){ - return elementData.remove(elementData.size()); - } - - public boolean isEmpty(){ - return elementData.size() == 0; - } - - public int size(){ - return elementData.size(); - } -} diff --git a/group27/772642286/basic/Stack.java b/group27/772642286/basic/Stack.java deleted file mode 100644 index 0e6901c0ce..0000000000 --- a/group27/772642286/basic/Stack.java +++ /dev/null @@ -1,23 +0,0 @@ -package week01.basic; - -public class Stack { - private LinkedList elementData = new LinkedList(); - - public void push(Object o){ - elementData.add(o); - } - - public Object pop(){ - return elementData.remove(0); - } - - public Object peek(){ - return elementData.get(0); - } - public boolean isEmpty(){ - return elementData.size() == 0; - } - public int size(){ - return elementData.size(); - } -} diff --git a/group27/772642286/test/ArrayListTest.java b/group27/772642286/test/ArrayListTest.java deleted file mode 100644 index e8409a7d40..0000000000 --- a/group27/772642286/test/ArrayListTest.java +++ /dev/null @@ -1,55 +0,0 @@ -package week01.test; - - -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; - -import week01.basic.ArrayList; -import week01.basic.Iterator; - - -public class ArrayListTest { - ArrayList list = null; - - @Before - public void init(){ - list = new ArrayList(); - for(int i=1;i<=500;i++){ - list.add(i); - } - } - - @Test - public void addTest(){ - Assert.assertEquals(500, list.size()); - for(int i=1;i<=list.size();i++){ - Assert.assertEquals(i, list.get(i-1)); - } - } - - @Test - public void addIndexTest(){ - list.add(250, 3333); - Assert.assertEquals(3333, list.get(250)); - Assert.assertEquals(500, list.get(500)); - } - - @Test - public void removeIndexTest(){ - list.remove(250); - Assert.assertEquals(499, list.size()); - Assert.assertEquals(252, list.get(250)); - Assert.assertEquals(500, list.get(498)); - } - - @Test - public void iteratorTest(){ - Iterator iterator = list.iterator(); - int count = 1; - while(iterator.hasNext()){ - Assert.assertEquals(++count, iterator.next()); - } - } - -} diff --git a/group27/772642286/test/BinaryTreeNodeTest.java b/group27/772642286/test/BinaryTreeNodeTest.java deleted file mode 100644 index c0e12d2eb5..0000000000 --- a/group27/772642286/test/BinaryTreeNodeTest.java +++ /dev/null @@ -1,6 +0,0 @@ -package week01.test; - -public class BinaryTreeNodeTest { - - -} diff --git a/group27/772642286/test/LinkedListTest.java b/group27/772642286/test/LinkedListTest.java deleted file mode 100644 index cae56aad19..0000000000 --- a/group27/772642286/test/LinkedListTest.java +++ /dev/null @@ -1,52 +0,0 @@ -package week01.test; - -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; - -import week01.basic.Iterator; -import week01.basic.LinkedList; - -public class LinkedListTest { - LinkedList list = null; - - @Before - public void init(){ - list = new LinkedList(); - for(int i=1;i<=500;i++){ - list.add(i); - } - } - - @Test - public void addTest(){ - Assert.assertEquals(500, list.size()); - for(int i=1;i<=list.size();i++){ - Assert.assertEquals(i, list.get(i-1)); - } - } - - @Test - public void addIndexTest(){ - list.add(250, 3333); - Assert.assertEquals(3333, list.get(250)); - Assert.assertEquals(500, list.get(500)); - } - - @Test - public void removeIndexTest(){ - list.remove(250); - Assert.assertEquals(499, list.size()); - Assert.assertEquals(252, list.get(250)); - Assert.assertEquals(500, list.get(498)); - } - - @Test - public void iteratorTest(){ - Iterator iterator = list.iterator(); - int count = 0; - while(iterator.hasNext()){ - Assert.assertEquals(++count, iterator.next()); - } - } -} diff --git a/group27/772642286/test/QueueTest.java b/group27/772642286/test/QueueTest.java deleted file mode 100644 index 14008f51b2..0000000000 --- a/group27/772642286/test/QueueTest.java +++ /dev/null @@ -1,45 +0,0 @@ -package week01.test; - -import org.junit.Assert; -import org.junit.Before; - -import week01.basic.Queue; - -public class QueueTest { - - private Queue queue; - - @Before - public void init(){ - queue = new Queue(); - for(int i=1;i<=500;i++){ - queue.enQueue(i); - } - } - - public void enQueueTest(){ - Assert.assertEquals(500, queue.size()); - } - - public void deQueue(){ - for(int i=500;i>=1 ;i--){ - Assert.assertEquals(i, queue.deQueue()); - } - - } - - public void isEmpty(){ - Assert.assertEquals(false, queue.isEmpty()); - for(int i=500;i>=1 ;i--){ - Assert.assertEquals(i, queue.deQueue()); - } - Assert.assertEquals(true, queue.isEmpty()); - } - - public void size(){ - for(int i=499;i>0 ;i--){ - queue.deQueue(); - Assert.assertEquals(i, queue.size()); - } - } -} diff --git a/group27/772642286/test/StackTest.java b/group27/772642286/test/StackTest.java deleted file mode 100644 index 40f0928a14..0000000000 --- a/group27/772642286/test/StackTest.java +++ /dev/null @@ -1,58 +0,0 @@ -package week01.test; - -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; - -import week01.basic.Stack; - -public class StackTest { - - private Stack stack; - - @Before - public void init(){ - stack = new Stack(); - for(int i=1;i<=500;i++){ - stack.push(i); - } - } - - @Test - public void pushTest(){ - Assert.assertEquals(500, stack.size()); - } - - @Test - public void popTest(){ - for(int i=1;i<=500 ;i++){ - Assert.assertEquals(i, stack.pop()); - } - } - - @Test - public void peekTest(){ - Assert.assertEquals(1, stack.peek()); - Assert.assertEquals(1, stack.peek()); - Assert.assertEquals(1, stack.pop()); - Assert.assertEquals(2, stack.peek()); - Assert.assertEquals(2, stack.peek()); - } - - @Test - public void isEmpty(){ - Assert.assertEquals(false, stack.isEmpty()); - for(int i=1;i<=500 ;i++){ - Assert.assertEquals(i, stack.pop()); - } - Assert.assertEquals(true, stack.isEmpty()); - } - - @Test - public void size(){ - for(int i=499;i>0 ;i--){ - stack.pop(); - Assert.assertEquals(i, stack.size()); - } - } -} diff --git a/group27/815591664/2017Learning/.classpath b/group27/815591664/2017Learning/.classpath deleted file mode 100644 index 3e0fb272a8..0000000000 --- a/group27/815591664/2017Learning/.classpath +++ /dev/null @@ -1,7 +0,0 @@ - - - - - - - diff --git a/group27/815591664/2017Learning/.gitignore b/group27/815591664/2017Learning/.gitignore deleted file mode 100644 index ae3c172604..0000000000 --- a/group27/815591664/2017Learning/.gitignore +++ /dev/null @@ -1 +0,0 @@ -/bin/ diff --git a/group27/815591664/2017Learning/.project b/group27/815591664/2017Learning/.project deleted file mode 100644 index fab8d7f04c..0000000000 --- a/group27/815591664/2017Learning/.project +++ /dev/null @@ -1,17 +0,0 @@ - - - 2017Learning - - - - - - org.eclipse.jdt.core.javabuilder - - - - - - org.eclipse.jdt.core.javanature - - diff --git a/group27/815591664/2017Learning/.settings/org.eclipse.core.resources.prefs b/group27/815591664/2017Learning/.settings/org.eclipse.core.resources.prefs deleted file mode 100644 index 3af089907a..0000000000 --- a/group27/815591664/2017Learning/.settings/org.eclipse.core.resources.prefs +++ /dev/null @@ -1,2 +0,0 @@ -eclipse.preferences.version=1 -encoding//src/com/coderising/array/ArrayUtil.java=UTF-8 diff --git a/group27/815591664/2017Learning/src/com/coderising/array/ArrayUtil.java b/group27/815591664/2017Learning/src/com/coderising/array/ArrayUtil.java deleted file mode 100644 index 7c30103d89..0000000000 --- a/group27/815591664/2017Learning/src/com/coderising/array/ArrayUtil.java +++ /dev/null @@ -1,348 +0,0 @@ -package com.coderising.array; - -import java.util.ArrayList; -import java.util.Arrays; - -import java.util.List; - - -public class ArrayUtil { - - /** - * 给定一个整形数组a , 对该数组的值进行置换 - 例如: a = [7, 9 , 30, 3] , 置换后为 [3, 30, 9,7] - 如果 a = [7, 9, 30, 3, 4] , 置换后为 [4,3, 30 , 9,7] - * @param origin - * @return - */ - - public static void main(String[] args) { - int[] a = {7, 9, 30, 3, 4}; - reverseArray(a); - System.out.println(Arrays.toString(a)); - - - int oldArr[]={1,3,4,5,0,0,6,6,0,5,4,7,6,7,0,5,0} ; - System.out.println(Arrays.toString(removeZero(oldArr))); - - - int[] a1 = {3, 5, 7,8}; - int[] a2 = {4, 5, 6,7}; - - System.out.println(Arrays.toString(merge(a1,a2))); - - - int[] b = { 2,3,6}; - System.out.println(Arrays.toString(grow(b,5))); - - System.out.println(genFibonacci(5)); - - System.out.println(Arrays.toString(fibonacci(30))); - - System.out.println(Arrays.toString(getPrimes(10000))); - - System.out.println(getFactor(10)); - - System.out.println(isPerfectNum(1000)); - -// System.out.println(); - System.out.println(Arrays.toString(getPerfectNumbers(100))); - - System.out.println(join(a,"&")); - - - } - public static void reverseArray(int[] origin){ - - if(origin.length==0){ - return; - - } - int[] copy = new int[origin.length]; - System.arraycopy(origin, 0, copy, 0, origin.length); - - for (int i = 0; i < copy.length; i++) { - - origin[i] = copy[copy.length-1-i]; - } - - - } - - /** - * 现在有如下的一个数组: int oldArr[]={1,3,4,5,0,0,6,6,0,5,4,7,6,7,0,5} - * 要求将以上数组中值为0的项去掉,将不为0的值存入一个新的数组,生成的新数组为: - * {1,3,4,5,6,6,5,4,7,6,7,5} - * @param oldArray - * @return - */ - - public static int[] removeZero(int[] oldArray){ - int newSize = 0; - for (int i = 0; i < oldArray.length; i++) { - if(oldArray[i]!=0){ - newSize++; - } - } - int index = 0; - int[] newArr = new int[newSize]; - for (int i = 0; i < oldArray.length; i++) { - if(oldArray[i]!=0){ - newArr[index] = oldArray[i]; - index++; - } - } - return newArr; - } - - /** - * 给定两个已经排序好的整形数组, a1和a2 , 创建一个新的数组a3, 使得a3 包含a1和a2 的所有元素, 并且仍然是有序的 - * 例如 a1 = [3, 5, 7,8] a2 = [4, 5, 6,7] 则 a3 为[3,4,5,6,7,8] , 注意: 已经消除了重复 - * @param array1 - * @param array2 - * @return - */ - - public static int[] merge(int[] array1, int[] array2){ - Arrays.sort(array1); - Arrays.sort(array2); - - int[] newArr = new int[array1.length+array2.length]; - - System.arraycopy(array1, 0, newArr, 0,array1.length ); - System.arraycopy(array2, 0, newArr, array1.length, array2.length); - Arrays.sort(newArr); - List list = new ArrayList(); - for(int i=0;i list = new ArrayList(); - for(int i =0;i list = new ArrayList(); - for(int i=2;i<=max;i++){ - if(isPrime(i)){ - list.add(i); - } - } - - return listToArray(list); - - - } - - public static int[] listToArray(List list){ - if(list == null){ - return null; - } - - int[] arr = new int[list.size()]; - - for(int i=0;i list = new ArrayList(); - for(int i=1;i<=max;i++){ - if(isPerfectNum(i)){ - list.add(i); - } - } - - return listToArray(list); - } - - - public static boolean isPerfectNum(int num){ - if(num <=1){ - return false; - } - - List factors = getFactor(num); - int sum = 0; - for (Integer integer : factors) { - sum = integer+sum; - } - if(sum == num){ - return true; - } - return false; - } - - public static List getFactor(int num){ - List list = new ArrayList(); - list.add(1); - - - for(int i=2;i getFactor(int num){ - List list = new ArrayList(); - list.add(1); - int temp = num; - - while(!isPrime(temp)){ - if(temp ==1){ - break; - } - for(int i=2;i<=temp;i++){ - if(temp % i ==0){ - list.add(i); - temp = temp/i; - break; - } - } - - } - list.add(temp); - - return list; - }*/ - - /** - * 用seperator 把数组 array给连接起来 - * 例如array= [3,8,9], seperator = "-" - * 则返回值为"3-8-9" - * @param array - * @param s - * @return - */ - public static String join(int[] array, String seperator){ - StringBuilder sb = new StringBuilder(); - for (int i : array) { - sb.append(i); - sb.append(seperator); - - } - - return sb.subSequence(0, sb.length()-1).toString(); - } - - -} diff --git a/group27/815591664/2017Learning/src/com/coderising/litestruts/LoginAction.java b/group27/815591664/2017Learning/src/com/coderising/litestruts/LoginAction.java deleted file mode 100644 index dcdbe226ed..0000000000 --- a/group27/815591664/2017Learning/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/group27/815591664/2017Learning/src/com/coderising/litestruts/Struts.java b/group27/815591664/2017Learning/src/com/coderising/litestruts/Struts.java deleted file mode 100644 index 85e2e22de3..0000000000 --- a/group27/815591664/2017Learning/src/com/coderising/litestruts/Struts.java +++ /dev/null @@ -1,34 +0,0 @@ -package com.coderising.litestruts; - -import java.util.Map; - - - -public class Struts { - - public static View runAction(String actionName, Map parameters) { - - /* - - 0. 读取配置文件struts.xml - - 1. 根据actionName找到相对应的class , 例如LoginAction, 通过反射实例化(创建对象) - 据parameters中的数据,调用对象的setter方法, 例如parameters中的数据是 - ("name"="test" , "password"="1234") , - 那就应该调用 setName和setPassword方法 - - 2. 通过反射调用对象的exectue 方法, 并获得返回值,例如"success" - - 3. 通过反射找到对象的所有getter方法(例如 getMessage), - 通过反射来调用, 把值和属性形成一个HashMap , 例如 {"message": "登录成功"} , - 放到View对象的parameters - - 4. 根据struts.xml中的 配置,以及execute的返回值, 确定哪一个jsp, - 放到View对象的jsp字段中。 - - */ - - return null; - } - -} diff --git a/group27/815591664/2017Learning/src/com/coderising/litestruts/StrutsTest.java b/group27/815591664/2017Learning/src/com/coderising/litestruts/StrutsTest.java deleted file mode 100644 index b8c81faf3c..0000000000 --- a/group27/815591664/2017Learning/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/group27/815591664/2017Learning/src/com/coderising/litestruts/View.java b/group27/815591664/2017Learning/src/com/coderising/litestruts/View.java deleted file mode 100644 index 07df2a5dab..0000000000 --- a/group27/815591664/2017Learning/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/group27/815591664/2017Learning/src/com/coderising/litestruts/struts.xml b/group27/815591664/2017Learning/src/com/coderising/litestruts/struts.xml deleted file mode 100644 index dd598a3664..0000000000 --- a/group27/815591664/2017Learning/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/group27/815591664/2017Learning/src/com/coding/basic/ArrayList.java b/group27/815591664/2017Learning/src/com/coding/basic/ArrayList.java deleted file mode 100644 index c983c04968..0000000000 --- a/group27/815591664/2017Learning/src/com/coding/basic/ArrayList.java +++ /dev/null @@ -1,146 +0,0 @@ -package com.coding.basic; - -import java.util.Arrays; -import java.util.LinkedList; - -/** - * @author hugaoqing - * created on 2017-3-8 - */ -public class ArrayList implements List { - - private int size = 0; - - private Object[] elementData = new Object[100]; - - - - /* - * sizelengthʱbufferԭ - * - */ - public void add(Object o){ - if(elementData.length == size){ - Object[] buffer = new Object[size+15]; - System.arraycopy(elementData, 0, buffer, 0, size); - elementData = buffer; - elementData[size] = o; - size++; - }else { - - elementData[size] = o; - size++; - } - - } - - - /* - * ָλԪ - * size+1 lengthҪٽӲ - */ - public void add(int index, Object o) throws Exception{ - if(index <0){ - throw new Exception("Ϊ0"); - - }else if(index >= size){ - throw new Exception("ޣ"); - }else if(size+1=size){ - throw new Exception("ޣ"); - } - return elementData[index]; - } - - public Object remove(int index) throws Exception{ - if(index>=size){ - throw new Exception("ޣ"); - } - Object out = elementData[index]; - Object[] temp = new Object[size-index-1]; - System.arraycopy(elementData, index+1, temp, 0, size-index-1); - System.arraycopy(temp, 0, elementData,index, size-index-1); - - size--; - return out; - } - - public int size(){ - return this.size; - } - - @Override - public String toString() { - Object[] objs = new Object[size]; - System.arraycopy(elementData, 0,objs , 0, size); - return Arrays.toString(objs); - - } - public Iterator iterator(){ - return new Iterator() { - int cursor = 0; - public Object next() throws Exception { - cursor++; - return get(cursor-1); - } - - public boolean hasNext() { - - return this.cursor ll = new LinkedList(); - ll.add(null); - - - - } - - - -} diff --git a/group27/815591664/2017Learning/src/com/coding/basic/BinaryTree.java b/group27/815591664/2017Learning/src/com/coding/basic/BinaryTree.java deleted file mode 100644 index ed69a3f16c..0000000000 --- a/group27/815591664/2017Learning/src/com/coding/basic/BinaryTree.java +++ /dev/null @@ -1,35 +0,0 @@ -package com.coding.basic; - -public class BinaryTree { - - private BinaryTreeNode root; - - public BinaryTreeNode insert(Integer data){ - BinaryTreeNode node = new BinaryTreeNode(data); - - - if(this.root==null){ - root = node; - root.setLeft(null); - root.setRight(null); - }else{ - BinaryTreeNode curNode = this.root; - - if(data.compareTo(root.getData())>0){ - while(curNode.getRight()!=null){ - curNode = curNode.getRight(); - } - curNode = node; - - }else{ - while(curNode.getLeft()!=null){ - curNode = curNode.getLeft(); - } - curNode = node; - } - - } - return null; - } - -} diff --git a/group27/815591664/2017Learning/src/com/coding/basic/BinaryTreeNode.java b/group27/815591664/2017Learning/src/com/coding/basic/BinaryTreeNode.java deleted file mode 100644 index 23e2b871a3..0000000000 --- a/group27/815591664/2017Learning/src/com/coding/basic/BinaryTreeNode.java +++ /dev/null @@ -1,43 +0,0 @@ -package com.coding.basic; - - - -/** - * @author hugaoqing - * created on 2017-3-11 - */ -public class BinaryTreeNode { - - private Integer data; - private BinaryTreeNode left; - private BinaryTreeNode right; - - public BinaryTreeNode(Integer data) { - super(); - this.data = data; - } - public Integer getData() { - return data; - } - public void setData(Integer 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){ - this.data = o; - return this; - }*/ - -} diff --git a/group27/815591664/2017Learning/src/com/coding/basic/Iterator.java b/group27/815591664/2017Learning/src/com/coding/basic/Iterator.java deleted file mode 100644 index d4656a7daf..0000000000 --- a/group27/815591664/2017Learning/src/com/coding/basic/Iterator.java +++ /dev/null @@ -1,9 +0,0 @@ -package com.coding.basic; - -public interface Iterator { - //ӿijԱĬ϶final static -// int cursor = 0; - public boolean hasNext(); - public Object next() throws Exception; - -} diff --git a/group27/815591664/2017Learning/src/com/coding/basic/LinkedList.java b/group27/815591664/2017Learning/src/com/coding/basic/LinkedList.java deleted file mode 100644 index 6f2fbf1f5b..0000000000 --- a/group27/815591664/2017Learning/src/com/coding/basic/LinkedList.java +++ /dev/null @@ -1,236 +0,0 @@ -package com.coding.basic; - -public class LinkedList implements List { - - private Node head; - private Node tail; - private int size; - - - public void add(Object o){ - this.addLast(o); - - } - public void add(int index , Object o) throws Exception{ - if(index==0){ - this.addFirst(o); - return; - }else if(index==size-1){ - this.addLast(o); - return; - }else{ - - - Node curNode = this.getNode(index); - Node pre = curNode.previous; -// Node next = curNode.next; - // - Node newNode = new Node(o, pre, curNode); - curNode.previous = newNode; - pre.next = newNode; - } - size++; - - - } - private Node getNode(int index) throws Exception{ - if(index>=size){ - throw new Exception("±곬"); - } - if(index ==0){ - return head; - }else if(index==size-1){ - return tail; - - }else{ - Node temp = head; - for(int i =1;i<=index;i++){ - temp = temp.next; - } - return temp; - } - } - public Object get(int index) throws Exception{ - if(index>=size){ - throw new Exception("±곬"); - } - if(index ==0){ - return head.data; - }else if(index==size-1){ - return tail.data; - - }else{ - Node temp = head; - for(int i =1;i<=index;i++){ - temp = temp.next; - } - return temp.data; - } - } - public Object remove(int index) throws Exception{ - if(index>=size){ - throw new Exception("±곬"); - } - Object o = null; - if(size == 1){ - o = head.data; - }else{ - if(index==0){ - - Node afterHead = head.next; - afterHead.previous = null; - head = afterHead; - o = head.data; - - }else if(index == size-1){ - Node beforeTail = tail.previous; - beforeTail.next = null; - tail = beforeTail; - o = tail.data; - }else{ - Node curNode = this.getNode(index); - Node pre = curNode.previous; - Node next = curNode.next; - //мڶϿָ - Node temp = new Node(next.data, pre, next.next); - pre.next = temp; - next = temp; - o = curNode.data; - - } - - - - } - - size--; - return o; - - - } - - public int size(){ - return this.size; - } - - public void addFirst(Object o){ - Node node = new Node(o, null, head); - - if(head == null){ - head = node; - tail = node; - }else{ - head.previous = node; - head = node; - } - size++; - - } - public void addLast(Object o){ - //½ڵpreviousָָtail - Node curNode = new Node(o, tail, null); - if(tail==null){ - //ǰΪʱýڵͷβΪýڵ - head = curNode; - tail = curNode; - }else{ - //Ϊʱһڵnextָָ¼Ľڵ㼴 - tail.next = curNode; - //¼ڵΪtail - tail = curNode; - - } - size++; - - } - public Object removeFirst() throws Exception{ - return this.remove(0); - } - public Object removeLast() throws Exception{ - return this.remove(size-1); - } - - private class Itr implements Iterator{ - int cursor = 0; - public boolean hasNext() { - return cursor Date: Sat, 18 Mar 2017 13:29:05 +0800 Subject: [PATCH 3/5] =?UTF-8?q?=E7=AC=AC=E4=BA=8C=E5=91=A8=E4=BD=9C?= =?UTF-8?q?=E4=B8=9A=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 第二周作业,增加测试用例,修改代码bug --- .../coding/coderising/array/ArrayUtil.java | 83 +++++++------ .../coderising/array/ArrayUtilTest.java | 110 ++++++++++++++++++ .../coderising/litestruts/StrutsTest.java | 12 +- 3 files changed, 169 insertions(+), 36 deletions(-) create mode 100644 group27/513274874/homework/src/com/coding/coderising/array/ArrayUtilTest.java diff --git a/group27/513274874/homework/src/com/coding/coderising/array/ArrayUtil.java b/group27/513274874/homework/src/com/coding/coderising/array/ArrayUtil.java index 2c0856829e..1684b512ad 100644 --- a/group27/513274874/homework/src/com/coding/coderising/array/ArrayUtil.java +++ b/group27/513274874/homework/src/com/coding/coderising/array/ArrayUtil.java @@ -10,14 +10,14 @@ public class ArrayUtil { * @param origin * @return */ - public void reverseArray(final int[] origin) { + public static void reverseArray(final int[] origin) { int size = origin.length; if (size <= 0) return; - int[] newArray = this.copyOf(origin); + int[] newArray = copyOf(origin); for (int i = 0; i < size; i++) { - origin[i] = newArray[size - i]; + origin[i] = newArray[size - 1 - i]; } } @@ -30,7 +30,7 @@ public void reverseArray(final int[] origin) { * @return */ - public int[] removeZero(int[] oldArray) { + public static int[] removeZero(int[] oldArray) { int size = oldArray.length; int countZero = 0; //首先判断数组中0的个数 @@ -43,7 +43,6 @@ public int[] removeZero(int[] oldArray) { for (int i = 0; i < size; i++) { if (oldArray[i] == 0) continue; newArray[cur++] = oldArray[i]; - //cur++; } return newArray; @@ -58,7 +57,7 @@ public int[] removeZero(int[] oldArray) { * @return */ - public int[] merge(int[] array1, int[] array2) { + public static int[] merge(int[] array1, int[] array2) { //判断数组是否为空 int size1 = array1.length; int size2 = array2.length; @@ -97,7 +96,7 @@ public int[] merge(int[] array1, int[] array2) { * @param size * @return */ - public int[] grow(int[] oldArray, int size) { + public static int[] grow(int[] oldArray, int size) { int oldSize = oldArray.length; if (oldSize == 0) return new int[size]; @@ -117,19 +116,25 @@ public int[] grow(int[] oldArray, int size) { * @param max * @return */ - public int[] fibonacci(int max) { + public static int[] fibonacci(int max) { //先确定数组长度 if (max == 1) return new int[]{}; //这里的cur指的是数组的下标,从0开始,而不是数学函数1开始 - int cur = 1; - while (cur * 2 - 1 <= max) { + int cur = 2; + int val_1 = 1; + int val_2 = 1; + while (val_1 + val_2 <= max) { + int temp = val_1; + val_1 = val_2; + val_2 += temp; ++cur; } - int[] newArray = new int[cur + 1]; - for (int i = 0; i <= cur + 1; i++) { + int[] newArray = new int[cur]; + for (int i = 0; i < cur; i++) { if (i == 0 || i == 1) { newArray[i] = 1; + continue; } newArray[i] = newArray[i - 1] + newArray[i - 2]; @@ -144,34 +149,43 @@ public int[] fibonacci(int max) { * @param max * @return */ - public int[] getPrimes(int max) { + public static int[] getPrimes(int max) { //先确定数组长度 //判断质数循环 int count = 0; - for (int i = 1; i <= max; i++) { + for (int i = 1; i < max; i++) { //去掉偶数 if (i == 1 || (i % 2 == 0 && i != 2)) continue; - //判断到开根号即可 + boolean flag = true; for (int j = 3; j <= Math.sqrt(i); j += 2) { if (i % j == 0) { - ++count; + flag = false; break; } } + if (flag) count++; } int[] newArray = new int[count]; int cur = 0; - for (int i = 1; i <= max; i++) { + for (int i = 1; i < max; i++) { //去掉偶数 if (i == 1 || (i % 2 == 0 && i != 2)) continue; //判断到开根号即可 + boolean flag = true; for (int j = 3; j <= Math.sqrt(i); j += 2) { if (i % j == 0) { - newArray[cur] = i; - ++cur; + flag = false; + } } + if (flag) { + newArray[cur] = i; + ++cur; + } + } + + return newArray; } @@ -182,27 +196,26 @@ public int[] getPrimes(int max) { * @param max * @return */ - public int[] getPerfectNumbers(int max) { + public static int[] getPerfectNumbers(int max) { //求数组长度 int count = 0; - for(int a=1;a<=max;a++){ - int sum=0; - for(int i=1;i<=a/2;i++) - if(a%i==0) - sum+=i; - if(a==sum) + for (int a = 1; a <= max; a++) { + int sum = 0; + for (int i = 1; i <= a / 2; i++) + if (a % i == 0) + sum += i; + if (a == sum) ++count; } int[] newArray = new int[count]; int cur = 0; - for(int a=1;a<=max;a++){ - int sum=0; - for(int i=1;i<=a/2;i++) - if(a%i==0) - sum+=i; - if(a==sum) - { + for (int a = 1; a <= max; a++) { + int sum = 0; + for (int i = 1; i <= a / 2; i++) + if (a % i == 0) + sum += i; + if (a == sum) { newArray[cur] = a; ++cur; } @@ -220,7 +233,7 @@ public int[] getPerfectNumbers(int max) { * @param seperator * @return */ - public String join(int[] array, String seperator) { + public static String join(int[] array, String seperator) { int size = array.length; if (size == 0) return ""; StringBuffer sb = new StringBuffer(""); @@ -235,7 +248,7 @@ public String join(int[] array, String seperator) { /** * 类私有函数,复制返回一个新的数组 */ - private int[] copyOf(int[] source) { + private static int[] copyOf(int[] source) { int size = source.length; if (size <= 0) return null; diff --git a/group27/513274874/homework/src/com/coding/coderising/array/ArrayUtilTest.java b/group27/513274874/homework/src/com/coding/coderising/array/ArrayUtilTest.java new file mode 100644 index 0000000000..7f5ca8fdf6 --- /dev/null +++ b/group27/513274874/homework/src/com/coding/coderising/array/ArrayUtilTest.java @@ -0,0 +1,110 @@ +package com.coding.coderising.array; + +import org.junit.After; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +/** + * ArrayUtil Tester. + * + * @author + * @version 1.0 + * @since
三月 14, 2017
+ */ +public class ArrayUtilTest { + + int[] testArray ; + + @Before + public void before() throws Exception { + } + + @After + public void after() throws Exception { + testArray = new int[]{}; + } + + /** + * Method: reverseArray(final int[] origin) + */ + @Test + public void testReverseArray() throws Exception { + testArray = new int[]{1,3,5,7,9,4,6}; + ArrayUtil.reverseArray(testArray); + Assert.assertArrayEquals(new int[]{6,4,9,7,5,3,1},testArray); + } + + + /** + * Method: removeZero(int[] oldArray) + */ + @Test + public void testRemoveZero() throws Exception { + testArray = new int[]{1,3,0,7,0,4,6}; + int[] newArray = ArrayUtil.removeZero(testArray); + Assert.assertArrayEquals(new int[]{1,3,7,4,6}, newArray); + } + + /** + * Method: merge(int[] array1, int[] array2) + */ + @Test + public void testMerge() throws Exception { + int[] testArray1 = new int[]{1,3,6,8,9}; + int[] testArray2 = new int[]{2,3,3,10,12}; + + int[] mergedArray = ArrayUtil.merge(testArray1,testArray2); + Assert.assertArrayEquals(new int[]{1,2,3,3,3,6,8,9,10,12},mergedArray); + } + + /** + * Method: grow(int[] oldArray, int size) + */ + @Test + public void testGrow() throws Exception { + testArray = new int[]{1,2,3,4,5,6}; + int[] grewArray = ArrayUtil.grow(testArray,4); + Assert.assertArrayEquals(new int[]{1,2,3,4,5,6,0,0,0,0},grewArray); + + } + + /** + * Method: fibonacci(int max) + */ + @Test + public void testFibonacci() throws Exception { + int[] fibArray = ArrayUtil.fibonacci(20); + Assert.assertArrayEquals(new int[]{1,1,2,3,5,8,13},fibArray); + } + + /** + * Method: getPrimes(int max) + */ + @Test + public void testGetPrimes() throws Exception { + testArray = ArrayUtil.getPrimes(23); + Assert.assertArrayEquals(new int[]{2,3,5,7,11,13,17,19},testArray); + } + + /** + * Method: getPerfectNumbers(int max) + */ + @Test + public void testGetPerfectNumbers() throws Exception { + testArray = ArrayUtil.getPerfectNumbers(1000); + Assert.assertArrayEquals(new int[]{6,28,496},testArray); + } + + /** + * Method: join(int[] array, String seperator) + */ + @Test + public void testJoin() throws Exception { + testArray = new int[]{1,2,3,5,7,9,12}; + String seperated = ArrayUtil.join(testArray,"-"); + Assert.assertEquals("1-2-3-5-7-9-12",seperated); + } + + +} diff --git a/group27/513274874/homework/src/com/coding/coderising/litestruts/StrutsTest.java b/group27/513274874/homework/src/com/coding/coderising/litestruts/StrutsTest.java index 2cf94955f6..9d876abfa4 100644 --- a/group27/513274874/homework/src/com/coding/coderising/litestruts/StrutsTest.java +++ b/group27/513274874/homework/src/com/coding/coderising/litestruts/StrutsTest.java @@ -1,6 +1,8 @@ package com.coding.coderising.litestruts; +import org.junit.After; import org.junit.Assert; +import org.junit.Before; import org.junit.Test; import java.util.HashMap; @@ -11,8 +13,16 @@ public class StrutsTest { + @Before + public void before() throws Exception { + Struts.init(); + } - @Test + @After + public void after() throws Exception { + } + + @Test public void testLoginActionSuccess() { String actionName = "login"; From fe04f49feb9cc73eb3b580214ad30821f4897fb8 Mon Sep 17 00:00:00 2001 From: GordenChow <513274874@qq.com> Date: Sat, 18 Mar 2017 14:38:58 +0800 Subject: [PATCH 4/5] test MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 测试 --- .../coderising/litestruts/LoginAction.java | 39 --- .../coding/coderising/litestruts/Struts.java | 254 ------------------ .../coderising/litestruts/StrutsTest.java | 53 ---- .../coding/coderising/litestruts/View.java | 23 -- .../coding/coderising/litestruts/struts.xml | 11 - 5 files changed, 380 deletions(-) delete mode 100644 group27/513274874/homework/src/com/coding/coderising/litestruts/LoginAction.java delete mode 100644 group27/513274874/homework/src/com/coding/coderising/litestruts/Struts.java delete mode 100644 group27/513274874/homework/src/com/coding/coderising/litestruts/StrutsTest.java delete mode 100644 group27/513274874/homework/src/com/coding/coderising/litestruts/View.java delete mode 100644 group27/513274874/homework/src/com/coding/coderising/litestruts/struts.xml diff --git a/group27/513274874/homework/src/com/coding/coderising/litestruts/LoginAction.java b/group27/513274874/homework/src/com/coding/coderising/litestruts/LoginAction.java deleted file mode 100644 index 689678f3ad..0000000000 --- a/group27/513274874/homework/src/com/coding/coderising/litestruts/LoginAction.java +++ /dev/null @@ -1,39 +0,0 @@ -package com.coding.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/group27/513274874/homework/src/com/coding/coderising/litestruts/Struts.java b/group27/513274874/homework/src/com/coding/coderising/litestruts/Struts.java deleted file mode 100644 index 7aa7dacb4a..0000000000 --- a/group27/513274874/homework/src/com/coding/coderising/litestruts/Struts.java +++ /dev/null @@ -1,254 +0,0 @@ -package com.coding.coderising.litestruts; - -import org.dom4j.Attribute; -import org.dom4j.Document; -import org.dom4j.DocumentException; -import org.dom4j.Element; -import org.dom4j.io.SAXReader; - -import java.beans.IntrospectionException; -import java.beans.PropertyDescriptor; -import java.io.File; -import java.io.FileNotFoundException; -import java.lang.reflect.Field; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Map; - - -public class Struts { - - private static Struts instance = null; - private static Map strutsXml; - - private Struts() { - } - - /** - * 单例模式初始化struts.xml,而不是每次跑runAction的时候都要初始化一次 - * - * @return - */ - public static Struts init() throws FileNotFoundException { - - if (instance == null) { - /** - * 0. 读取配置文件struts.xml - */ - //创建SAXReader对象 - SAXReader reader = new SAXReader(); - //读取文件 转换成Document - Document document = null; - try { - document = reader.read(new File("src/com/coding/coderising/litestruts/struts.xml")); - } catch (DocumentException e) { - e.printStackTrace(); - } - //获取根节点元素对象 - Element root = document.getRootElement(); - if ("struts".equals(root.getName())) { - strutsXml = new HashMap(); - - Iterator actions = root.elementIterator(); - while (actions.hasNext()) { - Element action = actions.next(); - List attrList = action.attributes(); - - String actionName = null; - StrutsXml xml = null; - if (!"action".equals(action.getName())) { - continue; - } - //遍历属性节点 - for (Attribute attribute : attrList) { - xml = new StrutsXml(); - if ("name".equals(attribute.getName())) { - actionName = attribute.getValue(); - } - if ("class".equals(attribute.getName())) { - xml.setClazz(attribute.getValue()); - //获取result信息 - Iterator results = action.elementIterator(); - while (results.hasNext()) { - Element result = results.next(); - List resultList = result.attributes(); - for (Attribute resultAttr : resultList) { - //System.out.println(resultAttr.getValue() + " ,"+result.getText()); - xml.getResult().put(resultAttr.getValue(), result.getText()); - } - } - - } - //System.out.println("属性"+attribute.getName() +":" + attribute.getValue()); - } - - strutsXml.put(actionName, xml); - } - } else { - throw new FileNotFoundException("not a struts XML file !"); - } - - - instance = new Struts(); - } - return instance; - } - - public static View runAction(String actionName, Map parameters) { - - if (instance == null) return null; - if (actionName == null || "".equals(actionName.trim())) return null; - View view = new View(); - StrutsXml struts = strutsXml.get(actionName); - - Class clazz = null; - /** - * 1. 根据actionName找到相对应的class , 例如LoginAction, 通过反射实例化(创建对象) - * 据parameters中的数据,调用对象的setter方法, 例如parameters中的数据是 - * ("name"="test" , "password"="1234") ,那就应该调用 setName和setPassword方法 - */ - //获取相应处理的action - if (struts != null) { - String className = struts.getClazz(); - try { - clazz = Class.forName(className); - } catch (ClassNotFoundException e) { - e.printStackTrace(); - } - } else { - throw new NullPointerException("action not found in struts file !"); - } - - if (clazz != null) { - Object action = null; - try { - action = clazz.newInstance(); - - //反射调用设置参数 - for (Map.Entry entry : parameters.entrySet()) { - String para = entry.getKey(); - if (!checkField(clazz, para)) continue; - //根据习惯,类的属性首字母在调用时大写,例如属性名是 age,则类方法为getAge - PropertyDescriptor pd = new PropertyDescriptor(para, clazz); - - Method setMethod = pd.getWriteMethod();//获得set方法 - - setMethod.invoke(action, entry.getValue()); - - } - /** - * 2. 通过反射调用对象的exectue 方法, 并获得返回值,例如"success" - */ - //执行execute() - Method excuteMethod = clazz.getDeclaredMethod("execute"); - String result = (String) excuteMethod.invoke(action); - //通过xml文件获取返回值 - String jsp = struts.getResult().get(result); - - if (jsp == null || jsp.trim().equals("")) { - throw new NullPointerException("the requested file is not found !"); - } - /** - * 3. 通过反射找到对象的所有getter方法(例如 getMessage), - * 通过反射来调用, 把值和属性形成一个HashMap , 例如 {"message": "登录成功"} , - * 放到View对象的parameters - */ - //执行get方法 - Map viewMap = new HashMap<>(); - Field[] fields = clazz.getDeclaredFields();//获得属性 - - for (Field field : fields) { - String getMethodName = "get" + field.getName().substring(0, 1).toUpperCase() + field.getName().substring(1); - Method getMethod = clazz.getDeclaredMethod(getMethodName); - String returnVal = (String) getMethod.invoke(action); - viewMap.put(field.getName(), returnVal); - } - /** - * 4. 根据struts.xml中的 配置,以及execute的返回值, 确定哪一个jsp, - * 放到View对象的jsp字段中。 - */ - view.setJsp(jsp); - view.setParameters(viewMap); - - } catch (IntrospectionException e) { - e.printStackTrace(); - } catch (InvocationTargetException e) { - e.printStackTrace(); - } catch (NoSuchMethodException e) { - e.printStackTrace(); - } catch (IllegalAccessException e) { - e.printStackTrace(); - } catch (InstantiationException e) { - e.printStackTrace(); - } - } - - return view; - - - } - - private static boolean checkField(Class clazz, String fieldName) { - if (fieldName == null || fieldName.trim().equals("")) return false; - Field[] fields = clazz.getDeclaredFields(); - for (Field field : fields) { - if (fieldName.equals(field.getName())) return true; - } - return false; - } - - - public static void main(String args[]) { - try { - Struts.init(); - } catch (FileNotFoundException e) { - e.printStackTrace(); - } - Map paras = new HashMap<>(); - paras.put("name", "test"); - paras.put("password", "1234"); - View view = Struts.runAction("login", paras); - } -} - -class StrutsXml { - private String actionName; - private String clazz; - private Map result = new HashMap<>(); - - public StrutsXml(String actionName, String clazz, Map result) { - this.actionName = actionName; - this.clazz = clazz; - this.result = result; - } - - public StrutsXml() { - } - - public String getActionName() { - return actionName; - } - - public void setActionName(String actionName) { - this.actionName = actionName; - } - - public String getClazz() { - return clazz; - } - - public void setClazz(String clazz) { - this.clazz = clazz; - } - - public Map getResult() { - return result; - } - - public void setResult(Map result) { - this.result = result; - } -} \ No newline at end of file diff --git a/group27/513274874/homework/src/com/coding/coderising/litestruts/StrutsTest.java b/group27/513274874/homework/src/com/coding/coderising/litestruts/StrutsTest.java deleted file mode 100644 index 9d876abfa4..0000000000 --- a/group27/513274874/homework/src/com/coding/coderising/litestruts/StrutsTest.java +++ /dev/null @@ -1,53 +0,0 @@ -package com.coding.coderising.litestruts; - -import org.junit.After; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; - -import java.util.HashMap; -import java.util.Map; - - - - - -public class StrutsTest { - @Before - public void before() throws Exception { - Struts.init(); - } - - @After - public void after() throws Exception { - } - - @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/group27/513274874/homework/src/com/coding/coderising/litestruts/View.java b/group27/513274874/homework/src/com/coding/coderising/litestruts/View.java deleted file mode 100644 index ab1297a4a0..0000000000 --- a/group27/513274874/homework/src/com/coding/coderising/litestruts/View.java +++ /dev/null @@ -1,23 +0,0 @@ -package com.coding.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/group27/513274874/homework/src/com/coding/coderising/litestruts/struts.xml b/group27/513274874/homework/src/com/coding/coderising/litestruts/struts.xml deleted file mode 100644 index 92cb2bcb23..0000000000 --- a/group27/513274874/homework/src/com/coding/coderising/litestruts/struts.xml +++ /dev/null @@ -1,11 +0,0 @@ - - - - /jsp/homepage.jsp - /jsp/showLogin.jsp - - - /jsp/welcome.jsp - /jsp/error.jsp - - From 6faa37597531586b8b68fb2695169ce3f6463250 Mon Sep 17 00:00:00 2001 From: GordenChow <513274874@qq.com> Date: Sat, 18 Mar 2017 14:45:34 +0800 Subject: [PATCH 5/5] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E7=AC=AC=E4=BA=8C?= =?UTF-8?q?=E5=91=A8=E4=BD=9C=E4=B8=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 修改第二周作业 --- .../coderising/litestruts/LoginAction.java | 39 +++ .../coding/coderising/litestruts/Struts.java | 254 ++++++++++++++++++ .../coderising/litestruts/StrutsTest.java | 53 ++++ .../coding/coderising/litestruts/View.java | 23 ++ .../coding/coderising/litestruts/struts.xml | 11 + 5 files changed, 380 insertions(+) create mode 100644 group27/513274874/homework/src/com/coding/coderising/litestruts/LoginAction.java create mode 100644 group27/513274874/homework/src/com/coding/coderising/litestruts/Struts.java create mode 100644 group27/513274874/homework/src/com/coding/coderising/litestruts/StrutsTest.java create mode 100644 group27/513274874/homework/src/com/coding/coderising/litestruts/View.java create mode 100644 group27/513274874/homework/src/com/coding/coderising/litestruts/struts.xml diff --git a/group27/513274874/homework/src/com/coding/coderising/litestruts/LoginAction.java b/group27/513274874/homework/src/com/coding/coderising/litestruts/LoginAction.java new file mode 100644 index 0000000000..689678f3ad --- /dev/null +++ b/group27/513274874/homework/src/com/coding/coderising/litestruts/LoginAction.java @@ -0,0 +1,39 @@ +package com.coding.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/group27/513274874/homework/src/com/coding/coderising/litestruts/Struts.java b/group27/513274874/homework/src/com/coding/coderising/litestruts/Struts.java new file mode 100644 index 0000000000..7aa7dacb4a --- /dev/null +++ b/group27/513274874/homework/src/com/coding/coderising/litestruts/Struts.java @@ -0,0 +1,254 @@ +package com.coding.coderising.litestruts; + +import org.dom4j.Attribute; +import org.dom4j.Document; +import org.dom4j.DocumentException; +import org.dom4j.Element; +import org.dom4j.io.SAXReader; + +import java.beans.IntrospectionException; +import java.beans.PropertyDescriptor; +import java.io.File; +import java.io.FileNotFoundException; +import java.lang.reflect.Field; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; + + +public class Struts { + + private static Struts instance = null; + private static Map strutsXml; + + private Struts() { + } + + /** + * 单例模式初始化struts.xml,而不是每次跑runAction的时候都要初始化一次 + * + * @return + */ + public static Struts init() throws FileNotFoundException { + + if (instance == null) { + /** + * 0. 读取配置文件struts.xml + */ + //创建SAXReader对象 + SAXReader reader = new SAXReader(); + //读取文件 转换成Document + Document document = null; + try { + document = reader.read(new File("src/com/coding/coderising/litestruts/struts.xml")); + } catch (DocumentException e) { + e.printStackTrace(); + } + //获取根节点元素对象 + Element root = document.getRootElement(); + if ("struts".equals(root.getName())) { + strutsXml = new HashMap(); + + Iterator actions = root.elementIterator(); + while (actions.hasNext()) { + Element action = actions.next(); + List attrList = action.attributes(); + + String actionName = null; + StrutsXml xml = null; + if (!"action".equals(action.getName())) { + continue; + } + //遍历属性节点 + for (Attribute attribute : attrList) { + xml = new StrutsXml(); + if ("name".equals(attribute.getName())) { + actionName = attribute.getValue(); + } + if ("class".equals(attribute.getName())) { + xml.setClazz(attribute.getValue()); + //获取result信息 + Iterator results = action.elementIterator(); + while (results.hasNext()) { + Element result = results.next(); + List resultList = result.attributes(); + for (Attribute resultAttr : resultList) { + //System.out.println(resultAttr.getValue() + " ,"+result.getText()); + xml.getResult().put(resultAttr.getValue(), result.getText()); + } + } + + } + //System.out.println("属性"+attribute.getName() +":" + attribute.getValue()); + } + + strutsXml.put(actionName, xml); + } + } else { + throw new FileNotFoundException("not a struts XML file !"); + } + + + instance = new Struts(); + } + return instance; + } + + public static View runAction(String actionName, Map parameters) { + + if (instance == null) return null; + if (actionName == null || "".equals(actionName.trim())) return null; + View view = new View(); + StrutsXml struts = strutsXml.get(actionName); + + Class clazz = null; + /** + * 1. 根据actionName找到相对应的class , 例如LoginAction, 通过反射实例化(创建对象) + * 据parameters中的数据,调用对象的setter方法, 例如parameters中的数据是 + * ("name"="test" , "password"="1234") ,那就应该调用 setName和setPassword方法 + */ + //获取相应处理的action + if (struts != null) { + String className = struts.getClazz(); + try { + clazz = Class.forName(className); + } catch (ClassNotFoundException e) { + e.printStackTrace(); + } + } else { + throw new NullPointerException("action not found in struts file !"); + } + + if (clazz != null) { + Object action = null; + try { + action = clazz.newInstance(); + + //反射调用设置参数 + for (Map.Entry entry : parameters.entrySet()) { + String para = entry.getKey(); + if (!checkField(clazz, para)) continue; + //根据习惯,类的属性首字母在调用时大写,例如属性名是 age,则类方法为getAge + PropertyDescriptor pd = new PropertyDescriptor(para, clazz); + + Method setMethod = pd.getWriteMethod();//获得set方法 + + setMethod.invoke(action, entry.getValue()); + + } + /** + * 2. 通过反射调用对象的exectue 方法, 并获得返回值,例如"success" + */ + //执行execute() + Method excuteMethod = clazz.getDeclaredMethod("execute"); + String result = (String) excuteMethod.invoke(action); + //通过xml文件获取返回值 + String jsp = struts.getResult().get(result); + + if (jsp == null || jsp.trim().equals("")) { + throw new NullPointerException("the requested file is not found !"); + } + /** + * 3. 通过反射找到对象的所有getter方法(例如 getMessage), + * 通过反射来调用, 把值和属性形成一个HashMap , 例如 {"message": "登录成功"} , + * 放到View对象的parameters + */ + //执行get方法 + Map viewMap = new HashMap<>(); + Field[] fields = clazz.getDeclaredFields();//获得属性 + + for (Field field : fields) { + String getMethodName = "get" + field.getName().substring(0, 1).toUpperCase() + field.getName().substring(1); + Method getMethod = clazz.getDeclaredMethod(getMethodName); + String returnVal = (String) getMethod.invoke(action); + viewMap.put(field.getName(), returnVal); + } + /** + * 4. 根据struts.xml中的 配置,以及execute的返回值, 确定哪一个jsp, + * 放到View对象的jsp字段中。 + */ + view.setJsp(jsp); + view.setParameters(viewMap); + + } catch (IntrospectionException e) { + e.printStackTrace(); + } catch (InvocationTargetException e) { + e.printStackTrace(); + } catch (NoSuchMethodException e) { + e.printStackTrace(); + } catch (IllegalAccessException e) { + e.printStackTrace(); + } catch (InstantiationException e) { + e.printStackTrace(); + } + } + + return view; + + + } + + private static boolean checkField(Class clazz, String fieldName) { + if (fieldName == null || fieldName.trim().equals("")) return false; + Field[] fields = clazz.getDeclaredFields(); + for (Field field : fields) { + if (fieldName.equals(field.getName())) return true; + } + return false; + } + + + public static void main(String args[]) { + try { + Struts.init(); + } catch (FileNotFoundException e) { + e.printStackTrace(); + } + Map paras = new HashMap<>(); + paras.put("name", "test"); + paras.put("password", "1234"); + View view = Struts.runAction("login", paras); + } +} + +class StrutsXml { + private String actionName; + private String clazz; + private Map result = new HashMap<>(); + + public StrutsXml(String actionName, String clazz, Map result) { + this.actionName = actionName; + this.clazz = clazz; + this.result = result; + } + + public StrutsXml() { + } + + public String getActionName() { + return actionName; + } + + public void setActionName(String actionName) { + this.actionName = actionName; + } + + public String getClazz() { + return clazz; + } + + public void setClazz(String clazz) { + this.clazz = clazz; + } + + public Map getResult() { + return result; + } + + public void setResult(Map result) { + this.result = result; + } +} \ No newline at end of file diff --git a/group27/513274874/homework/src/com/coding/coderising/litestruts/StrutsTest.java b/group27/513274874/homework/src/com/coding/coderising/litestruts/StrutsTest.java new file mode 100644 index 0000000000..9d876abfa4 --- /dev/null +++ b/group27/513274874/homework/src/com/coding/coderising/litestruts/StrutsTest.java @@ -0,0 +1,53 @@ +package com.coding.coderising.litestruts; + +import org.junit.After; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +import java.util.HashMap; +import java.util.Map; + + + + + +public class StrutsTest { + @Before + public void before() throws Exception { + Struts.init(); + } + + @After + public void after() throws Exception { + } + + @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/group27/513274874/homework/src/com/coding/coderising/litestruts/View.java b/group27/513274874/homework/src/com/coding/coderising/litestruts/View.java new file mode 100644 index 0000000000..ab1297a4a0 --- /dev/null +++ b/group27/513274874/homework/src/com/coding/coderising/litestruts/View.java @@ -0,0 +1,23 @@ +package com.coding.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/group27/513274874/homework/src/com/coding/coderising/litestruts/struts.xml b/group27/513274874/homework/src/com/coding/coderising/litestruts/struts.xml new file mode 100644 index 0000000000..92cb2bcb23 --- /dev/null +++ b/group27/513274874/homework/src/com/coding/coderising/litestruts/struts.xml @@ -0,0 +1,11 @@ + + + + /jsp/homepage.jsp + /jsp/showLogin.jsp + + + /jsp/welcome.jsp + /jsp/error.jsp + +