diff --git a/students/992331664/data-structure/data-structure/build.gradle b/students/992331664/data-structure/data-structure/build.gradle deleted file mode 100644 index e8037fb1c4..0000000000 --- a/students/992331664/data-structure/data-structure/build.gradle +++ /dev/null @@ -1,12 +0,0 @@ -apply plugin: 'java' - -repositories { - jcenter() -} - -dependencies { - compile 'org.slf4j:slf4j-api:1.7.21' - compile 'org.apache.poi:poi:3.16' - compile 'org.apache.poi:poi-ooxml:3.16' - testCompile 'junit:junit:4.12' -} diff --git a/students/992331664/data-structure/data-structure/src/main/java/com/coderising/download/DownloadThread.java b/students/992331664/data-structure/data-structure/src/main/java/com/coderising/download/DownloadThread.java deleted file mode 100644 index 900a3ad358..0000000000 --- a/students/992331664/data-structure/data-structure/src/main/java/com/coderising/download/DownloadThread.java +++ /dev/null @@ -1,20 +0,0 @@ -package com.coderising.download; - -import com.coderising.download.api.Connection; - -public class DownloadThread extends Thread{ - - Connection conn; - int startPos; - int endPos; - - public DownloadThread( Connection conn, int startPos, int endPos){ - - this.conn = conn; - this.startPos = startPos; - this.endPos = endPos; - } - public void run(){ - - } -} diff --git a/students/992331664/data-structure/data-structure/src/main/java/com/coderising/download/FileDownloader.java b/students/992331664/data-structure/data-structure/src/main/java/com/coderising/download/FileDownloader.java deleted file mode 100644 index c3c8a3f27d..0000000000 --- a/students/992331664/data-structure/data-structure/src/main/java/com/coderising/download/FileDownloader.java +++ /dev/null @@ -1,73 +0,0 @@ -package com.coderising.download; - -import com.coderising.download.api.Connection; -import com.coderising.download.api.ConnectionException; -import com.coderising.download.api.ConnectionManager; -import com.coderising.download.api.DownloadListener; - - -public class FileDownloader { - - String url; - - DownloadListener listener; - - ConnectionManager cm; - - - public FileDownloader(String _url) { - this.url = _url; - - } - - public void execute(){ - // 在这里实现你的代码, 注意: 需要用多线程实现下载 - // 这个类依赖于其他几个接口, 你需要写这几个接口的实现代码 - // (1) ConnectionManager , 可以打开一个连接,通过Connection可以读取其中的一段(用startPos, endPos来指定) - // (2) DownloadListener, 由于是多线程下载, 调用这个类的客户端不知道什么时候结束,所以你需要实现当所有 - // 线程都执行完以后, 调用listener的notifiedFinished方法, 这样客户端就能收到通知。 - // 具体的实现思路: - // 1. 需要调用ConnectionManager的open方法打开连接, 然后通过Connection.getContentLength方法获得文件的长度 - // 2. 至少启动3个线程下载, 注意每个线程需要先调用ConnectionManager的open方法 - // 然后调用read方法, read方法中有读取文件的开始位置和结束位置的参数, 返回值是byte[]数组 - // 3. 把byte数组写入到文件中 - // 4. 所有的线程都下载完成以后, 需要调用listener的notifiedFinished方法 - - // 下面的代码是示例代码, 也就是说只有一个线程, 你需要改造成多线程的。 - Connection conn = null; - try { - - conn = cm.open(this.url); - - int length = conn.getContentLength(); - - new DownloadThread(conn,0,length-1).start(); - - } catch (ConnectionException e) { - e.printStackTrace(); - }finally{ - if(conn != null){ - conn.close(); - } - } - - - - - } - - public void setListener(DownloadListener listener) { - this.listener = listener; - } - - - - public void setConnectionManager(ConnectionManager ucm){ - this.cm = ucm; - } - - public DownloadListener getListener(){ - return this.listener; - } - -} diff --git a/students/992331664/data-structure/data-structure/src/main/java/com/coderising/download/FileDownloaderTest.java b/students/992331664/data-structure/data-structure/src/main/java/com/coderising/download/FileDownloaderTest.java deleted file mode 100644 index 4ff7f46ae0..0000000000 --- a/students/992331664/data-structure/data-structure/src/main/java/com/coderising/download/FileDownloaderTest.java +++ /dev/null @@ -1,59 +0,0 @@ -package com.coderising.download; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import com.coderising.download.api.ConnectionManager; -import com.coderising.download.api.DownloadListener; -import com.coderising.download.impl.ConnectionManagerImpl; - -public class FileDownloaderTest { - boolean downloadFinished = false; - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void testDownload() { - - String url = "http://localhost:8080/test.jpg"; - - FileDownloader downloader = new FileDownloader(url); - - - ConnectionManager cm = new ConnectionManagerImpl(); - downloader.setConnectionManager(cm); - - downloader.setListener(new DownloadListener() { - @Override - public void notifyFinished() { - downloadFinished = true; - } - - }); - - - downloader.execute(); - - // 等待多线程下载程序执行完毕 - while (!downloadFinished) { - try { - System.out.println("还没有下载完成,休眠五秒"); - //休眠5秒 - Thread.sleep(5000); - } catch (InterruptedException e) { - e.printStackTrace(); - } - } - System.out.println("下载完成!"); - - - - } - -} diff --git a/students/992331664/data-structure/data-structure/src/main/java/com/coderising/download/api/Connection.java b/students/992331664/data-structure/data-structure/src/main/java/com/coderising/download/api/Connection.java deleted file mode 100644 index 0957eaf7f4..0000000000 --- a/students/992331664/data-structure/data-structure/src/main/java/com/coderising/download/api/Connection.java +++ /dev/null @@ -1,23 +0,0 @@ -package com.coderising.download.api; - -import java.io.IOException; - -public interface Connection { - /** - * 给定开始和结束位置, 读取数据, 返回值是字节数组 - * @param startPos 开始位置, 从0开始 - * @param endPos 结束位置 - * @return - */ - public byte[] read(int startPos,int endPos) throws IOException; - /** - * 得到数据内容的长度 - * @return - */ - public int getContentLength(); - - /** - * 关闭连接 - */ - public void close(); -} diff --git a/students/992331664/data-structure/data-structure/src/main/java/com/coderising/download/api/ConnectionException.java b/students/992331664/data-structure/data-structure/src/main/java/com/coderising/download/api/ConnectionException.java deleted file mode 100644 index 1551a80b3d..0000000000 --- a/students/992331664/data-structure/data-structure/src/main/java/com/coderising/download/api/ConnectionException.java +++ /dev/null @@ -1,5 +0,0 @@ -package com.coderising.download.api; - -public class ConnectionException extends Exception { - -} diff --git a/students/992331664/data-structure/data-structure/src/main/java/com/coderising/download/api/ConnectionManager.java b/students/992331664/data-structure/data-structure/src/main/java/com/coderising/download/api/ConnectionManager.java deleted file mode 100644 index ce045393b1..0000000000 --- a/students/992331664/data-structure/data-structure/src/main/java/com/coderising/download/api/ConnectionManager.java +++ /dev/null @@ -1,10 +0,0 @@ -package com.coderising.download.api; - -public interface ConnectionManager { - /** - * 给定一个url , 打开一个连接 - * @param url - * @return - */ - public Connection open(String url) throws ConnectionException; -} diff --git a/students/992331664/data-structure/data-structure/src/main/java/com/coderising/download/api/DownloadListener.java b/students/992331664/data-structure/data-structure/src/main/java/com/coderising/download/api/DownloadListener.java deleted file mode 100644 index bf9807b307..0000000000 --- a/students/992331664/data-structure/data-structure/src/main/java/com/coderising/download/api/DownloadListener.java +++ /dev/null @@ -1,5 +0,0 @@ -package com.coderising.download.api; - -public interface DownloadListener { - public void notifyFinished(); -} diff --git a/students/992331664/data-structure/data-structure/src/main/java/com/coderising/download/impl/ConnectionImpl.java b/students/992331664/data-structure/data-structure/src/main/java/com/coderising/download/impl/ConnectionImpl.java deleted file mode 100644 index 36a9d2ce15..0000000000 --- a/students/992331664/data-structure/data-structure/src/main/java/com/coderising/download/impl/ConnectionImpl.java +++ /dev/null @@ -1,27 +0,0 @@ -package com.coderising.download.impl; - -import java.io.IOException; - -import com.coderising.download.api.Connection; - -public class ConnectionImpl implements Connection{ - - @Override - public byte[] read(int startPos, int endPos) throws IOException { - - return null; - } - - @Override - public int getContentLength() { - - return 0; - } - - @Override - public void close() { - - - } - -} diff --git a/students/992331664/data-structure/data-structure/src/main/java/com/coderising/download/impl/ConnectionManagerImpl.java b/students/992331664/data-structure/data-structure/src/main/java/com/coderising/download/impl/ConnectionManagerImpl.java deleted file mode 100644 index 172371dd55..0000000000 --- a/students/992331664/data-structure/data-structure/src/main/java/com/coderising/download/impl/ConnectionManagerImpl.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.coderising.download.impl; - -import com.coderising.download.api.Connection; -import com.coderising.download.api.ConnectionException; -import com.coderising.download.api.ConnectionManager; - -public class ConnectionManagerImpl implements ConnectionManager { - - @Override - public Connection open(String url) throws ConnectionException { - - return null; - } - -} diff --git a/students/992331664/data-structure/data-structure/src/main/java/com/coderising/litestruts/LoginAction.java b/students/992331664/data-structure/data-structure/src/main/java/com/coderising/litestruts/LoginAction.java deleted file mode 100644 index dcdbe226ed..0000000000 --- a/students/992331664/data-structure/data-structure/src/main/java/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/students/992331664/data-structure/data-structure/src/main/java/com/coderising/litestruts/Struts.java b/students/992331664/data-structure/data-structure/src/main/java/com/coderising/litestruts/Struts.java deleted file mode 100644 index 85e2e22de3..0000000000 --- a/students/992331664/data-structure/data-structure/src/main/java/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/students/992331664/data-structure/data-structure/src/main/java/com/coderising/litestruts/StrutsTest.java b/students/992331664/data-structure/data-structure/src/main/java/com/coderising/litestruts/StrutsTest.java deleted file mode 100644 index b8c81faf3c..0000000000 --- a/students/992331664/data-structure/data-structure/src/main/java/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/students/992331664/data-structure/data-structure/src/main/java/com/coderising/litestruts/View.java b/students/992331664/data-structure/data-structure/src/main/java/com/coderising/litestruts/View.java deleted file mode 100644 index 07df2a5dab..0000000000 --- a/students/992331664/data-structure/data-structure/src/main/java/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/students/992331664/data-structure/data-structure/src/main/java/com/coderising/litestruts/struts.xml b/students/992331664/data-structure/data-structure/src/main/java/com/coderising/litestruts/struts.xml deleted file mode 100644 index e5d9aebba8..0000000000 --- a/students/992331664/data-structure/data-structure/src/main/java/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/students/992331664/data-structure/data-structure/src/main/java/com/coderising/ood/course/bad/Course.java b/students/992331664/data-structure/data-structure/src/main/java/com/coderising/ood/course/bad/Course.java deleted file mode 100644 index 436d092f58..0000000000 --- a/students/992331664/data-structure/data-structure/src/main/java/com/coderising/ood/course/bad/Course.java +++ /dev/null @@ -1,24 +0,0 @@ -package com.coderising.ood.course.bad; - -import java.util.List; - -public class Course { - private String id; - private String desc; - private int duration ; - - List prerequisites; - - public List getPrerequisites() { - return prerequisites; - } - - - public boolean equals(Object o){ - if(o == null || !(o instanceof Course)){ - return false; - } - Course c = (Course)o; - return (c != null) && c.id.equals(id); - } -} diff --git a/students/992331664/data-structure/data-structure/src/main/java/com/coderising/ood/course/bad/CourseOffering.java b/students/992331664/data-structure/data-structure/src/main/java/com/coderising/ood/course/bad/CourseOffering.java deleted file mode 100644 index ab8c764584..0000000000 --- a/students/992331664/data-structure/data-structure/src/main/java/com/coderising/ood/course/bad/CourseOffering.java +++ /dev/null @@ -1,26 +0,0 @@ -package com.coderising.ood.course.bad; - -import java.util.ArrayList; -import java.util.List; - - -public class CourseOffering { - private Course course; - private String location; - private String teacher; - private int maxStudents; - - List students = new ArrayList(); - - public int getMaxStudents() { - return maxStudents; - } - - public List getStudents() { - return students; - } - - public Course getCourse() { - return course; - } -} diff --git a/students/992331664/data-structure/data-structure/src/main/java/com/coderising/ood/course/bad/CourseService.java b/students/992331664/data-structure/data-structure/src/main/java/com/coderising/ood/course/bad/CourseService.java deleted file mode 100644 index 8c34bad0c3..0000000000 --- a/students/992331664/data-structure/data-structure/src/main/java/com/coderising/ood/course/bad/CourseService.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.coderising.ood.course.bad; - - - -public class CourseService { - - public void chooseCourse(Student student, CourseOffering sc){ - //如果学生上过该科目的先修科目,并且该课程还未满, 则学生可以加入该课程 - if(student.getCoursesAlreadyTaken().containsAll( - sc.getCourse().getPrerequisites()) - && sc.getMaxStudents() > sc.getStudents().size()){ - sc.getStudents().add(student); - } - - } -} diff --git a/students/992331664/data-structure/data-structure/src/main/java/com/coderising/ood/course/bad/Student.java b/students/992331664/data-structure/data-structure/src/main/java/com/coderising/ood/course/bad/Student.java deleted file mode 100644 index a651923ef5..0000000000 --- a/students/992331664/data-structure/data-structure/src/main/java/com/coderising/ood/course/bad/Student.java +++ /dev/null @@ -1,14 +0,0 @@ -package com.coderising.ood.course.bad; - -import java.util.ArrayList; -import java.util.List; - -public class Student { - private String id; - private String name; - private List coursesAlreadyTaken = new ArrayList(); - - public List getCoursesAlreadyTaken() { - return coursesAlreadyTaken; - } -} diff --git a/students/992331664/data-structure/data-structure/src/main/java/com/coderising/ood/course/good/Course.java b/students/992331664/data-structure/data-structure/src/main/java/com/coderising/ood/course/good/Course.java deleted file mode 100644 index aefc9692bb..0000000000 --- a/students/992331664/data-structure/data-structure/src/main/java/com/coderising/ood/course/good/Course.java +++ /dev/null @@ -1,18 +0,0 @@ -package com.coderising.ood.course.good; - -import java.util.List; - -public class Course { - private String id; - private String desc; - private int duration ; - - List prerequisites; - - public List getPrerequisites() { - return prerequisites; - } - -} - - diff --git a/students/992331664/data-structure/data-structure/src/main/java/com/coderising/ood/course/good/CourseOffering.java b/students/992331664/data-structure/data-structure/src/main/java/com/coderising/ood/course/good/CourseOffering.java deleted file mode 100644 index 8660ec8109..0000000000 --- a/students/992331664/data-structure/data-structure/src/main/java/com/coderising/ood/course/good/CourseOffering.java +++ /dev/null @@ -1,34 +0,0 @@ -package com.coderising.ood.course.good; - -import java.util.ArrayList; -import java.util.List; - -public class CourseOffering { - private Course course; - private String location; - private String teacher; - private int maxStudents; - - List students = new ArrayList(); - - public List getStudents() { - return students; - } - public int getMaxStudents() { - return maxStudents; - } - public Course getCourse() { - return course; - } - - - // 第二步: 把主要逻辑移动到CourseOffering 中 - public void addStudent(Student student){ - - if(student.canAttend(course) - && this.maxStudents > students.size()){ - students.add(student); - } - } - // 第三步: 重构CourseService -} diff --git a/students/992331664/data-structure/data-structure/src/main/java/com/coderising/ood/course/good/CourseService.java b/students/992331664/data-structure/data-structure/src/main/java/com/coderising/ood/course/good/CourseService.java deleted file mode 100644 index 22ba4a5450..0000000000 --- a/students/992331664/data-structure/data-structure/src/main/java/com/coderising/ood/course/good/CourseService.java +++ /dev/null @@ -1,14 +0,0 @@ -package com.coderising.ood.course.good; - - - -public class CourseService { - - public void chooseCourse(Student student, CourseOffering sc){ - //第一步:重构: canAttend , 但是还有问题 - if(student.canAttend(sc.getCourse()) - && sc.getMaxStudents() > sc.getStudents().size()){ - sc.getStudents().add(student); - } - } -} diff --git a/students/992331664/data-structure/data-structure/src/main/java/com/coderising/ood/course/good/Student.java b/students/992331664/data-structure/data-structure/src/main/java/com/coderising/ood/course/good/Student.java deleted file mode 100644 index 2c7e128b2a..0000000000 --- a/students/992331664/data-structure/data-structure/src/main/java/com/coderising/ood/course/good/Student.java +++ /dev/null @@ -1,21 +0,0 @@ -package com.coderising.ood.course.good; - -import java.util.ArrayList; -import java.util.List; - -public class Student { - private String id; - private String name; - private List coursesAlreadyTaken = new ArrayList(); - - public List getCoursesAlreadyTaken() { - return coursesAlreadyTaken; - } - - public boolean canAttend(Course course){ - return this.coursesAlreadyTaken.containsAll( - course.getPrerequisites()); - } -} - - diff --git a/students/992331664/data-structure/data-structure/src/main/java/com/coderising/ood/ocp/DateUtil.java b/students/992331664/data-structure/data-structure/src/main/java/com/coderising/ood/ocp/DateUtil.java deleted file mode 100644 index b6cf28c096..0000000000 --- a/students/992331664/data-structure/data-structure/src/main/java/com/coderising/ood/ocp/DateUtil.java +++ /dev/null @@ -1,10 +0,0 @@ -package com.coderising.ood.ocp; - -public class DateUtil { - - public static String getCurrentDateAsString() { - - return null; - } - -} diff --git a/students/992331664/data-structure/data-structure/src/main/java/com/coderising/ood/ocp/Logger.java b/students/992331664/data-structure/data-structure/src/main/java/com/coderising/ood/ocp/Logger.java deleted file mode 100644 index 0357c4d912..0000000000 --- a/students/992331664/data-structure/data-structure/src/main/java/com/coderising/ood/ocp/Logger.java +++ /dev/null @@ -1,38 +0,0 @@ -package com.coderising.ood.ocp; - -public class Logger { - - public final int RAW_LOG = 1; - public final int RAW_LOG_WITH_DATE = 2; - public final int EMAIL_LOG = 1; - public final int SMS_LOG = 2; - public final int PRINT_LOG = 3; - - int type = 0; - int method = 0; - - public Logger(int logType, int logMethod){ - this.type = logType; - this.method = logMethod; - } - public void log(String msg){ - - String logMsg = msg; - - if(this.type == RAW_LOG){ - logMsg = msg; - } else if(this.type == RAW_LOG_WITH_DATE){ - String txtDate = DateUtil.getCurrentDateAsString(); - logMsg = txtDate + ": " + msg; - } - - if(this.method == EMAIL_LOG){ - MailUtil.send(logMsg); - } else if(this.method == SMS_LOG){ - SMSUtil.send(logMsg); - } else if(this.method == PRINT_LOG){ - System.out.println(logMsg); - } - } -} - diff --git a/students/992331664/data-structure/data-structure/src/main/java/com/coderising/ood/ocp/MailUtil.java b/students/992331664/data-structure/data-structure/src/main/java/com/coderising/ood/ocp/MailUtil.java deleted file mode 100644 index ec54b839c5..0000000000 --- a/students/992331664/data-structure/data-structure/src/main/java/com/coderising/ood/ocp/MailUtil.java +++ /dev/null @@ -1,10 +0,0 @@ -package com.coderising.ood.ocp; - -public class MailUtil { - - public static void send(String logMsg) { - // TODO Auto-generated method stub - - } - -} diff --git a/students/992331664/data-structure/data-structure/src/main/java/com/coderising/ood/ocp/SMSUtil.java b/students/992331664/data-structure/data-structure/src/main/java/com/coderising/ood/ocp/SMSUtil.java deleted file mode 100644 index 13cf802418..0000000000 --- a/students/992331664/data-structure/data-structure/src/main/java/com/coderising/ood/ocp/SMSUtil.java +++ /dev/null @@ -1,10 +0,0 @@ -package com.coderising.ood.ocp; - -public class SMSUtil { - - public static void send(String logMsg) { - // TODO Auto-generated method stub - - } - -} diff --git a/students/992331664/data-structure/data-structure/src/main/java/com/coderising/ood/srp/Configuration.java b/students/992331664/data-structure/data-structure/src/main/java/com/coderising/ood/srp/Configuration.java deleted file mode 100644 index f328c1816a..0000000000 --- a/students/992331664/data-structure/data-structure/src/main/java/com/coderising/ood/srp/Configuration.java +++ /dev/null @@ -1,23 +0,0 @@ -package com.coderising.ood.srp; -import java.util.HashMap; -import java.util.Map; - -public class Configuration { - - static Map configurations = new HashMap<>(); - static{ - configurations.put(ConfigurationKeys.SMTP_SERVER, "smtp.163.com"); - configurations.put(ConfigurationKeys.ALT_SMTP_SERVER, "smtp1.163.com"); - configurations.put(ConfigurationKeys.EMAIL_ADMIN, "admin@company.com"); - } - /** - * 应该从配置文件读, 但是这里简化为直接从一个map 中去读 - * @param key - * @return - */ - public String getProperty(String key) { - - return configurations.get(key); - } - -} diff --git a/students/992331664/data-structure/data-structure/src/main/java/com/coderising/ood/srp/ConfigurationKeys.java b/students/992331664/data-structure/data-structure/src/main/java/com/coderising/ood/srp/ConfigurationKeys.java deleted file mode 100644 index 8695aed644..0000000000 --- a/students/992331664/data-structure/data-structure/src/main/java/com/coderising/ood/srp/ConfigurationKeys.java +++ /dev/null @@ -1,9 +0,0 @@ -package com.coderising.ood.srp; - -public class ConfigurationKeys { - - public static final String SMTP_SERVER = "smtp.server"; - public static final String ALT_SMTP_SERVER = "alt.smtp.server"; - public static final String EMAIL_ADMIN = "email.admin"; - -} diff --git a/students/992331664/data-structure/data-structure/src/main/java/com/coderising/ood/srp/DBUtil.java b/students/992331664/data-structure/data-structure/src/main/java/com/coderising/ood/srp/DBUtil.java deleted file mode 100644 index 82e9261d18..0000000000 --- a/students/992331664/data-structure/data-structure/src/main/java/com/coderising/ood/srp/DBUtil.java +++ /dev/null @@ -1,25 +0,0 @@ -package com.coderising.ood.srp; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; - -public class DBUtil { - - /** - * 应该从数据库读, 但是简化为直接生成。 - * @param sql - * @return - */ - public static List query(String sql){ - - List userList = new ArrayList(); - for (int i = 1; i <= 3; i++) { - HashMap userInfo = new HashMap(); - userInfo.put("NAME", "User" + i); - userInfo.put("EMAIL", "aa@bb.com"); - userList.add(userInfo); - } - - return userList; - } -} diff --git a/students/992331664/data-structure/data-structure/src/main/java/com/coderising/ood/srp/MailUtil.java b/students/992331664/data-structure/data-structure/src/main/java/com/coderising/ood/srp/MailUtil.java deleted file mode 100644 index 9f9e749af7..0000000000 --- a/students/992331664/data-structure/data-structure/src/main/java/com/coderising/ood/srp/MailUtil.java +++ /dev/null @@ -1,18 +0,0 @@ -package com.coderising.ood.srp; - -public class MailUtil { - - public static void sendEmail(String toAddress, String fromAddress, String subject, String message, String smtpHost, - boolean debug) { - //假装发了一封邮件 - StringBuilder buffer = new StringBuilder(); - buffer.append("From:").append(fromAddress).append("\n"); - buffer.append("To:").append(toAddress).append("\n"); - buffer.append("Subject:").append(subject).append("\n"); - buffer.append("Content:").append(message).append("\n"); - System.out.println(buffer.toString()); - - } - - -} diff --git a/students/992331664/data-structure/data-structure/src/main/java/com/coderising/ood/srp/PromotionMail.java b/students/992331664/data-structure/data-structure/src/main/java/com/coderising/ood/srp/PromotionMail.java deleted file mode 100644 index 781587a846..0000000000 --- a/students/992331664/data-structure/data-structure/src/main/java/com/coderising/ood/srp/PromotionMail.java +++ /dev/null @@ -1,199 +0,0 @@ -package com.coderising.ood.srp; - -import java.io.BufferedReader; -import java.io.File; -import java.io.FileReader; -import java.io.IOException; -import java.io.Serializable; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; - -public class PromotionMail { - - - protected String sendMailQuery = null; - - - protected String smtpHost = null; - protected String altSmtpHost = null; - protected String fromAddress = null; - protected String toAddress = null; - protected String subject = null; - protected String message = null; - - protected String productID = null; - protected String productDesc = null; - - private static Configuration config; - - - - private static final String NAME_KEY = "NAME"; - private static final String EMAIL_KEY = "EMAIL"; - - - public static void main(String[] args) throws Exception { - - File f = new File("C:\\coderising\\workspace_ds\\ood-example\\src\\product_promotion.txt"); - boolean emailDebug = false; - - PromotionMail pe = new PromotionMail(f, emailDebug); - - } - - - public PromotionMail(File file, boolean mailDebug) throws Exception { - - //读取配置文件, 文件中只有一行用空格隔开, 例如 P8756 iPhone8 - readFile(file); - - - config = new Configuration(); - - setSMTPHost(); - setAltSMTPHost(); - - - setFromAddress(); - - - setLoadQuery(); - - sendEMails(mailDebug, loadMailingList()); - - - } - - - - - protected void setProductID(String productID) - { - this.productID = productID; - - } - - protected String getproductID() - { - return productID; - } - - protected void setLoadQuery() throws Exception { - - sendMailQuery = "Select name from subscriptions " - + "where product_id= '" + productID +"' " - + "and send_mail=1 "; - - - System.out.println("loadQuery set"); - } - - - protected void setSMTPHost() - { - smtpHost = config.getProperty(ConfigurationKeys.SMTP_SERVER); - } - - - protected void setAltSMTPHost() - { - altSmtpHost = config.getProperty(ConfigurationKeys.ALT_SMTP_SERVER); - - } - - - protected void setFromAddress() - { - fromAddress = config.getProperty(ConfigurationKeys.EMAIL_ADMIN); - } - - protected void setMessage(HashMap userInfo) throws IOException - { - - String name = (String) userInfo.get(NAME_KEY); - - subject = "您关注的产品降价了"; - message = "尊敬的 "+name+", 您关注的产品 " + productDesc + " 降价了,欢迎购买!" ; - - - - } - - - protected void readFile(File file) throws IOException // @02C - { - BufferedReader br = null; - try { - br = new BufferedReader(new FileReader(file)); - String temp = br.readLine(); - String[] data = temp.split(" "); - - setProductID(data[0]); - setProductDesc(data[1]); - - System.out.println("产品ID = " + productID + "\n"); - System.out.println("产品描述 = " + productDesc + "\n"); - - } catch (IOException e) { - throw new IOException(e.getMessage()); - } finally { - br.close(); - } - } - - private void setProductDesc(String desc) { - this.productDesc = desc; - } - - - protected void configureEMail(HashMap userInfo) throws IOException - { - toAddress = (String) userInfo.get(EMAIL_KEY); - if (toAddress.length() > 0) - setMessage(userInfo); - } - - protected List loadMailingList() throws Exception { - return DBUtil.query(this.sendMailQuery); - } - - - protected void sendEMails(boolean debug, List mailingList) throws IOException - { - - System.out.println("开始发送邮件"); - - - if (mailingList != null) { - Iterator iter = mailingList.iterator(); - while (iter.hasNext()) { - configureEMail((HashMap) iter.next()); - try - { - if (toAddress.length() > 0) - MailUtil.sendEmail(toAddress, fromAddress, subject, message, smtpHost, debug); - } - catch (Exception e) - { - - try { - MailUtil.sendEmail(toAddress, fromAddress, subject, message, altSmtpHost, debug); - - } catch (Exception e2) - { - System.out.println("通过备用 SMTP服务器发送邮件失败: " + e2.getMessage()); - } - } - } - - - } - - else { - System.out.println("没有邮件发送"); - - } - - } -} diff --git a/students/992331664/data-structure/data-structure/src/main/java/com/coderising/ood/srp/product_promotion.txt b/students/992331664/data-structure/data-structure/src/main/java/com/coderising/ood/srp/product_promotion.txt deleted file mode 100644 index a98917f829..0000000000 --- a/students/992331664/data-structure/data-structure/src/main/java/com/coderising/ood/srp/product_promotion.txt +++ /dev/null @@ -1,4 +0,0 @@ -P8756 iPhone8 -P3946 XiaoMi10 -P8904 Oppo R15 -P4955 Vivo X20 \ No newline at end of file diff --git a/students/992331664/data-structure/data-structure/src/main/java/com/coding/basic/Iterator.java b/students/992331664/data-structure/data-structure/src/main/java/com/coding/basic/Iterator.java deleted file mode 100644 index 06ef6311b2..0000000000 --- a/students/992331664/data-structure/data-structure/src/main/java/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/students/992331664/data-structure/data-structure/src/main/java/com/coding/basic/List.java b/students/992331664/data-structure/data-structure/src/main/java/com/coding/basic/List.java deleted file mode 100644 index 10d13b5832..0000000000 --- a/students/992331664/data-structure/data-structure/src/main/java/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/students/992331664/data-structure/data-structure/src/main/java/com/coding/basic/array/ArrayList.java b/students/992331664/data-structure/data-structure/src/main/java/com/coding/basic/array/ArrayList.java deleted file mode 100644 index 4576c016af..0000000000 --- a/students/992331664/data-structure/data-structure/src/main/java/com/coding/basic/array/ArrayList.java +++ /dev/null @@ -1,35 +0,0 @@ -package com.coding.basic.array; - -import com.coding.basic.Iterator; -import com.coding.basic.List; - -public class ArrayList implements List { - - private int size = 0; - - private Object[] elementData = new Object[100]; - - public void add(Object o){ - - } - public void add(int index, Object o){ - - } - - public Object get(int index){ - return null; - } - - public Object remove(int index){ - return null; - } - - public int size(){ - return -1; - } - - public Iterator iterator(){ - return null; - } - -} diff --git a/students/992331664/data-structure/data-structure/src/main/java/com/coding/basic/array/ArrayUtil.java b/students/992331664/data-structure/data-structure/src/main/java/com/coding/basic/array/ArrayUtil.java deleted file mode 100644 index c17e6def49..0000000000 --- a/students/992331664/data-structure/data-structure/src/main/java/com/coding/basic/array/ArrayUtil.java +++ /dev/null @@ -1,159 +0,0 @@ -package com.coding.basic.array; - -import java.util.Arrays; - -import javax.management.RuntimeErrorException; - -public class ArrayUtil { - - /** - * 给定一个整形数组a , 对该数组的值进行置换 例如: a = [7, 9 , 30, 3] , 置换后为 [3, 30, 9,7] 如果 a = - * [7, 9, 30, 3, 4] , 置换后为 [4,3, 30 , 9,7] - * - * @param origin - * @return - */ - public void reverseArray(int[] origin) { - if (origin != null && origin.length > 1) { - for (int i = 0; i < origin.length / 2; i++) { - int temp = origin[i]; - origin[i] = origin[origin.length - 1 - i]; - origin[origin.length - 1 - i] = temp; - } - } - } - - /** - * 现在有如下的一个数组: int oldArr[]={1,3,4,5,0,0,6,6,0,5,4,7,6,7,0,5} - * 要求将以上数组中值为0的项去掉,将不为0的值存入一个新的数组,生成的新数组为: {1,3,4,5,6,6,5,4,7,6,7,5} - * - * @param oldArray - * @return - */ - - public int[] removeZero(int[] oldArray) { - // JDK 1.8 - // int[] newArray = Arrays.stream(oldArray).filter(item->item - // !=0).toArray(); - - int[] newArray = new int[oldArray.length]; - - int zeroCount = 0; - for (int i = 0; i < oldArray.length; i++) { - if (oldArray[i] == 0) { - zeroCount++; - } else { - newArray[i - zeroCount] = oldArray[i]; - } - } - if (zeroCount == 0) { - return Arrays.copyOf(oldArray, oldArray.length); - } else { - return Arrays.copyOf(newArray, oldArray.length - zeroCount); - } - } - - /** - * 给定两个已经排序好的整形数组, a1和a2 , 创建一个新的数组a3, 使得a3 包含a1和a2 的所有元素, 并且仍然是有序的 例如 a1 = - * [3, 5, 7,8] a2 = [4, 5, 6,7] 则 a3 为[3,4,5,6,7,8] , 注意: 已经消除了重复 - * - * @param array1 - * @param array2 - * @return - */ - - public int[] merge(int[] array1, int[] array2) { - return null; - } - - /** - * 把一个已经存满数据的数组 oldArray的容量进行扩展, 扩展后的新数据大小为oldArray.length + size - * 注意,老数组的元素在新数组中需要保持 例如 oldArray = [2,3,6] , size = 3,则返回的新数组为 - * [2,3,6,0,0,0] - * - * @param oldArray - * @param size - * @return - */ - public int[] grow(int[] oldArray, int size) { - if (oldArray.length + size < 0) { - throw new RuntimeErrorException(null, "size + oldArray.length 不能小于0"); - } - int[] newArray = new int[oldArray.length + size]; - - if (size < 0) { - for (int i = 0; i < newArray.length; i++) { - newArray[i] = oldArray[i]; - } - } else { - for (int i = 0; i < oldArray.length; i++) { - newArray[i] = oldArray[i]; - } - } - 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[0]; - } - int a = 1; - int count = 1; - for (int i = 1; i <= max; i += a) { - a += i; - count+=2; - } - - int[] result = new int[count]; - - a = 1; - count = 0; - result[count++] = 1; - - for (int i = 1; i <= max; i += a) { - a += i; - result[count++] = i; - result[count++] = a; - } - return result; - } - - /** - * 返回小于给定最大值max的所有素数数组 例如max = 23, 返回的数组为[2,3,5,7,11,13,17,19] - * - * @param max - * @return - */ - public int[] getPrimes(int max) { - return null; - } - - /** - * 所谓“完数”, 是指这个数恰好等于它的因子之和,例如6=1+2+3 给定一个最大值max, 返回一个数组, 数组中是小于max 的所有完数 - * - * @param max - * @return - */ - public int[] getPerfectNumbers(int max) { - return null; - } - - /** - * 用seperator 把数组 array给连接起来 例如array= [3,8,9], seperator = "-" 则返回值为"3-8-9" - * - * @param array - * @param s - * @return - */ - public String join(int[] array, String seperator) { - return null; - } - -} diff --git a/students/992331664/data-structure/data-structure/src/main/java/com/coding/basic/linklist/LRUPageFrame.java b/students/992331664/data-structure/data-structure/src/main/java/com/coding/basic/linklist/LRUPageFrame.java deleted file mode 100644 index 994a241a3d..0000000000 --- a/students/992331664/data-structure/data-structure/src/main/java/com/coding/basic/linklist/LRUPageFrame.java +++ /dev/null @@ -1,57 +0,0 @@ -package com.coding.basic.linklist; - - -public class LRUPageFrame { - - private static class Node { - - Node prev; - Node next; - int pageNum; - - Node() { - } - } - - private int capacity; - - private int currentSize; - private Node first;// 链表头 - private Node last;// 链表尾 - - - public LRUPageFrame(int capacity) { - this.currentSize = 0; - this.capacity = capacity; - - } - - /** - * 获取缓存中对象 - * - * @param key - * @return - */ - public void access(int pageNum) { - - - } - - - public String toString(){ - StringBuilder buffer = new StringBuilder(); - Node node = first; - while(node != null){ - buffer.append(node.pageNum); - - node = node.next; - if(node != null){ - buffer.append(","); - } - } - return buffer.toString(); - } - - - -} diff --git a/students/992331664/data-structure/data-structure/src/main/java/com/coding/basic/linklist/LRUPageFrameTest.java b/students/992331664/data-structure/data-structure/src/main/java/com/coding/basic/linklist/LRUPageFrameTest.java deleted file mode 100644 index 7fd72fc2b4..0000000000 --- a/students/992331664/data-structure/data-structure/src/main/java/com/coding/basic/linklist/LRUPageFrameTest.java +++ /dev/null @@ -1,34 +0,0 @@ -package com.coding.basic.linklist; - -import org.junit.Assert; - -import org.junit.Test; - - -public class LRUPageFrameTest { - - @Test - public void testAccess() { - LRUPageFrame frame = new LRUPageFrame(3); - frame.access(7); - frame.access(0); - frame.access(1); - Assert.assertEquals("1,0,7", frame.toString()); - frame.access(2); - Assert.assertEquals("2,1,0", frame.toString()); - frame.access(0); - Assert.assertEquals("0,2,1", frame.toString()); - frame.access(0); - Assert.assertEquals("0,2,1", frame.toString()); - frame.access(3); - Assert.assertEquals("3,0,2", frame.toString()); - frame.access(0); - Assert.assertEquals("0,3,2", frame.toString()); - frame.access(4); - Assert.assertEquals("4,0,3", frame.toString()); - frame.access(5); - Assert.assertEquals("5,4,0", frame.toString()); - - } - -} diff --git a/students/992331664/data-structure/data-structure/src/main/java/com/coding/basic/linklist/LinkedList.java b/students/992331664/data-structure/data-structure/src/main/java/com/coding/basic/linklist/LinkedList.java deleted file mode 100644 index f4c7556a2e..0000000000 --- a/students/992331664/data-structure/data-structure/src/main/java/com/coding/basic/linklist/LinkedList.java +++ /dev/null @@ -1,125 +0,0 @@ -package com.coding.basic.linklist; - -import com.coding.basic.Iterator; -import com.coding.basic.List; - -public class LinkedList implements List { - - private Node head; - - public void add(Object o){ - - } - public void add(int index , Object o){ - - } - public Object get(int index){ - return null; - } - public Object remove(int index){ - return null; - } - - public int size(){ - return -1; - } - - public void addFirst(Object o){ - - } - public void addLast(Object o){ - - } - public Object removeFirst(){ - return null; - } - public Object removeLast(){ - return null; - } - public Iterator iterator(){ - return null; - } - - - private static class Node{ - Object data; - Node next; - - } - - /** - * 把该链表逆置 - * 例如链表为 3->7->10 , 逆置后变为 10->7->3 - */ - public void reverse(){ - - } - - /** - * 删除一个单链表的前半部分 - * 例如:list = 2->5->7->8 , 删除以后的值为 7->8 - * 如果list = 2->5->7->8->10 ,删除以后的值为7,8,10 - - */ - public void removeFirstHalf(){ - - } - - /** - * 从第i个元素开始, 删除length 个元素 , 注意i从0开始 - * @param i - * @param length - */ - public void remove(int i, int length){ - - } - /** - * 假定当前链表和listB均包含已升序排列的整数 - * 从当前链表中取出那些listB所指定的元素 - * 例如当前链表 = 11->101->201->301->401->501->601->701 - * listB = 1->3->4->6 - * 返回的结果应该是[101,301,401,601] - * @param list - */ - public int[] getElements(LinkedList list){ - return null; - } - - /** - * 已知链表中的元素以值递增有序排列,并以单链表作存储结构。 - * 从当前链表中中删除在listB中出现的元素 - - * @param list - */ - - public void subtract(LinkedList list){ - - } - - /** - * 已知当前链表中的元素以值递增有序排列,并以单链表作存储结构。 - * 删除表中所有值相同的多余元素(使得操作后的线性表中所有元素的值均不相同) - */ - public void removeDuplicateValues(){ - - } - - /** - * 已知链表中的元素以值递增有序排列,并以单链表作存储结构。 - * 试写一高效的算法,删除表中所有值大于min且小于max的元素(若表中存在这样的元素) - * @param min - * @param max - */ - public void removeRange(int min, int max){ - - } - - /** - * 假设当前链表和参数list指定的链表均以元素依值递增有序排列(同一表中的元素值各不相同) - * 现要求生成新链表C,其元素为当前链表和list中元素的交集,且表C中的元素有依值递增有序排列 - * @param list - */ - public LinkedList intersection( LinkedList list){ - return null; - } -} diff --git a/students/992331664/data-structure/data-structure/src/main/java/com/coding/basic/queue/CircleQueue.java b/students/992331664/data-structure/data-structure/src/main/java/com/coding/basic/queue/CircleQueue.java deleted file mode 100644 index 2e0550c67e..0000000000 --- a/students/992331664/data-structure/data-structure/src/main/java/com/coding/basic/queue/CircleQueue.java +++ /dev/null @@ -1,39 +0,0 @@ -package com.coding.basic.queue; - -/** - * 用数组实现循环队列 - * @author liuxin - * - * @param - */ -public class CircleQueue { - - private final static int DEFAULT_SIZE = 10; - - //用数组来保存循环队列的元素 - private Object[] elementData = new Object[DEFAULT_SIZE] ; - - //队头 - private int front = 0; - //队尾 - private int rear = 0; - - public boolean isEmpty() { - return false; - - } - - public int size() { - return -1; - } - - - - public void enQueue(E data) { - - } - - public E deQueue() { - return null; - } -} diff --git a/students/992331664/data-structure/data-structure/src/main/java/com/coding/basic/queue/Josephus.java b/students/992331664/data-structure/data-structure/src/main/java/com/coding/basic/queue/Josephus.java deleted file mode 100644 index 6a3ea639b9..0000000000 --- a/students/992331664/data-structure/data-structure/src/main/java/com/coding/basic/queue/Josephus.java +++ /dev/null @@ -1,18 +0,0 @@ -package com.coding.basic.queue; - -import java.util.List; - -/** - * 用Queue来实现Josephus问题 - * 在这个古老的问题当中, N个深陷绝境的人一致同意用这种方式减少生存人数: N个人围成一圈(位置记为0到N-1), 并且从第一个人报数, 报到M的人会被杀死, 直到最后一个人留下来 - * 该方法返回一个List, 包含了被杀死人的次序 - * @author liuxin - * - */ -public class Josephus { - - public static List execute(int n, int m){ - return null; - } - -} diff --git a/students/992331664/data-structure/data-structure/src/main/java/com/coding/basic/queue/JosephusTest.java b/students/992331664/data-structure/data-structure/src/main/java/com/coding/basic/queue/JosephusTest.java deleted file mode 100644 index 7d90318b51..0000000000 --- a/students/992331664/data-structure/data-structure/src/main/java/com/coding/basic/queue/JosephusTest.java +++ /dev/null @@ -1,27 +0,0 @@ -package com.coding.basic.queue; - -import org.junit.After; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; - - - -public class JosephusTest { - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void testExecute() { - - Assert.assertEquals("[1, 3, 5, 0, 4, 2, 6]", Josephus.execute(7, 2).toString()); - - } - -} diff --git a/students/992331664/data-structure/data-structure/src/main/java/com/coding/basic/queue/Queue.java b/students/992331664/data-structure/data-structure/src/main/java/com/coding/basic/queue/Queue.java deleted file mode 100644 index c4c4b7325e..0000000000 --- a/students/992331664/data-structure/data-structure/src/main/java/com/coding/basic/queue/Queue.java +++ /dev/null @@ -1,61 +0,0 @@ -package com.coding.basic.queue; - -import java.util.NoSuchElementException; - -public class Queue { - private Node first; - private Node last; - private int size; - - - private static class Node { - private E item; - private Node next; - } - - - public Queue() { - first = null; - last = null; - size = 0; - } - - - public boolean isEmpty() { - return first == null; - } - - public int size() { - return size; - } - - - - public void enQueue(E data) { - Node oldlast = last; - last = new Node(); - last.item = data; - last.next = null; - if (isEmpty()) { - first = last; - } - else{ - oldlast.next = last; - } - size++; - } - - public E deQueue() { - if (isEmpty()) { - throw new NoSuchElementException("Queue underflow"); - } - E item = first.item; - first = first.next; - size--; - if (isEmpty()) { - last = null; - } - return item; - } - -} diff --git a/students/992331664/data-structure/data-structure/src/main/java/com/coding/basic/queue/QueueWithTwoStacks.java b/students/992331664/data-structure/data-structure/src/main/java/com/coding/basic/queue/QueueWithTwoStacks.java deleted file mode 100644 index cef19a8b59..0000000000 --- a/students/992331664/data-structure/data-structure/src/main/java/com/coding/basic/queue/QueueWithTwoStacks.java +++ /dev/null @@ -1,47 +0,0 @@ -package com.coding.basic.queue; - -import java.util.Stack; - -/** - * 用两个栈来实现一个队列 - * @author liuxin - * - * @param - */ -public class QueueWithTwoStacks { - private Stack stack1; - private Stack stack2; - - - public QueueWithTwoStacks() { - stack1 = new Stack(); - stack2 = new Stack(); - } - - - - - public boolean isEmpty() { - return false; - } - - - - public int size() { - return -1; - } - - - - public void enQueue(E item) { - - } - - public E deQueue() { - return null; - } - - - - } - diff --git a/students/992331664/data-structure/data-structure/src/main/java/com/coding/basic/stack/QuickMinStack.java b/students/992331664/data-structure/data-structure/src/main/java/com/coding/basic/stack/QuickMinStack.java deleted file mode 100644 index f391d92b8f..0000000000 --- a/students/992331664/data-structure/data-structure/src/main/java/com/coding/basic/stack/QuickMinStack.java +++ /dev/null @@ -1,19 +0,0 @@ -package com.coding.basic.stack; - -/** - * 设计一个栈,支持栈的push和pop操作,以及第三种操作findMin, 它返回改数据结构中的最小元素 - * finMin操作最坏的情形下时间复杂度应该是O(1) , 简单来讲,操作一次就可以得到最小值 - * @author liuxin - * - */ -public class QuickMinStack { - public void push(int data){ - - } - public int pop(){ - return -1; - } - public int findMin(){ - return -1; - } -} diff --git a/students/992331664/data-structure/data-structure/src/main/java/com/coding/basic/stack/Stack.java b/students/992331664/data-structure/data-structure/src/main/java/com/coding/basic/stack/Stack.java deleted file mode 100644 index fedb243604..0000000000 --- a/students/992331664/data-structure/data-structure/src/main/java/com/coding/basic/stack/Stack.java +++ /dev/null @@ -1,24 +0,0 @@ -package com.coding.basic.stack; - -import com.coding.basic.array.ArrayList; - -public class Stack { - private ArrayList elementData = new ArrayList(); - - public void push(Object o){ - } - - public Object pop(){ - return null; - } - - public Object peek(){ - return null; - } - public boolean isEmpty(){ - return false; - } - public int size(){ - return -1; - } -} diff --git a/students/992331664/data-structure/data-structure/src/main/java/com/coding/basic/stack/StackUtil.java b/students/992331664/data-structure/data-structure/src/main/java/com/coding/basic/stack/StackUtil.java deleted file mode 100644 index b0ec38161d..0000000000 --- a/students/992331664/data-structure/data-structure/src/main/java/com/coding/basic/stack/StackUtil.java +++ /dev/null @@ -1,48 +0,0 @@ -package com.coding.basic.stack; -import java.util.Stack; -public class StackUtil { - - - - /** - * 假设栈中的元素是Integer, 从栈顶到栈底是 : 5,4,3,2,1 调用该方法后, 元素次序变为: 1,2,3,4,5 - * 注意:只能使用Stack的基本操作,即push,pop,peek,isEmpty, 可以使用另外一个栈来辅助 - */ - public static void reverse(Stack s) { - - - - } - - /** - * 删除栈中的某个元素 注意:只能使用Stack的基本操作,即push,pop,peek,isEmpty, 可以使用另外一个栈来辅助 - * - * @param o - */ - public static void remove(Stack s,Object o) { - - } - - /** - * 从栈顶取得len个元素, 原来的栈中元素保持不变 - * 注意:只能使用Stack的基本操作,即push,pop,peek,isEmpty, 可以使用另外一个栈来辅助 - * @param len - * @return - */ - public static Object[] getTop(Stack s,int len) { - return null; - } - /** - * 字符串s 可能包含这些字符: ( ) [ ] { }, a,b,c... x,yz - * 使用堆栈检查字符串s中的括号是不是成对出现的。 - * 例如s = "([e{d}f])" , 则该字符串中的括号是成对出现, 该方法返回true - * 如果 s = "([b{x]y})", 则该字符串中的括号不是成对出现的, 该方法返回false; - * @param s - * @return - */ - public static boolean isValidPairs(String s){ - return false; - } - - -} diff --git a/students/992331664/data-structure/data-structure/src/main/java/com/coding/basic/stack/StackUtilTest.java b/students/992331664/data-structure/data-structure/src/main/java/com/coding/basic/stack/StackUtilTest.java deleted file mode 100644 index 76f2cb7668..0000000000 --- a/students/992331664/data-structure/data-structure/src/main/java/com/coding/basic/stack/StackUtilTest.java +++ /dev/null @@ -1,65 +0,0 @@ -package com.coding.basic.stack; - -import java.util.Stack; - -import org.junit.After; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; -public class StackUtilTest { - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - - @Test - public void testReverse() { - Stack s = new Stack(); - s.push(1); - s.push(2); - s.push(3); - s.push(4); - s.push(5); - Assert.assertEquals("[1, 2, 3, 4, 5]", s.toString()); - StackUtil.reverse(s); - Assert.assertEquals("[5, 4, 3, 2, 1]", s.toString()); - } - - @Test - public void testRemove() { - Stack s = new Stack(); - s.push(1); - s.push(2); - s.push(3); - StackUtil.remove(s, 2); - Assert.assertEquals("[1, 3]", s.toString()); - } - - @Test - public void testGetTop() { - Stack s = new Stack(); - s.push(1); - s.push(2); - s.push(3); - s.push(4); - s.push(5); - { - Object[] values = StackUtil.getTop(s, 3); - Assert.assertEquals(5, values[0]); - Assert.assertEquals(4, values[1]); - Assert.assertEquals(3, values[2]); - } - } - - @Test - public void testIsValidPairs() { - Assert.assertTrue(StackUtil.isValidPairs("([e{d}f])")); - Assert.assertFalse(StackUtil.isValidPairs("([b{x]y})")); - } - -} diff --git a/students/992331664/data-structure/data-structure/src/main/java/com/coding/basic/stack/StackWithTwoQueues.java b/students/992331664/data-structure/data-structure/src/main/java/com/coding/basic/stack/StackWithTwoQueues.java deleted file mode 100644 index d0ab4387d2..0000000000 --- a/students/992331664/data-structure/data-structure/src/main/java/com/coding/basic/stack/StackWithTwoQueues.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.coding.basic.stack; - - -public class StackWithTwoQueues { - - - public void push(int data) { - - } - - public int pop() { - return -1; - } - - -} diff --git a/students/992331664/data-structure/data-structure/src/main/java/com/coding/basic/stack/TwoStackInOneArray.java b/students/992331664/data-structure/data-structure/src/main/java/com/coding/basic/stack/TwoStackInOneArray.java deleted file mode 100644 index e86d056a24..0000000000 --- a/students/992331664/data-structure/data-structure/src/main/java/com/coding/basic/stack/TwoStackInOneArray.java +++ /dev/null @@ -1,57 +0,0 @@ -package com.coding.basic.stack; - -/** - * 用一个数组实现两个栈 - * 将数组的起始位置看作是第一个栈的栈底,将数组的尾部看作第二个栈的栈底,压栈时,栈顶指针分别向中间移动,直到两栈顶指针相遇,则扩容。 - * @author liuxin - * - */ -public class TwoStackInOneArray { - Object[] data = new Object[10]; - - /** - * 向第一个栈中压入元素 - * @param o - */ - public void push1(Object o){ - - } - /** - * 从第一个栈中弹出元素 - * @return - */ - public Object pop1(){ - return null; - } - - /** - * 获取第一个栈的栈顶元素 - * @return - */ - - public Object peek1(){ - return null; - } - /* - * 向第二个栈压入元素 - */ - public void push2(Object o){ - - } - /** - * 从第二个栈弹出元素 - * @return - */ - public Object pop2(){ - return null; - } - /** - * 获取第二个栈的栈顶元素 - * @return - */ - - public Object peek2(){ - return null; - } - -} diff --git a/students/992331664/data-structure/data-structure/src/main/java/com/coding/basic/stack/expr/InfixExpr.java b/students/992331664/data-structure/data-structure/src/main/java/com/coding/basic/stack/expr/InfixExpr.java deleted file mode 100644 index ef85ff007f..0000000000 --- a/students/992331664/data-structure/data-structure/src/main/java/com/coding/basic/stack/expr/InfixExpr.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.coding.basic.stack.expr; - -public class InfixExpr { - String expr = null; - - public InfixExpr(String expr) { - this.expr = expr; - } - - public float evaluate() { - return 0.0f; - } - - -} diff --git a/students/992331664/data-structure/data-structure/src/main/java/com/coding/basic/stack/expr/InfixExprTest.java b/students/992331664/data-structure/data-structure/src/main/java/com/coding/basic/stack/expr/InfixExprTest.java deleted file mode 100644 index 20e34e8852..0000000000 --- a/students/992331664/data-structure/data-structure/src/main/java/com/coding/basic/stack/expr/InfixExprTest.java +++ /dev/null @@ -1,52 +0,0 @@ -package com.coding.basic.stack.expr; - -import org.junit.After; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; - - -public class InfixExprTest { - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void testEvaluate() { - //InfixExpr expr = new InfixExpr("300*20+12*5-20/4"); - { - InfixExpr expr = new InfixExpr("2+3*4+5"); - Assert.assertEquals(19.0, expr.evaluate(), 0.001f); - } - { - InfixExpr expr = new InfixExpr("3*20+12*5-40/2"); - Assert.assertEquals(100.0, expr.evaluate(), 0.001f); - } - - { - InfixExpr expr = new InfixExpr("3*20/2"); - Assert.assertEquals(30, expr.evaluate(), 0.001f); - } - - { - InfixExpr expr = new InfixExpr("20/2*3"); - Assert.assertEquals(30, expr.evaluate(), 0.001f); - } - - { - InfixExpr expr = new InfixExpr("10-30+50"); - Assert.assertEquals(30, expr.evaluate(), 0.001f); - } - { - InfixExpr expr = new InfixExpr("10-2*3+50"); - Assert.assertEquals(54, expr.evaluate(), 0.001f); - } - - } - -} diff --git a/students/992331664/data-structure/data-structure/src/main/java/com/coding/basic/stack/expr/InfixToPostfix.java b/students/992331664/data-structure/data-structure/src/main/java/com/coding/basic/stack/expr/InfixToPostfix.java deleted file mode 100644 index 96a2194a67..0000000000 --- a/students/992331664/data-structure/data-structure/src/main/java/com/coding/basic/stack/expr/InfixToPostfix.java +++ /dev/null @@ -1,14 +0,0 @@ -package com.coding.basic.stack.expr; - -import java.util.List; - -public class InfixToPostfix { - - public static List convert(String expr) { - - return null; - } - - - -} diff --git a/students/992331664/data-structure/data-structure/src/main/java/com/coding/basic/stack/expr/PostfixExpr.java b/students/992331664/data-structure/data-structure/src/main/java/com/coding/basic/stack/expr/PostfixExpr.java deleted file mode 100644 index dcbb18be4b..0000000000 --- a/students/992331664/data-structure/data-structure/src/main/java/com/coding/basic/stack/expr/PostfixExpr.java +++ /dev/null @@ -1,18 +0,0 @@ -package com.coding.basic.stack.expr; - -import java.util.List; -import java.util.Stack; - -public class PostfixExpr { -String expr = null; - - public PostfixExpr(String expr) { - this.expr = expr; - } - - public float evaluate() { - return 0.0f; - } - - -} diff --git a/students/992331664/data-structure/data-structure/src/main/java/com/coding/basic/stack/expr/PostfixExprTest.java b/students/992331664/data-structure/data-structure/src/main/java/com/coding/basic/stack/expr/PostfixExprTest.java deleted file mode 100644 index c0435a2db5..0000000000 --- a/students/992331664/data-structure/data-structure/src/main/java/com/coding/basic/stack/expr/PostfixExprTest.java +++ /dev/null @@ -1,41 +0,0 @@ -package com.coding.basic.stack.expr; - - - -import org.junit.After; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; - - - -public class PostfixExprTest { - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void testEvaluate() { - { - PostfixExpr expr = new PostfixExpr("6 5 2 3 + 8 * + 3 + *"); - Assert.assertEquals(288, expr.evaluate(),0.0f); - } - { - //9+(3-1)*3+10/2 - PostfixExpr expr = new PostfixExpr("9 3 1-3*+ 10 2/+"); - Assert.assertEquals(20, expr.evaluate(),0.0f); - } - - { - //10-2*3+50 - PostfixExpr expr = new PostfixExpr("10 2 3 * - 50 +"); - Assert.assertEquals(54, expr.evaluate(),0.0f); - } - } - -} diff --git a/students/992331664/data-structure/data-structure/src/main/java/com/coding/basic/stack/expr/PrefixExpr.java b/students/992331664/data-structure/data-structure/src/main/java/com/coding/basic/stack/expr/PrefixExpr.java deleted file mode 100644 index 956927e2df..0000000000 --- a/students/992331664/data-structure/data-structure/src/main/java/com/coding/basic/stack/expr/PrefixExpr.java +++ /dev/null @@ -1,18 +0,0 @@ -package com.coding.basic.stack.expr; - -import java.util.List; -import java.util.Stack; - -public class PrefixExpr { - String expr = null; - - public PrefixExpr(String expr) { - this.expr = expr; - } - - public float evaluate() { - return 0.0f; - } - - -} diff --git a/students/992331664/data-structure/data-structure/src/main/java/com/coding/basic/stack/expr/PrefixExprTest.java b/students/992331664/data-structure/data-structure/src/main/java/com/coding/basic/stack/expr/PrefixExprTest.java deleted file mode 100644 index 5cec210e75..0000000000 --- a/students/992331664/data-structure/data-structure/src/main/java/com/coding/basic/stack/expr/PrefixExprTest.java +++ /dev/null @@ -1,45 +0,0 @@ -package com.coding.basic.stack.expr; - -import org.junit.After; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; - - -public class PrefixExprTest { - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void testEvaluate() { - { - // 2*3+4*5 - PrefixExpr expr = new PrefixExpr("+ * 2 3* 4 5"); - Assert.assertEquals(26, expr.evaluate(),0.001f); - } - { - // 4*2 + 6+9*2/3 -8 - PrefixExpr expr = new PrefixExpr("-++6/*2 9 3 * 4 2 8"); - Assert.assertEquals(12, expr.evaluate(),0.001f); - } - { - //(3+4)*5-6 - PrefixExpr expr = new PrefixExpr("- * + 3 4 5 6"); - Assert.assertEquals(29, expr.evaluate(),0.001f); - } - { - //1+((2+3)*4)-5 - PrefixExpr expr = new PrefixExpr("- + 1 * + 2 3 4 5"); - Assert.assertEquals(16, expr.evaluate(),0.001f); - } - - - } - -} diff --git a/students/992331664/data-structure/data-structure/src/main/java/com/coding/basic/stack/expr/Token.java b/students/992331664/data-structure/data-structure/src/main/java/com/coding/basic/stack/expr/Token.java deleted file mode 100644 index 8579743fe9..0000000000 --- a/students/992331664/data-structure/data-structure/src/main/java/com/coding/basic/stack/expr/Token.java +++ /dev/null @@ -1,50 +0,0 @@ -package com.coding.basic.stack.expr; - -import java.util.Arrays; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -class Token { - public static final List OPERATORS = Arrays.asList("+", "-", "*", "/"); - private static final Map priorities = new HashMap<>(); - static { - priorities.put("+", 1); - priorities.put("-", 1); - priorities.put("*", 2); - priorities.put("/", 2); - } - static final int OPERATOR = 1; - static final int NUMBER = 2; - String value; - int type; - public Token(int type, String value){ - this.type = type; - this.value = value; - } - - public boolean isNumber() { - return type == NUMBER; - } - - public boolean isOperator() { - return type == OPERATOR; - } - - public int getIntValue() { - return Integer.valueOf(value).intValue(); - } - public String toString(){ - return value; - } - - public boolean hasHigherPriority(Token t){ - if(!this.isOperator() && !t.isOperator()){ - throw new RuntimeException("numbers can't compare priority"); - } - return priorities.get(this.value) - priorities.get(t.value) > 0; - } - - - -} \ No newline at end of file diff --git a/students/992331664/data-structure/data-structure/src/main/java/com/coding/basic/stack/expr/TokenParser.java b/students/992331664/data-structure/data-structure/src/main/java/com/coding/basic/stack/expr/TokenParser.java deleted file mode 100644 index d3b0f167e1..0000000000 --- a/students/992331664/data-structure/data-structure/src/main/java/com/coding/basic/stack/expr/TokenParser.java +++ /dev/null @@ -1,57 +0,0 @@ -package com.coding.basic.stack.expr; - -import java.util.ArrayList; -import java.util.List; - -public class TokenParser { - - - public List parse(String expr) { - List tokens = new ArrayList<>(); - - int i = 0; - - while (i < expr.length()) { - - char c = expr.charAt(i); - - if (isOperator(c)) { - - Token t = new Token(Token.OPERATOR, String.valueOf(c)); - tokens.add(t); - i++; - - } else if (Character.isDigit(c)) { - - int nextOperatorIndex = indexOfNextOperator(i, expr); - String value = expr.substring(i, nextOperatorIndex); - Token t = new Token(Token.NUMBER, value); - tokens.add(t); - i = nextOperatorIndex; - - } else{ - System.out.println("char :["+c+"] is not number or operator,ignore"); - i++; - } - - } - return tokens; - } - - private int indexOfNextOperator(int i, String expr) { - - while (Character.isDigit(expr.charAt(i))) { - i++; - if (i == expr.length()) { - break; - } - } - return i; - - } - - private boolean isOperator(char c) { - String sc = String.valueOf(c); - return Token.OPERATORS.contains(sc); - } -} diff --git a/students/992331664/data-structure/data-structure/src/main/java/com/coding/basic/stack/expr/TokenParserTest.java b/students/992331664/data-structure/data-structure/src/main/java/com/coding/basic/stack/expr/TokenParserTest.java deleted file mode 100644 index 399d3e857e..0000000000 --- a/students/992331664/data-structure/data-structure/src/main/java/com/coding/basic/stack/expr/TokenParserTest.java +++ /dev/null @@ -1,41 +0,0 @@ -package com.coding.basic.stack.expr; - -import static org.junit.Assert.*; - -import java.util.List; - -import org.junit.After; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; - -public class TokenParserTest { - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void test() { - - TokenParser parser = new TokenParser(); - List tokens = parser.parse("300*20+12*5-20/4"); - - Assert.assertEquals(300, tokens.get(0).getIntValue()); - Assert.assertEquals("*", tokens.get(1).toString()); - Assert.assertEquals(20, tokens.get(2).getIntValue()); - Assert.assertEquals("+", tokens.get(3).toString()); - Assert.assertEquals(12, tokens.get(4).getIntValue()); - Assert.assertEquals("*", tokens.get(5).toString()); - Assert.assertEquals(5, tokens.get(6).getIntValue()); - Assert.assertEquals("-", tokens.get(7).toString()); - Assert.assertEquals(20, tokens.get(8).getIntValue()); - Assert.assertEquals("/", tokens.get(9).toString()); - Assert.assertEquals(4, tokens.get(10).getIntValue()); - } - -} diff --git a/students/992331664/data-structure/data-structure/src/main/java/com/coding/basic/tree/BinarySearchTree.java b/students/992331664/data-structure/data-structure/src/main/java/com/coding/basic/tree/BinarySearchTree.java deleted file mode 100644 index 4536ee7a2b..0000000000 --- a/students/992331664/data-structure/data-structure/src/main/java/com/coding/basic/tree/BinarySearchTree.java +++ /dev/null @@ -1,55 +0,0 @@ -package com.coding.basic.tree; - -import java.util.ArrayList; -import java.util.List; - -import com.coding.basic.queue.Queue; - -public class BinarySearchTree { - - BinaryTreeNode root; - public BinarySearchTree(BinaryTreeNode root){ - this.root = root; - } - public BinaryTreeNode getRoot(){ - return root; - } - public T findMin(){ - return null; - } - public T findMax(){ - return null; - } - public int height() { - return -1; - } - public int size() { - return -1; - } - public void remove(T e){ - - } - public List levelVisit(){ - - return null; - } - public boolean isValid(){ - return false; - } - public T getLowestCommonAncestor(T n1, T n2){ - return null; - - } - /** - * 返回所有满足下列条件的节点的值: n1 <= n <= n2 , n 为 - * 该二叉查找树中的某一节点 - * @param n1 - * @param n2 - * @return - */ - public List getNodesBetween(T n1, T n2){ - return null; - } - -} - diff --git a/students/992331664/data-structure/data-structure/src/main/java/com/coding/basic/tree/BinarySearchTreeTest.java b/students/992331664/data-structure/data-structure/src/main/java/com/coding/basic/tree/BinarySearchTreeTest.java deleted file mode 100644 index 4a53dbe2f1..0000000000 --- a/students/992331664/data-structure/data-structure/src/main/java/com/coding/basic/tree/BinarySearchTreeTest.java +++ /dev/null @@ -1,109 +0,0 @@ -package com.coding.basic.tree; - -import java.util.List; - -import org.junit.After; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; - - - -public class BinarySearchTreeTest { - - BinarySearchTree tree = null; - - @Before - public void setUp() throws Exception { - BinaryTreeNode root = new BinaryTreeNode(6); - root.left = new BinaryTreeNode(2); - root.right = new BinaryTreeNode(8); - root.left.left = new BinaryTreeNode(1); - root.left.right = new BinaryTreeNode(4); - root.left.right.left = new BinaryTreeNode(3); - root.left.right.right = new BinaryTreeNode(5); - tree = new BinarySearchTree(root); - } - - @After - public void tearDown() throws Exception { - tree = null; - } - - @Test - public void testFindMin() { - Assert.assertEquals(1, tree.findMin().intValue()); - - } - - @Test - public void testFindMax() { - Assert.assertEquals(8, tree.findMax().intValue()); - } - - @Test - public void testHeight() { - Assert.assertEquals(4, tree.height()); - } - - @Test - public void testSize() { - Assert.assertEquals(7, tree.size()); - } - - @Test - public void testRemoveLeaf() { - tree.remove(3); - BinaryTreeNode root= tree.getRoot(); - Assert.assertEquals(4, root.left.right.data.intValue()); - - } - @Test - public void testRemoveMiddleNode1() { - tree.remove(4); - BinaryTreeNode root= tree.getRoot(); - Assert.assertEquals(5, root.left.right.data.intValue()); - Assert.assertEquals(3, root.left.right.left.data.intValue()); - } - @Test - public void testRemoveMiddleNode2() { - tree.remove(2); - BinaryTreeNode root= tree.getRoot(); - Assert.assertEquals(3, root.left.data.intValue()); - Assert.assertEquals(4, root.left.right.data.intValue()); - } - - @Test - public void testLevelVisit() { - List values = tree.levelVisit(); - Assert.assertEquals("[6, 2, 8, 1, 4, 3, 5]", values.toString()); - - } - @Test - public void testLCA(){ - Assert.assertEquals(2,tree.getLowestCommonAncestor(1, 5).intValue()); - Assert.assertEquals(2,tree.getLowestCommonAncestor(1, 4).intValue()); - Assert.assertEquals(6,tree.getLowestCommonAncestor(3, 8).intValue()); - } - @Test - public void testIsValid() { - - Assert.assertTrue(tree.isValid()); - - BinaryTreeNode root = new BinaryTreeNode(6); - root.left = new BinaryTreeNode(2); - root.right = new BinaryTreeNode(8); - root.left.left = new BinaryTreeNode(4); - root.left.right = new BinaryTreeNode(1); - root.left.right.left = new BinaryTreeNode(3); - tree = new BinarySearchTree(root); - - Assert.assertFalse(tree.isValid()); - } - @Test - public void testGetNodesBetween(){ - List numbers = this.tree.getNodesBetween(3, 8); - System.out.println(numbers.toString()); - - } -} diff --git a/students/992331664/data-structure/data-structure/src/main/java/com/coding/basic/tree/BinaryTreeNode.java b/students/992331664/data-structure/data-structure/src/main/java/com/coding/basic/tree/BinaryTreeNode.java deleted file mode 100644 index c1421cd398..0000000000 --- a/students/992331664/data-structure/data-structure/src/main/java/com/coding/basic/tree/BinaryTreeNode.java +++ /dev/null @@ -1,35 +0,0 @@ -package com.coding.basic.tree; - -public class BinaryTreeNode { - - public T data; - public BinaryTreeNode left; - public BinaryTreeNode right; - - public BinaryTreeNode(T data){ - this.data=data; - } - 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(Object o){ - return null; - } - -} diff --git a/students/992331664/data-structure/data-structure/src/main/java/com/coding/basic/tree/BinaryTreeUtil.java b/students/992331664/data-structure/data-structure/src/main/java/com/coding/basic/tree/BinaryTreeUtil.java deleted file mode 100644 index b033cbe1d5..0000000000 --- a/students/992331664/data-structure/data-structure/src/main/java/com/coding/basic/tree/BinaryTreeUtil.java +++ /dev/null @@ -1,66 +0,0 @@ -package com.coding.basic.tree; - -import java.util.ArrayList; -import java.util.List; -import java.util.Stack; - -public class BinaryTreeUtil { - /** - * 用递归的方式实现对二叉树的前序遍历, 需要通过BinaryTreeUtilTest测试 - * - * @param root - * @return - */ - public static List preOrderVisit(BinaryTreeNode root) { - List result = new ArrayList(); - - return result; - } - - /** - * 用递归的方式实现对二叉树的中遍历 - * - * @param root - * @return - */ - public static List inOrderVisit(BinaryTreeNode root) { - List result = new ArrayList(); - - return result; - } - - /** - * 用递归的方式实现对二叉树的后遍历 - * - * @param root - * @return - */ - public static List postOrderVisit(BinaryTreeNode root) { - List result = new ArrayList(); - - return result; - } - /** - * 用非递归的方式实现对二叉树的前序遍历 - * @param root - * @return - */ - public static List preOrderWithoutRecursion(BinaryTreeNode root) { - - List result = new ArrayList(); - - return result; - } - /** - * 用非递归的方式实现对二叉树的中序遍历 - * @param root - * @return - */ - public static List inOrderWithoutRecursion(BinaryTreeNode root) { - - List result = new ArrayList(); - - return result; - } - -} diff --git a/students/992331664/data-structure/data-structure/src/main/java/com/coding/basic/tree/BinaryTreeUtilTest.java b/students/992331664/data-structure/data-structure/src/main/java/com/coding/basic/tree/BinaryTreeUtilTest.java deleted file mode 100644 index 41857e137d..0000000000 --- a/students/992331664/data-structure/data-structure/src/main/java/com/coding/basic/tree/BinaryTreeUtilTest.java +++ /dev/null @@ -1,75 +0,0 @@ -package com.coding.basic.tree; - -import java.util.List; - -import org.junit.After; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; - - - -public class BinaryTreeUtilTest { - - BinaryTreeNode root = null; - @Before - public void setUp() throws Exception { - root = new BinaryTreeNode(1); - root.setLeft(new BinaryTreeNode(2)); - root.setRight(new BinaryTreeNode(5)); - root.getLeft().setLeft(new BinaryTreeNode(3)); - root.getLeft().setRight(new BinaryTreeNode(4)); - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void testPreOrderVisit() { - - List result = BinaryTreeUtil.preOrderVisit(root); - Assert.assertEquals("[1, 2, 3, 4, 5]", result.toString()); - - - } - @Test - public void testInOrderVisit() { - - - List result = BinaryTreeUtil.inOrderVisit(root); - Assert.assertEquals("[3, 2, 4, 1, 5]", result.toString()); - - } - - @Test - public void testPostOrderVisit() { - - - List result = BinaryTreeUtil.postOrderVisit(root); - Assert.assertEquals("[3, 4, 2, 5, 1]", result.toString()); - - } - - - @Test - public void testInOrderVisitWithoutRecursion() { - BinaryTreeNode node = root.getLeft().getRight(); - node.setLeft(new BinaryTreeNode(6)); - node.setRight(new BinaryTreeNode(7)); - - List result = BinaryTreeUtil.inOrderWithoutRecursion(root); - Assert.assertEquals("[3, 2, 6, 4, 7, 1, 5]", result.toString()); - - } - @Test - public void testPreOrderVisitWithoutRecursion() { - BinaryTreeNode node = root.getLeft().getRight(); - node.setLeft(new BinaryTreeNode(6)); - node.setRight(new BinaryTreeNode(7)); - - List result = BinaryTreeUtil.preOrderWithoutRecursion(root); - Assert.assertEquals("[1, 2, 3, 4, 6, 7, 5]", result.toString()); - - } -} diff --git a/students/992331664/data-structure/data-structure/src/main/java/com/coding/basic/tree/FileList.java b/students/992331664/data-structure/data-structure/src/main/java/com/coding/basic/tree/FileList.java deleted file mode 100644 index 6e65192e4a..0000000000 --- a/students/992331664/data-structure/data-structure/src/main/java/com/coding/basic/tree/FileList.java +++ /dev/null @@ -1,10 +0,0 @@ -package com.coding.basic.tree; - -import java.io.File; - -public class FileList { - public void list(File f) { - } - - -} diff --git a/students/992331664/data-structure/data-structure/src/test/java/com/coding/basic/array/ArrayUtilTest.java b/students/992331664/data-structure/data-structure/src/test/java/com/coding/basic/array/ArrayUtilTest.java deleted file mode 100644 index 255267ce2c..0000000000 --- a/students/992331664/data-structure/data-structure/src/test/java/com/coding/basic/array/ArrayUtilTest.java +++ /dev/null @@ -1,52 +0,0 @@ -package com.coding.basic.array; - -import java.util.Arrays; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -public class ArrayUtilTest { - - ArrayUtil arrayUtil; - - int[] resultArray ; - - @Before - public void before(){ - arrayUtil = new ArrayUtil(); - } - - @After - public void printArray(){ - System.out.println(Arrays.toString(resultArray)); - } - - @Test - public void testReverseArray(){ - int[] arr = {12,344,5,6,0,4,65,4,}; - arrayUtil.reverseArray(arr); - resultArray = arr; - } - - @Test - public void testRemoveZero(){ - int[] arr = {}; - resultArray = arrayUtil.removeZero(arr); - } - - @Test - public void testMerge(){ - } - - @Test - public void testGrow(){ - int[] arr = {1,6,4,2,0}; - resultArray = arrayUtil.grow(arr, 2); - } - - @Test - public void testFibonacci(){ - resultArray = arrayUtil.fibonacci(15); - } -} diff --git a/students/992331664/knowledge-point/build.gradle b/students/992331664/knowledge-point/build.gradle new file mode 100644 index 0000000000..f9024614dc --- /dev/null +++ b/students/992331664/knowledge-point/build.gradle @@ -0,0 +1,30 @@ +/* + * This build file was auto generated by running the Gradle 'init' task + * by 'gant' at '17-6-25 下午6:29' with Gradle 3.2.1 + * + * This generated file contains a sample Java project to get you started. + * For more details take a look at the Java Quickstart chapter in the Gradle + * user guide available at https://docs.gradle.org/3.2.1/userguide/tutorial_java_projects.html + */ + +// Apply the java plugin to add support for Java +apply plugin: 'java' + +// In this section you declare where to find the dependencies of your project +repositories { + // Use 'jcenter' for resolving your dependencies. + // You can declare any Maven/Ivy/file repository here. + jcenter() +} + +// In this section you declare the dependencies for your production and test code +dependencies { + // The production code uses the SLF4J logging API at compile time + compile 'org.slf4j:slf4j-api:1.7.21' + + // Declare the dependency for your favourite test framework you want to use in your tests. + // TestNG is also supported by the Gradle Test task. Just change the + // testCompile dependency to testCompile 'org.testng:testng:6.8.1' and add + // 'test.useTestNG()' to your build script. + testCompile 'junit:junit:4.12' +} diff --git a/students/992331664/ood/ood/gradle/wrapper/gradle-wrapper.properties b/students/992331664/knowledge-point/gradle/wrapper/gradle-wrapper.properties similarity index 80% rename from students/992331664/ood/ood/gradle/wrapper/gradle-wrapper.properties rename to students/992331664/knowledge-point/gradle/wrapper/gradle-wrapper.properties index 5a2cbbeeab..fc7cf23abf 100644 --- a/students/992331664/ood/ood/gradle/wrapper/gradle-wrapper.properties +++ b/students/992331664/knowledge-point/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Tue Jun 13 11:30:26 CST 2017 +#Sun Jun 25 18:29:16 CST 2017 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-3.0-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-3.2.1-bin.zip diff --git a/students/992331664/data-structure/data-structure/gradlew b/students/992331664/knowledge-point/gradlew similarity index 90% rename from students/992331664/data-structure/data-structure/gradlew rename to students/992331664/knowledge-point/gradlew index 9aa616c273..4453ccea33 100644 --- a/students/992331664/data-structure/data-structure/gradlew +++ b/students/992331664/knowledge-point/gradlew @@ -1,4 +1,4 @@ -#!/usr/bin/env bash +#!/usr/bin/env sh ############################################################################## ## @@ -154,16 +154,19 @@ if $cygwin ; then esac fi -# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules -function splitJvmOpts() { - JVM_OPTS=("$@") +# Escape application args +save ( ) { + for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done + echo " " } -eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS -JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" +APP_ARGS=$(save "$@") + +# Collect all arguments for the java command, following the shell quoting and substitution rules +eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong -if [[ "$(uname)" == "Darwin" ]] && [[ "$HOME" == "$PWD" ]]; then +if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then cd "$(dirname "$0")" fi -exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" +exec "$JAVACMD" "$@" diff --git a/students/992331664/data-structure/data-structure/gradlew.bat b/students/992331664/knowledge-point/gradlew.bat similarity index 100% rename from students/992331664/data-structure/data-structure/gradlew.bat rename to students/992331664/knowledge-point/gradlew.bat diff --git a/students/992331664/data-structure/data-structure/settings.gradle b/students/992331664/knowledge-point/settings.gradle similarity index 72% rename from students/992331664/data-structure/data-structure/settings.gradle rename to students/992331664/knowledge-point/settings.gradle index e5c7e27790..21e9a09806 100644 --- a/students/992331664/data-structure/data-structure/settings.gradle +++ b/students/992331664/knowledge-point/settings.gradle @@ -1,12 +1,12 @@ /* * This settings file was auto generated by the Gradle buildInit task - * by 'gant' at '17-6-13 上午11:30' with Gradle 3.0 + * by 'gant' at '17-6-25 下午6:29' with Gradle 3.2.1 * * The settings file is used to specify which projects to include in your build. * In a single project build this file can be empty or even removed. * * Detailed information about configuring a multi-project build in Gradle can be found - * in the user guide at https://docs.gradle.org/3.0/userguide/multi_project_builds.html + * in the user guide at https://docs.gradle.org/3.2.1/userguide/multi_project_builds.html */ /* @@ -16,4 +16,4 @@ include 'api' include 'services:webservice' */ -rootProject.name = 'data-structure' +rootProject.name = 'knowledge-point' diff --git a/students/992331664/knowledge-point/src/main/java/cas/CASSequence.java b/students/992331664/knowledge-point/src/main/java/cas/CASSequence.java new file mode 100644 index 0000000000..dcff77d9bf --- /dev/null +++ b/students/992331664/knowledge-point/src/main/java/cas/CASSequence.java @@ -0,0 +1,18 @@ +package cas; + +import java.util.concurrent.atomic.AtomicInteger; + +public class CASSequence{ + + private AtomicInteger count = new AtomicInteger(0); + + public int next(){ + while(true){ + int current = count.get(); + int next = current +1; + if(count.compareAndSet(current, next)){ + return next; + } + } + } +} \ No newline at end of file diff --git a/students/992331664/knowledge-point/src/main/java/cas/NoBlockingStack.java b/students/992331664/knowledge-point/src/main/java/cas/NoBlockingStack.java new file mode 100644 index 0000000000..d7be44c69a --- /dev/null +++ b/students/992331664/knowledge-point/src/main/java/cas/NoBlockingStack.java @@ -0,0 +1,34 @@ +package cas; + +import java.util.concurrent.atomic.AtomicReference; + +public class NoBlockingStack { + static class Node { + final E item; + Node next; + public Node(E item) { this.item = item; } + } + + AtomicReference> head = new AtomicReference>(); + + public void push(E item) { + Node newHead = new Node(item); + Node oldHead; + do { + oldHead = head.get(); + newHead.next = oldHead; + } while (!head.compareAndSet(oldHead, newHead)); + } + public E pop() { + Node oldHead; + Node newHead; + do { + oldHead = head.get(); + if (oldHead == null) + return null; + newHead = oldHead.next; + } while (!head.compareAndSet(oldHead,newHead)); + return oldHead.item; + } + +} diff --git a/students/992331664/knowledge-point/src/main/java/cas/Sequence.java b/students/992331664/knowledge-point/src/main/java/cas/Sequence.java new file mode 100644 index 0000000000..688224e251 --- /dev/null +++ b/students/992331664/knowledge-point/src/main/java/cas/Sequence.java @@ -0,0 +1,11 @@ +package cas; + +public class Sequence{ + + private int value; + + public int next(){ + return value ++; + } + +} diff --git a/students/992331664/knowledge-point/src/main/java/threadlocal/Context.java b/students/992331664/knowledge-point/src/main/java/threadlocal/Context.java new file mode 100644 index 0000000000..d84584397b --- /dev/null +++ b/students/992331664/knowledge-point/src/main/java/threadlocal/Context.java @@ -0,0 +1,20 @@ +package threadlocal; +import java.util.HashMap; +import java.util.Map; + +public class Context { + + private static final ThreadLocal txThreadLocal + = new ThreadLocal(); + + public static void setTransactionID(String txID) { + txThreadLocal.set(txID); + + } + + public static String getTransactionId() { + return txThreadLocal.get(); + } + +} + diff --git a/students/992331664/knowledge-point/src/main/java/threadlocal/TransactionManager.java b/students/992331664/knowledge-point/src/main/java/threadlocal/TransactionManager.java new file mode 100644 index 0000000000..8a5283fcab --- /dev/null +++ b/students/992331664/knowledge-point/src/main/java/threadlocal/TransactionManager.java @@ -0,0 +1,22 @@ +package threadlocal; + +public class TransactionManager { + private static final ThreadLocal context = new ThreadLocal(); + + public static void startTransaction() { + // logic to start a transaction + // ... + String txID = null; + context.set(txID); + } + + public static String getTransactionId() { + return context.get(); + } + + public static void endTransaction() { + // logic to end a transaction + // … + context.remove(); + } +} diff --git a/students/992331664/knowledge-point/src/main/java/threadpool/BlockingQueue.java b/students/992331664/knowledge-point/src/main/java/threadpool/BlockingQueue.java new file mode 100644 index 0000000000..faca2d2c70 --- /dev/null +++ b/students/992331664/knowledge-point/src/main/java/threadpool/BlockingQueue.java @@ -0,0 +1,35 @@ +package threadpool; +import java.util.LinkedList; +import java.util.List; + +public class BlockingQueue { + + private List queue = new LinkedList(); + private int limit = 10; + + public BlockingQueue(int limit) { + this.limit = limit; + } + + public synchronized void enqueue(Object item) throws InterruptedException { + while (this.queue.size() == this.limit) { + wait(); + } + if (this.queue.size() == 0) { + notifyAll(); + } + this.queue.add(item); + } + + public synchronized Object dequeue() throws InterruptedException { + while (this.queue.size() == 0) { + wait(); + } + if (this.queue.size() == this.limit) { + notifyAll(); + } + + return this.queue.remove(0); + } + +} diff --git a/students/992331664/knowledge-point/src/main/java/threadpool/Task.java b/students/992331664/knowledge-point/src/main/java/threadpool/Task.java new file mode 100644 index 0000000000..07413d9798 --- /dev/null +++ b/students/992331664/knowledge-point/src/main/java/threadpool/Task.java @@ -0,0 +1,5 @@ +package threadpool; + +public interface Task { + public void execute(); +} diff --git a/students/992331664/knowledge-point/src/main/java/threadpool/ThreadPool.java b/students/992331664/knowledge-point/src/main/java/threadpool/ThreadPool.java new file mode 100644 index 0000000000..f508f76eb5 --- /dev/null +++ b/students/992331664/knowledge-point/src/main/java/threadpool/ThreadPool.java @@ -0,0 +1,37 @@ +package threadpool; +import java.util.ArrayList; +import java.util.List; + + +public class ThreadPool { + + private BlockingQueue taskQueue = null; + private List threads = new ArrayList(); + private boolean isStopped = false; + + public ThreadPool(int numOfThreads, int maxNumOfTasks){ + taskQueue = new BlockingQueue(maxNumOfTasks); + + for(int i=0; i mails = getMails(subscriptions); // 发送邮箱 - sendEMails(new ConnectionConfig(new Configuration()), mails, mailDebug); + sendEmails(mails); } // 得到发送的邮箱对象 protected List getMails(List subscriptions) { - List mails = new ArrayList(); String subject = "您关注的产品降价了"; for (Subscriptions sub : subscriptions) { String productDesc = sub.getProduct().getProductDesc(); - String message = "尊敬的 " + sub.getName() + ", 您关注的产品 " + productDesc + " 降价了,欢迎购买!"; - mails.add(new MailInfo(subject, message, sub.getEmail())); + User user = sub.getUser(); + String message = "尊敬的 " + user.getName() + ", 您关注的产品 " + productDesc + " 降价了,欢迎购买!"; + mails.add(new MailInfo(subject, message, user.getEmail())); } return mails; } // 发送邮件 - protected void sendEMails(ConnectionConfig config, List mails, boolean debug) { + protected void sendEmails(List mails) { if (mails == null) { System.out.println("没有邮件需要发送"); return; } - System.out.println("开始发送邮件"); - Iterator iter = mails.iterator(); - while (iter.hasNext()) { - MailInfo mail = iter.next(); - if (mail.getToAddress().length() <= 0) { - continue; - } - try { - MailUtil.sendEmail(mail.getToAddress(), config.getFromAddress(), mail.getSubject(), mail.getMessage(),config.getSmtpHost(), debug); - } catch (Exception e) { - try { - MailUtil.sendEmail(mail.getToAddress(), config.getFromAddress(), mail.getSubject(),mail.getMessage(), config.getAltSmtpHost(), debug); - - } catch (Exception e2) { - System.out.println("通过备用 SMTP服务器发送邮件失败: " + e2.getMessage()); - } - } + for (MailInfo mail : mails) { + mailService.sendMail(mail); } System.out.println("发送邮件结束"); } diff --git a/students/992331664/ood/ood/src/main/java/com/coderising/ood/srp/config/Configuration.java b/students/992331664/ood/ood-first/src/main/java/com/coderising/ood/srp/config/Configuration.java similarity index 100% rename from students/992331664/ood/ood/src/main/java/com/coderising/ood/srp/config/Configuration.java rename to students/992331664/ood/ood-first/src/main/java/com/coderising/ood/srp/config/Configuration.java diff --git a/students/992331664/ood/ood/src/main/java/com/coderising/ood/srp/config/ConfigurationKeys.java b/students/992331664/ood/ood-first/src/main/java/com/coderising/ood/srp/config/ConfigurationKeys.java similarity index 100% rename from students/992331664/ood/ood/src/main/java/com/coderising/ood/srp/config/ConfigurationKeys.java rename to students/992331664/ood/ood-first/src/main/java/com/coderising/ood/srp/config/ConfigurationKeys.java diff --git a/students/992331664/ood/ood/src/main/java/com/coderising/ood/srp/model/MailInfo.java b/students/992331664/ood/ood-first/src/main/java/com/coderising/ood/srp/model/MailInfo.java similarity index 100% rename from students/992331664/ood/ood/src/main/java/com/coderising/ood/srp/model/MailInfo.java rename to students/992331664/ood/ood-first/src/main/java/com/coderising/ood/srp/model/MailInfo.java diff --git a/students/992331664/ood/ood/src/main/java/com/coderising/ood/srp/model/Product.java b/students/992331664/ood/ood-first/src/main/java/com/coderising/ood/srp/model/Product.java similarity index 100% rename from students/992331664/ood/ood/src/main/java/com/coderising/ood/srp/model/Product.java rename to students/992331664/ood/ood-first/src/main/java/com/coderising/ood/srp/model/Product.java diff --git a/students/992331664/ood/ood-first/src/main/java/com/coderising/ood/srp/model/Subscriptions.java b/students/992331664/ood/ood-first/src/main/java/com/coderising/ood/srp/model/Subscriptions.java new file mode 100644 index 0000000000..273254e710 --- /dev/null +++ b/students/992331664/ood/ood-first/src/main/java/com/coderising/ood/srp/model/Subscriptions.java @@ -0,0 +1,42 @@ +package com.coderising.ood.srp.model; + +/** + * 订阅信息,主要有订阅产品,订阅用户 + * + */ +public class Subscriptions { + + private User user; + private Product product; + + public Subscriptions() { + super(); + } + + public Subscriptions(User user, Product product) { + super(); + this.user = user; + this.product = product; + } + + public User getUser() { + return user; + } + + public void setUser(User user) { + this.user = user; + } + + public Product getProduct() { + return product; + } + + public void setProduct(Product product) { + this.product = product; + } + + @Override + public String toString() { + return "Subscriptions [user=" + user + ", product=" + product + "]"; + } +} diff --git a/students/992331664/ood/ood-first/src/main/java/com/coderising/ood/srp/model/User.java b/students/992331664/ood/ood-first/src/main/java/com/coderising/ood/srp/model/User.java new file mode 100644 index 0000000000..d0e13e38e6 --- /dev/null +++ b/students/992331664/ood/ood-first/src/main/java/com/coderising/ood/srp/model/User.java @@ -0,0 +1,30 @@ +package com.coderising.ood.srp.model; + +public class User { + private String name; + private String email; + public User() { + super(); + } + public User(String name, String email) { + super(); + this.name = name; + this.email = email; + } + public String getName() { + return name; + } + public void setName(String name) { + this.name = name; + } + public String getEmail() { + return email; + } + public void setEmail(String email) { + this.email = email; + } + @Override + public String toString() { + return "User [name=" + name + ", email=" + email + "]"; + } +} diff --git a/students/992331664/ood/ood/src/main/java/com/coderising/ood/srp/product_promotion.txt b/students/992331664/ood/ood-first/src/main/java/com/coderising/ood/srp/product_promotion.txt similarity index 100% rename from students/992331664/ood/ood/src/main/java/com/coderising/ood/srp/product_promotion.txt rename to students/992331664/ood/ood-first/src/main/java/com/coderising/ood/srp/product_promotion.txt diff --git a/students/992331664/ood/ood-first/src/main/java/com/coderising/ood/srp/service/MailService.java b/students/992331664/ood/ood-first/src/main/java/com/coderising/ood/srp/service/MailService.java new file mode 100644 index 0000000000..b16d6b7397 --- /dev/null +++ b/students/992331664/ood/ood-first/src/main/java/com/coderising/ood/srp/service/MailService.java @@ -0,0 +1,10 @@ +package com.coderising.ood.srp.service; + +import java.util.List; + +import com.coderising.ood.srp.model.MailInfo; + +public interface MailService { + + void sendMail(MailInfo mail); +} diff --git a/students/992331664/ood/ood/src/main/java/com/coderising/ood/srp/service/ProductService.java b/students/992331664/ood/ood-first/src/main/java/com/coderising/ood/srp/service/ProductService.java similarity index 100% rename from students/992331664/ood/ood/src/main/java/com/coderising/ood/srp/service/ProductService.java rename to students/992331664/ood/ood-first/src/main/java/com/coderising/ood/srp/service/ProductService.java diff --git a/students/992331664/ood/ood/src/main/java/com/coderising/ood/srp/service/SubscriptionsService.java b/students/992331664/ood/ood-first/src/main/java/com/coderising/ood/srp/service/SubscriptionsService.java similarity index 100% rename from students/992331664/ood/ood/src/main/java/com/coderising/ood/srp/service/SubscriptionsService.java rename to students/992331664/ood/ood-first/src/main/java/com/coderising/ood/srp/service/SubscriptionsService.java diff --git a/students/992331664/ood/ood-first/src/main/java/com/coderising/ood/srp/service/impl/MailServiceImpl.java b/students/992331664/ood/ood-first/src/main/java/com/coderising/ood/srp/service/impl/MailServiceImpl.java new file mode 100644 index 0000000000..21305cde09 --- /dev/null +++ b/students/992331664/ood/ood-first/src/main/java/com/coderising/ood/srp/service/impl/MailServiceImpl.java @@ -0,0 +1,42 @@ +package com.coderising.ood.srp.service.impl; + +import com.coderising.ood.srp.config.Configuration; +import com.coderising.ood.srp.config.ConfigurationKeys; +import com.coderising.ood.srp.model.MailInfo; +import com.coderising.ood.srp.service.MailService; +import com.coderising.ood.srp.util.MailUtil; + +public class MailServiceImpl implements MailService { + + private String fromAddress; + private String smtpHost; + private String altSmtpHost; + + public MailServiceImpl(Configuration config) { + this.fromAddress = config.getProperty(ConfigurationKeys.EMAIL_ADMIN); + this.smtpHost = config.getProperty(ConfigurationKeys.SMTP_SERVER); + this.altSmtpHost = config.getProperty(ConfigurationKeys.ALT_SMTP_SERVER); + } + + public void sendMail(MailInfo mail) { + try { + sendEmail(mail, this.smtpHost); + } catch (Exception e) { + try { + sendEmail(mail, this.altSmtpHost); + } catch (Exception ex) { + System.out.println("通过备用 SMTP服务器发送邮件失败: " + ex.getMessage()); + } + + } + } + + private void sendEmail(MailInfo mail, String smtpHost) { + String toAddress = mail.getToAddress(); + String subject = mail.getSubject(); + String message = mail.getMessage(); + MailUtil.sendEmail(toAddress, fromAddress, subject, message, smtpHost, false); + // 发送邮件 + } + +} diff --git a/students/992331664/ood/ood/src/main/java/com/coderising/ood/srp/service/impl/ProductServiceImpl.java b/students/992331664/ood/ood-first/src/main/java/com/coderising/ood/srp/service/impl/ProductServiceImpl.java similarity index 100% rename from students/992331664/ood/ood/src/main/java/com/coderising/ood/srp/service/impl/ProductServiceImpl.java rename to students/992331664/ood/ood-first/src/main/java/com/coderising/ood/srp/service/impl/ProductServiceImpl.java diff --git a/students/992331664/ood/ood-first/src/main/java/com/coderising/ood/srp/service/impl/SubscriptionsServiceImpl.java b/students/992331664/ood/ood-first/src/main/java/com/coderising/ood/srp/service/impl/SubscriptionsServiceImpl.java new file mode 100644 index 0000000000..026dd19cc5 --- /dev/null +++ b/students/992331664/ood/ood-first/src/main/java/com/coderising/ood/srp/service/impl/SubscriptionsServiceImpl.java @@ -0,0 +1,27 @@ +package com.coderising.ood.srp.service.impl; + +import java.util.ArrayList; +import java.util.List; + +import com.coderising.ood.srp.model.Product; +import com.coderising.ood.srp.model.Subscriptions; +import com.coderising.ood.srp.model.User; +import com.coderising.ood.srp.service.SubscriptionsService; + +public class SubscriptionsServiceImpl implements SubscriptionsService { + + @Override + public List doFindByProducts(List products) { + + // 这里只是模拟数据 + List subscriptions = new ArrayList(); + for (int i = 0; i < 3; i++) { + Subscriptions ss = new Subscriptions(); + ss.setUser(new User("User" + i, "aa@bb.com")); + ss.setProduct(products.get(i)); + subscriptions.add(ss); + } + return subscriptions; + } + +} diff --git a/students/992331664/ood/ood/src/main/java/com/coderising/ood/srp/util/MailUtil.java b/students/992331664/ood/ood-first/src/main/java/com/coderising/ood/srp/util/MailUtil.java similarity index 100% rename from students/992331664/ood/ood/src/main/java/com/coderising/ood/srp/util/MailUtil.java rename to students/992331664/ood/ood-first/src/main/java/com/coderising/ood/srp/util/MailUtil.java diff --git a/students/992331664/ood/ood/src/test/java/com/coderising/ood/srp/PromotionMailTest.java b/students/992331664/ood/ood-first/src/test/java/com/coderising/ood/srp/PromotionMailTest.java similarity index 100% rename from students/992331664/ood/ood/src/test/java/com/coderising/ood/srp/PromotionMailTest.java rename to students/992331664/ood/ood-first/src/test/java/com/coderising/ood/srp/PromotionMailTest.java diff --git a/students/992331664/ood/ood/src/main/java/com/coderising/ood/srp/config/ConnectionConfig.java b/students/992331664/ood/ood/src/main/java/com/coderising/ood/srp/config/ConnectionConfig.java deleted file mode 100644 index 531efe251d..0000000000 --- a/students/992331664/ood/ood/src/main/java/com/coderising/ood/srp/config/ConnectionConfig.java +++ /dev/null @@ -1,41 +0,0 @@ -package com.coderising.ood.srp.config; - -/** - * 邮箱连接配置类 - * - */ -public class ConnectionConfig { - private String smtpHost; - private String altSmtpHost; - private String fromAddress; - - public ConnectionConfig(Configuration config) { - this.smtpHost = config.getProperty(ConfigurationKeys.SMTP_SERVER); - this.altSmtpHost = config.getProperty(ConfigurationKeys.ALT_SMTP_SERVER); - this.fromAddress = config.getProperty(ConfigurationKeys.EMAIL_ADMIN); - } - - public String getSmtpHost() { - return smtpHost; - } - - public void setSmtpHost(String smtpHost) { - this.smtpHost = smtpHost; - } - - public String getAltSmtpHost() { - return altSmtpHost; - } - - public void setAltSmtpHost(String altSmtpHost) { - this.altSmtpHost = altSmtpHost; - } - - public String getFromAddress() { - return fromAddress; - } - - public void setFromAddress(String fromAddress) { - this.fromAddress = fromAddress; - } -} diff --git a/students/992331664/ood/ood/src/main/java/com/coderising/ood/srp/model/Subscriptions.java b/students/992331664/ood/ood/src/main/java/com/coderising/ood/srp/model/Subscriptions.java deleted file mode 100644 index 8a25fe19ed..0000000000 --- a/students/992331664/ood/ood/src/main/java/com/coderising/ood/srp/model/Subscriptions.java +++ /dev/null @@ -1,53 +0,0 @@ -package com.coderising.ood.srp.model; - -/** - * 订阅信息,主要有订阅产品,订阅用户 - * - */ -public class Subscriptions { - - // name 和 email 应该存放在用户信息中,如叫订阅用户, - private String name; - private String email; - private String productId; - private Product product; - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public String getEmail() { - return email; - } - - public void setEmail(String email) { - this.email = email; - } - - public String getProductId() { - return productId; - } - - public void setProductId(String productId) { - this.productId = productId; - } - - public Product getProduct() { - return product; - } - - public void setProduct(Product product) { - this.product = product; - } - - @Override - public String toString() { - return "Subscriptions [name=" + name + ", email=" + email + ", productId=" + productId + ", product=" + product - + "]"; - } - -} diff --git a/students/992331664/ood/ood/src/main/java/com/coderising/ood/srp/service/impl/SubscriptionsServiceImpl.java b/students/992331664/ood/ood/src/main/java/com/coderising/ood/srp/service/impl/SubscriptionsServiceImpl.java deleted file mode 100644 index 164621e2ea..0000000000 --- a/students/992331664/ood/ood/src/main/java/com/coderising/ood/srp/service/impl/SubscriptionsServiceImpl.java +++ /dev/null @@ -1,40 +0,0 @@ -package com.coderising.ood.srp.service.impl; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.stream.Collectors; - -import com.coderising.ood.srp.model.Product; -import com.coderising.ood.srp.model.Subscriptions; -import com.coderising.ood.srp.service.SubscriptionsService; -import com.coderising.ood.srp.util.DBUtil; - -public class SubscriptionsServiceImpl implements SubscriptionsService { - - private static final String NAME_KEY = "NAME"; - private static final String EMAIL_KEY = "EMAIL"; - - @SuppressWarnings({ "unused", "rawtypes" }) - @Override - public List doFindByProducts(List products) { - - List productIds = products.stream().map(Product::getProductID).collect(Collectors.toList()); - String sendMailQuery = "Select name from subscriptions where product_id in( productIds ) and send_mail = 1 "; - List list = DBUtil.query(sendMailQuery); - - // 这里只是模拟数据 - List subscriptions = new ArrayList(); - for (int i = 0; i < list.size(); i++) { - HashMap userInfo = (HashMap) list.get(i); - Subscriptions ss = new Subscriptions(); - ss.setName((String) userInfo.get(NAME_KEY)); - ss.setEmail((String) userInfo.get(EMAIL_KEY)); - ss.setProduct(products.get(i)); - subscriptions.add(ss); - } - - return subscriptions; - } - -} diff --git a/students/992331664/ood/ood/src/main/java/com/coderising/ood/srp/util/DBUtil.java b/students/992331664/ood/ood/src/main/java/com/coderising/ood/srp/util/DBUtil.java deleted file mode 100644 index 33bb5cfd43..0000000000 --- a/students/992331664/ood/ood/src/main/java/com/coderising/ood/srp/util/DBUtil.java +++ /dev/null @@ -1,28 +0,0 @@ -package com.coderising.ood.srp.util; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; - -public class DBUtil { - - /** - * 应该从数据库读, 但是简化为直接生成。 - * - * @param sql - * @return - */ - @SuppressWarnings({ "rawtypes", "unchecked" }) - public static List query(String sql) { - - List userList = new ArrayList(); - for (int i = 1; i <= 3; i++) { - HashMap userInfo = new HashMap(); - userInfo.put("NAME", "User" + i); - userInfo.put("EMAIL", "aa@bb.com"); - userList.add(userInfo); - } - - return userList; - } -}