From 7441f76e79741b9ea050d76dede1266305615b90 Mon Sep 17 00:00:00 2001
From: onlyLYJ <382266293@qq.com>
Date: Sun, 11 Jun 2017 22:12:13 +0800
Subject: [PATCH 001/436] Merge pull request #6 from onlyliuxin/master
season 2
---
students/382266293/src/pom.xml | 32 ++++
.../com/coderising/ood/srp/Configuration.java | 27 +++
.../coderising/ood/srp/ConfigurationKeys.java | 9 +
.../java/com/coderising/ood/srp/DBUtil.java | 27 +++
.../java/com/coderising/ood/srp/MailUtil.java | 18 ++
.../com/coderising/ood/srp/PromotionMail.java | 172 ++++++++++++++++++
.../coderising/ood/srp/product_promotion.txt | 4 +
students/382266293/src/test.java | 9 +
8 files changed, 298 insertions(+)
create mode 100644 students/382266293/src/pom.xml
create mode 100644 students/382266293/src/src/main/java/com/coderising/ood/srp/Configuration.java
create mode 100644 students/382266293/src/src/main/java/com/coderising/ood/srp/ConfigurationKeys.java
create mode 100644 students/382266293/src/src/main/java/com/coderising/ood/srp/DBUtil.java
create mode 100644 students/382266293/src/src/main/java/com/coderising/ood/srp/MailUtil.java
create mode 100644 students/382266293/src/src/main/java/com/coderising/ood/srp/PromotionMail.java
create mode 100644 students/382266293/src/src/main/java/com/coderising/ood/srp/product_promotion.txt
create mode 100644 students/382266293/src/test.java
diff --git a/students/382266293/src/pom.xml b/students/382266293/src/pom.xml
new file mode 100644
index 0000000000..2bf55e64c9
--- /dev/null
+++ b/students/382266293/src/pom.xml
@@ -0,0 +1,32 @@
+
+ 4.0.0
+
+ com.coderising
+ ood-assignment
+ 0.0.1-SNAPSHOT
+ jar
+
+ ood-assignment
+ http://maven.apache.org
+
+
+ UTF-8
+
+
+
+
+
+ junit
+ junit
+ 4.12
+
+
+
+
+
+ aliyunmaven
+ http://maven.aliyun.com/nexus/content/groups/public/
+
+
+
diff --git a/students/382266293/src/src/main/java/com/coderising/ood/srp/Configuration.java b/students/382266293/src/src/main/java/com/coderising/ood/srp/Configuration.java
new file mode 100644
index 0000000000..db20a8a5d5
--- /dev/null
+++ b/students/382266293/src/src/main/java/com/coderising/ood/srp/Configuration.java
@@ -0,0 +1,27 @@
+package src.main.java.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/382266293/src/src/main/java/com/coderising/ood/srp/ConfigurationKeys.java b/students/382266293/src/src/main/java/com/coderising/ood/srp/ConfigurationKeys.java
new file mode 100644
index 0000000000..4946f09f38
--- /dev/null
+++ b/students/382266293/src/src/main/java/com/coderising/ood/srp/ConfigurationKeys.java
@@ -0,0 +1,9 @@
+package src.main.java.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/382266293/src/src/main/java/com/coderising/ood/srp/DBUtil.java b/students/382266293/src/src/main/java/com/coderising/ood/srp/DBUtil.java
new file mode 100644
index 0000000000..6edf953e19
--- /dev/null
+++ b/students/382266293/src/src/main/java/com/coderising/ood/srp/DBUtil.java
@@ -0,0 +1,27 @@
+package src.main.java.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/382266293/src/src/main/java/com/coderising/ood/srp/MailUtil.java b/students/382266293/src/src/main/java/com/coderising/ood/srp/MailUtil.java
new file mode 100644
index 0000000000..3b6716de70
--- /dev/null
+++ b/students/382266293/src/src/main/java/com/coderising/ood/srp/MailUtil.java
@@ -0,0 +1,18 @@
+package src.main.java.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/382266293/src/src/main/java/com/coderising/ood/srp/PromotionMail.java b/students/382266293/src/src/main/java/com/coderising/ood/srp/PromotionMail.java
new file mode 100644
index 0000000000..e23638c4b2
--- /dev/null
+++ b/students/382266293/src/src/main/java/com/coderising/ood/srp/PromotionMail.java
@@ -0,0 +1,172 @@
+package src.main.java.com.coderising.ood.srp;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileReader;
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+
+public class PromotionMail {
+
+
+ private static final String NAME_KEY = "NAME";
+ private static final String EMAIL_KEY = "EMAIL";
+ private static Configuration config;
+ 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;
+
+
+ public PromotionMail(File file, boolean mailDebug) throws Exception {
+
+ //读取配置文件, 文件中只有一行用空格隔开, 例如 P8756 iPhone8
+ readFile(file);
+
+
+ config = new Configuration();
+
+ setSMTPHost();
+ setAltSMTPHost();
+
+
+ setFromAddress();
+
+
+ setLoadQuery();
+
+ sendEMails(mailDebug, loadMailingList());
+
+
+ }
+
+ public static void main(String[] args) throws Exception {
+
+ File f = new File("E:\\git\\coding2017\\students\\382266293\\src\\src\\main\\java\\com\\coderising\\ood\\srp\\product_promotion.txt");
+ boolean emailDebug = false;
+
+ PromotionMail pe = new PromotionMail(f, emailDebug);
+
+ }
+
+ 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/382266293/src/src/main/java/com/coderising/ood/srp/product_promotion.txt b/students/382266293/src/src/main/java/com/coderising/ood/srp/product_promotion.txt
new file mode 100644
index 0000000000..b7a974adb3
--- /dev/null
+++ b/students/382266293/src/src/main/java/com/coderising/ood/srp/product_promotion.txt
@@ -0,0 +1,4 @@
+P8756 iPhone8
+P3946 XiaoMi10
+P8904 Oppo_R15
+P4955 Vivo_X20
\ No newline at end of file
diff --git a/students/382266293/src/test.java b/students/382266293/src/test.java
new file mode 100644
index 0000000000..56d4d4396e
--- /dev/null
+++ b/students/382266293/src/test.java
@@ -0,0 +1,9 @@
+/**
+ * Created by onlyLYJ on 2017/6/11.
+ */
+
+
+public class test {
+
+
+}
From 883818b1bad21bdb336ddac8dbc7af674cb40b7c Mon Sep 17 00:00:00 2001
From: Wen Wei
Date: Sun, 11 Jun 2017 23:02:32 +0800
Subject: [PATCH 002/436] test
---
students/463256809/src/Demo.java | 6 ++++++
1 file changed, 6 insertions(+)
create mode 100644 students/463256809/src/Demo.java
diff --git a/students/463256809/src/Demo.java b/students/463256809/src/Demo.java
new file mode 100644
index 0000000000..a67375a605
--- /dev/null
+++ b/students/463256809/src/Demo.java
@@ -0,0 +1,6 @@
+
+public class Demo {
+ public static void main(String[] args) {
+ System.out.println("Test");
+ }
+}
From 704865b3cefc5da7e1487acb5a6af8062c43995f Mon Sep 17 00:00:00 2001
From: SYCHS <429301805@qq.com>
Date: Sun, 11 Jun 2017 23:14:59 +0800
Subject: [PATCH 003/436] This is a test
---
students/429301805/src/gz/sychs/cn/test.java | 10 ++++++++++
1 file changed, 10 insertions(+)
create mode 100644 students/429301805/src/gz/sychs/cn/test.java
diff --git a/students/429301805/src/gz/sychs/cn/test.java b/students/429301805/src/gz/sychs/cn/test.java
new file mode 100644
index 0000000000..9fa342b44f
--- /dev/null
+++ b/students/429301805/src/gz/sychs/cn/test.java
@@ -0,0 +1,10 @@
+package gz.sychs.cn;
+
+public class test {
+
+ public static void main(String[] args) {
+ // TODO Auto-generated method stub
+ System.out.println("This is a test");
+ }
+
+}
From 45f8857bffbb3b4256cb1831b74af6df3ed28ea0 Mon Sep 17 00:00:00 2001
From: Lyccccc
Date: Mon, 12 Jun 2017 10:27:09 +0800
Subject: [PATCH 004/436] first commit
---
students/472779948/helloworld.txt | 1 +
1 file changed, 1 insertion(+)
create mode 100644 students/472779948/helloworld.txt
diff --git a/students/472779948/helloworld.txt b/students/472779948/helloworld.txt
new file mode 100644
index 0000000000..fe51499bb2
--- /dev/null
+++ b/students/472779948/helloworld.txt
@@ -0,0 +1 @@
+helloworld!
\ No newline at end of file
From 866444ee2a2c807d7be4024735573b3a0879053c Mon Sep 17 00:00:00 2001
From: nightn
Date: Mon, 12 Jun 2017 10:36:31 +0800
Subject: [PATCH 005/436] first commit
---
students/276137509/276137509Learning/readme.md | 1 +
1 file changed, 1 insertion(+)
create mode 100644 students/276137509/276137509Learning/readme.md
diff --git a/students/276137509/276137509Learning/readme.md b/students/276137509/276137509Learning/readme.md
new file mode 100644
index 0000000000..88093b9187
--- /dev/null
+++ b/students/276137509/276137509Learning/readme.md
@@ -0,0 +1 @@
+### nightn (杭州-莱顿) 的代码仓库
\ No newline at end of file
From 0c42579305e136986ed644c3302e1bcb72ba614c Mon Sep 17 00:00:00 2001
From: nightn
Date: Mon, 12 Jun 2017 10:51:44 +0800
Subject: [PATCH 006/436] update readme.md
---
students/276137509/276137509Learning/readme.md | 2 +-
students/276137509/readme.md | 1 +
2 files changed, 2 insertions(+), 1 deletion(-)
create mode 100644 students/276137509/readme.md
diff --git a/students/276137509/276137509Learning/readme.md b/students/276137509/276137509Learning/readme.md
index 88093b9187..7c847014a2 100644
--- a/students/276137509/276137509Learning/readme.md
+++ b/students/276137509/276137509Learning/readme.md
@@ -1 +1 @@
-### nightn (杭州-莱顿) 的代码仓库
\ No newline at end of file
+### This is my first project just for testing
\ No newline at end of file
diff --git a/students/276137509/readme.md b/students/276137509/readme.md
new file mode 100644
index 0000000000..065efcdbbe
--- /dev/null
+++ b/students/276137509/readme.md
@@ -0,0 +1 @@
+#### Nightn (杭州-莱顿) 代码仓库
\ No newline at end of file
From 0e40448f7e46700db6f500d8b4a3ed80380daf4c Mon Sep 17 00:00:00 2001
From: maneng
Date: Mon, 12 Jun 2017 11:58:00 +0800
Subject: [PATCH 007/436] first pull request
---
students/643449856/readme.md | 1 +
1 file changed, 1 insertion(+)
create mode 100644 students/643449856/readme.md
diff --git a/students/643449856/readme.md b/students/643449856/readme.md
new file mode 100644
index 0000000000..b8e87ead7c
--- /dev/null
+++ b/students/643449856/readme.md
@@ -0,0 +1 @@
+first pull request
\ No newline at end of file
From fd03bd64cdf5db36ba0b104c978ebdbe4a5367c4 Mon Sep 17 00:00:00 2001
From: tjc <501917623@qq.com>
Date: Mon, 12 Jun 2017 12:05:47 +0800
Subject: [PATCH 008/436] =?UTF-8?q?=E6=B5=8B=E8=AF=95git?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
students/501917623/src/work/Test/Test.java | 10 ++++++++++
1 file changed, 10 insertions(+)
create mode 100644 students/501917623/src/work/Test/Test.java
diff --git a/students/501917623/src/work/Test/Test.java b/students/501917623/src/work/Test/Test.java
new file mode 100644
index 0000000000..3da24e1f28
--- /dev/null
+++ b/students/501917623/src/work/Test/Test.java
@@ -0,0 +1,10 @@
+package work.Test;
+
+public class Test {
+
+ public static void main(String[] args) {
+ // TODO Auto-generated method stub
+ System.out.println("hello world");
+ }
+
+}
From 87119062e0aa3f88c40d447fa40a4f5fcdf33437 Mon Sep 17 00:00:00 2001
From: maneng
Date: Mon, 12 Jun 2017 12:08:15 +0800
Subject: [PATCH 009/436] =?UTF-8?q?=E5=88=9D=E5=A7=8B=E5=8C=96=E9=A1=B9?=
=?UTF-8?q?=E7=9B=AE?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
students/643449856/ood-assignment/pom.xml | 32 +++
.../com/coderising/ood/srp/Configuration.java | 23 ++
.../coderising/ood/srp/ConfigurationKeys.java | 9 +
.../java/com/coderising/ood/srp/DBUtil.java | 25 +++
.../java/com/coderising/ood/srp/MailUtil.java | 18 ++
.../com/coderising/ood/srp/PromotionMail.java | 199 ++++++++++++++++++
.../coderising/ood/srp/product_promotion.txt | 4 +
7 files changed, 310 insertions(+)
create mode 100644 students/643449856/ood-assignment/pom.xml
create mode 100644 students/643449856/ood-assignment/src/main/java/com/coderising/ood/srp/Configuration.java
create mode 100644 students/643449856/ood-assignment/src/main/java/com/coderising/ood/srp/ConfigurationKeys.java
create mode 100644 students/643449856/ood-assignment/src/main/java/com/coderising/ood/srp/DBUtil.java
create mode 100644 students/643449856/ood-assignment/src/main/java/com/coderising/ood/srp/MailUtil.java
create mode 100644 students/643449856/ood-assignment/src/main/java/com/coderising/ood/srp/PromotionMail.java
create mode 100644 students/643449856/ood-assignment/src/main/java/com/coderising/ood/srp/product_promotion.txt
diff --git a/students/643449856/ood-assignment/pom.xml b/students/643449856/ood-assignment/pom.xml
new file mode 100644
index 0000000000..cac49a5328
--- /dev/null
+++ b/students/643449856/ood-assignment/pom.xml
@@ -0,0 +1,32 @@
+
+ 4.0.0
+
+ com.coderising
+ ood-assignment
+ 0.0.1-SNAPSHOT
+ jar
+
+ ood-assignment
+ http://maven.apache.org
+
+
+ UTF-8
+
+
+
+
+
+ junit
+ junit
+ 4.12
+
+
+
+
+
+ aliyunmaven
+ http://maven.aliyun.com/nexus/content/groups/public/
+
+
+
diff --git a/students/643449856/ood-assignment/src/main/java/com/coderising/ood/srp/Configuration.java b/students/643449856/ood-assignment/src/main/java/com/coderising/ood/srp/Configuration.java
new file mode 100644
index 0000000000..f328c1816a
--- /dev/null
+++ b/students/643449856/ood-assignment/src/main/java/com/coderising/ood/srp/Configuration.java
@@ -0,0 +1,23 @@
+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/643449856/ood-assignment/src/main/java/com/coderising/ood/srp/ConfigurationKeys.java b/students/643449856/ood-assignment/src/main/java/com/coderising/ood/srp/ConfigurationKeys.java
new file mode 100644
index 0000000000..8695aed644
--- /dev/null
+++ b/students/643449856/ood-assignment/src/main/java/com/coderising/ood/srp/ConfigurationKeys.java
@@ -0,0 +1,9 @@
+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/643449856/ood-assignment/src/main/java/com/coderising/ood/srp/DBUtil.java b/students/643449856/ood-assignment/src/main/java/com/coderising/ood/srp/DBUtil.java
new file mode 100644
index 0000000000..82e9261d18
--- /dev/null
+++ b/students/643449856/ood-assignment/src/main/java/com/coderising/ood/srp/DBUtil.java
@@ -0,0 +1,25 @@
+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/643449856/ood-assignment/src/main/java/com/coderising/ood/srp/MailUtil.java b/students/643449856/ood-assignment/src/main/java/com/coderising/ood/srp/MailUtil.java
new file mode 100644
index 0000000000..9f9e749af7
--- /dev/null
+++ b/students/643449856/ood-assignment/src/main/java/com/coderising/ood/srp/MailUtil.java
@@ -0,0 +1,18 @@
+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/643449856/ood-assignment/src/main/java/com/coderising/ood/srp/PromotionMail.java b/students/643449856/ood-assignment/src/main/java/com/coderising/ood/srp/PromotionMail.java
new file mode 100644
index 0000000000..781587a846
--- /dev/null
+++ b/students/643449856/ood-assignment/src/main/java/com/coderising/ood/srp/PromotionMail.java
@@ -0,0 +1,199 @@
+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/643449856/ood-assignment/src/main/java/com/coderising/ood/srp/product_promotion.txt b/students/643449856/ood-assignment/src/main/java/com/coderising/ood/srp/product_promotion.txt
new file mode 100644
index 0000000000..b7a974adb3
--- /dev/null
+++ b/students/643449856/ood-assignment/src/main/java/com/coderising/ood/srp/product_promotion.txt
@@ -0,0 +1,4 @@
+P8756 iPhone8
+P3946 XiaoMi10
+P8904 Oppo_R15
+P4955 Vivo_X20
\ No newline at end of file
From 67d0e7d5a2829f07f7c5c52dcff384c4232c94a9 Mon Sep 17 00:00:00 2001
From: tianxianhu <329866097@qq.com>
Date: Mon, 12 Jun 2017 17:23:02 +0800
Subject: [PATCH 010/436] initial homework environment
---
students/329866097/.gitignore | 80 +++++++
students/329866097/README.md | 1 +
students/329866097/pom.xml | 45 ++++
.../com/coderising/ood/srp/Configuration.java | 23 ++
.../coderising/ood/srp/ConfigurationKeys.java | 9 +
.../java/com/coderising/ood/srp/DBUtil.java | 25 +++
.../java/com/coderising/ood/srp/MailUtil.java | 18 ++
.../com/coderising/ood/srp/PromotionMail.java | 198 ++++++++++++++++++
.../src/main/resources/product_promotion.txt | 4 +
9 files changed, 403 insertions(+)
create mode 100644 students/329866097/.gitignore
create mode 100644 students/329866097/README.md
create mode 100644 students/329866097/pom.xml
create mode 100644 students/329866097/src/main/java/com/coderising/ood/srp/Configuration.java
create mode 100644 students/329866097/src/main/java/com/coderising/ood/srp/ConfigurationKeys.java
create mode 100644 students/329866097/src/main/java/com/coderising/ood/srp/DBUtil.java
create mode 100644 students/329866097/src/main/java/com/coderising/ood/srp/MailUtil.java
create mode 100644 students/329866097/src/main/java/com/coderising/ood/srp/PromotionMail.java
create mode 100644 students/329866097/src/main/resources/product_promotion.txt
diff --git a/students/329866097/.gitignore b/students/329866097/.gitignore
new file mode 100644
index 0000000000..bf58d0a162
--- /dev/null
+++ b/students/329866097/.gitignore
@@ -0,0 +1,80 @@
+######################
+# 解决java产生文件
+######################
+*.class
+
+# Mobile Tools for Java (J2ME)
+.mtj.tmp/
+
+# Package Files #
+*.jar
+*.war
+*.ear
+
+# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
+hs_err_pid*
+
+######################
+# 解决maven产生的文件
+######################
+
+target/
+**/target/
+pom.xml.tag
+pom.xml.releaseBackup
+pom.xml.versionsBackup
+pom.xml.next
+release.properties
+dependency-reduced-pom.xml
+buildNumber.properties
+.mvn/timing.properties
+
+######################
+# 解决各类编辑器自动产生的文件
+######################
+
+*.iml
+
+## Directory-based project format:
+.idea/
+# if you remove the above rule, at least ignore the following:
+
+# User-specific stuff:
+# .idea/workspace.xml
+# .idea/tasks.xml
+# .idea/dictionaries
+
+# Sensitive or high-churn files:
+# .idea/dataSources.ids
+# .idea/dataSources.xml
+# .idea/sqlDataSources.xml
+# .idea/dynamic.xml
+# .idea/uiDesigner.xml
+
+# Gradle:
+# .idea/gradle.xml
+# .idea/libraries
+
+# Mongo Explorer plugin:
+# .idea/mongoSettings.xml
+
+## File-based project format:
+*.ipr
+*.iws
+
+## Plugin-specific files:
+
+# IntelliJ
+/out/
+/target/
+
+# mpeltonen/sbt-idea plugin
+.idea_modules/
+
+# JIRA plugin
+atlassian-ide-plugin.xml
+
+# Crashlytics plugin (for Android Studio and IntelliJ)
+com_crashlytics_export_strings.xml
+crashlytics.properties
+crashlytics-build.properties
diff --git a/students/329866097/README.md b/students/329866097/README.md
new file mode 100644
index 0000000000..87f2e553da
--- /dev/null
+++ b/students/329866097/README.md
@@ -0,0 +1 @@
+Mr.Who 作业提交
\ No newline at end of file
diff --git a/students/329866097/pom.xml b/students/329866097/pom.xml
new file mode 100644
index 0000000000..b1b8d4d410
--- /dev/null
+++ b/students/329866097/pom.xml
@@ -0,0 +1,45 @@
+
+
+ 4.0.0
+
+ com.coderising
+ ood-assignment-txh
+ 1.0-SNAPSHOT
+
+
+ UTF-8
+
+
+
+
+
+ junit
+ junit
+ 4.12
+
+
+
+
+
+ aliyunmaven
+ http://maven.aliyun.com/nexus/content/groups/public/
+
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-compiler-plugin
+
+ 1.8
+ 1.8
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/students/329866097/src/main/java/com/coderising/ood/srp/Configuration.java b/students/329866097/src/main/java/com/coderising/ood/srp/Configuration.java
new file mode 100644
index 0000000000..f328c1816a
--- /dev/null
+++ b/students/329866097/src/main/java/com/coderising/ood/srp/Configuration.java
@@ -0,0 +1,23 @@
+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/329866097/src/main/java/com/coderising/ood/srp/ConfigurationKeys.java b/students/329866097/src/main/java/com/coderising/ood/srp/ConfigurationKeys.java
new file mode 100644
index 0000000000..8695aed644
--- /dev/null
+++ b/students/329866097/src/main/java/com/coderising/ood/srp/ConfigurationKeys.java
@@ -0,0 +1,9 @@
+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/329866097/src/main/java/com/coderising/ood/srp/DBUtil.java b/students/329866097/src/main/java/com/coderising/ood/srp/DBUtil.java
new file mode 100644
index 0000000000..82e9261d18
--- /dev/null
+++ b/students/329866097/src/main/java/com/coderising/ood/srp/DBUtil.java
@@ -0,0 +1,25 @@
+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/329866097/src/main/java/com/coderising/ood/srp/MailUtil.java b/students/329866097/src/main/java/com/coderising/ood/srp/MailUtil.java
new file mode 100644
index 0000000000..9f9e749af7
--- /dev/null
+++ b/students/329866097/src/main/java/com/coderising/ood/srp/MailUtil.java
@@ -0,0 +1,18 @@
+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/329866097/src/main/java/com/coderising/ood/srp/PromotionMail.java b/students/329866097/src/main/java/com/coderising/ood/srp/PromotionMail.java
new file mode 100644
index 0000000000..d32df49c79
--- /dev/null
+++ b/students/329866097/src/main/java/com/coderising/ood/srp/PromotionMail.java
@@ -0,0 +1,198 @@
+package com.coderising.ood.srp;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileReader;
+import java.io.IOException;
+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("src/main/resources/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/329866097/src/main/resources/product_promotion.txt b/students/329866097/src/main/resources/product_promotion.txt
new file mode 100644
index 0000000000..b7a974adb3
--- /dev/null
+++ b/students/329866097/src/main/resources/product_promotion.txt
@@ -0,0 +1,4 @@
+P8756 iPhone8
+P3946 XiaoMi10
+P8904 Oppo_R15
+P4955 Vivo_X20
\ No newline at end of file
From 92191804f605251d5d8b3b394b582738d5ec5b54 Mon Sep 17 00:00:00 2001
From: renxin
Date: Mon, 12 Jun 2017 17:30:23 +0800
Subject: [PATCH 011/436] =?UTF-8?q?=E6=B5=8B=E8=AF=95=E4=B8=8A=E6=AC=A1?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
students/335402763/pom.xml | 6 ++++++
1 file changed, 6 insertions(+)
create mode 100644 students/335402763/pom.xml
diff --git a/students/335402763/pom.xml b/students/335402763/pom.xml
new file mode 100644
index 0000000000..d73cd62750
--- /dev/null
+++ b/students/335402763/pom.xml
@@ -0,0 +1,6 @@
+
+ 4.0.0
+ com.coderising
+ 335402763Learning
+ 0.0.1-SNAPSHOT
+
\ No newline at end of file
From a0c616972623b4a600ee2ad1d180bf8a4125eda9 Mon Sep 17 00:00:00 2001
From: renxin
Date: Mon, 12 Jun 2017 17:32:32 +0800
Subject: [PATCH 012/436] =?UTF-8?q?=E4=B8=8A=E4=BC=A0=E5=8E=9F=E5=A7=8Bcod?=
=?UTF-8?q?e?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../com/coderising/ood/srp/Configuration.java | 23 ++
.../coderising/ood/srp/ConfigurationKeys.java | 9 +
.../java/com/coderising/ood/srp/DBUtil.java | 25 +++
.../java/com/coderising/ood/srp/MailUtil.java | 18 ++
.../com/coderising/ood/srp/PromotionMail.java | 199 ++++++++++++++++++
.../coderising/ood/srp/product_promotion.txt | 4 +
6 files changed, 278 insertions(+)
create mode 100644 students/335402763/src/main/java/com/coderising/ood/srp/Configuration.java
create mode 100644 students/335402763/src/main/java/com/coderising/ood/srp/ConfigurationKeys.java
create mode 100644 students/335402763/src/main/java/com/coderising/ood/srp/DBUtil.java
create mode 100644 students/335402763/src/main/java/com/coderising/ood/srp/MailUtil.java
create mode 100644 students/335402763/src/main/java/com/coderising/ood/srp/PromotionMail.java
create mode 100644 students/335402763/src/main/java/com/coderising/ood/srp/product_promotion.txt
diff --git a/students/335402763/src/main/java/com/coderising/ood/srp/Configuration.java b/students/335402763/src/main/java/com/coderising/ood/srp/Configuration.java
new file mode 100644
index 0000000000..927c7155cc
--- /dev/null
+++ b/students/335402763/src/main/java/com/coderising/ood/srp/Configuration.java
@@ -0,0 +1,23 @@
+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/335402763/src/main/java/com/coderising/ood/srp/ConfigurationKeys.java b/students/335402763/src/main/java/com/coderising/ood/srp/ConfigurationKeys.java
new file mode 100644
index 0000000000..868a03ff83
--- /dev/null
+++ b/students/335402763/src/main/java/com/coderising/ood/srp/ConfigurationKeys.java
@@ -0,0 +1,9 @@
+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/335402763/src/main/java/com/coderising/ood/srp/DBUtil.java b/students/335402763/src/main/java/com/coderising/ood/srp/DBUtil.java
new file mode 100644
index 0000000000..65383e4dba
--- /dev/null
+++ b/students/335402763/src/main/java/com/coderising/ood/srp/DBUtil.java
@@ -0,0 +1,25 @@
+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/335402763/src/main/java/com/coderising/ood/srp/MailUtil.java b/students/335402763/src/main/java/com/coderising/ood/srp/MailUtil.java
new file mode 100644
index 0000000000..373f3ee306
--- /dev/null
+++ b/students/335402763/src/main/java/com/coderising/ood/srp/MailUtil.java
@@ -0,0 +1,18 @@
+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/335402763/src/main/java/com/coderising/ood/srp/PromotionMail.java b/students/335402763/src/main/java/com/coderising/ood/srp/PromotionMail.java
new file mode 100644
index 0000000000..94bfcbaf54
--- /dev/null
+++ b/students/335402763/src/main/java/com/coderising/ood/srp/PromotionMail.java
@@ -0,0 +1,199 @@
+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/335402763/src/main/java/com/coderising/ood/srp/product_promotion.txt b/students/335402763/src/main/java/com/coderising/ood/srp/product_promotion.txt
new file mode 100644
index 0000000000..0c0124cc61
--- /dev/null
+++ b/students/335402763/src/main/java/com/coderising/ood/srp/product_promotion.txt
@@ -0,0 +1,4 @@
+P8756 iPhone8
+P3946 XiaoMi10
+P8904 Oppo_R15
+P4955 Vivo_X20
\ No newline at end of file
From b684e959f56984552b1073c5e518b2119a38a703 Mon Sep 17 00:00:00 2001
From: gongxun
Date: Mon, 12 Jun 2017 19:02:26 +0800
Subject: [PATCH 013/436] =?UTF-8?q?=E6=9A=82=E5=AD=98?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../first/ood/srp/Configuration.java | 28 +++++++++
.../first/ood/srp/ConfigurationKeys.java | 10 ++++
students/785396327/first/ood/srp/DBUtil.java | 38 ++++++++++++
students/785396327/first/ood/srp/Email.java | 59 +++++++++++++++++++
.../785396327/first/ood/srp/EmailParser.java | 54 +++++++++++++++++
.../785396327/first/ood/srp/FileParser.java | 44 ++++++++++++++
.../785396327/first/ood/srp/MailSender.java | 22 +++++++
.../785396327/first/ood/srp/MailUtil.java | 16 +++++
.../first/ood/srp/PromotionMail.java | 26 ++++++++
.../785396327/first/ood/srp/SendMailTest.java | 11 ++++
.../785396327/first/ood/srp/StringUtils.java | 17 ++++++
.../first/ood/srp/product_promotion.txt | 4 ++
12 files changed, 329 insertions(+)
create mode 100644 students/785396327/first/ood/srp/Configuration.java
create mode 100644 students/785396327/first/ood/srp/ConfigurationKeys.java
create mode 100644 students/785396327/first/ood/srp/DBUtil.java
create mode 100644 students/785396327/first/ood/srp/Email.java
create mode 100644 students/785396327/first/ood/srp/EmailParser.java
create mode 100644 students/785396327/first/ood/srp/FileParser.java
create mode 100644 students/785396327/first/ood/srp/MailSender.java
create mode 100644 students/785396327/first/ood/srp/MailUtil.java
create mode 100644 students/785396327/first/ood/srp/PromotionMail.java
create mode 100644 students/785396327/first/ood/srp/SendMailTest.java
create mode 100644 students/785396327/first/ood/srp/StringUtils.java
create mode 100644 students/785396327/first/ood/srp/product_promotion.txt
diff --git a/students/785396327/first/ood/srp/Configuration.java b/students/785396327/first/ood/srp/Configuration.java
new file mode 100644
index 0000000000..2d4130423e
--- /dev/null
+++ b/students/785396327/first/ood/srp/Configuration.java
@@ -0,0 +1,28 @@
+package first.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/785396327/first/ood/srp/ConfigurationKeys.java b/students/785396327/first/ood/srp/ConfigurationKeys.java
new file mode 100644
index 0000000000..28de2ced0a
--- /dev/null
+++ b/students/785396327/first/ood/srp/ConfigurationKeys.java
@@ -0,0 +1,10 @@
+package first.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";
+ public static final String NAME_KEY = "NAME";
+ public static final String EMAIL_KEY = "EMAIL";
+}
diff --git a/students/785396327/first/ood/srp/DBUtil.java b/students/785396327/first/ood/srp/DBUtil.java
new file mode 100644
index 0000000000..463b464df4
--- /dev/null
+++ b/students/785396327/first/ood/srp/DBUtil.java
@@ -0,0 +1,38 @@
+package first.ood.srp;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+public class DBUtil {
+
+ /**
+ * 应该从数据库读, 但是简化为直接生成。
+ *
+ * @param sql
+ * @return
+ */
+ public static List> query(String sql) {
+// validateSQL(sql, params);
+
+ List userList = new ArrayList();
+ for (int i = 1; i <= 3; i++) {
+ Map userInfo = new HashMap();
+ userInfo.put("NAME", "User" + i);
+ userInfo.put("EMAIL", "aa@bb.com");
+ userList.add(userInfo);
+ }
+
+ return userList;
+ }
+
+ private static void validateSQL(String sql, Object[] params) {
+ if (StringUtils.isEmpty(sql))
+ throw new RuntimeException("empty sql");
+ String[] sqlFaction = sql.split("\\?");
+ if (sqlFaction.length - 1 != params.length)
+ throw new RuntimeException("wrong number of parameters");
+
+ }
+}
diff --git a/students/785396327/first/ood/srp/Email.java b/students/785396327/first/ood/srp/Email.java
new file mode 100644
index 0000000000..417e9aba6d
--- /dev/null
+++ b/students/785396327/first/ood/srp/Email.java
@@ -0,0 +1,59 @@
+package first.ood.srp;
+
+/**
+ * Created by gongxun on 2017/6/12.
+ */
+public class Email {
+ protected String smtpHost;
+ protected String altSmtpHost;
+ protected String fromAddress;
+ protected String toAddress;
+ protected String subject;
+ protected String message;
+
+ public Email() {
+
+ }
+
+ public Email(String smtpHost, String altSmtpHost, String fromAddress, String toAddress, String subject, String message) {
+ this.smtpHost = smtpHost;
+ this.altSmtpHost = altSmtpHost;
+ this.fromAddress = fromAddress;
+ this.toAddress = toAddress;
+ this.subject = subject;
+ this.message = message;
+ }
+
+ protected void setSMTPHost(String smtpHost) {
+ this.smtpHost = smtpHost;
+ }
+
+ protected void setAltSMTPHost(String altSmtpHost) {
+ this.altSmtpHost = altSmtpHost;
+
+ }
+
+ protected void setFromAddress(String fromAddress) {
+ this.fromAddress = fromAddress;
+ }
+
+ protected void setMessage(String message) {
+ this.message = message;
+ }
+
+ public String getToAddress() {
+ return toAddress;
+ }
+
+ public void setToAddress(String toAddress) {
+ this.toAddress = toAddress;
+ }
+
+ public String getSubject() {
+ return subject;
+ }
+
+ public void setSubject(String subject) {
+ this.subject = subject;
+ }
+}
diff --git a/students/785396327/first/ood/srp/EmailParser.java b/students/785396327/first/ood/srp/EmailParser.java
new file mode 100644
index 0000000000..1129beaf34
--- /dev/null
+++ b/students/785396327/first/ood/srp/EmailParser.java
@@ -0,0 +1,54 @@
+package first.ood.srp;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+
+/**
+ * Created by gongxun on 2017/6/12.
+ */
+public class EmailParser {
+
+ public List parseEmailList(String filepath, String loadQuery) {
+ List mailList = new ArrayList();
+ Email email = parseCommonInfo(filepath);
+ List> individualInfo = getIndividualInfo(loadQuery);
+ for (HashMap map : individualInfo) {
+ PromotionMail promotionMail = new PromotionMail(email);
+ promotionMail.setToAddress(parseToAddress(map));
+ promotionMail.setMessage(parseMessage(map, promotionMail));
+ promotionMail.setSubject("您关注的产品降价了");
+ mailList.add(promotionMail);
+ }
+ return mailList;
+ }
+
+ private String parseMessage(HashMap map, PromotionMail promotionMail) {
+ String name = map.get(ConfigurationKeys.NAME_KEY);
+ String message = "尊敬的 " + name + ", 您关注的产品 " + promotionMail.getProductDesc() + " 降价了,欢迎购买!";
+ return message;
+ }
+
+ private String parseToAddress(HashMap map) {
+ return map.get(ConfigurationKeys.EMAIL_KEY);
+ }
+
+ private PromotionMail parseCommonInfo(String filepath) {
+ Email email = new Email();
+
+ FileParser fileParser = new FileParser(filepath);
+// email.setProductID(fileParser.parseProductID());
+// email.setProductDesc(fileParser.parseProductDesc());
+
+ Configuration configuration = new Configuration();
+// promotionMail.setSMTPHost(configuration.getProperty(ConfigurationKeys.SMTP_SERVER));
+// promotionMail.setFromAddress(configuration.getProperty(ConfigurationKeys.EMAIL_ADMIN));
+// promotionMail.setAltSMTPHost(configuration.getProperty(ConfigurationKeys.ALT_SMTP_SERVER));
+// return promotionMail;
+ return null;
+ }
+
+ private List> getIndividualInfo(String loadQuery) {
+ return DBUtil.query(loadQuery);
+ }
+}
diff --git a/students/785396327/first/ood/srp/FileParser.java b/students/785396327/first/ood/srp/FileParser.java
new file mode 100644
index 0000000000..52827cdd32
--- /dev/null
+++ b/students/785396327/first/ood/srp/FileParser.java
@@ -0,0 +1,44 @@
+package first.ood.srp;
+
+import java.io.BufferedReader;
+import java.io.FileReader;
+import java.io.IOException;
+
+/**
+ * Created by gongxun on 2017/6/12.
+ */
+public class FileParser {
+ private String[] data;
+
+ public FileParser(String filePath) {
+ try {
+ if (StringUtils.isEmpty(filePath))
+ throw new RuntimeException("init file parser must contains a legal file");
+ readFile(filePath);
+ } catch (IOException e) {
+ throw new RuntimeException("parse file cause errors");
+ }
+ }
+
+ private void readFile(String filePath) throws IOException
+ {
+ BufferedReader br = null;
+ try {
+ br = new BufferedReader(new FileReader(filePath));
+ String temp = br.readLine();
+ data = temp.split(" ");
+ } catch (IOException e) {
+ throw new IOException(e.getMessage());
+ } finally {
+ br.close();
+ }
+ }
+
+ public String parseProductID() {
+ return data[0];
+ }
+
+ public String parseProductDesc() {
+ return data[1];
+ }
+}
diff --git a/students/785396327/first/ood/srp/MailSender.java b/students/785396327/first/ood/srp/MailSender.java
new file mode 100644
index 0000000000..90d7f42bdb
--- /dev/null
+++ b/students/785396327/first/ood/srp/MailSender.java
@@ -0,0 +1,22 @@
+package first.ood.srp;
+
+import java.util.Iterator;
+import java.util.List;
+
+/**
+ * Created by gongxun on 2017/6/12.
+ */
+public class MailSender {
+
+ private void sendMail(PromotionMail mail, boolean isDebug) {
+ MailUtil.sendEmail(mail.toAddress, mail.fromAddress, mail.subject, mail.message, StringUtils.isEmpty(mail.smtpHost) == true ? mail.smtpHost : mail.altSmtpHost, isDebug);
+ }
+
+ public void sendMailList(List mailList, boolean isDebug) {
+ if (mailList != null) {
+ for (Iterator iterator = mailList.iterator(); iterator.hasNext(); ) {
+ sendMail(iterator.next(), isDebug);
+ }
+ }
+ }
+}
diff --git a/students/785396327/first/ood/srp/MailUtil.java b/students/785396327/first/ood/srp/MailUtil.java
new file mode 100644
index 0000000000..2ec9de8c42
--- /dev/null
+++ b/students/785396327/first/ood/srp/MailUtil.java
@@ -0,0 +1,16 @@
+package first.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/785396327/first/ood/srp/PromotionMail.java b/students/785396327/first/ood/srp/PromotionMail.java
new file mode 100644
index 0000000000..1a604b7fe3
--- /dev/null
+++ b/students/785396327/first/ood/srp/PromotionMail.java
@@ -0,0 +1,26 @@
+package first.ood.srp;
+
+public class PromotionMail extends Email {
+ private String productID = null;
+ private String productDesc = null;
+
+ public PromotionMail(Email email) {
+ super(email.smtpHost, email.altSmtpHost, email.fromAddress, email.toAddress, email.subject, email.message);
+ }
+
+ public void setProductID(String productID) {
+ this.productID = productID;
+ }
+
+ public String getproductID() {
+ return productID;
+ }
+
+ public void setProductDesc(String desc) {
+ this.productDesc = desc;
+ }
+
+ public String getProductDesc() {
+ return this.productDesc;
+ }
+}
diff --git a/students/785396327/first/ood/srp/SendMailTest.java b/students/785396327/first/ood/srp/SendMailTest.java
new file mode 100644
index 0000000000..69681f6c6d
--- /dev/null
+++ b/students/785396327/first/ood/srp/SendMailTest.java
@@ -0,0 +1,11 @@
+package first.ood.srp;
+
+/**
+ * Created by gongxun on 2017/6/12.
+ */
+public class SendMailTest {
+
+ public static void main(String[] args) {
+ String loadQuery = "Select name from subscriptions where product_id= ? and send_mail=1";
+ }
+}
diff --git a/students/785396327/first/ood/srp/StringUtils.java b/students/785396327/first/ood/srp/StringUtils.java
new file mode 100644
index 0000000000..f5321161bb
--- /dev/null
+++ b/students/785396327/first/ood/srp/StringUtils.java
@@ -0,0 +1,17 @@
+package first.ood.srp;
+
+/**
+ * Created by gongxun on 2017/6/12.
+ */
+public class StringUtils {
+
+ /**
+ * 判断文件路径是否为空
+ *
+ * @param filePath
+ * @return
+ */
+ public static boolean isEmpty(String filePath) {
+ return filePath == null || filePath.trim().isEmpty();
+ }
+}
diff --git a/students/785396327/first/ood/srp/product_promotion.txt b/students/785396327/first/ood/srp/product_promotion.txt
new file mode 100644
index 0000000000..b7a974adb3
--- /dev/null
+++ b/students/785396327/first/ood/srp/product_promotion.txt
@@ -0,0 +1,4 @@
+P8756 iPhone8
+P3946 XiaoMi10
+P8904 Oppo_R15
+P4955 Vivo_X20
\ No newline at end of file
From 68efe80768238d3a81eaac6762076b6c4df3f30e Mon Sep 17 00:00:00 2001
From: luoziyihao
Date: Mon, 12 Jun 2017 21:44:50 +0800
Subject: [PATCH 014/436] add 1204187480
---
students/1204187480/.gitignore | 21 ++
students/1204187480/code/homework/.gitignore | 21 ++
.../code/homework/coderising/pom.xml | 26 ++
.../com/coderising/jvm/clz/AccessFlag.java | 7 +
.../com/coderising/jvm/clz/ClassFile.java | 7 +
.../com/coderising/jvm/clz/ClassIndex.java | 10 +
.../jvm/loader/ClassFileLoader.java | 114 ++++++
.../jvm/loader/ClassFileParser.java | 7 +
.../coderising/litestruts/LoginAction.java | 39 ++
.../com/coderising/litestruts/Struts.java | 121 ++++++
.../com/coderising/litestruts/StrutsTest.java | 43 +++
.../java/com/coderising/litestruts/View.java | 23 ++
.../litestruts/parser/ActionConfig.java | 45 +++
.../parser/DefaultStrutsParser.java | 52 +++
.../coderising/litestruts/parser/Result.java | 22 ++
.../litestruts/parser/StrutsConfig.java | 23 ++
.../litestruts/parser/StrutsParser.java | 8 +
.../coderising/src/main/resources/struts.xml | 11 +
.../java/com/coderising/api/ComputeTest.java | 21 ++
.../java/com/coderising/api/CycleTest.java | 25 ++
.../java/com/coderising/api/FileTest.java | 32 ++
.../java/com/coderising/api/ObjectTest.java | 18 +
.../java/com/coderising/api/StrmanTest.java | 17 +
.../jvm/test/ClassFileloaderTest.java | 354 ++++++++++++++++++
.../com/coderising/jvm/test/EmployeeV1.java | 28 ++
.../litestruts/parser/StructsParserTest.java | 14 +
.../1204187480/code/homework/coding/pom.xml | 12 +
.../java/com/coding/basic/BinaryTreeNode.java | 32 ++
.../main/java/com/coding/basic/Iterator.java | 7 +
.../src/main/java/com/coding/basic/List.java | 10 +
.../src/main/java/com/coding/basic/Queue.java | 24 ++
.../src/main/java/com/coding/basic/Stack.java | 32 ++
.../com/coding/basic/array/ArrayList.java | 111 ++++++
.../com/coding/basic/array/ArrayUtil.java | 252 +++++++++++++
.../coding/basic/linklist/LRUPageFrame.java | 169 +++++++++
.../basic/linklist/LRUPageFrameTest.java | 34 ++
.../com/coding/basic/linklist/LinkedList.java | 351 +++++++++++++++++
.../test/java/com/coding/api/ArraysTest.java | 22 ++
.../test/java/com/coding/api/SystemTest.java | 24 ++
.../java/com/coding/basic/LinkedListTest.java | 202 ++++++++++
.../com/coding/basic/array/ArrayListTest.java | 37 ++
.../com/coding/basic/array/ArrayUtilTest.java | 76 ++++
.../1204187480/code/homework/common/pom.xml | 13 +
.../com/coding/common/util/BeanUtils.java | 144 +++++++
.../com/coding/common/util/ByteUtils.java | 21 ++
.../com/coding/common/util/FileUtils2.java | 69 ++++
.../java/com/coding/common/util/IOUtils2.java | 24 ++
.../com/coding/common/util/StringUtils2.java | 34 ++
.../test/java/com/coding/api/ArraysTest.java | 22 ++
.../test/java/com/coding/api/SystemTest.java | 24 ++
.../com/coding/common/util/ByteUtilsTest.java | 20 +
.../coding/common/util/FileUtils2Test.java | 35 ++
.../code/homework/parent-dependencies/pom.xml | 169 +++++++++
.../1204187480/code/homework/parent/pom.xml | 23 ++
students/1204187480/code/homework/pom.xml | 18 +
...0\210\350\256\241\347\256\227\346\234\272" | 0
students/1204187480/note/todo/homework.md | 8 +
57 files changed, 3128 insertions(+)
create mode 100644 students/1204187480/.gitignore
create mode 100644 students/1204187480/code/homework/.gitignore
create mode 100644 students/1204187480/code/homework/coderising/pom.xml
create mode 100644 students/1204187480/code/homework/coderising/src/main/java/com/coderising/jvm/clz/AccessFlag.java
create mode 100644 students/1204187480/code/homework/coderising/src/main/java/com/coderising/jvm/clz/ClassFile.java
create mode 100644 students/1204187480/code/homework/coderising/src/main/java/com/coderising/jvm/clz/ClassIndex.java
create mode 100644 students/1204187480/code/homework/coderising/src/main/java/com/coderising/jvm/loader/ClassFileLoader.java
create mode 100644 students/1204187480/code/homework/coderising/src/main/java/com/coderising/jvm/loader/ClassFileParser.java
create mode 100644 students/1204187480/code/homework/coderising/src/main/java/com/coderising/litestruts/LoginAction.java
create mode 100644 students/1204187480/code/homework/coderising/src/main/java/com/coderising/litestruts/Struts.java
create mode 100644 students/1204187480/code/homework/coderising/src/main/java/com/coderising/litestruts/StrutsTest.java
create mode 100644 students/1204187480/code/homework/coderising/src/main/java/com/coderising/litestruts/View.java
create mode 100644 students/1204187480/code/homework/coderising/src/main/java/com/coderising/litestruts/parser/ActionConfig.java
create mode 100644 students/1204187480/code/homework/coderising/src/main/java/com/coderising/litestruts/parser/DefaultStrutsParser.java
create mode 100644 students/1204187480/code/homework/coderising/src/main/java/com/coderising/litestruts/parser/Result.java
create mode 100644 students/1204187480/code/homework/coderising/src/main/java/com/coderising/litestruts/parser/StrutsConfig.java
create mode 100644 students/1204187480/code/homework/coderising/src/main/java/com/coderising/litestruts/parser/StrutsParser.java
create mode 100644 students/1204187480/code/homework/coderising/src/main/resources/struts.xml
create mode 100644 students/1204187480/code/homework/coderising/src/test/java/com/coderising/api/ComputeTest.java
create mode 100644 students/1204187480/code/homework/coderising/src/test/java/com/coderising/api/CycleTest.java
create mode 100644 students/1204187480/code/homework/coderising/src/test/java/com/coderising/api/FileTest.java
create mode 100644 students/1204187480/code/homework/coderising/src/test/java/com/coderising/api/ObjectTest.java
create mode 100644 students/1204187480/code/homework/coderising/src/test/java/com/coderising/api/StrmanTest.java
create mode 100644 students/1204187480/code/homework/coderising/src/test/java/com/coderising/jvm/test/ClassFileloaderTest.java
create mode 100644 students/1204187480/code/homework/coderising/src/test/java/com/coderising/jvm/test/EmployeeV1.java
create mode 100644 students/1204187480/code/homework/coderising/src/test/java/com/coderising/litestruts/parser/StructsParserTest.java
create mode 100644 students/1204187480/code/homework/coding/pom.xml
create mode 100644 students/1204187480/code/homework/coding/src/main/java/com/coding/basic/BinaryTreeNode.java
create mode 100644 students/1204187480/code/homework/coding/src/main/java/com/coding/basic/Iterator.java
create mode 100644 students/1204187480/code/homework/coding/src/main/java/com/coding/basic/List.java
create mode 100644 students/1204187480/code/homework/coding/src/main/java/com/coding/basic/Queue.java
create mode 100644 students/1204187480/code/homework/coding/src/main/java/com/coding/basic/Stack.java
create mode 100644 students/1204187480/code/homework/coding/src/main/java/com/coding/basic/array/ArrayList.java
create mode 100644 students/1204187480/code/homework/coding/src/main/java/com/coding/basic/array/ArrayUtil.java
create mode 100644 students/1204187480/code/homework/coding/src/main/java/com/coding/basic/linklist/LRUPageFrame.java
create mode 100644 students/1204187480/code/homework/coding/src/main/java/com/coding/basic/linklist/LRUPageFrameTest.java
create mode 100644 students/1204187480/code/homework/coding/src/main/java/com/coding/basic/linklist/LinkedList.java
create mode 100644 students/1204187480/code/homework/coding/src/test/java/com/coding/api/ArraysTest.java
create mode 100644 students/1204187480/code/homework/coding/src/test/java/com/coding/api/SystemTest.java
create mode 100644 students/1204187480/code/homework/coding/src/test/java/com/coding/basic/LinkedListTest.java
create mode 100644 students/1204187480/code/homework/coding/src/test/java/com/coding/basic/array/ArrayListTest.java
create mode 100644 students/1204187480/code/homework/coding/src/test/java/com/coding/basic/array/ArrayUtilTest.java
create mode 100644 students/1204187480/code/homework/common/pom.xml
create mode 100755 students/1204187480/code/homework/common/src/main/java/com/coding/common/util/BeanUtils.java
create mode 100644 students/1204187480/code/homework/common/src/main/java/com/coding/common/util/ByteUtils.java
create mode 100644 students/1204187480/code/homework/common/src/main/java/com/coding/common/util/FileUtils2.java
create mode 100644 students/1204187480/code/homework/common/src/main/java/com/coding/common/util/IOUtils2.java
create mode 100644 students/1204187480/code/homework/common/src/main/java/com/coding/common/util/StringUtils2.java
create mode 100644 students/1204187480/code/homework/common/src/test/java/com/coding/api/ArraysTest.java
create mode 100644 students/1204187480/code/homework/common/src/test/java/com/coding/api/SystemTest.java
create mode 100644 students/1204187480/code/homework/common/src/test/java/com/coding/common/util/ByteUtilsTest.java
create mode 100644 students/1204187480/code/homework/common/src/test/java/com/coding/common/util/FileUtils2Test.java
create mode 100644 students/1204187480/code/homework/parent-dependencies/pom.xml
create mode 100644 students/1204187480/code/homework/parent/pom.xml
create mode 100644 students/1204187480/code/homework/pom.xml
create mode 100644 "students/1204187480/note/homework/cpu, \345\206\205\345\255\230, \347\243\201\347\233\230, \346\214\207\344\273\244-\346\274\253\350\260\210\350\256\241\347\256\227\346\234\272"
create mode 100644 students/1204187480/note/todo/homework.md
diff --git a/students/1204187480/.gitignore b/students/1204187480/.gitignore
new file mode 100644
index 0000000000..2a5296f902
--- /dev/null
+++ b/students/1204187480/.gitignore
@@ -0,0 +1,21 @@
+*.class
+# Mobile Tools for Java (J2ME)
+.mtj.tmp/
+
+# Package Files #
+*.jar
+*.war
+*.ear
+
+# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
+hs_err_pid*
+
+#ide config
+.metadata
+.recommenders
+.idea/
+*.iml
+rebel.*
+.rebel.*
+
+target
diff --git a/students/1204187480/code/homework/.gitignore b/students/1204187480/code/homework/.gitignore
new file mode 100644
index 0000000000..2a5296f902
--- /dev/null
+++ b/students/1204187480/code/homework/.gitignore
@@ -0,0 +1,21 @@
+*.class
+# Mobile Tools for Java (J2ME)
+.mtj.tmp/
+
+# Package Files #
+*.jar
+*.war
+*.ear
+
+# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
+hs_err_pid*
+
+#ide config
+.metadata
+.recommenders
+.idea/
+*.iml
+rebel.*
+.rebel.*
+
+target
diff --git a/students/1204187480/code/homework/coderising/pom.xml b/students/1204187480/code/homework/coderising/pom.xml
new file mode 100644
index 0000000000..d7d922d4d8
--- /dev/null
+++ b/students/1204187480/code/homework/coderising/pom.xml
@@ -0,0 +1,26 @@
+
+ 4.0.0
+ coderising
+
+ com.coding
+ parent
+ 1.0-SNAPSHOT
+ ../parent/pom.xml
+
+
+
+ 2.1
+
+
+
+
+
+ commons-digester
+ commons-digester
+ ${commons-digester.version}
+
+
+
+
+
\ No newline at end of file
diff --git a/students/1204187480/code/homework/coderising/src/main/java/com/coderising/jvm/clz/AccessFlag.java b/students/1204187480/code/homework/coderising/src/main/java/com/coderising/jvm/clz/AccessFlag.java
new file mode 100644
index 0000000000..6b60e0bed2
--- /dev/null
+++ b/students/1204187480/code/homework/coderising/src/main/java/com/coderising/jvm/clz/AccessFlag.java
@@ -0,0 +1,7 @@
+package com.coderising.jvm.clz;
+
+/**
+ * Created by luoziyihao on 5/23/17.
+ */
+public class AccessFlag {
+}
diff --git a/students/1204187480/code/homework/coderising/src/main/java/com/coderising/jvm/clz/ClassFile.java b/students/1204187480/code/homework/coderising/src/main/java/com/coderising/jvm/clz/ClassFile.java
new file mode 100644
index 0000000000..855bf9c7e0
--- /dev/null
+++ b/students/1204187480/code/homework/coderising/src/main/java/com/coderising/jvm/clz/ClassFile.java
@@ -0,0 +1,7 @@
+package com.coderising.jvm.clz;
+
+/**
+ * Created by luoziyihao on 5/23/17.
+ */
+public class ClassFile {
+}
diff --git a/students/1204187480/code/homework/coderising/src/main/java/com/coderising/jvm/clz/ClassIndex.java b/students/1204187480/code/homework/coderising/src/main/java/com/coderising/jvm/clz/ClassIndex.java
new file mode 100644
index 0000000000..7b177aa12f
--- /dev/null
+++ b/students/1204187480/code/homework/coderising/src/main/java/com/coderising/jvm/clz/ClassIndex.java
@@ -0,0 +1,10 @@
+package com.coderising.jvm.clz;
+
+/**
+ * Created by luoziyihao on 5/23/17.
+ */
+public class ClassIndex {
+
+ String minorVersion;
+ String majorVersion;
+}
diff --git a/students/1204187480/code/homework/coderising/src/main/java/com/coderising/jvm/loader/ClassFileLoader.java b/students/1204187480/code/homework/coderising/src/main/java/com/coderising/jvm/loader/ClassFileLoader.java
new file mode 100644
index 0000000000..1c5f8196e8
--- /dev/null
+++ b/students/1204187480/code/homework/coderising/src/main/java/com/coderising/jvm/loader/ClassFileLoader.java
@@ -0,0 +1,114 @@
+package com.coderising.jvm.loader;
+
+
+import com.coding.common.util.FileUtils2;
+import org.apache.commons.lang3.StringUtils;
+import strman.Strman;
+
+import java.io.File;
+import java.util.*;
+import java.util.concurrent.ConcurrentHashMap;
+
+import static com.coding.common.util.FileUtils2.getCanonicalPath;
+import static org.apache.commons.lang3.StringUtils.replace;
+import static org.apache.commons.lang3.StringUtils.substringAfter;
+
+/**
+ * Created by luoziyihao on 4/27/17.
+ */
+public class ClassFileLoader {
+
+ private List clzPaths;
+
+ private Map clzContext;
+
+ public void addClassPath(String path) {
+ if (clzPaths == null) {
+ clzPaths = new ArrayList<>(5);
+ }
+ if (StringUtils.isBlank(path)) {
+ return;
+ }
+ File file = new File(path);
+ if (!file.isDirectory()) {
+ return;
+ }
+ String canonicalName = getCanonicalPath(file);
+ if (clzPaths.contains(canonicalName)) {
+ return;
+ }
+ clzPaths.add(getCanonicalPath(file));
+ }
+
+
+ private static final String SPLIT = ";";
+
+ public String getClassPath() {
+ StringBuilder classPath = new StringBuilder();
+
+ for (String e : clzPaths) {
+ classPath.append(e)
+ .append(SPLIT);
+ }
+ if (classPath.length() > 1) {
+ classPath.deleteCharAt(classPath.length() - 1);
+ }
+ return classPath.toString();
+ }
+
+ private static final String CLZ_SUFFIX = ".class";
+
+ public byte[] readBinaryCode(String className) {
+ if (StringUtils.isBlank(className)) {
+ throw new IllegalStateException("className is blank");
+ }
+ byte[] binaryCode = getClzContext().get(Strman.append(className, CLZ_SUFFIX));
+ if (binaryCode == null) {
+ throw new IllegalStateException(
+ Strman.format("className={0} is not found in classpath", className));
+ }
+ return binaryCode;
+ }
+
+ private Map getClzContext() {
+ if (clzContext == null) {
+ clzContext = createClzContextWithClzPaths(clzPaths);
+ }
+ return clzContext;
+ }
+
+ private Map createClzContextWithClzPaths(List clzPaths) {
+ Map clzContext = new ConcurrentHashMap<>(60);
+ for (String e : clzPaths) {
+ File file = new File(e);
+ if (file.isDirectory()) {
+ List files = FileUtils2.listAllFiles(file);
+ clzContext = addClassElements(clzContext, e, files);
+ }
+ }
+ return clzContext;
+ }
+
+ private Map addClassElements(Map clzContext, String classpath, List files) {
+ for (File classFile : files) {
+ String filePath = getCanonicalPath(classFile);
+ String canonicalName = getCanonicalName(classpath, filePath);
+ byte[] bytes = FileUtils2.getBytes(classFile);
+ clzContext.put(canonicalName, bytes);
+ }
+ return clzContext;
+ }
+
+ /**
+ * 将classpath 下的文件路径转成 a.b.c.class 的格式
+ */
+ private static final String POINT = ".";
+
+ private String getCanonicalName(String classpath, String filePath) {
+ String tmp = replace(substringAfter(filePath, classpath), File.separator, POINT);
+ if (tmp.startsWith(POINT)) {
+ tmp = StringUtils.removeStart(tmp, POINT);
+ }
+ return tmp;
+ }
+}
diff --git a/students/1204187480/code/homework/coderising/src/main/java/com/coderising/jvm/loader/ClassFileParser.java b/students/1204187480/code/homework/coderising/src/main/java/com/coderising/jvm/loader/ClassFileParser.java
new file mode 100644
index 0000000000..9c77821341
--- /dev/null
+++ b/students/1204187480/code/homework/coderising/src/main/java/com/coderising/jvm/loader/ClassFileParser.java
@@ -0,0 +1,7 @@
+package com.coderising.jvm.loader;
+
+/**
+ * Created by luoziyihao on 5/23/17.
+ */
+public class ClassFileParser {
+}
diff --git a/students/1204187480/code/homework/coderising/src/main/java/com/coderising/litestruts/LoginAction.java b/students/1204187480/code/homework/coderising/src/main/java/com/coderising/litestruts/LoginAction.java
new file mode 100644
index 0000000000..dcdbe226ed
--- /dev/null
+++ b/students/1204187480/code/homework/coderising/src/main/java/com/coderising/litestruts/LoginAction.java
@@ -0,0 +1,39 @@
+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/1204187480/code/homework/coderising/src/main/java/com/coderising/litestruts/Struts.java b/students/1204187480/code/homework/coderising/src/main/java/com/coderising/litestruts/Struts.java
new file mode 100644
index 0000000000..0b238b2db0
--- /dev/null
+++ b/students/1204187480/code/homework/coderising/src/main/java/com/coderising/litestruts/Struts.java
@@ -0,0 +1,121 @@
+package com.coderising.litestruts;
+
+import com.coderising.litestruts.parser.ActionConfig;
+import com.coderising.litestruts.parser.DefaultStrutsParser;
+import com.coderising.litestruts.parser.StrutsConfig;
+import com.coderising.litestruts.parser.StrutsParser;
+import com.coding.common.util.BeanUtils;
+
+import java.util.Map;
+
+
+public class Struts {
+
+ private static StrutsParser strutsParser = new DefaultStrutsParser();
+
+ private static final String STRUTS_CONFIG_PATH = "struts.xml";
+ private static final BeanUtils beanUtils = new BeanUtils();
+
+ 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字段中。
+
+ */
+
+ /**
+ * 0. 读取配置文件struts.xml
+ */
+ StrutsConfig strutsConfig = strutsParser.parser(STRUTS_CONFIG_PATH);
+ ActionConfig actionConfig = strutsConfig.getActions().get(actionName);
+ /**
+ * 1. 根据actionName找到相对应的class , 例如LoginAction, 通过反射实例化(创建对象)
+ 据parameters中的数据,调用对象的setter方法, 例如parameters中的数据是
+ ("name"="test" , "password"="1234") ,
+ 那就应该调用 setName和setPassword方法
+ */
+ Object action = setPropertiesForAction(actionConfig, actionName, parameters);
+
+ /**
+ * 2. 通过反射调用对象的exectue 方法, 并获得返回值,例如"success"
+ */
+ String resultName = doExecute(action);
+ /**
+ * 3. 通过反射找到对象的所有getter方法(例如 getMessage),
+ 通过反射来调用, 把值和属性形成一个HashMap , 例如 {"message": "登录成功"} ,
+ 放到View对象的parameters
+ */
+ View view = createViewAndSetParameters(action);
+ /**
+ * 4. 根据struts.xml中的 配置,以及execute的返回值, 确定哪一个jsp,
+ 放到View对象的jsp字段中。
+ */
+ setViewValue(view, resultName, actionConfig);
+ return view;
+ }
+
+ private static void setViewValue(View view, String resultName, ActionConfig config) {
+ view.setJsp(config.getResults().get(resultName).getView());
+ }
+
+ private static View createViewAndSetParameters(Object action) {
+ View view = new View();
+ view.setParameters(beanUtils.describe(action));
+ return view;
+ }
+
+ private static String doExecute(Object action) {
+ return (String) beanUtils.invokeWithNoParamter("execute", action);
+ }
+
+ private static Object setPropertiesForAction(ActionConfig actionConfig, String actionName, Map parameters) {
+ Object action = createInstance(findActionClass(actionConfig.getClassName()));
+ for (Map.Entry entry : parameters.entrySet()) {
+ setProperty(entry.getKey(), entry.getValue(), action);
+ }
+ return action;
+ }
+
+ /**
+ * todo 校验 key 是否存在
+ *
+ * @param key
+ * @param value
+ * @param action
+ */
+ private static void setProperty(String key, String value, Object action) {
+ beanUtils.setPara(value, key, action);
+ }
+
+ private static Object createInstance(Class classValue) {
+ try {
+ return classValue.newInstance();
+ } catch (InstantiationException | IllegalAccessException e) {
+ throw new IllegalStateException(e);
+ }
+ }
+
+ private static Class findActionClass(String className) {
+ try {
+ return Class.forName(className);
+ } catch (ClassNotFoundException e) {
+ throw new IllegalStateException(e);
+ }
+ }
+
+}
diff --git a/students/1204187480/code/homework/coderising/src/main/java/com/coderising/litestruts/StrutsTest.java b/students/1204187480/code/homework/coderising/src/main/java/com/coderising/litestruts/StrutsTest.java
new file mode 100644
index 0000000000..b8c81faf3c
--- /dev/null
+++ b/students/1204187480/code/homework/coderising/src/main/java/com/coderising/litestruts/StrutsTest.java
@@ -0,0 +1,43 @@
+package com.coderising.litestruts;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+
+
+
+
+public class StrutsTest {
+
+ @Test
+ public void testLoginActionSuccess() {
+
+ 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/1204187480/code/homework/coderising/src/main/java/com/coderising/litestruts/View.java b/students/1204187480/code/homework/coderising/src/main/java/com/coderising/litestruts/View.java
new file mode 100644
index 0000000000..07df2a5dab
--- /dev/null
+++ b/students/1204187480/code/homework/coderising/src/main/java/com/coderising/litestruts/View.java
@@ -0,0 +1,23 @@
+package com.coderising.litestruts;
+
+import java.util.Map;
+
+public class View {
+ private String jsp;
+ private Map parameters;
+
+ public String getJsp() {
+ return jsp;
+ }
+ public View setJsp(String jsp) {
+ this.jsp = jsp;
+ return this;
+ }
+ public Map getParameters() {
+ return parameters;
+ }
+ public View setParameters(Map parameters) {
+ this.parameters = parameters;
+ return this;
+ }
+}
diff --git a/students/1204187480/code/homework/coderising/src/main/java/com/coderising/litestruts/parser/ActionConfig.java b/students/1204187480/code/homework/coderising/src/main/java/com/coderising/litestruts/parser/ActionConfig.java
new file mode 100644
index 0000000000..4aaba284fb
--- /dev/null
+++ b/students/1204187480/code/homework/coderising/src/main/java/com/coderising/litestruts/parser/ActionConfig.java
@@ -0,0 +1,45 @@
+package com.coderising.litestruts.parser;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Created by luoziyihao on 3/5/17.
+ */
+public class ActionConfig {
+ private String name;
+ private String className;
+ private Map results = new HashMap<>(10);
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public String getClassName() {
+ return className;
+ }
+
+ public void setClassName(String className) {
+ this.className = className;
+ }
+
+ public Map getResults() {
+ return results;
+ }
+
+ public void setResults(Map results) {
+ this.results = results;
+ }
+
+ public void addResult(Result result) {
+ this.results.put(result.getName(), result);
+ }
+
+
+}
diff --git a/students/1204187480/code/homework/coderising/src/main/java/com/coderising/litestruts/parser/DefaultStrutsParser.java b/students/1204187480/code/homework/coderising/src/main/java/com/coderising/litestruts/parser/DefaultStrutsParser.java
new file mode 100644
index 0000000000..ea58507738
--- /dev/null
+++ b/students/1204187480/code/homework/coderising/src/main/java/com/coderising/litestruts/parser/DefaultStrutsParser.java
@@ -0,0 +1,52 @@
+package com.coderising.litestruts.parser;
+
+import com.alibaba.fastjson.JSON;
+import org.apache.commons.digester.Digester;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.xml.sax.SAXException;
+
+import java.io.File;
+import java.io.IOException;
+
+/**
+ * 解析 struts.xml 文件
+ * @apiNote 借鉴 http://www.everycoding.com/coding/78.html; http://blog.csdn.net/caihaijiang/article/details/5944955
+ * Created by luoziyihao on 3/5/17.
+ */
+public class DefaultStrutsParser implements StrutsParser {
+ private final Logger logger = LoggerFactory.getLogger(this.getClass());
+
+ @Override
+ public StrutsConfig parser(String filePathInClasspath) {
+ String path = this.getClass().getClassLoader().getResource(filePathInClasspath).getPath();
+ File input = new File(path);
+ Digester digester = new Digester();
+ // 创建 StrutsConfig 对象
+ digester.addObjectCreate("struts", StrutsConfig.class);
+ // 将 struts 节点上的attribute属性映射到 StrutsConfig 对象的属性上
+ digester.addSetProperties("struts");
+ digester.addObjectCreate("struts/action", ActionConfig.class);
+ // 将 struts/action 节点上的attribute属性映射到 Action 对象的属性上, 并自定义属性映射
+ digester.addSetProperties("struts/action"
+ , new String[]{"name", "class"}, new String[]{"name", "className"});
+ digester.addObjectCreate("struts/action/result", Result.class);
+ digester.addSetProperties("struts/action/result"
+ , new String[]{"name"}, new String[]{"name"});
+ // 将 struts/action/result 节点上的body属性映射到 Result 对象的属性上
+ digester.addCallMethod("struts/action/result", "setView", 0);
+ // 对应struts/action/result 生成的对象添加到 Action中
+ digester.addSetNext("struts/action/result", "addResult");
+ // 对应struts/action 生成的对象添加到 Struts中
+ digester.addSetNext("struts/action", "addAction");
+
+ try {
+ StrutsConfig strutsConfig = (StrutsConfig) digester.parse(input);
+ logger.debug("strutsConfig={}", JSON.toJSONString(strutsConfig));
+ return strutsConfig;
+ } catch (IOException | SAXException e) {
+ throw new IllegalStateException(e);
+ }
+
+ }
+}
diff --git a/students/1204187480/code/homework/coderising/src/main/java/com/coderising/litestruts/parser/Result.java b/students/1204187480/code/homework/coderising/src/main/java/com/coderising/litestruts/parser/Result.java
new file mode 100644
index 0000000000..c402418e6b
--- /dev/null
+++ b/students/1204187480/code/homework/coderising/src/main/java/com/coderising/litestruts/parser/Result.java
@@ -0,0 +1,22 @@
+package com.coderising.litestruts.parser;
+
+public class Result {
+ private String name;
+ private String view;
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public String getView() {
+ return view;
+ }
+
+ public void setView(String view) {
+ this.view = view;
+ }
+}
\ No newline at end of file
diff --git a/students/1204187480/code/homework/coderising/src/main/java/com/coderising/litestruts/parser/StrutsConfig.java b/students/1204187480/code/homework/coderising/src/main/java/com/coderising/litestruts/parser/StrutsConfig.java
new file mode 100644
index 0000000000..88f769157e
--- /dev/null
+++ b/students/1204187480/code/homework/coderising/src/main/java/com/coderising/litestruts/parser/StrutsConfig.java
@@ -0,0 +1,23 @@
+package com.coderising.litestruts.parser;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * Created by luoziyihao on 3/5/17.
+ */
+public class StrutsConfig {
+ public Map actions = new HashMap<>(10);
+
+ public Map getActions() {
+ return actions;
+ }
+
+ public void setActions(Map actions) {
+ this.actions = actions;
+ }
+
+ public void addAction(ActionConfig action) {
+ this.actions.put(action.getName(), action);
+ }
+}
diff --git a/students/1204187480/code/homework/coderising/src/main/java/com/coderising/litestruts/parser/StrutsParser.java b/students/1204187480/code/homework/coderising/src/main/java/com/coderising/litestruts/parser/StrutsParser.java
new file mode 100644
index 0000000000..ab7358c777
--- /dev/null
+++ b/students/1204187480/code/homework/coderising/src/main/java/com/coderising/litestruts/parser/StrutsParser.java
@@ -0,0 +1,8 @@
+package com.coderising.litestruts.parser;
+
+/**
+ * Created by luoziyihao on 3/5/17.
+ */
+public interface StrutsParser {
+ StrutsConfig parser(String filePathInClasspath);
+}
diff --git a/students/1204187480/code/homework/coderising/src/main/resources/struts.xml b/students/1204187480/code/homework/coderising/src/main/resources/struts.xml
new file mode 100644
index 0000000000..876156eb4d
--- /dev/null
+++ b/students/1204187480/code/homework/coderising/src/main/resources/struts.xml
@@ -0,0 +1,11 @@
+
+
+
+ /jsp/homepage.jsp
+ /jsp/showLogin.jsp
+
+
+ /jsp/welcome.jsp
+ /jsp/error.jsp
+
+
\ No newline at end of file
diff --git a/students/1204187480/code/homework/coderising/src/test/java/com/coderising/api/ComputeTest.java b/students/1204187480/code/homework/coderising/src/test/java/com/coderising/api/ComputeTest.java
new file mode 100644
index 0000000000..f02816a555
--- /dev/null
+++ b/students/1204187480/code/homework/coderising/src/test/java/com/coderising/api/ComputeTest.java
@@ -0,0 +1,21 @@
+package com.coderising.api;
+
+import org.junit.Test;
+
+/**
+ * Created by luoziyihao on 3/5/17.
+ */
+public class ComputeTest {
+
+ @Test
+ public void testDivisionExactly(){
+ System.out.println( 7 >> 1);
+ System.out.println( -5 >> 2);
+ System.out.println( -5 << 2);
+ }
+
+ @Test
+ public void testSqrt() {
+ System.out.println(Math.sqrt(10));
+ }
+}
diff --git a/students/1204187480/code/homework/coderising/src/test/java/com/coderising/api/CycleTest.java b/students/1204187480/code/homework/coderising/src/test/java/com/coderising/api/CycleTest.java
new file mode 100644
index 0000000000..6abb5d925d
--- /dev/null
+++ b/students/1204187480/code/homework/coderising/src/test/java/com/coderising/api/CycleTest.java
@@ -0,0 +1,25 @@
+package com.coderising.api;
+
+import org.junit.Test;
+
+/**
+ * Created by luoziyihao on 3/5/17.
+ */
+public class CycleTest {
+
+ /**
+ * checkIndex will be excuted in each cycle
+ */
+ @Test
+ public void testForSize() {
+ int[] arr = new int[]{1, 2, 3, 4, 54};
+ for (int i = 0; checkIndex(i, arr); i++ ) {
+
+ }
+ }
+
+ private boolean checkIndex(int i, int[] arr) {
+ System.out.println(i);
+ return i < arr.length;
+ }
+}
diff --git a/students/1204187480/code/homework/coderising/src/test/java/com/coderising/api/FileTest.java b/students/1204187480/code/homework/coderising/src/test/java/com/coderising/api/FileTest.java
new file mode 100644
index 0000000000..bd918a011c
--- /dev/null
+++ b/students/1204187480/code/homework/coderising/src/test/java/com/coderising/api/FileTest.java
@@ -0,0 +1,32 @@
+package com.coderising.api;
+
+import lombok.extern.slf4j.Slf4j;
+import org.junit.Assert;
+import org.junit.Test;
+
+import java.io.File;
+import java.io.IOException;
+
+/**
+ * Created by luoziyihao on 4/28/17.
+ */
+@Slf4j
+public class FileTest {
+
+ @Test
+ public void testFile() {
+ File file = new File("./hahah");
+ Assert.assertFalse(file.isDirectory());
+
+ }
+
+ @Test
+ public void testAbsolutePath() throws IOException {
+ File file = new File("../src");
+ log.info("isDirectory={}", file.isDirectory());
+ log.info(file.getAbsolutePath());
+ log.info(file.getCanonicalPath());
+ log.info(file.getName());
+ log.info(file.getPath());
+ }
+}
diff --git a/students/1204187480/code/homework/coderising/src/test/java/com/coderising/api/ObjectTest.java b/students/1204187480/code/homework/coderising/src/test/java/com/coderising/api/ObjectTest.java
new file mode 100644
index 0000000000..06cd373de5
--- /dev/null
+++ b/students/1204187480/code/homework/coderising/src/test/java/com/coderising/api/ObjectTest.java
@@ -0,0 +1,18 @@
+package com.coderising.api;
+
+import lombok.extern.slf4j.Slf4j;
+import org.junit.Test;
+
+/**
+ * Created by luoziyihao on 5/2/17.
+ */
+@Slf4j
+public class ObjectTest {
+ @Test
+ public void test(){
+ Object a[] = {1};
+ log.info(a.getClass().getName());
+ log.info(a.getClass().getCanonicalName());
+ log.info(a.getClass().getSimpleName());
+ }
+}
diff --git a/students/1204187480/code/homework/coderising/src/test/java/com/coderising/api/StrmanTest.java b/students/1204187480/code/homework/coderising/src/test/java/com/coderising/api/StrmanTest.java
new file mode 100644
index 0000000000..6831eb0ad6
--- /dev/null
+++ b/students/1204187480/code/homework/coderising/src/test/java/com/coderising/api/StrmanTest.java
@@ -0,0 +1,17 @@
+package com.coderising.api;
+
+import org.junit.Test;
+import strman.Strman;
+
+/**
+ * Created by luoziyihao on 5/3/17.
+ */
+public class StrmanTest {
+
+ @Test
+ public void testFormat() {
+
+ System.out.println(Strman.format("className is not found in classpath, className={1}", ",333 ","cccc"));
+
+ }
+}
diff --git a/students/1204187480/code/homework/coderising/src/test/java/com/coderising/jvm/test/ClassFileloaderTest.java b/students/1204187480/code/homework/coderising/src/test/java/com/coderising/jvm/test/ClassFileloaderTest.java
new file mode 100644
index 0000000000..b7c5bab54e
--- /dev/null
+++ b/students/1204187480/code/homework/coderising/src/test/java/com/coderising/jvm/test/ClassFileloaderTest.java
@@ -0,0 +1,354 @@
+package com.coderising.jvm.test;
+
+import java.io.File;
+import java.util.List;
+
+import ch.qos.logback.core.encoder.ByteArrayUtil;
+import com.coding.common.util.ByteUtils;
+import com.coding.common.util.FileUtils2;
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+//import com.coderising.jvm.clz.ClassFile;
+//import com.coderising.jvm.clz.ClassIndex;
+//import com.coderising.jvm.cmd.BiPushCmd;
+//import com.coderising.jvm.cmd.ByteCodeCommand;
+//import com.coderising.jvm.cmd.OneOperandCmd;
+//import com.coderising.jvm.cmd.TwoOperandCmd;
+//import com.coderising.jvm.constant.ClassInfo;
+//import com.coderising.jvm.constant.ConstantPool;
+//import com.coderising.jvm.constant.MethodRefInfo;
+//import com.coderising.jvm.constant.NameAndTypeInfo;
+//import com.coderising.jvm.constant.UTF8Info;
+//import com.coderising.jvm.field.Field;
+import com.coderising.jvm.loader.ClassFileLoader;
+
+import static com.coding.common.util.FileUtils2.getCanonicalPath;
+//import com.coderising.jvm.method.Method;
+
+
+
+
+
+public class ClassFileloaderTest {
+
+
+ private static final String FULL_QUALIFIED_CLASS_NAME = "com/coderising/jvm/test/EmployeeV1";
+
+ static String path1 = "target/classes";
+ static String path2 = "target/test-classes";
+
+// static ClassFile clzFile = null;
+// static {
+// ClassFileLoader loader = new ClassFileLoader();
+// loader.addClassPath(path1);
+// String className = "com.coderising.jvm.test.EmployeeV1";
+//
+// clzFile = loader.loadClass(className);
+//
+// }
+
+
+ @Before
+ public void setUp() throws Exception {
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ }
+
+ private void addClassPath(ClassFileLoader loader) {
+ loader.addClassPath(path1);
+ loader.addClassPath(path2);
+ }
+
+ @Test
+ public void testClassPath(){
+
+ ClassFileLoader loader = new ClassFileLoader();
+ addClassPath(loader);
+ String clzPath = loader.getClassPath();
+
+ Assert.assertEquals(getCanonicalPath(new File(path1))+";"+getCanonicalPath(new File(path2)),clzPath);
+
+ }
+
+ @Test
+ public void testClassFileLength() {
+
+ ClassFileLoader loader = new ClassFileLoader();
+ addClassPath(loader);
+
+ String className = "com.coderising.jvm.test.EmployeeV1";
+
+ byte[] byteCodes = loader.readBinaryCode(className);
+
+ // 注意:这个字节数可能和你的JVM版本有关系, 你可以看看编译好的类到底有多大
+ Assert.assertEquals(1056, byteCodes.length);
+
+ }
+
+
+ @Test
+ public void testMagicNumber(){
+ ClassFileLoader loader = new ClassFileLoader();
+ addClassPath(loader);
+ String className = "com.coderising.jvm.test.EmployeeV1";
+ byte[] byteCodes = loader.readBinaryCode(className);
+ byte[] codes = new byte[]{byteCodes[0],byteCodes[1],byteCodes[2],byteCodes[3]};
+
+
+ String acctualValue = this.byteToHexString(codes);
+
+ Assert.assertEquals("cafebabe", acctualValue);
+ }
+
+
+
+ private String byteToHexString(byte[] codes ){
+ return ByteUtils.byteToHexString(codes);
+ }
+
+// add comment for behind test
+// /**
+// * ----------------------------------------------------------------------
+// */
+//
+//
+// @Test
+// public void testVersion(){
+//
+// Assert.assertEquals(0, clzFile.getMinorVersion());
+// Assert.assertEquals(52, clzFile.getMajorVersion());
+//
+// }
+//
+// @Test
+// public void testConstantPool(){
+//
+//
+// ConstantPool pool = clzFile.getConstantPool();
+//
+// Assert.assertEquals(53, pool.getSize());
+//
+// {
+// ClassInfo clzInfo = (ClassInfo) pool.getConstantInfo(1);
+// Assert.assertEquals(2, clzInfo.getUtf8Index());
+//
+// UTF8Info utf8Info = (UTF8Info) pool.getConstantInfo(2);
+// Assert.assertEquals(FULL_QUALIFIED_CLASS_NAME, utf8Info.getValue());
+// }
+// {
+// ClassInfo clzInfo = (ClassInfo) pool.getConstantInfo(3);
+// Assert.assertEquals(4, clzInfo.getUtf8Index());
+//
+// UTF8Info utf8Info = (UTF8Info) pool.getConstantInfo(4);
+// Assert.assertEquals("java/lang/Object", utf8Info.getValue());
+// }
+// {
+// UTF8Info utf8Info = (UTF8Info) pool.getConstantInfo(5);
+// Assert.assertEquals("name", utf8Info.getValue());
+//
+// utf8Info = (UTF8Info) pool.getConstantInfo(6);
+// Assert.assertEquals("Ljava/lang/String;", utf8Info.getValue());
+//
+// utf8Info = (UTF8Info) pool.getConstantInfo(7);
+// Assert.assertEquals("age", utf8Info.getValue());
+//
+// utf8Info = (UTF8Info) pool.getConstantInfo(8);
+// Assert.assertEquals("I", utf8Info.getValue());
+//
+// utf8Info = (UTF8Info) pool.getConstantInfo(9);
+// Assert.assertEquals("", utf8Info.getValue());
+//
+// utf8Info = (UTF8Info) pool.getConstantInfo(10);
+// Assert.assertEquals("(Ljava/lang/String;I)V", utf8Info.getValue());
+//
+// utf8Info = (UTF8Info) pool.getConstantInfo(11);
+// Assert.assertEquals("Code", utf8Info.getValue());
+// }
+//
+// {
+// MethodRefInfo methodRef = (MethodRefInfo)pool.getConstantInfo(12);
+// Assert.assertEquals(3, methodRef.getClassInfoIndex());
+// Assert.assertEquals(13, methodRef.getNameAndTypeIndex());
+// }
+//
+// {
+// NameAndTypeInfo nameAndType = (NameAndTypeInfo) pool.getConstantInfo(13);
+// Assert.assertEquals(9, nameAndType.getIndex1());
+// Assert.assertEquals(14, nameAndType.getIndex2());
+// }
+// //抽查几个吧
+// {
+// MethodRefInfo methodRef = (MethodRefInfo)pool.getConstantInfo(45);
+// Assert.assertEquals(1, methodRef.getClassInfoIndex());
+// Assert.assertEquals(46, methodRef.getNameAndTypeIndex());
+// }
+//
+// {
+// UTF8Info utf8Info = (UTF8Info) pool.getConstantInfo(53);
+// Assert.assertEquals("EmployeeV1.java", utf8Info.getValue());
+// }
+// }
+// @Test
+// public void testClassIndex(){
+//
+// ClassIndex clzIndex = clzFile.getClzIndex();
+// ClassInfo thisClassInfo = (ClassInfo)clzFile.getConstantPool().getConstantInfo(clzIndex.getThisClassIndex());
+// ClassInfo superClassInfo = (ClassInfo)clzFile.getConstantPool().getConstantInfo(clzIndex.getSuperClassIndex());
+//
+//
+// Assert.assertEquals(FULL_QUALIFIED_CLASS_NAME, thisClassInfo.getClassName());
+// Assert.assertEquals("java/lang/Object", superClassInfo.getClassName());
+// }
+//
+// /**
+// * 下面是第三次JVM课应实现的测试用例
+// */
+// @Test
+// public void testReadFields(){
+//
+// List fields = clzFile.getFields();
+// Assert.assertEquals(2, fields.size());
+// {
+// Field f = fields.get(0);
+// Assert.assertEquals("name:Ljava/lang/String;", f.toString());
+// }
+// {
+// Field f = fields.get(1);
+// Assert.assertEquals("age:I", f.toString());
+// }
+// }
+// @Test
+// public void testMethods(){
+//
+// List methods = clzFile.getMethods();
+// ConstantPool pool = clzFile.getConstantPool();
+//
+// {
+// Method m = methods.get(0);
+// assertMethodEquals(pool,m,
+// "",
+// "(Ljava/lang/String;I)V",
+// "2ab7000c2a2bb5000f2a1cb50011b1");
+//
+// }
+// {
+// Method m = methods.get(1);
+// assertMethodEquals(pool,m,
+// "setName",
+// "(Ljava/lang/String;)V",
+// "2a2bb5000fb1");
+//
+// }
+// {
+// Method m = methods.get(2);
+// assertMethodEquals(pool,m,
+// "setAge",
+// "(I)V",
+// "2a1bb50011b1");
+// }
+// {
+// Method m = methods.get(3);
+// assertMethodEquals(pool,m,
+// "sayHello",
+// "()V",
+// "b2001c1222b60024b1");
+//
+// }
+// {
+// Method m = methods.get(4);
+// assertMethodEquals(pool,m,
+// "main",
+// "([Ljava/lang/String;)V",
+// "bb000159122b101db7002d4c2bb6002fb1");
+// }
+// }
+//
+// private void assertMethodEquals(ConstantPool pool,Method m , String expectedName, String expectedDesc,String expectedCode){
+// String methodName = pool.getUTF8String(m.getNameIndex());
+// String methodDesc = pool.getUTF8String(m.getDescriptorIndex());
+// String code = m.getCodeAttr().getCode();
+// Assert.assertEquals(expectedName, methodName);
+// Assert.assertEquals(expectedDesc, methodDesc);
+// Assert.assertEquals(expectedCode, code);
+// }
+//
+// @Test
+// public void testByteCodeCommand(){
+// {
+// Method initMethod = this.clzFile.getMethod("", "(Ljava/lang/String;I)V");
+// ByteCodeCommand [] cmds = initMethod.getCmds();
+//
+// assertOpCodeEquals("0: aload_0", cmds[0]);
+// assertOpCodeEquals("1: invokespecial #12", cmds[1]);
+// assertOpCodeEquals("4: aload_0", cmds[2]);
+// assertOpCodeEquals("5: aload_1", cmds[3]);
+// assertOpCodeEquals("6: putfield #15", cmds[4]);
+// assertOpCodeEquals("9: aload_0", cmds[5]);
+// assertOpCodeEquals("10: iload_2", cmds[6]);
+// assertOpCodeEquals("11: putfield #17", cmds[7]);
+// assertOpCodeEquals("14: return", cmds[8]);
+// }
+//
+// {
+// Method setNameMethod = this.clzFile.getMethod("setName", "(Ljava/lang/String;)V");
+// ByteCodeCommand [] cmds = setNameMethod.getCmds();
+//
+// assertOpCodeEquals("0: aload_0", cmds[0]);
+// assertOpCodeEquals("1: aload_1", cmds[1]);
+// assertOpCodeEquals("2: putfield #15", cmds[2]);
+// assertOpCodeEquals("5: return", cmds[3]);
+//
+// }
+//
+// {
+// Method sayHelloMethod = this.clzFile.getMethod("sayHello", "()V");
+// ByteCodeCommand [] cmds = sayHelloMethod.getCmds();
+//
+// assertOpCodeEquals("0: getstatic #28", cmds[0]);
+// assertOpCodeEquals("3: ldc #34", cmds[1]);
+// assertOpCodeEquals("5: invokevirtual #36", cmds[2]);
+// assertOpCodeEquals("8: return", cmds[3]);
+//
+// }
+//
+// {
+// Method mainMethod = this.clzFile.getMainMethod();
+//
+// ByteCodeCommand [] cmds = mainMethod.getCmds();
+//
+// assertOpCodeEquals("0: new #1", cmds[0]);
+// assertOpCodeEquals("3: dup", cmds[1]);
+// assertOpCodeEquals("4: ldc #43", cmds[2]);
+// assertOpCodeEquals("6: bipush 29", cmds[3]);
+// assertOpCodeEquals("8: invokespecial #45", cmds[4]);
+// assertOpCodeEquals("11: astore_1", cmds[5]);
+// assertOpCodeEquals("12: aload_1", cmds[6]);
+// assertOpCodeEquals("13: invokevirtual #47", cmds[7]);
+// assertOpCodeEquals("16: return", cmds[8]);
+// }
+//
+// }
+//
+// private void assertOpCodeEquals(String expected, ByteCodeCommand cmd){
+//
+// String acctual = cmd.getOffset()+": "+cmd.getReadableCodeText();
+//
+// if(cmd instanceof OneOperandCmd){
+// if(cmd instanceof BiPushCmd){
+// acctual += " " + ((OneOperandCmd)cmd).getOperand();
+// } else{
+// acctual += " #" + ((OneOperandCmd)cmd).getOperand();
+// }
+// }
+// if(cmd instanceof TwoOperandCmd){
+// acctual += " #" + ((TwoOperandCmd)cmd).getIndex();
+// }
+// Assert.assertEquals(expected, acctual);
+// }
+
+}
diff --git a/students/1204187480/code/homework/coderising/src/test/java/com/coderising/jvm/test/EmployeeV1.java b/students/1204187480/code/homework/coderising/src/test/java/com/coderising/jvm/test/EmployeeV1.java
new file mode 100644
index 0000000000..12e3d7efdd
--- /dev/null
+++ b/students/1204187480/code/homework/coderising/src/test/java/com/coderising/jvm/test/EmployeeV1.java
@@ -0,0 +1,28 @@
+package com.coderising.jvm.test;
+
+public class EmployeeV1 {
+
+
+ private String name;
+ private int age;
+
+ public EmployeeV1(String name, int age) {
+ this.name = name;
+ this.age = age;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+ public void setAge(int age){
+ this.age = age;
+ }
+ public void sayHello() {
+ System.out.println("Hello , this is class Employee ");
+ }
+ public static void main(String[] args){
+ EmployeeV1 p = new EmployeeV1("Andy",29);
+ p.sayHello();
+
+ }
+}
\ No newline at end of file
diff --git a/students/1204187480/code/homework/coderising/src/test/java/com/coderising/litestruts/parser/StructsParserTest.java b/students/1204187480/code/homework/coderising/src/test/java/com/coderising/litestruts/parser/StructsParserTest.java
new file mode 100644
index 0000000000..72e841a230
--- /dev/null
+++ b/students/1204187480/code/homework/coderising/src/test/java/com/coderising/litestruts/parser/StructsParserTest.java
@@ -0,0 +1,14 @@
+package com.coderising.litestruts.parser;
+
+import org.junit.Test;
+
+/**
+ * Created by luoziyihao on 3/5/17.
+ */
+public class StructsParserTest {
+ @Test
+ public void parser() throws Exception {
+ new DefaultStrutsParser().parser("struts.xml");
+ }
+
+}
\ No newline at end of file
diff --git a/students/1204187480/code/homework/coding/pom.xml b/students/1204187480/code/homework/coding/pom.xml
new file mode 100644
index 0000000000..08acfc3528
--- /dev/null
+++ b/students/1204187480/code/homework/coding/pom.xml
@@ -0,0 +1,12 @@
+
+ 4.0.0
+ coding
+
+ com.coding
+ parent
+ 1.0-SNAPSHOT
+ ../parent/pom.xml
+
+
+
\ No newline at end of file
diff --git a/students/1204187480/code/homework/coding/src/main/java/com/coding/basic/BinaryTreeNode.java b/students/1204187480/code/homework/coding/src/main/java/com/coding/basic/BinaryTreeNode.java
new file mode 100644
index 0000000000..d7ac820192
--- /dev/null
+++ b/students/1204187480/code/homework/coding/src/main/java/com/coding/basic/BinaryTreeNode.java
@@ -0,0 +1,32 @@
+package com.coding.basic;
+
+public class BinaryTreeNode {
+
+ private Object data;
+ private BinaryTreeNode left;
+ private BinaryTreeNode right;
+
+ public Object getData() {
+ return data;
+ }
+ public void setData(Object data) {
+ this.data = data;
+ }
+ public BinaryTreeNode getLeft() {
+ return left;
+ }
+ public void setLeft(BinaryTreeNode left) {
+ this.left = left;
+ }
+ public BinaryTreeNode getRight() {
+ return right;
+ }
+ public void setRight(BinaryTreeNode right) {
+ this.right = right;
+ }
+
+ public BinaryTreeNode insert(Object o){
+ return null;
+ }
+
+}
diff --git a/students/1204187480/code/homework/coding/src/main/java/com/coding/basic/Iterator.java b/students/1204187480/code/homework/coding/src/main/java/com/coding/basic/Iterator.java
new file mode 100644
index 0000000000..06ef6311b2
--- /dev/null
+++ b/students/1204187480/code/homework/coding/src/main/java/com/coding/basic/Iterator.java
@@ -0,0 +1,7 @@
+package com.coding.basic;
+
+public interface Iterator {
+ public boolean hasNext();
+ public Object next();
+
+}
diff --git a/students/1204187480/code/homework/coding/src/main/java/com/coding/basic/List.java b/students/1204187480/code/homework/coding/src/main/java/com/coding/basic/List.java
new file mode 100644
index 0000000000..ef939ae2cc
--- /dev/null
+++ b/students/1204187480/code/homework/coding/src/main/java/com/coding/basic/List.java
@@ -0,0 +1,10 @@
+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();
+ public Iterator iterator();
+}
diff --git a/students/1204187480/code/homework/coding/src/main/java/com/coding/basic/Queue.java b/students/1204187480/code/homework/coding/src/main/java/com/coding/basic/Queue.java
new file mode 100644
index 0000000000..e333496198
--- /dev/null
+++ b/students/1204187480/code/homework/coding/src/main/java/com/coding/basic/Queue.java
@@ -0,0 +1,24 @@
+package com.coding.basic;
+
+import com.coding.basic.linklist.LinkedList;
+
+public class Queue {
+
+ private LinkedList elementData = new LinkedList();
+
+ public void enQueue(Object o){
+ elementData.add(o);
+ }
+
+ public Object deQueue(){
+ return elementData.remove(0);
+ }
+
+ public boolean isEmpty(){
+ return size() == 0;
+ }
+
+ public int size(){
+ return elementData.size();
+ }
+}
diff --git a/students/1204187480/code/homework/coding/src/main/java/com/coding/basic/Stack.java b/students/1204187480/code/homework/coding/src/main/java/com/coding/basic/Stack.java
new file mode 100644
index 0000000000..7336dccfe9
--- /dev/null
+++ b/students/1204187480/code/homework/coding/src/main/java/com/coding/basic/Stack.java
@@ -0,0 +1,32 @@
+package com.coding.basic;
+
+import com.coding.basic.array.ArrayList;
+
+public class Stack {
+ private ArrayList elementData = new ArrayList();
+
+ public void push(Object o){
+ elementData.add(o);
+ }
+
+ public Object pop(){
+ if (isEmpty()) {
+ throw new IllegalStateException("the stack is empty");
+ }
+ return elementData.remove(elementData.size() - 1);
+ }
+
+ public Object peek(){
+ if (isEmpty()) {
+ throw new IllegalStateException("the stack is empty");
+ }
+ return elementData.get(elementData.size() - 1);
+ }
+
+ public boolean isEmpty(){
+ return size() == 0;
+ }
+ public int size(){
+ return elementData.size();
+ }
+}
diff --git a/students/1204187480/code/homework/coding/src/main/java/com/coding/basic/array/ArrayList.java b/students/1204187480/code/homework/coding/src/main/java/com/coding/basic/array/ArrayList.java
new file mode 100644
index 0000000000..cbe1f87a05
--- /dev/null
+++ b/students/1204187480/code/homework/coding/src/main/java/com/coding/basic/array/ArrayList.java
@@ -0,0 +1,111 @@
+package com.coding.basic.array;
+
+import com.coding.basic.Iterator;
+import com.coding.basic.List;
+
+import java.util.Arrays;
+
+public class ArrayList implements List {
+
+ private int size = 0;
+
+ private Object[] elementData = new Object[100];
+
+ private Iterator iterator = new ArrayListIterator();
+
+ private int length() {
+ return elementData.length;
+ }
+
+ private static final int ENLARGE_LENGTH = 100;
+
+ private Object[] enlarge(Object[] origin) {
+ return Arrays.copyOf(origin, origin.length + ENLARGE_LENGTH);
+ }
+
+ private void enLargeElementData() {
+ if (size == length()) {
+ elementData = enlarge(elementData);
+ }
+ }
+
+ public void add(Object o) {
+ enLargeElementData();
+ elementData[size] = o;
+ size++;
+ }
+
+ public void add(int index, Object o) {
+ checkForAdd(index);
+ enLargeElementData();
+ // 备份 index 处及后面的数据
+ Object[] elementsBehindIndex = backBehindElements(elementData, index);
+ // 给index处 设值
+ elementData[index] = o;
+ // 追加 备份的数据
+ appendElement(elementData, index, elementsBehindIndex);
+ size++;
+ }
+
+ private void appendElement(Object[] origin, int pos, Object[] append) {
+ System.arraycopy(append, 0, origin, pos, append.length);
+ }
+
+ private Object[] backBehindElements(Object[] elementData, int index) {
+ int backSize = size - index;
+ Object[] back = new Object[backSize];
+ System.arraycopy(elementData, index, back, 0, backSize);
+ return back;
+ }
+
+ public Object get(int index) {
+ checkIndex(index);
+ return elementData[index];
+ }
+
+ private void checkIndex(int index) {
+ if (index < 0 || index >= size) {
+ throw new ArrayIndexOutOfBoundsException(String.format("index=%s, size=%s", index, size));
+ }
+ }
+
+ private void checkForAdd(int index) {
+ if (index < 0 || index > size) {
+ throw new ArrayIndexOutOfBoundsException(String.format("index=%s, size=%s", index, size));
+ }
+ }
+
+ public Object remove(int index) {
+ checkIndex(index);
+ Object[] back = backBehindElements(elementData, index + 1);
+ System.arraycopy(back, 0, elementData, index, back.length);
+ Object ret = elementData[index];
+ elementData[index] = null;
+ size--;
+ return ret;
+ }
+
+ public int size() {
+ return size;
+ }
+
+ public Iterator iterator() {
+ return iterator;
+ }
+
+ private class ArrayListIterator implements Iterator {
+
+ int next = 0;
+
+ @Override
+ public boolean hasNext() {
+ return next < size;
+ }
+
+ @Override
+ public Object next() {
+ return elementData[next++];
+ }
+ }
+
+}
diff --git a/students/1204187480/code/homework/coding/src/main/java/com/coding/basic/array/ArrayUtil.java b/students/1204187480/code/homework/coding/src/main/java/com/coding/basic/array/ArrayUtil.java
new file mode 100644
index 0000000000..42ec6efe57
--- /dev/null
+++ b/students/1204187480/code/homework/coding/src/main/java/com/coding/basic/array/ArrayUtil.java
@@ -0,0 +1,252 @@
+package com.coding.basic.array;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class ArrayUtil {
+ private final Logger logger = LoggerFactory.getLogger(this.getClass());
+ /**
+ * 给定一个整形数组a , 对该数组的值进行置换
+ 例如: a = [7, 9 , 30, 3] , 置换后为 [3, 30, 9,7]
+ 如果 a = [7, 9, 30, 3, 4] , 置换后为 [4,3, 30 , 9,7]
+ * @param origin
+ * @return
+ */
+ public void reverseArray(int[] origin){
+ int length = origin.length;
+ int mid = length >> 1;
+ for (int i = 0; i < mid; i++) {
+ int hIndex = length - 1 -i;
+ int l = origin[i];
+ int h = origin[hIndex];
+ origin[hIndex] = l;
+ origin[i] = h;
+ }
+
+ }
+
+ /**
+ * 现在有如下的一个数组: int oldArr[]={1,3,4,5,0,0,6,6,0,5,4,7,6,7,0,5}
+ * 要求将以上数组中值为0的项去掉,将不为0的值存入一个新的数组,生成的新数组为:
+ * {1,3,4,5,6,6,5,4,7,6,7,5}
+ * @param oldArray
+ * @return
+ */
+
+ public int[] removeZero(int[] oldArray){
+ int removeValue = 0;
+ return removeValue(oldArray, removeValue);
+ }
+
+ private int[] removeValue(int[] oldArray, int removeValue) {
+ int length = oldArray.length;
+ int[] dest = new int[length];
+ int j = 0;
+ for(int i = 0; i < length; i++) {
+ int v = oldArray[i];
+ if (v != removeValue) {
+ dest[j++] = v;
+ }
+ }
+
+ int[] retArray = new int[j];
+ System.arraycopy(dest, 0, retArray, 0, j);
+ return retArray;
+ }
+
+ /**
+ * 给定两个已经排序好的整形数组, a1和a2 , 创建一个新的数组a3, 使得a3 包含a1和a2 的所有元素, 并且仍然是有序的
+ * 例如 a1 = [3, 5, 7,8] a2 = [4, 5, 6,7] 则 a3 为[3,4,5,6,7,8] , 注意: 已经消除了重复
+ * todo 数组 a1, b1 自身去重
+ * @param array1
+ * @param array2
+ * @return
+ */
+
+ public int[] merge(int[] array1, int[] array2){
+ int length1 = array1.length;
+ int length2 = array2.length;
+ int length = length1 + length2;
+ int[] newArray = new int[length];
+
+ return findAndSetLeastWithOutDuplicate(array1, array2, 0, 0, 0, 0, newArray);
+ }
+
+ /**
+ * todo 优化递归出口判断, 优化三个条件判断为一个
+ * @param array1
+ * @param array2
+ * @param i
+ * @param j
+ * @param k
+ * @param duplicate
+ * @param newArray
+ * @return
+ */
+ private int[] findAndSetLeastWithOutDuplicate(int[] array1, int[] array2, int i, int j, int k, int duplicate, int[] newArray) {
+
+ if (i == array1.length && j < array2.length) {
+ System.arraycopy(array2, j, newArray, k, array2.length - j);
+ return copyLastValues(newArray, duplicate);
+ }
+ if (j == array2.length && i < array1.length) {
+ System.arraycopy(array1, i, newArray, k, array1.length - i);
+ return copyLastValues(newArray, duplicate);
+ }
+ if (j == array2.length && i == array1.length) {
+ return copyLastValues(newArray, duplicate);
+ }
+
+ int v1 = array1[i];
+ int v2 = array2[j];
+ if (v1 < v2) {
+ newArray [k] = v1;
+ return findAndSetLeastWithOutDuplicate(array1, array2, ++i, j, ++k, duplicate, newArray);
+ } else if (v1 > v2){
+ newArray [k] = v2;
+ return findAndSetLeastWithOutDuplicate(array1, array2, i, ++j, ++k, duplicate, newArray);
+ } else {
+ newArray [k] = v2;
+ return findAndSetLeastWithOutDuplicate(array1, array2, ++i, ++j, ++k, ++duplicate, newArray);
+ }
+
+ }
+
+ private int[] copyLastValues(int[] newArray, int duplicate) {
+ int[] retArray = new int[newArray.length - duplicate];
+ System.arraycopy(newArray, 0, retArray, 0, retArray.length);
+ return retArray;
+ }
+
+
+ /**
+ * 把一个已经存满数据的数组 oldArray的容量进行扩展, 扩展后的新数据大小为oldArray.length + size
+ * 注意,老数组的元素在新数组中需要保持
+ * 例如 oldArray = [2,3,6] , size = 3,则返回的新数组为
+ * [2,3,6,0,0,0]
+ * @param oldArray
+ * @param size
+ * @return
+ */
+ public int[] grow(int [] oldArray, int size){
+ int[] newArray = new int[oldArray.length + size];
+ System.arraycopy(oldArray, 0, newArray, 0, oldArray.length);
+ 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[]{};
+ }
+ int [] newArray = new int[max];
+ newArray[0] = 1;
+ return fibonacciN(1, 1, 1, max, newArray);
+ }
+
+ private int[] fibonacciN(int size, int current, int next, int max, int[] newArray) {
+ if (next >= max) {
+ int[] retArray = new int[size];
+ System.arraycopy(newArray, 0, retArray, 0, size);
+ return retArray;
+ } else {
+ newArray[++size - 1] = next;
+ return fibonacciN(size, next, current + next, max, newArray);
+ }
+ }
+
+ /**
+ * 返回小于给定最大值max的所有素数数组
+ * 例如max = 23, 返回的数组为[2,3,5,7,11,13,17,19]
+ * todo 使用已有的质数序列 优化质数验证
+ * @param max
+ * @return
+ */
+ public int[] getPrimes(int max){
+ if (max <= 2) {
+ return new int[]{};
+ }
+
+ int[] newArray = new int[max];
+ int j = 0;
+ for (int i = 2; i < max; i++) {
+ if (isPrime(i)) {
+ newArray[j++] = i;
+ }
+ }
+ int[] retArray = new int[j];
+ System.arraycopy(newArray, 0, retArray, 0, j);
+ return retArray;
+ }
+
+ private boolean isPrime(int number) {
+ int limit = Double.valueOf(Math.sqrt(number)).intValue();
+ for(int i = 2; i <= limit; i++) {
+ if (number % i == 0 ) {
+ return false;
+ }
+ }
+ return true;
+
+ }
+
+ /**
+ * 所谓“完数”, 是指这个数恰好等于它的因子之和,例如6=1+2+3
+ * 给定一个最大值max, 返回一个数组, 数组中是小于max 的所有完数
+ * @param max
+ * @return
+ */
+ public int[] getPerfectNumbers(int max){
+ int[] newArray = new int[48]; // 经过不少数学家研究,到2013年2月6日为止,一共找到了48个完全数。
+ int j = 0;
+ for (int i = 2; i < max; i++) {
+ if (isPerfectNumber(i)) {
+ if (j >= newArray.length) {
+ newArray = this.grow(newArray, 1);
+ }
+ newArray[j++] = i;
+
+ }
+ }
+ int[] retArray = new int[j];
+ System.arraycopy(newArray, 0, retArray, 0, j);
+ return retArray;
+ }
+
+ private boolean isPerfectNumber(int number) {
+ int sum = 0;
+ for (int i = 1; i < number; i++) {
+ if (number % i == 0) {
+ sum += i;
+ }
+ }
+
+ return sum == number;
+ }
+
+ /**
+ * 用seperator 把数组 array给连接起来
+ * 例如array= [3,8,9], seperator = "-"
+ * 则返回值为"3-8-9"
+ * @param array
+ * @param seperator
+ * @return
+ */
+ public String join(int[] array, String seperator){
+ StringBuilder builder = new StringBuilder(20);
+ int length = array.length;
+ for (int i = 0; i< length; i++) {
+ builder.append(array[i]).append(seperator);
+ }
+ builder.deleteCharAt(builder.length() - seperator.length());
+ return builder.toString();
+ }
+
+
+}
diff --git a/students/1204187480/code/homework/coding/src/main/java/com/coding/basic/linklist/LRUPageFrame.java b/students/1204187480/code/homework/coding/src/main/java/com/coding/basic/linklist/LRUPageFrame.java
new file mode 100644
index 0000000000..96c2e2cdab
--- /dev/null
+++ b/students/1204187480/code/homework/coding/src/main/java/com/coding/basic/linklist/LRUPageFrame.java
@@ -0,0 +1,169 @@
+package com.coding.basic.linklist;
+
+import lombok.extern.slf4j.Slf4j;
+
+/**
+ * 定长链表
+ * 命中后更新 pageNumber的位置
+ * 随时要考虑 first, node 的变化
+ */
+@Slf4j
+public class LRUPageFrame {
+
+ private static class Node {
+
+ Node prev;
+ Node next;
+ int pageNum;
+
+ public Node(Node next, int pageNum) {
+ this.next = next;
+ this.pageNum = pageNum;
+ }
+
+ public Node(int pageNum) {
+ this.pageNum = pageNum;
+ }
+
+ Node() {
+ }
+
+ public String debug() {
+ return new StringBuilder().
+ append("\n##########################pre: ")
+ .append(prev)
+ .append("\n##########################node: ")
+ .append(this)
+ .append("\n##########################next: ")
+ .append(next)
+ .append("\n##########################pageNum: ")
+ .append(pageNum)
+
+ .toString();
+ }
+ }
+
+
+ private int capacity;
+
+ private int currentSize;
+ private Node first;// 链表头
+ private Node last;// 链表尾
+
+
+ public LRUPageFrame(int capacity) {
+ this.currentSize = 0;
+ this.capacity = capacity;
+
+ }
+
+ /**
+ * 获取缓存中对象
+ * 新的对象应该放在前面
+ *
+ * @param pageNum
+ * @return
+ */
+ public void access(int pageNum) {
+ if (capacity == 0) {
+ return;
+ }
+
+ // 如果已经存在, 删除已经存在的
+ removeContainedNode(pageNum);
+
+ /**
+ * 向前追加
+ */
+ // 如果 first 为空, first=last=newNode
+ if (first == null && last == null) {
+ first = last = new Node(pageNum);
+ // 如果不为空 , first=newNode, first.next.pre = first
+ } else {
+ first = new Node(first, pageNum);
+ first.next.prev = first;
+ }
+ // 修改 size
+ currentSize++;
+ debugContent("addNewNode");
+
+ // 如果 size = capacity + 1, 去除last (额外考虑 capacity 为 1 的情况), last.next=null
+ if (currentSize == capacity + 1) {
+ last = last.prev;
+ last.next = null;
+ currentSize--;
+ debugContent("rmSpareNode");
+ }
+ }
+
+ private Node removeContainedNode(int pageNum) {
+ Node node = first;
+ while (node != null) {
+
+ if (node.pageNum == pageNum) {
+ Node nodePre = node.prev;
+ Node nodeNext = node.next;
+ if (nodePre == null) { // 说明在第一个节点就 hit了
+ first = nodeNext;
+ first.prev = null;
+ } else {
+ nodePre.next = nodeNext;
+ if (nodeNext != null) {
+ nodeNext.prev = nodePre;
+ } else {
+ last = nodePre; // 如果 nodeNext 为空, 说明原先 last 是 node, 现在是 nodePre
+ }
+ }
+ currentSize--;
+ return node;
+ }
+ node = node.next;
+ }
+ debugContent("removeContainedNode");
+ return null;
+ }
+
+ private void debugContent(String tag) {
+ log.debug("tag={}, currentSize={}, toString={}", tag, currentSize, debug());
+ }
+
+
+ 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();
+ }
+
+ public String debug() {
+ StringBuilder buffer = new StringBuilder();
+ Node node = first;
+ while (node != null) {
+ buffer
+ .append(node.debug())
+ .append("\n##########################last: ")
+ .append(last)
+ .append("\n##########################capacity: ")
+ .append(capacity)
+ .append("\n##########################toString: ")
+ .append(toString())
+
+ ;
+
+ node = node.next;
+ if (node != null) {
+ buffer.append("\n,");
+ }
+ }
+ return buffer.toString() + "\n";
+ }
+
+
+}
diff --git a/students/1204187480/code/homework/coding/src/main/java/com/coding/basic/linklist/LRUPageFrameTest.java b/students/1204187480/code/homework/coding/src/main/java/com/coding/basic/linklist/LRUPageFrameTest.java
new file mode 100644
index 0000000000..7fd72fc2b4
--- /dev/null
+++ b/students/1204187480/code/homework/coding/src/main/java/com/coding/basic/linklist/LRUPageFrameTest.java
@@ -0,0 +1,34 @@
+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/1204187480/code/homework/coding/src/main/java/com/coding/basic/linklist/LinkedList.java b/students/1204187480/code/homework/coding/src/main/java/com/coding/basic/linklist/LinkedList.java
new file mode 100644
index 0000000000..d9c4ee3c7b
--- /dev/null
+++ b/students/1204187480/code/homework/coding/src/main/java/com/coding/basic/linklist/LinkedList.java
@@ -0,0 +1,351 @@
+package com.coding.basic.linklist;
+
+import com.coding.basic.Iterator;
+import com.coding.basic.List;
+
+public class LinkedList implements List {
+
+ private Node head;
+ private int size = 0;
+
+ public void add(Object o) {
+ Node newNode = new Node(o, null);
+ if (head == null) {
+ head = newNode;
+ } else {
+ node(size - 1).next = newNode;
+ }
+ size++;
+ }
+
+ public void add(int index, Object o) {
+ checkForAdd(index);
+ if (index == size) {
+ add(o);
+ } else {
+ Node newNode = new Node(o, null);
+ if (index == 0) {
+ addFirst(o);
+ } else {
+ Node preNode = node(index - 1);
+ Node now = preNode.next;
+ preNode.next = newNode;
+ newNode.next = now;
+ size++;
+ }
+ }
+
+ }
+
+ private Node node(int index) {
+ Node x = head;
+ for (int i = 0; i < index; i++) {
+ x = x.next;
+ }
+ return x;
+ }
+
+ public Object get(int index) {
+ checkIndex(index);
+ return node(index).data;
+ }
+
+ /**
+ * 让被删除的引用的持有者指向下一个节点
+ *
+ * @param index
+ * @return
+ */
+ public Object remove(int index) {
+ final Object ret;
+ checkIndex(index);
+ if (index == 0) {
+ Node removeNode = head;
+ ret = head.data;
+ head = removeNode.next;
+ } else {
+ Node pre = node(index - 1);
+ Node removeNode = pre.next;
+ ret = removeNode.data;
+ pre.next = removeNode.next;
+ }
+ size--;
+ return ret;
+ }
+
+ public int size() {
+ return size;
+ }
+
+ public void addFirst(Object o) {
+ head = new Node(o, head);
+ ;
+ size++;
+ }
+
+ public void addLast(Object o) {
+ add(o);
+ }
+
+ public Object removeFirst() {
+ if (size == 0) {
+ return null;
+ } else {
+ return remove(0);
+ }
+ }
+
+ public Object removeLast() {
+ return remove(size - 1);
+ }
+
+ public LinkedListIterator iterator() {
+ return new LinkedListIterator(head);
+ }
+
+ private void checkIndex(int index) {
+ if (index < 0 || index >= size) {
+ throw new ArrayIndexOutOfBoundsException(String.format("index=%s, size=%s", index, size));
+ }
+ }
+
+ private void checkForAdd(int index) {
+ if (index < 0 || index > size) {
+ throw new ArrayIndexOutOfBoundsException(String.format("index=%s, size=%s", index, size));
+ }
+ }
+
+
+ @Override
+ public String toString() {
+ Iterator iterator = iterator();
+ StringBuilder builder = new StringBuilder("[");
+ while ((iterator.hasNext())) {
+ builder.append(iterator.next()).append(',');
+ }
+ if (size() > 0) {
+ builder.deleteCharAt(builder.length() - 1);
+ }
+ return builder
+ .append(']')
+ .toString();
+ }
+
+ /**
+ * 把该链表逆置
+ * 例如链表为 3->7->10 , 逆置后变为 10->7->3
+ */
+ public void reverse() {
+ if (size == 0) {
+ return;
+ }
+ Object[] datas = new Object[size];
+ int i = 0;
+ // 迭代链表的数据生成数组
+ Iterator iterator = iterator();
+ while (iterator.hasNext()) {
+ datas[i++] = iterator.next();
+ }
+ // 遍历数组越生成新的 链表
+ Node newHead = new Node(datas[--i], null);
+ Node next = newHead;
+ for (int j = --i; j >= 0; j--) {
+ next.next = new Node(datas[j], null);
+ next = next.next;
+
+ }
+ this.head = newHead;
+
+ }
+
+ /**
+ * 删除一个单链表的前半部分
+ * 例如:list = 2->5->7->8 , 删除以后的值为 7->8
+ * 如果list = 2->5->7->8->10 ,删除以后的值为7,8,10
+ */
+ public void removeFirstHalf() {
+ removeFirstSize(size >> 1);
+ }
+
+ public void removeFirstSize(int firstSize) {
+ firstSize = firstSize > size() ? size() : firstSize;
+ LinkedListIterator iterator = iterator();
+ int i = 1;
+ while (i++ <= firstSize) {
+ iterator.nextNode();
+ }
+ if (size > 0) {
+ head = iterator.nextNode();
+ size = size() - firstSize;
+ }
+ }
+
+
+ /**
+ * 从第i个元素开始, 删除length 个元素 , 注意i从0开始
+ *
+ * @param i
+ * @param length
+ */
+ public void remove(int i, int length) {
+ if (i == 0) {
+ removeFirstSize(length);
+ return;
+ }
+ if (i >= size || length == 0) {
+ return;
+ }
+
+ int lastLenth = size - i;
+ length = length <= lastLenth ? length : lastLenth;
+ Node pre = node(i - 1);
+ int j = 0;
+
+ Node next = pre;
+ while (j++ < length) {
+ next = next.next;
+ }
+ pre.next = next.next;
+ size = size - 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) {
+ if (size() == 0) {
+ return new int[0];
+ }
+ Iterator iterator = list.iterator();
+ Node fromNode = iterator().nextNode();
+ int fromIndex = 0;
+
+ int[] retArray = new int[list.size()];
+ int retIndex = 0;
+ while (iterator.hasNext()) {
+ int index = (int) iterator.next();
+ Node node = node(fromNode, fromIndex, index);
+ fromIndex = index;
+ fromNode = node;
+ if (node == null) {
+ return retArray;
+ } else {
+ retArray[retIndex++] = (int)node.data;
+ }
+ }
+ return retArray;
+ }
+
+ private Node node(Node fromNode, int fromIndex, int index) {
+ Node next = fromNode;
+ int nextIndex = fromIndex;
+ while (next != null && nextIndex < index) {
+ next = next.next;
+ nextIndex++;
+ }
+ if (nextIndex == index) {
+ return next;
+ } else {
+ 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;
+ }
+
+ private static class Node {
+ Object data;
+ Node next;
+
+ public Node() {
+ }
+
+ public Node(Object data, Node next) {
+ this.data = data;
+ this.next = next;
+ }
+ }
+
+ private class LinkedListIterator implements Iterator {
+
+ private Node next;
+
+ public LinkedListIterator() {
+ }
+
+ private LinkedListIterator(Node next) {
+ this.next = next;
+ }
+
+ @Override
+ public boolean hasNext() {
+ return next != null;
+ }
+
+ @Override
+ public Object next() {
+ if (next == null) {
+ throw new IndexOutOfBoundsException("there is no node in list");
+ }
+ Node ret = next;
+ next = next.next;
+ return ret.data;
+ }
+
+
+ private Node nextNode() {
+ if (next == null) {
+ throw new IndexOutOfBoundsException("there is no node in list");
+ }
+ Node ret = next;
+ next = next.next;
+ return ret;
+ }
+ }
+}
diff --git a/students/1204187480/code/homework/coding/src/test/java/com/coding/api/ArraysTest.java b/students/1204187480/code/homework/coding/src/test/java/com/coding/api/ArraysTest.java
new file mode 100644
index 0000000000..eb41a7e262
--- /dev/null
+++ b/students/1204187480/code/homework/coding/src/test/java/com/coding/api/ArraysTest.java
@@ -0,0 +1,22 @@
+package com.coding.api;
+
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.Arrays;
+
+/**
+ * Created by luoziyihao on 2/25/17.
+ */
+public class ArraysTest {
+ private final Logger logger = LoggerFactory.getLogger(this.getClass());
+
+
+ @Test
+ public void testCopyOf(){
+ Object[] a = new Object[]{1, 2, 3, 4};
+ Object[] b = Arrays.copyOf(a, 10);
+ logger.info("a={}, b={}", Arrays.toString(a), Arrays.toString(b));
+ }
+}
diff --git a/students/1204187480/code/homework/coding/src/test/java/com/coding/api/SystemTest.java b/students/1204187480/code/homework/coding/src/test/java/com/coding/api/SystemTest.java
new file mode 100644
index 0000000000..efc4022378
--- /dev/null
+++ b/students/1204187480/code/homework/coding/src/test/java/com/coding/api/SystemTest.java
@@ -0,0 +1,24 @@
+package com.coding.api;
+
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.Arrays;
+
+/**
+ * Created by luoziyihao on 2/25/17.
+ */
+public class SystemTest {
+
+ private final Logger logger = LoggerFactory.getLogger(this.getClass());
+
+ @Test
+ public void testArrayCopy() {
+ int[] a = new int[]{1, 2, 3, 4, 5, 6, 7};
+ int[] b = new int[]{11, 22, 33, 44, 55, 66, 77};
+ System.arraycopy(a, 2, b, 4, 3);
+ logger.info("b={}", Arrays.toString(b));
+
+ }
+}
diff --git a/students/1204187480/code/homework/coding/src/test/java/com/coding/basic/LinkedListTest.java b/students/1204187480/code/homework/coding/src/test/java/com/coding/basic/LinkedListTest.java
new file mode 100644
index 0000000000..9e951354ef
--- /dev/null
+++ b/students/1204187480/code/homework/coding/src/test/java/com/coding/basic/LinkedListTest.java
@@ -0,0 +1,202 @@
+package com.coding.basic;
+
+import com.coding.basic.linklist.LinkedList;
+import org.junit.Assert;
+import org.junit.Test;
+
+import java.util.Arrays;
+
+/**
+ * Created by luoziyihao on 3/23/17.
+ */
+public class LinkedListTest {
+
+ @Test
+ public void add() throws Exception {
+
+ }
+
+ @Test
+ public void add1() throws Exception {
+
+ }
+
+ @Test
+ public void get() throws Exception {
+
+ }
+
+ @Test
+ public void remove() throws Exception {
+
+ }
+
+ @Test
+ public void size() throws Exception {
+
+ }
+
+ @Test
+ public void addFirst() throws Exception {
+
+ }
+
+ @Test
+ public void addLast() throws Exception {
+
+ }
+
+ @Test
+ public void removeFirst() throws Exception {
+
+ }
+
+ @Test
+ public void removeLast() throws Exception {
+
+ }
+
+ @Test
+ public void removeFirstHalf() throws Exception {
+ LinkedList linkedList = createAndFillLinkedList(0);
+ linkedList.removeFirstHalf();
+ Assert.assertEquals("[]", linkedList.toString());
+ }
+
+ @Test
+ public void removeFirstHalf1() throws Exception {
+ LinkedList linkedList = createAndFillLinkedList(1);
+ linkedList.removeFirstHalf();
+ Assert.assertEquals("[1]", linkedList.toString());
+ }
+
+ @Test
+ public void removeFirstHalf2() throws Exception {
+ LinkedList linkedList = createAndFillLinkedList(2);
+ linkedList.removeFirstHalf();
+ Assert.assertEquals("[2]", linkedList.toString());
+ }
+
+ @Test
+ public void removeFirstHalf3() throws Exception {
+ LinkedList linkedList = createAndFillLinkedList(3);
+ linkedList.removeFirstHalf();
+ Assert.assertEquals("[2,3]", linkedList.toString());
+ }
+
+ private LinkedList createAndFillLinkedList() {
+ return createAndFillLinkedList(4);
+ }
+
+ private LinkedList createAndFillLinkedList(int length) {
+ return createAndFillLinkedList(1, length);
+ }
+
+ private LinkedList createAndFillLinkedList(int start, int length) {
+ LinkedList linkedList = new LinkedList();
+ for (int i = start; i <= length; i++) {
+ linkedList.add(i);
+ }
+ return linkedList;
+ }
+
+ @Test
+ public void remove1() throws Exception {
+ LinkedList list = createAndFillLinkedList(4);
+ list.remove(0, 0);
+ Assert.assertEquals("[1,2,3,4]", list.toString());
+ }
+
+ @Test
+ public void remove2() throws Exception {
+ LinkedList list = createAndFillLinkedList(4);
+ list.remove(0, 1);
+ Assert.assertEquals("[2,3,4]", list.toString());
+ }
+
+ @Test
+ public void remove3() throws Exception {
+ LinkedList list = createAndFillLinkedList(4);
+ list.remove(1, 0);
+ Assert.assertEquals("[1,2,3,4]", list.toString());
+ }
+
+ @Test
+ public void remove4() throws Exception {
+ LinkedList list = createAndFillLinkedList(4);
+ list.remove(1, 1);
+ Assert.assertEquals("[1,3,4]", list.toString());
+ }
+
+ @Test
+ public void remove5() throws Exception {
+ LinkedList list = createAndFillLinkedList(4);
+ list.remove(1, 3);
+ Assert.assertEquals("[1]", list.toString());
+ }
+
+ @Test
+ public void remove6() throws Exception {
+ LinkedList list = createAndFillLinkedList(4);
+ list.remove(1, 4);
+ Assert.assertEquals("[1]", list.toString());
+ }
+
+ @Test
+ public void remove7() throws Exception {
+ LinkedList list = createAndFillLinkedList(4);
+ list.remove(1, 5);
+ Assert.assertEquals("[1]", list.toString());
+ }
+
+ @Test
+ public void getElements() throws Exception {
+// LinkedList listA = createAndFillLinkedList(0, 8);
+// LinkedList listB = createAndFillLinkedList(4, 4);
+// Assert.assertEquals("[4,5,6,7]", Arrays.toString(listA.getElements(listB)));
+
+ }
+
+ @Test
+ public void subtract() throws Exception {
+
+ }
+
+ @Test
+ public void removeDuplicateValues() throws Exception {
+
+ }
+
+ @Test
+ public void removeRange() throws Exception {
+
+ }
+
+ @Test
+ public void intersection() throws Exception {
+
+ }
+
+ @Test
+ public void iterator() throws Exception {
+
+ List linkedList = new LinkedList();
+ linkedList.add("1");
+ linkedList.add("2");
+ linkedList.add("3");
+ linkedList.add("4");
+ Assert.assertEquals("[1,2,3,4]", linkedList.toString());
+ }
+
+ @Test
+ public void reverse() throws Exception {
+ LinkedList linkedList = new LinkedList();
+ linkedList.add("1");
+ linkedList.add("2");
+ linkedList.add("3");
+ linkedList.add("4");
+ linkedList.reverse();
+ Assert.assertEquals("[4,3,2,1]", linkedList.toString());
+ }
+
+}
\ No newline at end of file
diff --git a/students/1204187480/code/homework/coding/src/test/java/com/coding/basic/array/ArrayListTest.java b/students/1204187480/code/homework/coding/src/test/java/com/coding/basic/array/ArrayListTest.java
new file mode 100644
index 0000000000..e70c52a725
--- /dev/null
+++ b/students/1204187480/code/homework/coding/src/test/java/com/coding/basic/array/ArrayListTest.java
@@ -0,0 +1,37 @@
+package com.coding.basic.array;
+
+import com.coding.basic.List;
+import com.coding.basic.array.ArrayList;
+import org.junit.Before;
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+/**
+ * Created by luoziyihao on 2/25/17.
+ */
+public class ArrayListTest {
+
+ private final Logger logger = LoggerFactory.getLogger(this.getClass());
+
+
+ private List list = new ArrayList();
+
+ @Before
+ public void before() {
+
+ }
+
+ @Test
+ public void add() throws Exception {
+ list.add(1);
+ }
+
+ @Test
+ public void get() throws Exception {
+ add();
+ logger.info("{}", list.get(0));
+ }
+
+}
\ No newline at end of file
diff --git a/students/1204187480/code/homework/coding/src/test/java/com/coding/basic/array/ArrayUtilTest.java b/students/1204187480/code/homework/coding/src/test/java/com/coding/basic/array/ArrayUtilTest.java
new file mode 100644
index 0000000000..04c8b51547
--- /dev/null
+++ b/students/1204187480/code/homework/coding/src/test/java/com/coding/basic/array/ArrayUtilTest.java
@@ -0,0 +1,76 @@
+package com.coding.basic.array;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import java.util.Arrays;
+
+import static org.junit.Assert.*;
+
+/**
+ * Created by luoziyihao on 3/5/17.
+ */
+public class ArrayUtilTest {
+
+ private ArrayUtil creatArrayUtil(){
+ return new ArrayUtil();
+ }
+
+ @Test
+ public void reverseArray() throws Exception {
+ int[] origin = new int[]{1, 2, 3};
+ int[] destArray = new int[]{3, 2, 1};
+ creatArrayUtil().reverseArray(origin);
+ Assert.assertArrayEquals(destArray, origin);
+ }
+
+ @Test
+ public void removeZero() throws Exception {
+ int[] origin = new int[]{1, 2, 3, 0, 10};
+ int[] destArray = new int[]{1, 2, 3, 10};
+ int[] retArray = creatArrayUtil().removeZero(origin);
+ Assert.assertArrayEquals(destArray, retArray);
+ }
+
+ @Test
+ public void merge() throws Exception {
+ int[] a = new int[]{1, 2, 3};
+ int[] b = new int[]{2, 3};
+
+ int[] newArray = creatArrayUtil().merge(a, b);
+ info(newArray);
+ assertArrayEquals(new int[]{1, 2, 3}, newArray);
+ }
+
+ @Test
+ public void grow() throws Exception {
+ assertArrayEquals(new int[]{1, 2, 0, 0}, creatArrayUtil().grow(new int[]{1, 2}, 2));
+ }
+
+ @Test
+ public void fibonacci() throws Exception {
+ assertArrayEquals(new int[]{1, 1, 2, 3, 5, 8}, creatArrayUtil().fibonacci(10));
+ }
+
+ @Test
+ public void getPrimes() throws Exception {
+ int max = Double.valueOf(Math.pow(2, 4)).intValue();
+ assertArrayEquals(new int[]{2, 3, 5, 7, 11, 13}, creatArrayUtil().getPrimes(max));
+ }
+
+ @Test
+ public void getPerfectNumbers() throws Exception {
+ int max = Double.valueOf(Math.pow(2, 8)).intValue();
+ assertArrayEquals(new int[]{6, 28}, creatArrayUtil().getPerfectNumbers(max));
+
+ }
+
+ @Test
+ public void join() throws Exception {
+ assertEquals("1_2_3_10", creatArrayUtil().join(new int[]{1, 2, 3, 10}, "_"));
+ }
+
+ private void info(int[] array) {
+ System.out.println(Arrays.toString(array));
+ }
+}
\ No newline at end of file
diff --git a/students/1204187480/code/homework/common/pom.xml b/students/1204187480/code/homework/common/pom.xml
new file mode 100644
index 0000000000..3cbad444b6
--- /dev/null
+++ b/students/1204187480/code/homework/common/pom.xml
@@ -0,0 +1,13 @@
+
+ 4.0.0
+ common
+ jar
+
+ com.coding
+ parent-dependencies
+ 1.0-SNAPSHOT
+ ../parent-dependencies/pom.xml
+
+
+
\ No newline at end of file
diff --git a/students/1204187480/code/homework/common/src/main/java/com/coding/common/util/BeanUtils.java b/students/1204187480/code/homework/common/src/main/java/com/coding/common/util/BeanUtils.java
new file mode 100755
index 0000000000..67dd8fd1f1
--- /dev/null
+++ b/students/1204187480/code/homework/common/src/main/java/com/coding/common/util/BeanUtils.java
@@ -0,0 +1,144 @@
+package com.coding.common.util;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.math.BigDecimal;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * Created by luoziyihao on 5/25/16.
+ */
+public class BeanUtils {
+
+
+ public static final String SET = "set";
+ public static final String GET = "get";
+ // 日志输出类
+ private final Logger log = LoggerFactory.getLogger(this.getClass());
+ private final StringUtils2 stringUtils = new StringUtils2();
+
+ public Object setInvoke(Object para, String methodName, Object obj) {
+ Method method = null;
+ Object returnObj = null;
+ try {
+
+ method = obj.getClass().getMethod(methodName, para.getClass());
+ returnObj = method.invoke(obj, para);
+ } catch (Exception e) {
+ log.error(e.getMessage(), e);
+ }
+ return returnObj;
+ }
+
+ public Object getInvoke(String methodName, Object obj) {
+ Method method = null;
+ Object returnObj = null;
+ try {
+ method = obj.getClass().getMethod(methodName);
+ returnObj = method.invoke(obj);
+ } catch (Exception e) {
+ log.error(e.getMessage(), e);
+ }
+ return returnObj;
+ }
+
+ public Object invokeWithNoParamter(String methodName, Object obj) {
+ Method method;
+ Object returnObj = null;
+ try {
+ method = obj.getClass().getMethod(methodName);
+ returnObj = method.invoke(obj);
+ } catch (Exception e) {
+ log.error(e.getMessage(), e);
+ }
+ return returnObj;
+ }
+
+
+
+ public Object getPara(String paraName, Object object) {
+ if (stringUtils.isSpaceOrNull(paraName)) {
+ throw new RuntimeException("paraname is null or space");
+ }
+ String methodName = new StringBuilder().append(GET).append(stringUtils.toUpperCase(paraName, 0)).toString();
+ return getInvoke(methodName, object);
+ }
+
+
+
+ public Object setPara(Object para, String paraName, Object object) {
+ if (stringUtils.isSpaceOrNull(paraName)) {
+ throw new RuntimeException("paraname is null or space");
+ }
+ String methodName = new StringBuilder().append(SET).append(stringUtils.toUpperCase(paraName, 0)).toString();
+ return setInvoke(para, methodName, object);
+ }
+
+ public T get(String paraName, Object object, Class clazz) {
+ return (T) getPara(paraName, object);
+ }
+
+ public Integer getInt(String paraName, Object object) {
+ return (Integer) getPara(paraName, object);
+ }
+
+ public Long getLong(String paraName, Object object) {
+ return (Long) getPara(paraName, object);
+ }
+
+ public Double getDouble(String paraName, Object object) {
+ return (Double) getPara(paraName, object);
+ }
+
+ public BigDecimal getBigDecimal(String paraName, Object object) {
+ return (BigDecimal) getPara(paraName, object);
+ }
+
+ public String getString(String paraName, Object object) {
+ return getPara(paraName, object).toString();
+ }
+
+ public Date getDate(String paraName, Object object) {
+ return (Date) getPara(paraName, object);
+ }
+
+ public Long getLongByString(String paraName, Object object) {
+ return Long.parseLong(getString(paraName, object));
+ }
+
+ public Integer getIntByString(String paraName, Object object) {
+ return Integer.parseInt(getString(paraName, object));
+ }
+
+ public Double getDoubleByString(String paraName, Object object) {
+ return Double.parseDouble(getString(paraName, object));
+ }
+
+ public BigDecimal getBigDecimalByString(String paraName, Object object) {
+ return new BigDecimal(getString(paraName, object));
+ }
+
+ private final static String GETTER_PRE = "get";
+ public Map describe(Object model) {
+ Method[] methods = model.getClass().getDeclaredMethods(); //获取实体类的所有属性,返回Field数组
+ Map properties = new HashMap<>();
+ for (Method method : methods) {
+ String methodName = method.getName();
+ if (methodName.startsWith(GETTER_PRE)) {
+ try {
+ Object o = method.invoke(model);
+ String valueName = stringUtils.toLowwerCase(methodName.substring(GETTER_PRE.length()), 0);
+ properties.put(valueName, o);
+ } catch (IllegalAccessException | InvocationTargetException e) {
+ throw new IllegalStateException(e);
+ }
+ }
+ }
+ return properties;
+ }
+}
diff --git a/students/1204187480/code/homework/common/src/main/java/com/coding/common/util/ByteUtils.java b/students/1204187480/code/homework/common/src/main/java/com/coding/common/util/ByteUtils.java
new file mode 100644
index 0000000000..4126765ff1
--- /dev/null
+++ b/students/1204187480/code/homework/common/src/main/java/com/coding/common/util/ByteUtils.java
@@ -0,0 +1,21 @@
+package com.coding.common.util;
+
+/**
+ * Created by luoziyihao on 5/2/17.
+ */
+public abstract class ByteUtils {
+
+ public static String byteToHexString(byte[] codes ){
+ StringBuffer buffer = new StringBuffer();
+ for(int i=0;i listAllFiles(File directory) {
+ Preconditions.checkNotNull(directory);
+ Preconditions.checkArgument(directory.isDirectory()
+ , "file=%s is not directory", directory.getPath());
+ return listAllFiles(new ArrayList<>(), directory);
+ }
+
+ private static List listAllFiles(List files, File directory) {
+ File[] fileArr = directory.listFiles();
+ if (fileArr == null) {
+ return files;
+ }
+ for (File file : fileArr) {
+ if (file.isDirectory()) {
+ files = listAllFiles(files, file);
+ } else {
+ files.add(file);
+ }
+ }
+ return files;
+ }
+
+
+ public static String getCanonicalPath(File file) {
+ Preconditions.checkNotNull(file);
+ try {
+ return file.getCanonicalPath();
+ } catch (IOException e) {
+ throw new IllegalStateException(e);
+ }
+ }
+
+
+ public static byte[] getBytes(File classFile) throws IllegalStateException {
+ // byteArrayOutputStream, 可写的动长数组
+ ByteArrayOutputStream baos = null;
+ BufferedInputStream bis = null;
+ try {
+ baos = new ByteArrayOutputStream();
+ bis = new BufferedInputStream(new FileInputStream(classFile));
+ int intTmp = bis.read();
+ while (intTmp != -1) {
+ baos.write(intTmp);
+ intTmp = bis.read();
+ }
+ return baos.toByteArray();
+ } catch (IOException e) {
+ throw new IllegalStateException(e);
+ } finally {
+ IOUtils2.close(baos);
+ IOUtils2.close(bis);
+ }
+ }
+
+
+}
diff --git a/students/1204187480/code/homework/common/src/main/java/com/coding/common/util/IOUtils2.java b/students/1204187480/code/homework/common/src/main/java/com/coding/common/util/IOUtils2.java
new file mode 100644
index 0000000000..a302a6c199
--- /dev/null
+++ b/students/1204187480/code/homework/common/src/main/java/com/coding/common/util/IOUtils2.java
@@ -0,0 +1,24 @@
+package com.coding.common.util;
+
+import java.io.Closeable;
+import java.io.IOException;
+import java.io.OutputStream;
+
+/**
+ * Created by luoziyihao on 5/2/17.
+ */
+public abstract class IOUtils2 {
+
+ public static void close(Closeable closeable) {
+ if (closeable != null) {
+ try {
+ closeable.close();
+ } catch (IOException e) {
+ throw new IllegalStateException(e);
+
+ }
+ }
+ }
+
+
+}
diff --git a/students/1204187480/code/homework/common/src/main/java/com/coding/common/util/StringUtils2.java b/students/1204187480/code/homework/common/src/main/java/com/coding/common/util/StringUtils2.java
new file mode 100644
index 0000000000..0883351690
--- /dev/null
+++ b/students/1204187480/code/homework/common/src/main/java/com/coding/common/util/StringUtils2.java
@@ -0,0 +1,34 @@
+package com.coding.common.util;
+
+/**
+ * Created by luoziyihao on 3/5/17.
+ */
+public class StringUtils2 {
+
+ /**
+ * 改变指定位置的 char的大小写
+ */
+ public String toUpperCase(String str, int index) {
+ char[] chars = str.toCharArray();
+ if (index + 1 > chars.length) {
+ throw new RuntimeException("the char at the index don't exist");
+ }
+ chars[index] = Character.toUpperCase(chars[index]);
+ return new String(chars);
+ }
+
+ /**
+ * 改变指定位置的 char的大小写
+ */
+ public String toLowwerCase(String str, int index) {
+ char[] chars = str.toCharArray();
+ if (index + 1 > chars.length ) {throw new RuntimeException("the char at the index don't exist");}
+ chars[index] = Character.toLowerCase(chars[index]);
+ return new String(chars);
+ }
+
+ public boolean isSpaceOrNull(String paraName) {
+ return (paraName == null || paraName.trim().isEmpty());
+ }
+
+}
diff --git a/students/1204187480/code/homework/common/src/test/java/com/coding/api/ArraysTest.java b/students/1204187480/code/homework/common/src/test/java/com/coding/api/ArraysTest.java
new file mode 100644
index 0000000000..eb41a7e262
--- /dev/null
+++ b/students/1204187480/code/homework/common/src/test/java/com/coding/api/ArraysTest.java
@@ -0,0 +1,22 @@
+package com.coding.api;
+
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.Arrays;
+
+/**
+ * Created by luoziyihao on 2/25/17.
+ */
+public class ArraysTest {
+ private final Logger logger = LoggerFactory.getLogger(this.getClass());
+
+
+ @Test
+ public void testCopyOf(){
+ Object[] a = new Object[]{1, 2, 3, 4};
+ Object[] b = Arrays.copyOf(a, 10);
+ logger.info("a={}, b={}", Arrays.toString(a), Arrays.toString(b));
+ }
+}
diff --git a/students/1204187480/code/homework/common/src/test/java/com/coding/api/SystemTest.java b/students/1204187480/code/homework/common/src/test/java/com/coding/api/SystemTest.java
new file mode 100644
index 0000000000..efc4022378
--- /dev/null
+++ b/students/1204187480/code/homework/common/src/test/java/com/coding/api/SystemTest.java
@@ -0,0 +1,24 @@
+package com.coding.api;
+
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.Arrays;
+
+/**
+ * Created by luoziyihao on 2/25/17.
+ */
+public class SystemTest {
+
+ private final Logger logger = LoggerFactory.getLogger(this.getClass());
+
+ @Test
+ public void testArrayCopy() {
+ int[] a = new int[]{1, 2, 3, 4, 5, 6, 7};
+ int[] b = new int[]{11, 22, 33, 44, 55, 66, 77};
+ System.arraycopy(a, 2, b, 4, 3);
+ logger.info("b={}", Arrays.toString(b));
+
+ }
+}
diff --git a/students/1204187480/code/homework/common/src/test/java/com/coding/common/util/ByteUtilsTest.java b/students/1204187480/code/homework/common/src/test/java/com/coding/common/util/ByteUtilsTest.java
new file mode 100644
index 0000000000..62dd4907cc
--- /dev/null
+++ b/students/1204187480/code/homework/common/src/test/java/com/coding/common/util/ByteUtilsTest.java
@@ -0,0 +1,20 @@
+package com.coding.common.util;
+
+import org.junit.Test;
+
+/**
+ * Created by luoziyihao on 5/2/17.
+ */
+public class ByteUtilsTest {
+
+ @Test
+ public void testByteToHexString(){
+ byte[] bytes = new byte[]{
+ 1,
+ (byte) 255
+ };
+ System.out.println(ByteUtils.byteToHexString(bytes));
+ System.out.println(Integer.toHexString(255));
+ }
+
+}
\ No newline at end of file
diff --git a/students/1204187480/code/homework/common/src/test/java/com/coding/common/util/FileUtils2Test.java b/students/1204187480/code/homework/common/src/test/java/com/coding/common/util/FileUtils2Test.java
new file mode 100644
index 0000000000..cb58cf99c5
--- /dev/null
+++ b/students/1204187480/code/homework/common/src/test/java/com/coding/common/util/FileUtils2Test.java
@@ -0,0 +1,35 @@
+package com.coding.common.util;
+
+import org.junit.Test;
+
+import java.io.File;
+import java.util.List;
+
+/**
+ * Created by luoziyihao on 4/28/17.
+ */
+public class FileUtils2Test {
+ @Test
+ public void getCanonicalPath() throws Exception {
+ System.out.println(FileUtils2.getCanonicalPath(new File("")));
+ }
+
+ @Test
+ public void getBytes() throws Exception {
+ byte[] bytes = FileUtils2.getBytes(new File("pom.xml"));
+ System.out.println(new String(bytes));
+ System.out.println(ByteUtils.byteToHexString(bytes));
+
+ }
+
+
+ @Test
+ public void listAllFiles() throws Exception {
+ String currentPath = new File("").getCanonicalPath();
+ List files = FileUtils2.listAllFiles(new File(currentPath ));
+ for (File file : files) {
+ System.out.println(file.getCanonicalPath());
+ }
+ }
+
+}
\ No newline at end of file
diff --git a/students/1204187480/code/homework/parent-dependencies/pom.xml b/students/1204187480/code/homework/parent-dependencies/pom.xml
new file mode 100644
index 0000000000..b961e90c59
--- /dev/null
+++ b/students/1204187480/code/homework/parent-dependencies/pom.xml
@@ -0,0 +1,169 @@
+
+ 4.0.0
+
+ com.coding
+ parent-dependencies
+ pom
+ 1.0-SNAPSHOT
+ https://github.com/luoziyihao/coding2017
+
+
+
+ alimaven
+ aliyun maven
+ http://maven.aliyun.com/nexus/content/groups/public/
+
+ true
+
+
+ true
+
+
+
+
+
+ alimaven
+ aliyun maven
+ http://maven.aliyun.com/nexus/content/groups/public/
+
+ true
+
+
+ true
+
+
+
+ spring-snapshots
+ Spring Snapshots
+ https://repo.spring.io/libs-snapshot
+
+ true
+
+
+
+
+
+
+ UTF-8
+ UTF-8
+ 1.8
+ UTF-8
+ 1.8
+ 1.8
+ 3.0
+ 1.1.7
+ 1.1.7
+ 1.2
+ 1.2.17
+ 4.12
+ 3.4
+ 4.1
+ 2.5
+ 1.9.2
+ 19.0
+ 1.1.6
+ 1.16.10
+ 1.2.22
+ 0.2.0
+ 2.9.4
+
+
+
+
+
+
+ ch.qos.logback
+ logback-classic
+ ${logback-classic.version}
+
+
+
+ commons-logging
+ commons-logging
+ ${commons-logging.version}
+
+
+ log4j
+ log4j
+ ${log4j.version}
+
+
+
+
+ org.apache.commons
+ commons-lang3
+ ${commons-lang3.version}
+
+
+ org.apache.commons
+ commons-collections4
+ ${commons-collections4.version}
+
+
+ commons-io
+ commons-io
+ ${commons-io.version}
+
+
+ commons-beanutils
+ commons-beanutils
+ ${commons-beanutils.version}
+
+
+ com.google.guava
+ guava
+ ${guava.version}
+
+
+ org.projectlombok
+ lombok
+ ${lombok.version}
+
+
+ joda-time
+ joda-time
+ ${joda-time.version}
+
+
+ io.reactivex
+ rxjava
+ ${rxjava.version}
+
+
+ com.alibaba
+ fastjson
+ ${fastjson.version}
+
+
+ com.shekhargulati
+ strman
+ ${strman.version}
+
+
+
+
+
+ junit
+ junit
+ ${junit.version}
+
+
+
+
+ ${project.artifactId}
+
+
+
+ org.apache.maven.plugins
+ maven-compiler-plugin
+ ${maven-compiler-plugin.version}
+
+ ${maven.compiler.source}
+ ${maven.compiler.target}
+
+
+
+
+
+
\ No newline at end of file
diff --git a/students/1204187480/code/homework/parent/pom.xml b/students/1204187480/code/homework/parent/pom.xml
new file mode 100644
index 0000000000..e6a94a2e4f
--- /dev/null
+++ b/students/1204187480/code/homework/parent/pom.xml
@@ -0,0 +1,23 @@
+
+
+ 4.0.0
+ parent
+ pom
+ manage the dependencies for modules
+
+ com.coding
+ parent-dependencies
+ 1.0-SNAPSHOT
+ ../parent-dependencies/pom.xml
+
+
+
+
+ com.coding
+ common
+ 1.0-SNAPSHOT
+
+
+
+
\ No newline at end of file
diff --git a/students/1204187480/code/homework/pom.xml b/students/1204187480/code/homework/pom.xml
new file mode 100644
index 0000000000..28ac74f159
--- /dev/null
+++ b/students/1204187480/code/homework/pom.xml
@@ -0,0 +1,18 @@
+
+
+ 4.0.0
+ com.coding
+ coding2017
+ 1.0-SNAPSHOT
+ pom
+
+ parent-dependencies
+ common
+ parent
+ coding
+ coderising
+
+
+
+
diff --git "a/students/1204187480/note/homework/cpu, \345\206\205\345\255\230, \347\243\201\347\233\230, \346\214\207\344\273\244-\346\274\253\350\260\210\350\256\241\347\256\227\346\234\272" "b/students/1204187480/note/homework/cpu, \345\206\205\345\255\230, \347\243\201\347\233\230, \346\214\207\344\273\244-\346\274\253\350\260\210\350\256\241\347\256\227\346\234\272"
new file mode 100644
index 0000000000..e69de29bb2
diff --git a/students/1204187480/note/todo/homework.md b/students/1204187480/note/todo/homework.md
new file mode 100644
index 0000000000..5f111a9ea6
--- /dev/null
+++ b/students/1204187480/note/todo/homework.md
@@ -0,0 +1,8 @@
+# 0326 操作系统中的lru算法
+
+ClassFileLoader
+
+LRUPageFrame
+
+深入理解java虚拟机 第6章
+
From f0447b8a16bbe95a71ffc12e1970ef8c8d1a20c1 Mon Sep 17 00:00:00 2001
From: luoziyihao
Date: Mon, 12 Jun 2017 21:53:50 +0800
Subject: [PATCH 015/436] add ood src:
---
.../com/coderising/ood/srp/Configuration.java | 23 ++
.../coderising/ood/srp/ConfigurationKeys.java | 9 +
.../java/com/coderising/ood/srp/DBUtil.java | 25 +++
.../java/com/coderising/ood/srp/MailUtil.java | 18 ++
.../com/coderising/ood/srp/PromotionMail.java | 199 ++++++++++++++++++
.../src/main/resources/product_promotion.txt | 4 +
6 files changed, 278 insertions(+)
create mode 100644 students/1204187480/code/homework/coderising/src/main/java/com/coderising/ood/srp/Configuration.java
create mode 100644 students/1204187480/code/homework/coderising/src/main/java/com/coderising/ood/srp/ConfigurationKeys.java
create mode 100644 students/1204187480/code/homework/coderising/src/main/java/com/coderising/ood/srp/DBUtil.java
create mode 100644 students/1204187480/code/homework/coderising/src/main/java/com/coderising/ood/srp/MailUtil.java
create mode 100644 students/1204187480/code/homework/coderising/src/main/java/com/coderising/ood/srp/PromotionMail.java
create mode 100644 students/1204187480/code/homework/coderising/src/main/resources/product_promotion.txt
diff --git a/students/1204187480/code/homework/coderising/src/main/java/com/coderising/ood/srp/Configuration.java b/students/1204187480/code/homework/coderising/src/main/java/com/coderising/ood/srp/Configuration.java
new file mode 100644
index 0000000000..f328c1816a
--- /dev/null
+++ b/students/1204187480/code/homework/coderising/src/main/java/com/coderising/ood/srp/Configuration.java
@@ -0,0 +1,23 @@
+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/1204187480/code/homework/coderising/src/main/java/com/coderising/ood/srp/ConfigurationKeys.java b/students/1204187480/code/homework/coderising/src/main/java/com/coderising/ood/srp/ConfigurationKeys.java
new file mode 100644
index 0000000000..8695aed644
--- /dev/null
+++ b/students/1204187480/code/homework/coderising/src/main/java/com/coderising/ood/srp/ConfigurationKeys.java
@@ -0,0 +1,9 @@
+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/1204187480/code/homework/coderising/src/main/java/com/coderising/ood/srp/DBUtil.java b/students/1204187480/code/homework/coderising/src/main/java/com/coderising/ood/srp/DBUtil.java
new file mode 100644
index 0000000000..82e9261d18
--- /dev/null
+++ b/students/1204187480/code/homework/coderising/src/main/java/com/coderising/ood/srp/DBUtil.java
@@ -0,0 +1,25 @@
+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/1204187480/code/homework/coderising/src/main/java/com/coderising/ood/srp/MailUtil.java b/students/1204187480/code/homework/coderising/src/main/java/com/coderising/ood/srp/MailUtil.java
new file mode 100644
index 0000000000..9f9e749af7
--- /dev/null
+++ b/students/1204187480/code/homework/coderising/src/main/java/com/coderising/ood/srp/MailUtil.java
@@ -0,0 +1,18 @@
+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/1204187480/code/homework/coderising/src/main/java/com/coderising/ood/srp/PromotionMail.java b/students/1204187480/code/homework/coderising/src/main/java/com/coderising/ood/srp/PromotionMail.java
new file mode 100644
index 0000000000..781587a846
--- /dev/null
+++ b/students/1204187480/code/homework/coderising/src/main/java/com/coderising/ood/srp/PromotionMail.java
@@ -0,0 +1,199 @@
+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/1204187480/code/homework/coderising/src/main/resources/product_promotion.txt b/students/1204187480/code/homework/coderising/src/main/resources/product_promotion.txt
new file mode 100644
index 0000000000..a98917f829
--- /dev/null
+++ b/students/1204187480/code/homework/coderising/src/main/resources/product_promotion.txt
@@ -0,0 +1,4 @@
+P8756 iPhone8
+P3946 XiaoMi10
+P8904 Oppo R15
+P4955 Vivo X20
\ No newline at end of file
From e80ed54717dc7af1d2728d77150bfb29f11f1773 Mon Sep 17 00:00:00 2001
From: leozhaopeng <14zhaopeng@gmail.com>
Date: Mon, 12 Jun 2017 21:57:55 +0800
Subject: [PATCH 016/436] =?UTF-8?q?git=E6=8F=90=E4=BA=A4=E6=B5=8B=E8=AF=95?=
=?UTF-8?q?=EF=BC=8C=E7=AC=AC=E4=B8=80=E6=AC=A1=E6=8F=90=E4=BA=A4?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
students/309229350/readme.md | 1 +
1 file changed, 1 insertion(+)
create mode 100644 students/309229350/readme.md
diff --git a/students/309229350/readme.md b/students/309229350/readme.md
new file mode 100644
index 0000000000..48b857086e
--- /dev/null
+++ b/students/309229350/readme.md
@@ -0,0 +1 @@
+#测试git,第一次提交
From 4280fc089c9452b1a52ec7a02303d0c039c2ff75 Mon Sep 17 00:00:00 2001
From: EightWolf <675554906@qq.com>
Date: Mon, 12 Jun 2017 22:00:19 +0800
Subject: [PATCH 017/436] this is a test
---
students/675554906/readme.md | 1 +
1 file changed, 1 insertion(+)
create mode 100644 students/675554906/readme.md
diff --git a/students/675554906/readme.md b/students/675554906/readme.md
new file mode 100644
index 0000000000..a51b977d60
--- /dev/null
+++ b/students/675554906/readme.md
@@ -0,0 +1 @@
+第一次提交 仅为学习
\ No newline at end of file
From 060700d899c23d957d4b6d3394fd6e9c772bfad8 Mon Sep 17 00:00:00 2001
From: gongxun
Date: Mon, 12 Jun 2017 22:06:25 +0800
Subject: [PATCH 018/436] =?UTF-8?q?=E7=AC=AC=E4=B8=80=E7=89=88?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.gitignore | 3 +
.../785396327/first/ood/srp/BeanUtils.java | 12 ++++
students/785396327/first/ood/srp/DBUtil.java | 11 +++-
students/785396327/first/ood/srp/Email.java | 13 -----
.../785396327/first/ood/srp/EmailParser.java | 55 +++++++++++--------
.../first/ood/srp/PromotionMail.java | 8 +--
.../785396327/first/ood/srp/SendMailTest.java | 9 +++
7 files changed, 66 insertions(+), 45 deletions(-)
create mode 100644 students/785396327/first/ood/srp/BeanUtils.java
diff --git a/.gitignore b/.gitignore
index f1e9957cfa..4b65de1971 100644
--- a/.gitignore
+++ b/.gitignore
@@ -280,6 +280,9 @@ target
liuxin/.DS_Store
liuxin/src/.DS_Store
+students/*
+!students/785396327
+
diff --git a/students/785396327/first/ood/srp/BeanUtils.java b/students/785396327/first/ood/srp/BeanUtils.java
new file mode 100644
index 0000000000..617c96666e
--- /dev/null
+++ b/students/785396327/first/ood/srp/BeanUtils.java
@@ -0,0 +1,12 @@
+package first.ood.srp;
+
+/**
+ * Created by IBM on 2017/6/12.
+ */
+public class BeanUtils {
+
+ public static void copyProperties(Object dst, Object src) {
+ //拷贝方法暂不实现
+ }
+
+}
diff --git a/students/785396327/first/ood/srp/DBUtil.java b/students/785396327/first/ood/srp/DBUtil.java
index 463b464df4..473b8b1ca4 100644
--- a/students/785396327/first/ood/srp/DBUtil.java
+++ b/students/785396327/first/ood/srp/DBUtil.java
@@ -13,8 +13,8 @@ public class DBUtil {
* @param sql
* @return
*/
- public static List> query(String sql) {
-// validateSQL(sql, params);
+ public static List> query(String sql, Object[] params) {
+ formateSQL(sql, params);
List userList = new ArrayList();
for (int i = 1; i <= 3; i++) {
@@ -27,12 +27,17 @@ public static List> query(String sql) {
return userList;
}
- private static void validateSQL(String sql, Object[] params) {
+ private static String formateSQL(String sql, Object[] params) {
if (StringUtils.isEmpty(sql))
throw new RuntimeException("empty sql");
String[] sqlFaction = sql.split("\\?");
if (sqlFaction.length - 1 != params.length)
throw new RuntimeException("wrong number of parameters");
+ for (int i = 0; i < params.length; i++) {
+ sql = sql.replaceFirst("\\?", "'" + params[i].toString() + "'");
+ }
+ return sql;
}
+
}
diff --git a/students/785396327/first/ood/srp/Email.java b/students/785396327/first/ood/srp/Email.java
index 417e9aba6d..11a2c408ae 100644
--- a/students/785396327/first/ood/srp/Email.java
+++ b/students/785396327/first/ood/srp/Email.java
@@ -11,19 +11,6 @@ public class Email {
protected String subject;
protected String message;
- public Email() {
-
- }
-
- public Email(String smtpHost, String altSmtpHost, String fromAddress, String toAddress, String subject, String message) {
- this.smtpHost = smtpHost;
- this.altSmtpHost = altSmtpHost;
- this.fromAddress = fromAddress;
- this.toAddress = toAddress;
- this.subject = subject;
- this.message = message;
- }
-
protected void setSMTPHost(String smtpHost) {
this.smtpHost = smtpHost;
}
diff --git a/students/785396327/first/ood/srp/EmailParser.java b/students/785396327/first/ood/srp/EmailParser.java
index 1129beaf34..4c14b8a66f 100644
--- a/students/785396327/first/ood/srp/EmailParser.java
+++ b/students/785396327/first/ood/srp/EmailParser.java
@@ -9,18 +9,10 @@
*/
public class EmailParser {
- public List parseEmailList(String filepath, String loadQuery) {
- List mailList = new ArrayList();
- Email email = parseCommonInfo(filepath);
- List> individualInfo = getIndividualInfo(loadQuery);
- for (HashMap map : individualInfo) {
- PromotionMail promotionMail = new PromotionMail(email);
- promotionMail.setToAddress(parseToAddress(map));
- promotionMail.setMessage(parseMessage(map, promotionMail));
- promotionMail.setSubject("您关注的产品降价了");
- mailList.add(promotionMail);
- }
- return mailList;
+ public List parseEmailList(String filepath, String loadQuery, Object[] params) {
+ PromotionMail email = packageInfoFromConfig();
+ packageInfoFromFile(email, filepath);
+ return packageInfoFromDB(loadQuery, email, params);
}
private String parseMessage(HashMap map, PromotionMail promotionMail) {
@@ -33,22 +25,39 @@ private String parseToAddress(HashMap map) {
return map.get(ConfigurationKeys.EMAIL_KEY);
}
- private PromotionMail parseCommonInfo(String filepath) {
- Email email = new Email();
+ private List packageInfoFromDB(String loadQuery, PromotionMail email, Object[] params) {
+ List> individualInfo = getIndividualInfo(loadQuery, params);
+ List mailList = new ArrayList();
+ for (HashMap map : individualInfo) {
+ PromotionMail completeMail = new PromotionMail();
+ BeanUtils.copyProperties(completeMail, email);
+ completeMail.setToAddress(parseToAddress(map));
+ completeMail.setMessage(parseMessage(map, completeMail));
+ completeMail.setSubject("您关注的产品降价了");
+ mailList.add(completeMail);
+ }
+ return mailList;
+ }
+
+ private PromotionMail packageInfoFromFile(PromotionMail email, String filepath) {
FileParser fileParser = new FileParser(filepath);
-// email.setProductID(fileParser.parseProductID());
-// email.setProductDesc(fileParser.parseProductDesc());
+ email.setProductDesc(fileParser.parseProductDesc());
+ email.setProductID(fileParser.parseProductID());
+ return email;
+ }
+
+ private PromotionMail packageInfoFromConfig() {
+ PromotionMail email = new PromotionMail();
Configuration configuration = new Configuration();
-// promotionMail.setSMTPHost(configuration.getProperty(ConfigurationKeys.SMTP_SERVER));
-// promotionMail.setFromAddress(configuration.getProperty(ConfigurationKeys.EMAIL_ADMIN));
-// promotionMail.setAltSMTPHost(configuration.getProperty(ConfigurationKeys.ALT_SMTP_SERVER));
-// return promotionMail;
- return null;
+ email.setSMTPHost(configuration.getProperty(ConfigurationKeys.SMTP_SERVER));
+ email.setFromAddress(configuration.getProperty(ConfigurationKeys.EMAIL_ADMIN));
+ email.setAltSMTPHost(configuration.getProperty(ConfigurationKeys.ALT_SMTP_SERVER));
+ return email;
}
- private List> getIndividualInfo(String loadQuery) {
- return DBUtil.query(loadQuery);
+ private List> getIndividualInfo(String loadQuery, Object[] params) {
+ return DBUtil.query(loadQuery, params);
}
}
diff --git a/students/785396327/first/ood/srp/PromotionMail.java b/students/785396327/first/ood/srp/PromotionMail.java
index 1a604b7fe3..48096fa54a 100644
--- a/students/785396327/first/ood/srp/PromotionMail.java
+++ b/students/785396327/first/ood/srp/PromotionMail.java
@@ -1,12 +1,8 @@
package first.ood.srp;
public class PromotionMail extends Email {
- private String productID = null;
- private String productDesc = null;
-
- public PromotionMail(Email email) {
- super(email.smtpHost, email.altSmtpHost, email.fromAddress, email.toAddress, email.subject, email.message);
- }
+ private String productID;
+ private String productDesc;
public void setProductID(String productID) {
this.productID = productID;
diff --git a/students/785396327/first/ood/srp/SendMailTest.java b/students/785396327/first/ood/srp/SendMailTest.java
index 69681f6c6d..d82df14609 100644
--- a/students/785396327/first/ood/srp/SendMailTest.java
+++ b/students/785396327/first/ood/srp/SendMailTest.java
@@ -1,5 +1,7 @@
package first.ood.srp;
+import java.util.List;
+
/**
* Created by gongxun on 2017/6/12.
*/
@@ -7,5 +9,12 @@ public class SendMailTest {
public static void main(String[] args) {
String loadQuery = "Select name from subscriptions where product_id= ? and send_mail=1";
+ String filepath = "D:\\workspace\\IDEA\\homework\\coding2017_section2\\coding2017\\students\\785396327\\first\\ood\\srp\\product_promotion.txt";
+ boolean isDebug = false;
+
+ EmailParser emailParser = new EmailParser();
+ List promotionMails = emailParser.parseEmailList(filepath, loadQuery);
+ MailSender mailSender = new MailSender();
+ mailSender.sendMailList(promotionMails, isDebug);
}
}
From c46230c4f1587df2c2bc4b1939f3e3328d12ae4d Mon Sep 17 00:00:00 2001
From: gongxun
Date: Mon, 12 Jun 2017 22:11:58 +0800
Subject: [PATCH 019/436] update
---
students/785396327/first/ood/srp/EmailParser.java | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/students/785396327/first/ood/srp/EmailParser.java b/students/785396327/first/ood/srp/EmailParser.java
index 4c14b8a66f..06782d2c09 100644
--- a/students/785396327/first/ood/srp/EmailParser.java
+++ b/students/785396327/first/ood/srp/EmailParser.java
@@ -9,10 +9,10 @@
*/
public class EmailParser {
- public List parseEmailList(String filepath, String loadQuery, Object[] params) {
+ public List parseEmailList(String filepath, String loadQuery) {
PromotionMail email = packageInfoFromConfig();
packageInfoFromFile(email, filepath);
- return packageInfoFromDB(loadQuery, email, params);
+ return packageInfoFromDB(loadQuery, email);
}
private String parseMessage(HashMap map, PromotionMail promotionMail) {
@@ -26,8 +26,8 @@ private String parseToAddress(HashMap map) {
}
- private List packageInfoFromDB(String loadQuery, PromotionMail email, Object[] params) {
- List> individualInfo = getIndividualInfo(loadQuery, params);
+ private List packageInfoFromDB(String loadQuery, PromotionMail email) {
+ List> individualInfo = getIndividualInfo(loadQuery, new Object[]{email.getproductID()});
List mailList = new ArrayList();
for (HashMap map : individualInfo) {
PromotionMail completeMail = new PromotionMail();
From 793257d2362df0ac5eb765533560737066e16589 Mon Sep 17 00:00:00 2001
From: cheungchan <1377699408@qq.com>
Date: Mon, 12 Jun 2017 22:27:47 +0800
Subject: [PATCH 020/436] =?UTF-8?q?=E5=A2=9E=E5=8A=A0readmee?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
students/1377699408/README.md | 2 ++
1 file changed, 2 insertions(+)
create mode 100644 students/1377699408/README.md
diff --git a/students/1377699408/README.md b/students/1377699408/README.md
new file mode 100644
index 0000000000..bf3d9bbc98
--- /dev/null
+++ b/students/1377699408/README.md
@@ -0,0 +1,2 @@
+## 1377699408的文件夹
+测试
From 219d3c7e9e92d7cba1a50d23bf2c510e8065a63d Mon Sep 17 00:00:00 2001
From: luoziyihao
Date: Mon, 12 Jun 2017 22:31:26 +0800
Subject: [PATCH 021/436] design fro promotionMail
---
.../ood/srp/optimize/EmailSendClaim.java | 17 +++++++++++++++++
.../srp/optimize/EmailSendableBehavior.java | 12 ++++++++++++
.../coderising/ood/srp/optimize/Product.java | 9 +++++++++
.../ood/srp/optimize/ProductParser.java | 19 +++++++++++++++++++
.../ood/srp/optimize/PromotionMail.java | 11 +++++++++++
.../ood/srp/optimize/SmptPropeties.java | 10 ++++++++++
.../com/coderising/ood/srp/optimize/User.java | 9 +++++++++
.../ood/srp/optimize/UserService.java | 13 +++++++++++++
8 files changed, 100 insertions(+)
create mode 100644 students/1204187480/code/homework/coderising/src/main/java/com/coderising/ood/srp/optimize/EmailSendClaim.java
create mode 100644 students/1204187480/code/homework/coderising/src/main/java/com/coderising/ood/srp/optimize/EmailSendableBehavior.java
create mode 100644 students/1204187480/code/homework/coderising/src/main/java/com/coderising/ood/srp/optimize/Product.java
create mode 100644 students/1204187480/code/homework/coderising/src/main/java/com/coderising/ood/srp/optimize/ProductParser.java
create mode 100644 students/1204187480/code/homework/coderising/src/main/java/com/coderising/ood/srp/optimize/PromotionMail.java
create mode 100644 students/1204187480/code/homework/coderising/src/main/java/com/coderising/ood/srp/optimize/SmptPropeties.java
create mode 100644 students/1204187480/code/homework/coderising/src/main/java/com/coderising/ood/srp/optimize/User.java
create mode 100644 students/1204187480/code/homework/coderising/src/main/java/com/coderising/ood/srp/optimize/UserService.java
diff --git a/students/1204187480/code/homework/coderising/src/main/java/com/coderising/ood/srp/optimize/EmailSendClaim.java b/students/1204187480/code/homework/coderising/src/main/java/com/coderising/ood/srp/optimize/EmailSendClaim.java
new file mode 100644
index 0000000000..e61704ec60
--- /dev/null
+++ b/students/1204187480/code/homework/coderising/src/main/java/com/coderising/ood/srp/optimize/EmailSendClaim.java
@@ -0,0 +1,17 @@
+package com.coderising.ood.srp.optimize;
+
+/**
+ * Created by luoziyihao on 6/12/17.
+ */
+public class EmailSendClaim {
+ private String toAddress;
+ private String fromAddress;
+ private String subject;
+ private String message;
+ private String smtpHost;
+ private String debug;
+
+ public void setMessage(Product product, User user) {
+ this.message = null;
+ }
+}
diff --git a/students/1204187480/code/homework/coderising/src/main/java/com/coderising/ood/srp/optimize/EmailSendableBehavior.java b/students/1204187480/code/homework/coderising/src/main/java/com/coderising/ood/srp/optimize/EmailSendableBehavior.java
new file mode 100644
index 0000000000..aede0fdc66
--- /dev/null
+++ b/students/1204187480/code/homework/coderising/src/main/java/com/coderising/ood/srp/optimize/EmailSendableBehavior.java
@@ -0,0 +1,12 @@
+package com.coderising.ood.srp.optimize;
+
+import java.util.List;
+
+/**
+ * Created by luoziyihao on 6/12/17.
+ */
+public class EmailSendableBehavior {
+ void send(List emailSendClaimList) {
+
+ }
+}
diff --git a/students/1204187480/code/homework/coderising/src/main/java/com/coderising/ood/srp/optimize/Product.java b/students/1204187480/code/homework/coderising/src/main/java/com/coderising/ood/srp/optimize/Product.java
new file mode 100644
index 0000000000..652897a7f3
--- /dev/null
+++ b/students/1204187480/code/homework/coderising/src/main/java/com/coderising/ood/srp/optimize/Product.java
@@ -0,0 +1,9 @@
+package com.coderising.ood.srp.optimize;
+
+/**
+ * Created by luoziyihao on 6/12/17.
+ */
+public class Product {
+ private static String productID;
+ private static String productDesc;
+}
diff --git a/students/1204187480/code/homework/coderising/src/main/java/com/coderising/ood/srp/optimize/ProductParser.java b/students/1204187480/code/homework/coderising/src/main/java/com/coderising/ood/srp/optimize/ProductParser.java
new file mode 100644
index 0000000000..7860dd6047
--- /dev/null
+++ b/students/1204187480/code/homework/coderising/src/main/java/com/coderising/ood/srp/optimize/ProductParser.java
@@ -0,0 +1,19 @@
+package com.coderising.ood.srp.optimize;
+
+import java.util.List;
+
+/**
+ * Created by luoziyihao on 6/12/17.
+ */
+public class ProductParser {
+
+ private String productFilePath;
+
+ public void setProductFilePath(String productFilePath) {
+ this.productFilePath = productFilePath;
+ }
+
+ public List parse(){
+ return null;
+ }
+}
diff --git a/students/1204187480/code/homework/coderising/src/main/java/com/coderising/ood/srp/optimize/PromotionMail.java b/students/1204187480/code/homework/coderising/src/main/java/com/coderising/ood/srp/optimize/PromotionMail.java
new file mode 100644
index 0000000000..4288925d1e
--- /dev/null
+++ b/students/1204187480/code/homework/coderising/src/main/java/com/coderising/ood/srp/optimize/PromotionMail.java
@@ -0,0 +1,11 @@
+package com.coderising.ood.srp.optimize;
+
+/**
+ * Created by luoziyihao on 6/12/17.
+ */
+public class PromotionMail {
+
+ public static void main(String args[]){
+
+ }
+}
diff --git a/students/1204187480/code/homework/coderising/src/main/java/com/coderising/ood/srp/optimize/SmptPropeties.java b/students/1204187480/code/homework/coderising/src/main/java/com/coderising/ood/srp/optimize/SmptPropeties.java
new file mode 100644
index 0000000000..fd6d7be8d7
--- /dev/null
+++ b/students/1204187480/code/homework/coderising/src/main/java/com/coderising/ood/srp/optimize/SmptPropeties.java
@@ -0,0 +1,10 @@
+package com.coderising.ood.srp.optimize;
+
+/**
+ * Created by luoziyihao on 6/12/17.
+ */
+public class SmptPropeties {
+ private String smtpHost;
+ private String altSmtpHost;
+ private String fromAddress;
+}
diff --git a/students/1204187480/code/homework/coderising/src/main/java/com/coderising/ood/srp/optimize/User.java b/students/1204187480/code/homework/coderising/src/main/java/com/coderising/ood/srp/optimize/User.java
new file mode 100644
index 0000000000..45f7739a7b
--- /dev/null
+++ b/students/1204187480/code/homework/coderising/src/main/java/com/coderising/ood/srp/optimize/User.java
@@ -0,0 +1,9 @@
+package com.coderising.ood.srp.optimize;
+
+/**
+ * Created by luoziyihao on 6/12/17.
+ */
+public class User {
+ private String name;
+ private String email;
+}
diff --git a/students/1204187480/code/homework/coderising/src/main/java/com/coderising/ood/srp/optimize/UserService.java b/students/1204187480/code/homework/coderising/src/main/java/com/coderising/ood/srp/optimize/UserService.java
new file mode 100644
index 0000000000..5178489e0f
--- /dev/null
+++ b/students/1204187480/code/homework/coderising/src/main/java/com/coderising/ood/srp/optimize/UserService.java
@@ -0,0 +1,13 @@
+package com.coderising.ood.srp.optimize;
+
+import java.util.List;
+
+/**
+ * Created by luoziyihao on 6/12/17.
+ */
+public class UserService {
+
+ List loadMailingList(){
+ return null;
+ }
+}
From bde7e7b6f698ad4c594b4e2c703d2b1ba0bd1869 Mon Sep 17 00:00:00 2001
From: luoziyihao
Date: Mon, 12 Jun 2017 22:34:50 +0800
Subject: [PATCH 022/436] design fro promotionMail2
---
.../optimize/{PromotionMail.java => PromotionMailApp.java} | 2 +-
.../{EmailSendClaim.java => PromotionMailClaim.java} | 2 +-
...lSendableBehavior.java => PromotionMailableBehavior.java} | 5 +++--
3 files changed, 5 insertions(+), 4 deletions(-)
rename students/1204187480/code/homework/coderising/src/main/java/com/coderising/ood/srp/optimize/{PromotionMail.java => PromotionMailApp.java} (81%)
rename students/1204187480/code/homework/coderising/src/main/java/com/coderising/ood/srp/optimize/{EmailSendClaim.java => PromotionMailClaim.java} (91%)
rename students/1204187480/code/homework/coderising/src/main/java/com/coderising/ood/srp/optimize/{EmailSendableBehavior.java => PromotionMailableBehavior.java} (53%)
diff --git a/students/1204187480/code/homework/coderising/src/main/java/com/coderising/ood/srp/optimize/PromotionMail.java b/students/1204187480/code/homework/coderising/src/main/java/com/coderising/ood/srp/optimize/PromotionMailApp.java
similarity index 81%
rename from students/1204187480/code/homework/coderising/src/main/java/com/coderising/ood/srp/optimize/PromotionMail.java
rename to students/1204187480/code/homework/coderising/src/main/java/com/coderising/ood/srp/optimize/PromotionMailApp.java
index 4288925d1e..ef89a79d77 100644
--- a/students/1204187480/code/homework/coderising/src/main/java/com/coderising/ood/srp/optimize/PromotionMail.java
+++ b/students/1204187480/code/homework/coderising/src/main/java/com/coderising/ood/srp/optimize/PromotionMailApp.java
@@ -3,7 +3,7 @@
/**
* Created by luoziyihao on 6/12/17.
*/
-public class PromotionMail {
+public class PromotionMailApp {
public static void main(String args[]){
diff --git a/students/1204187480/code/homework/coderising/src/main/java/com/coderising/ood/srp/optimize/EmailSendClaim.java b/students/1204187480/code/homework/coderising/src/main/java/com/coderising/ood/srp/optimize/PromotionMailClaim.java
similarity index 91%
rename from students/1204187480/code/homework/coderising/src/main/java/com/coderising/ood/srp/optimize/EmailSendClaim.java
rename to students/1204187480/code/homework/coderising/src/main/java/com/coderising/ood/srp/optimize/PromotionMailClaim.java
index e61704ec60..06d447b817 100644
--- a/students/1204187480/code/homework/coderising/src/main/java/com/coderising/ood/srp/optimize/EmailSendClaim.java
+++ b/students/1204187480/code/homework/coderising/src/main/java/com/coderising/ood/srp/optimize/PromotionMailClaim.java
@@ -3,7 +3,7 @@
/**
* Created by luoziyihao on 6/12/17.
*/
-public class EmailSendClaim {
+public class PromotionMailClaim {
private String toAddress;
private String fromAddress;
private String subject;
diff --git a/students/1204187480/code/homework/coderising/src/main/java/com/coderising/ood/srp/optimize/EmailSendableBehavior.java b/students/1204187480/code/homework/coderising/src/main/java/com/coderising/ood/srp/optimize/PromotionMailableBehavior.java
similarity index 53%
rename from students/1204187480/code/homework/coderising/src/main/java/com/coderising/ood/srp/optimize/EmailSendableBehavior.java
rename to students/1204187480/code/homework/coderising/src/main/java/com/coderising/ood/srp/optimize/PromotionMailableBehavior.java
index aede0fdc66..548f69722a 100644
--- a/students/1204187480/code/homework/coderising/src/main/java/com/coderising/ood/srp/optimize/EmailSendableBehavior.java
+++ b/students/1204187480/code/homework/coderising/src/main/java/com/coderising/ood/srp/optimize/PromotionMailableBehavior.java
@@ -5,8 +5,9 @@
/**
* Created by luoziyihao on 6/12/17.
*/
-public class EmailSendableBehavior {
- void send(List emailSendClaimList) {
+public class PromotionMailableBehavior {
+
+ void send(List emailSendClaimList) {
}
}
From 251022e66ff6a536a6ead1d31d8152a64dddfcfb Mon Sep 17 00:00:00 2001
From: palmshe
Date: Mon, 12 Jun 2017 22:57:15 +0800
Subject: [PATCH 023/436] =?UTF-8?q?=E6=8C=89=E5=8D=95=E4=B8=80=E8=B4=A3?=
=?UTF-8?q?=E4=BB=BB=E5=8E=9F=E5=88=99=E8=BF=9B=E8=A1=8C=E4=BF=AE=E6=94=B9?=
=?UTF-8?q?=E4=BB=A3=E7=A0=81?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../com/coderising/ood/srp/Configuration.java | 2 +-
.../com/coderising/ood/srp/DataGenerator.java | 64 ++++++
.../com/coderising/ood/srp/InitDataUtils.java | 61 ------
.../java/com/coderising/ood/srp/MailUtil.java | 39 +++-
.../java/com/coderising/ood/srp/Main.java | 34 +++
.../com/coderising/ood/srp/PromotionMail.java | 207 +-----------------
6 files changed, 142 insertions(+), 265 deletions(-)
create mode 100644 students/2842295913/ood-assignment/src/main/java/com/coderising/ood/srp/DataGenerator.java
delete mode 100644 students/2842295913/ood-assignment/src/main/java/com/coderising/ood/srp/InitDataUtils.java
create mode 100644 students/2842295913/ood-assignment/src/main/java/com/coderising/ood/srp/Main.java
diff --git a/students/2842295913/ood-assignment/src/main/java/com/coderising/ood/srp/Configuration.java b/students/2842295913/ood-assignment/src/main/java/com/coderising/ood/srp/Configuration.java
index f328c1816a..1faff3f68d 100644
--- a/students/2842295913/ood-assignment/src/main/java/com/coderising/ood/srp/Configuration.java
+++ b/students/2842295913/ood-assignment/src/main/java/com/coderising/ood/srp/Configuration.java
@@ -15,7 +15,7 @@ public class Configuration {
* @param key
* @return
*/
- public String getProperty(String key) {
+ public static String getProperty(String key) {
return configurations.get(key);
}
diff --git a/students/2842295913/ood-assignment/src/main/java/com/coderising/ood/srp/DataGenerator.java b/students/2842295913/ood-assignment/src/main/java/com/coderising/ood/srp/DataGenerator.java
new file mode 100644
index 0000000000..6e9f1c2e84
--- /dev/null
+++ b/students/2842295913/ood-assignment/src/main/java/com/coderising/ood/srp/DataGenerator.java
@@ -0,0 +1,64 @@
+/**
+ * 版权 (c) 2017 palmshe.com
+ * 保留所有权利。
+ */
+package com.coderising.ood.srp;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileReader;
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * @Description:
+ * @author palmshe
+ * @date 2017年6月11日 下午10:24:46
+ */
+public class DataGenerator {
+
+ /**
+ * @Description:获取商品
+ * @param file
+ * @return
+ * @throws IOException
+ */
+ public static Map generateGoods(File file) throws IOException{
+ Map good= new HashMap();
+ BufferedReader br = null;
+ try {
+ br = new BufferedReader(new FileReader(file));
+ String temp = br.readLine();
+ String[] data = temp.split(" ");
+
+ good.put(PromotionMail.ID_KEY, data[0]);
+ good.put(PromotionMail.DESC_KEY, data[1]);
+
+ System.out.println("产品ID = " + data[0] + "\n");
+ System.out.println("产品描述 = " + data[1] + "\n");
+
+ } catch (IOException e) {
+ throw new IOException(e.getMessage());
+ } finally {
+ br.close();
+ }
+ return good;
+ }
+
+ /**
+ * @Description:获取客户
+ * @param good
+ * @return
+ * @throws Exception
+ */
+ public static List loadMailingList(Map good) throws Exception {
+ String id= (String)good.get(PromotionMail.ID_KEY);
+ String sendMailQuery = "Select name from subscriptions "
+ + "where product_id= '" + id +"' "
+ + "and send_mail=1 ";
+
+ return DBUtil.query(sendMailQuery);
+ }
+}
diff --git a/students/2842295913/ood-assignment/src/main/java/com/coderising/ood/srp/InitDataUtils.java b/students/2842295913/ood-assignment/src/main/java/com/coderising/ood/srp/InitDataUtils.java
deleted file mode 100644
index 35cdb939f6..0000000000
--- a/students/2842295913/ood-assignment/src/main/java/com/coderising/ood/srp/InitDataUtils.java
+++ /dev/null
@@ -1,61 +0,0 @@
-/**
- * 版权 (c) 2017 palmshe.com
- * 保留所有权利。
- */
-package com.coderising.ood.srp;
-
-import java.io.BufferedReader;
-import java.io.File;
-import java.io.FileReader;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-/**
- * @Description: 加载所需要的数据,以便PromotionMail取用
- * @author palmshe
- * @date 2017年6月11日 下午10:24:46
- */
-public class InitDataUtils {
-
- protected static final String GOOD_NAME= "good_name";
- protected static final String GOOD_ID= "good_id";
-
- /**
- * @Description:生产商品
- * @param file
- * @return
- * @throws IOException
- */
- public static List generateGoods(File file) throws IOException{
- List goods= new ArrayList();
- BufferedReader br = null;
- try {
- br = new BufferedReader(new FileReader(file));
- String temp = br.readLine();
- String[] data = temp.split(" ");
-
- for (int i = 0; i < 1; i++) {
- Map goodMaps= new HashMap();
- goodMaps.put(GOOD_ID, data[0]);
- goodMaps.put(GOOD_NAME, data[1]);
- goods.add(goodMaps);
- }
-
-// 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();
- }
-
- return goods;
- }
-}
diff --git a/students/2842295913/ood-assignment/src/main/java/com/coderising/ood/srp/MailUtil.java b/students/2842295913/ood-assignment/src/main/java/com/coderising/ood/srp/MailUtil.java
index 9f9e749af7..e31d8a9b75 100644
--- a/students/2842295913/ood-assignment/src/main/java/com/coderising/ood/srp/MailUtil.java
+++ b/students/2842295913/ood-assignment/src/main/java/com/coderising/ood/srp/MailUtil.java
@@ -2,17 +2,40 @@
public class MailUtil {
- public static void sendEmail(String toAddress, String fromAddress, String subject, String message, String smtpHost,
- boolean debug) {
- //假装发了一封邮件
+ private static String fromAddress;
+ private static String smtpServer;
+ private static String altSmtpServer;
+
+ public MailUtil(String fromAddress, String smtpServer, String altSmtpServer){
+ this.fromAddress= fromAddress;
+ this.smtpServer= smtpServer;
+ this.altSmtpServer= altSmtpServer;
+ }
+
+ /**
+ * @Description:发送邮件
+ * @param pm
+ * @param debug
+ */
+ public void sendEmail(PromotionMail pm, boolean debug){
+ try {
+ sendEmail(fromAddress, pm.toAddress, pm.subject, pm.message, smtpServer, debug);
+ } catch (Exception e1) {
+ try {
+ sendEmail(fromAddress, pm.toAddress, pm.subject, pm.message, altSmtpServer, debug);
+ } catch (Exception e2) {
+ System.out.println("通过备用 SMTP服务器发送邮件失败: " + e2.getMessage());
+ }
+ }
+ }
+
+ private void sendEmail(String from, String to, String subject, String message, String server, boolean debug){
+// 假装发了一封邮件
StringBuilder buffer = new StringBuilder();
- buffer.append("From:").append(fromAddress).append("\n");
- buffer.append("To:").append(toAddress).append("\n");
+ buffer.append("From:").append(from).append("\n");
+ buffer.append("To:").append(to).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/2842295913/ood-assignment/src/main/java/com/coderising/ood/srp/Main.java b/students/2842295913/ood-assignment/src/main/java/com/coderising/ood/srp/Main.java
new file mode 100644
index 0000000000..8029d24a4c
--- /dev/null
+++ b/students/2842295913/ood-assignment/src/main/java/com/coderising/ood/srp/Main.java
@@ -0,0 +1,34 @@
+/**
+ * 版权 (c) 2017 palmshe.com
+ * 保留所有权利。
+ */
+package com.coderising.ood.srp;
+
+import java.io.File;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * @Description:
+ * @author palmshe
+ * @date 2017年6月12日 下午10:07:23
+ */
+public class Main {
+ public static void main(String[] args) {
+ try {
+ File f = new File("E:\\Workspace-Sourcetree\\coding2017\\students\\2842295913\\ood-assignment\\src\\main\\java\\com\\coderising\\ood\\srp\\product_promotion.txt");
+ MailUtil maiUtil= new MailUtil(Configuration.getProperty(ConfigurationKeys.EMAIL_ADMIN), Configuration.getProperty(ConfigurationKeys.SMTP_SERVER), Configuration.getProperty(ConfigurationKeys.ALT_SMTP_SERVER));
+ Map good = DataGenerator.generateGoods(f);
+ List users= DataGenerator.loadMailingList(good);
+ if (!users.isEmpty()) {
+ Iterator it= users.iterator();
+ while (it.hasNext()) {
+ maiUtil.sendEmail(new PromotionMail((Map)it.next(), good), true);
+ }
+ }
+ } catch (Exception e) {
+ System.out.println("构造发送邮件数据失败:"+ e.getMessage());
+ }
+ }
+}
diff --git a/students/2842295913/ood-assignment/src/main/java/com/coderising/ood/srp/PromotionMail.java b/students/2842295913/ood-assignment/src/main/java/com/coderising/ood/srp/PromotionMail.java
index f293eb1f45..a773d878ee 100644
--- a/students/2842295913/ood-assignment/src/main/java/com/coderising/ood/srp/PromotionMail.java
+++ b/students/2842295913/ood-assignment/src/main/java/com/coderising/ood/srp/PromotionMail.java
@@ -1,209 +1,26 @@
package com.coderising.ood.srp;
-import java.io.BufferedReader;
-import java.io.File;
-import java.io.FileReader;
-import java.io.IOException;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
import java.util.Map;
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());
-
-
- }
-
-
-
-
- private 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("没有邮件发送");
-
- }
-
- }
-
- /**
- * @Description:设置商品信息
- * @param goods
- */
- public void setGoods(List goods){
- Map goodMap= (HashMap)goods.get(0);
- setProductDesc((String)goodMap.get(InitDataUtils.GOOD_NAME));
- setProductID((String)goodMap.get(InitDataUtils.GOOD_ID));
+ protected static final String NAME_KEY = "NAME";
+ protected static final String EMAIL_KEY = "EMAIL";
+ protected static final String ID_KEY = "ID";
+ protected static final String DESC_KEY = "DESC";
+
+ public PromotionMail(Map user, Map good){
+ String name = (String)user.get(NAME_KEY);
+ this.productDesc= (String)good.get(DESC_KEY);
+ this.productID= (String)good.get(ID_KEY);
+ this.toAddress= (String)user.get(EMAIL_KEY);
+ this.subject = "您关注的产品降价了";
+ this.message = "尊敬的 "+name+", 您关注的产品 " + productDesc + " 降价了,欢迎购买!" ;
}
}
From 7f7332d57fdbf085027ffafcbae8ad2a5a968a01 Mon Sep 17 00:00:00 2001
From: fade <511739113@qq.com>
Date: Mon, 12 Jun 2017 23:39:04 +0800
Subject: [PATCH 024/436] =?UTF-8?q?=E6=8F=90=E4=BA=A4=20=E5=8E=9F=E7=89=88?=
=?UTF-8?q?=E4=BB=A3=E7=A0=81?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../511739113/6.11/ood-assignment/pom.xml | 32 +++
.../com/coderising/ood/srp/Configuration.java | 23 ++
.../coderising/ood/srp/ConfigurationKeys.java | 9 +
.../java/com/coderising/ood/srp/DBUtil.java | 25 +++
.../java/com/coderising/ood/srp/MailUtil.java | 18 ++
.../com/coderising/ood/srp/PromotionMail.java | 199 ++++++++++++++++++
.../coderising/ood/srp/product_promotion.txt | 4 +
7 files changed, 310 insertions(+)
create mode 100644 students/511739113/6.11/ood-assignment/pom.xml
create mode 100644 students/511739113/6.11/ood-assignment/src/main/java/com/coderising/ood/srp/Configuration.java
create mode 100644 students/511739113/6.11/ood-assignment/src/main/java/com/coderising/ood/srp/ConfigurationKeys.java
create mode 100644 students/511739113/6.11/ood-assignment/src/main/java/com/coderising/ood/srp/DBUtil.java
create mode 100644 students/511739113/6.11/ood-assignment/src/main/java/com/coderising/ood/srp/MailUtil.java
create mode 100644 students/511739113/6.11/ood-assignment/src/main/java/com/coderising/ood/srp/PromotionMail.java
create mode 100644 students/511739113/6.11/ood-assignment/src/main/java/com/coderising/ood/srp/product_promotion.txt
diff --git a/students/511739113/6.11/ood-assignment/pom.xml b/students/511739113/6.11/ood-assignment/pom.xml
new file mode 100644
index 0000000000..cac49a5328
--- /dev/null
+++ b/students/511739113/6.11/ood-assignment/pom.xml
@@ -0,0 +1,32 @@
+
+ 4.0.0
+
+ com.coderising
+ ood-assignment
+ 0.0.1-SNAPSHOT
+ jar
+
+ ood-assignment
+ http://maven.apache.org
+
+
+ UTF-8
+
+
+
+
+
+ junit
+ junit
+ 4.12
+
+
+
+
+
+ aliyunmaven
+ http://maven.aliyun.com/nexus/content/groups/public/
+
+
+
diff --git a/students/511739113/6.11/ood-assignment/src/main/java/com/coderising/ood/srp/Configuration.java b/students/511739113/6.11/ood-assignment/src/main/java/com/coderising/ood/srp/Configuration.java
new file mode 100644
index 0000000000..f328c1816a
--- /dev/null
+++ b/students/511739113/6.11/ood-assignment/src/main/java/com/coderising/ood/srp/Configuration.java
@@ -0,0 +1,23 @@
+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/511739113/6.11/ood-assignment/src/main/java/com/coderising/ood/srp/ConfigurationKeys.java b/students/511739113/6.11/ood-assignment/src/main/java/com/coderising/ood/srp/ConfigurationKeys.java
new file mode 100644
index 0000000000..8695aed644
--- /dev/null
+++ b/students/511739113/6.11/ood-assignment/src/main/java/com/coderising/ood/srp/ConfigurationKeys.java
@@ -0,0 +1,9 @@
+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/511739113/6.11/ood-assignment/src/main/java/com/coderising/ood/srp/DBUtil.java b/students/511739113/6.11/ood-assignment/src/main/java/com/coderising/ood/srp/DBUtil.java
new file mode 100644
index 0000000000..82e9261d18
--- /dev/null
+++ b/students/511739113/6.11/ood-assignment/src/main/java/com/coderising/ood/srp/DBUtil.java
@@ -0,0 +1,25 @@
+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/511739113/6.11/ood-assignment/src/main/java/com/coderising/ood/srp/MailUtil.java b/students/511739113/6.11/ood-assignment/src/main/java/com/coderising/ood/srp/MailUtil.java
new file mode 100644
index 0000000000..9f9e749af7
--- /dev/null
+++ b/students/511739113/6.11/ood-assignment/src/main/java/com/coderising/ood/srp/MailUtil.java
@@ -0,0 +1,18 @@
+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/511739113/6.11/ood-assignment/src/main/java/com/coderising/ood/srp/PromotionMail.java b/students/511739113/6.11/ood-assignment/src/main/java/com/coderising/ood/srp/PromotionMail.java
new file mode 100644
index 0000000000..781587a846
--- /dev/null
+++ b/students/511739113/6.11/ood-assignment/src/main/java/com/coderising/ood/srp/PromotionMail.java
@@ -0,0 +1,199 @@
+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/511739113/6.11/ood-assignment/src/main/java/com/coderising/ood/srp/product_promotion.txt b/students/511739113/6.11/ood-assignment/src/main/java/com/coderising/ood/srp/product_promotion.txt
new file mode 100644
index 0000000000..0c0124cc61
--- /dev/null
+++ b/students/511739113/6.11/ood-assignment/src/main/java/com/coderising/ood/srp/product_promotion.txt
@@ -0,0 +1,4 @@
+P8756 iPhone8
+P3946 XiaoMi10
+P8904 Oppo_R15
+P4955 Vivo_X20
\ No newline at end of file
From 37e47d3afa21b0f22a12f0c848fb4f5035887499 Mon Sep 17 00:00:00 2001
From: peng
Date: Mon, 12 Jun 2017 23:39:21 +0800
Subject: [PATCH 025/436] work init
---
students/1395844061/.gitignore | 27 +++++++++++++++++++
students/1395844061/README.md | 1 +
students/1395844061/build.gradle | 18 +++++++++++++
students/1395844061/course-pro-1/build.gradle | 14 ++++++++++
students/1395844061/settings.gradle | 2 ++
5 files changed, 62 insertions(+)
create mode 100644 students/1395844061/.gitignore
create mode 100644 students/1395844061/README.md
create mode 100644 students/1395844061/build.gradle
create mode 100644 students/1395844061/course-pro-1/build.gradle
create mode 100644 students/1395844061/settings.gradle
diff --git a/students/1395844061/.gitignore b/students/1395844061/.gitignore
new file mode 100644
index 0000000000..15df76b3b5
--- /dev/null
+++ b/students/1395844061/.gitignore
@@ -0,0 +1,27 @@
+# Created by .ignore support plugin (hsz.mobi)
+### Java template
+# Compiled class file
+*.class
+
+# Log file
+*.log
+
+# BlueJ files
+*.ctxt
+
+# Mobile Tools for Java (J2ME)
+.mtj.tmp/
+
+# Package Files #
+*.jar
+*.war
+*.ear
+*.zip
+*.tar.gz
+*.rar
+
+# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
+hs_err_pid*
+
+1395844061.iml
+src/
diff --git a/students/1395844061/README.md b/students/1395844061/README.md
new file mode 100644
index 0000000000..8b13789179
--- /dev/null
+++ b/students/1395844061/README.md
@@ -0,0 +1 @@
+
diff --git a/students/1395844061/build.gradle b/students/1395844061/build.gradle
new file mode 100644
index 0000000000..db1cbf8def
--- /dev/null
+++ b/students/1395844061/build.gradle
@@ -0,0 +1,18 @@
+group 'peng-test'
+version '1.0-SNAPSHOT'
+
+apply plugin: 'java'
+
+sourceCompatibility = 1.5
+
+repositories {
+ maven{
+ url "http://maven.oschina.net/content/groups/public/"
+ }
+}
+
+dependencies {
+
+ compile 'org.htmlparser:htmlparser:2.1'
+ testCompile group: 'junit', name: 'junit', version: '4.11'
+}
diff --git a/students/1395844061/course-pro-1/build.gradle b/students/1395844061/course-pro-1/build.gradle
new file mode 100644
index 0000000000..939cf6ccbe
--- /dev/null
+++ b/students/1395844061/course-pro-1/build.gradle
@@ -0,0 +1,14 @@
+group 'peng-test'
+version '1.0-SNAPSHOT'
+
+apply plugin: 'java'
+
+sourceCompatibility = 1.8
+
+repositories {
+ mavenCentral()
+}
+
+dependencies {
+ testCompile group: 'junit', name: 'junit', version: '4.12'
+}
diff --git a/students/1395844061/settings.gradle b/students/1395844061/settings.gradle
new file mode 100644
index 0000000000..f66e41c2f9
--- /dev/null
+++ b/students/1395844061/settings.gradle
@@ -0,0 +1,2 @@
+include 'course-pro-1'
+
From 56965fe72c76a7dd73a0e538e623f91d910c1d1f Mon Sep 17 00:00:00 2001
From: peng
Date: Mon, 12 Jun 2017 23:44:23 +0800
Subject: [PATCH 026/436] work init
---
.../com/coderising/ood/srp/Configuration.java | 33 +++
.../coderising/ood/srp/ConfigurationKeys.java | 16 ++
.../java/com/coderising/ood/srp/DBUtil.java | 31 +++
.../java/com/coderising/ood/srp/MailUtil.java | 27 +++
.../com/coderising/ood/srp/PromotionMail.java | 203 ++++++++++++++++++
5 files changed, 310 insertions(+)
create mode 100644 students/1395844061/course-pro-1/src/main/java/com/coderising/ood/srp/Configuration.java
create mode 100644 students/1395844061/course-pro-1/src/main/java/com/coderising/ood/srp/ConfigurationKeys.java
create mode 100644 students/1395844061/course-pro-1/src/main/java/com/coderising/ood/srp/DBUtil.java
create mode 100644 students/1395844061/course-pro-1/src/main/java/com/coderising/ood/srp/MailUtil.java
create mode 100644 students/1395844061/course-pro-1/src/main/java/com/coderising/ood/srp/PromotionMail.java
diff --git a/students/1395844061/course-pro-1/src/main/java/com/coderising/ood/srp/Configuration.java b/students/1395844061/course-pro-1/src/main/java/com/coderising/ood/srp/Configuration.java
new file mode 100644
index 0000000000..cd447ad225
--- /dev/null
+++ b/students/1395844061/course-pro-1/src/main/java/com/coderising/ood/srp/Configuration.java
@@ -0,0 +1,33 @@
+package com.coderising.ood.srp;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * Configuration
+ *
+ * @author Chenpz
+ * @package com.coderising.ood.srp
+ * @date 2017/6/12/23:30
+ */
+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/1395844061/course-pro-1/src/main/java/com/coderising/ood/srp/ConfigurationKeys.java b/students/1395844061/course-pro-1/src/main/java/com/coderising/ood/srp/ConfigurationKeys.java
new file mode 100644
index 0000000000..7c3aa420b9
--- /dev/null
+++ b/students/1395844061/course-pro-1/src/main/java/com/coderising/ood/srp/ConfigurationKeys.java
@@ -0,0 +1,16 @@
+package com.coderising.ood.srp;
+
+/**
+ * ConfigurationKeys
+ *
+ * @author Chenpz
+ * @package com.coderising.ood.srp
+ * @date 2017/6/12/23:31
+ */
+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/1395844061/course-pro-1/src/main/java/com/coderising/ood/srp/DBUtil.java b/students/1395844061/course-pro-1/src/main/java/com/coderising/ood/srp/DBUtil.java
new file mode 100644
index 0000000000..437a74cb40
--- /dev/null
+++ b/students/1395844061/course-pro-1/src/main/java/com/coderising/ood/srp/DBUtil.java
@@ -0,0 +1,31 @@
+package com.coderising.ood.srp;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+
+/**
+ * DBUtil
+ *
+ * @author Chenpz
+ * @package com.coderising.ood.srp
+ * @date 2017/6/12/23:32
+ */
+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/1395844061/course-pro-1/src/main/java/com/coderising/ood/srp/MailUtil.java b/students/1395844061/course-pro-1/src/main/java/com/coderising/ood/srp/MailUtil.java
new file mode 100644
index 0000000000..83b3ef844b
--- /dev/null
+++ b/students/1395844061/course-pro-1/src/main/java/com/coderising/ood/srp/MailUtil.java
@@ -0,0 +1,27 @@
+package com.coderising.ood.srp;
+
+/**
+ * MailUtil
+ *
+ * @author Chenpz
+ * @package com.coderising.ood.srp
+ * @date 2017/6/12/23:28
+ */
+public final class MailUtil {
+
+
+ private MailUtil(){
+ throw new RuntimeException("illegal called!");
+ }
+
+ 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/1395844061/course-pro-1/src/main/java/com/coderising/ood/srp/PromotionMail.java b/students/1395844061/course-pro-1/src/main/java/com/coderising/ood/srp/PromotionMail.java
new file mode 100644
index 0000000000..331537f5d9
--- /dev/null
+++ b/students/1395844061/course-pro-1/src/main/java/com/coderising/ood/srp/PromotionMail.java
@@ -0,0 +1,203 @@
+package com.coderising.ood.srp;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileReader;
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+
+/**
+ * PromotionMail
+ *
+ * @author Chenpz
+ * @package com.coderising.ood.srp
+ * @date 2017/6/12/23:33
+ */
+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("没有邮件发送");
+
+ }
+
+ }
+}
From 029e31e55bdf64c11fbe2cb4cd885e2bb5791ab4 Mon Sep 17 00:00:00 2001
From: peng
Date: Mon, 12 Jun 2017 23:45:27 +0800
Subject: [PATCH 027/436] add gitignore file
---
students/1395844061/.gitignore | 1 -
1 file changed, 1 deletion(-)
diff --git a/students/1395844061/.gitignore b/students/1395844061/.gitignore
index 15df76b3b5..d41523dfd3 100644
--- a/students/1395844061/.gitignore
+++ b/students/1395844061/.gitignore
@@ -24,4 +24,3 @@
hs_err_pid*
1395844061.iml
-src/
From 876cf64589f2c647c3314983fa4c445e49477370 Mon Sep 17 00:00:00 2001
From: lujiajia
Date: Mon, 12 Jun 2017 23:45:33 +0800
Subject: [PATCH 028/436] =?UTF-8?q?=E6=8F=90=E4=BA=A4=E5=87=86=E5=A4=87?=
=?UTF-8?q?=E4=BB=A3=E7=A0=81?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../250103158/data-structure/answer/pom.xml | 32 +++
.../coderising/download/DownloadThread.java | 20 ++
.../coderising/download/FileDownloader.java | 73 +++++++
.../download/FileDownloaderTest.java | 59 ++++++
.../coderising/download/api/Connection.java | 23 ++
.../download/api/ConnectionException.java | 5 +
.../download/api/ConnectionManager.java | 10 +
.../download/api/DownloadListener.java | 5 +
.../download/impl/ConnectionImpl.java | 27 +++
.../download/impl/ConnectionManagerImpl.java | 15 ++
.../coderising/litestruts/LoginAction.java | 39 ++++
.../com/coderising/litestruts/Struts.java | 34 +++
.../com/coderising/litestruts/StrutsTest.java | 43 ++++
.../java/com/coderising/litestruts/View.java | 23 ++
.../java/com/coderising/litestruts/struts.xml | 11 +
.../main/java/com/coding/basic/Iterator.java | 7 +
.../src/main/java/com/coding/basic/List.java | 9 +
.../com/coding/basic/array/ArrayList.java | 35 +++
.../com/coding/basic/array/ArrayUtil.java | 96 +++++++++
.../coding/basic/linklist/LRUPageFrame.java | 164 +++++++++++++++
.../basic/linklist/LRUPageFrameTest.java | 34 +++
.../com/coding/basic/linklist/LinkedList.java | 125 +++++++++++
.../com/coding/basic/queue/CircleQueue.java | 47 +++++
.../coding/basic/queue/CircleQueueTest.java | 44 ++++
.../java/com/coding/basic/queue/Josephus.java | 39 ++++
.../com/coding/basic/queue/JosephusTest.java | 27 +++
.../java/com/coding/basic/queue/Queue.java | 61 ++++++
.../basic/queue/QueueWithTwoStacks.java | 55 +++++
.../com/coding/basic/stack/QuickMinStack.java | 44 ++++
.../coding/basic/stack/QuickMinStackTest.java | 39 ++++
.../java/com/coding/basic/stack/Stack.java | 24 +++
.../com/coding/basic/stack/StackUtil.java | 168 +++++++++++++++
.../com/coding/basic/stack/StackUtilTest.java | 86 ++++++++
.../basic/stack/StackWithTwoQueues.java | 53 +++++
.../basic/stack/StackWithTwoQueuesTest.java | 36 ++++
.../java/com/coding/basic/stack/Tail.java | 5 +
.../basic/stack/TwoStackInOneArray.java | 117 ++++++++++
.../basic/stack/TwoStackInOneArrayTest.java | 65 ++++++
.../coding/basic/stack/expr/InfixExpr.java | 72 +++++++
.../basic/stack/expr/InfixExprTest.java | 52 +++++
.../basic/stack/expr/InfixToPostfix.java | 43 ++++
.../basic/stack/expr/InfixToPostfixTest.java | 41 ++++
.../coding/basic/stack/expr/PostfixExpr.java | 46 ++++
.../basic/stack/expr/PostfixExprTest.java | 41 ++++
.../coding/basic/stack/expr/PrefixExpr.java | 52 +++++
.../basic/stack/expr/PrefixExprTest.java | 45 ++++
.../com/coding/basic/stack/expr/Token.java | 50 +++++
.../coding/basic/stack/expr/TokenParser.java | 57 +++++
.../basic/stack/expr/TokenParserTest.java | 41 ++++
.../coding/basic/tree/BinarySearchTree.java | 189 +++++++++++++++++
.../basic/tree/BinarySearchTreeTest.java | 108 ++++++++++
.../com/coding/basic/tree/BinaryTreeNode.java | 36 ++++
.../com/coding/basic/tree/BinaryTreeUtil.java | 116 ++++++++++
.../coding/basic/tree/BinaryTreeUtilTest.java | 75 +++++++
.../java/com/coding/basic/tree/FileList.java | 34 +++
.../data-structure/assignment/pom.xml | 32 +++
.../coderising/download/DownloadThread.java | 20 ++
.../coderising/download/FileDownloader.java | 73 +++++++
.../download/FileDownloaderTest.java | 59 ++++++
.../coderising/download/api/Connection.java | 23 ++
.../download/api/ConnectionException.java | 5 +
.../download/api/ConnectionManager.java | 10 +
.../download/api/DownloadListener.java | 5 +
.../download/impl/ConnectionImpl.java | 27 +++
.../download/impl/ConnectionManagerImpl.java | 15 ++
.../coderising/litestruts/LoginAction.java | 39 ++++
.../com/coderising/litestruts/Struts.java | 34 +++
.../com/coderising/litestruts/StrutsTest.java | 43 ++++
.../java/com/coderising/litestruts/View.java | 23 ++
.../java/com/coderising/litestruts/struts.xml | 11 +
.../com/coderising/ood/course/bad/Course.java | 24 +++
.../ood/course/bad/CourseOffering.java | 26 +++
.../ood/course/bad/CourseService.java | 16 ++
.../coderising/ood/course/bad/Student.java | 14 ++
.../coderising/ood/course/good/Course.java | 18 ++
.../ood/course/good/CourseOffering.java | 34 +++
.../ood/course/good/CourseService.java | 14 ++
.../coderising/ood/course/good/Student.java | 21 ++
.../java/com/coderising/ood/ocp/DateUtil.java | 10 +
.../java/com/coderising/ood/ocp/Logger.java | 38 ++++
.../java/com/coderising/ood/ocp/MailUtil.java | 10 +
.../java/com/coderising/ood/ocp/SMSUtil.java | 10 +
.../com/coderising/ood/srp/Configuration.java | 23 ++
.../coderising/ood/srp/ConfigurationKeys.java | 9 +
.../java/com/coderising/ood/srp/DBUtil.java | 25 +++
.../java/com/coderising/ood/srp/MailUtil.java | 18 ++
.../com/coderising/ood/srp/PromotionMail.java | 199 ++++++++++++++++++
.../coderising/ood/srp/product_promotion.txt | 4 +
.../main/java/com/coding/basic/Iterator.java | 7 +
.../src/main/java/com/coding/basic/List.java | 9 +
.../com/coding/basic/array/ArrayList.java | 35 +++
.../com/coding/basic/array/ArrayUtil.java | 96 +++++++++
.../coding/basic/linklist/LRUPageFrame.java | 57 +++++
.../basic/linklist/LRUPageFrameTest.java | 34 +++
.../com/coding/basic/linklist/LinkedList.java | 125 +++++++++++
.../com/coding/basic/queue/CircleQueue.java | 39 ++++
.../java/com/coding/basic/queue/Josephus.java | 18 ++
.../com/coding/basic/queue/JosephusTest.java | 27 +++
.../java/com/coding/basic/queue/Queue.java | 61 ++++++
.../basic/queue/QueueWithTwoStacks.java | 47 +++++
.../com/coding/basic/stack/QuickMinStack.java | 19 ++
.../java/com/coding/basic/stack/Stack.java | 24 +++
.../com/coding/basic/stack/StackUtil.java | 48 +++++
.../com/coding/basic/stack/StackUtilTest.java | 65 ++++++
.../basic/stack/StackWithTwoQueues.java | 16 ++
.../basic/stack/TwoStackInOneArray.java | 57 +++++
.../coding/basic/stack/expr/InfixExpr.java | 15 ++
.../basic/stack/expr/InfixExprTest.java | 52 +++++
.../basic/stack/expr/InfixToPostfix.java | 14 ++
.../coding/basic/stack/expr/PostfixExpr.java | 18 ++
.../basic/stack/expr/PostfixExprTest.java | 41 ++++
.../coding/basic/stack/expr/PrefixExpr.java | 18 ++
.../basic/stack/expr/PrefixExprTest.java | 45 ++++
.../com/coding/basic/stack/expr/Token.java | 50 +++++
.../coding/basic/stack/expr/TokenParser.java | 57 +++++
.../basic/stack/expr/TokenParserTest.java | 41 ++++
.../coding/basic/tree/BinarySearchTree.java | 55 +++++
.../basic/tree/BinarySearchTreeTest.java | 109 ++++++++++
.../com/coding/basic/tree/BinaryTreeNode.java | 35 +++
.../com/coding/basic/tree/BinaryTreeUtil.java | 66 ++++++
.../coding/basic/tree/BinaryTreeUtilTest.java | 75 +++++++
.../java/com/coding/basic/tree/FileList.java | 10 +
students/250103158/ood/ood-assignment/pom.xml | 32 +++
.../com/coderising/ood/srp/Configuration.java | 23 ++
.../coderising/ood/srp/ConfigurationKeys.java | 9 +
.../java/com/coderising/ood/srp/DBUtil.java | 25 +++
.../java/com/coderising/ood/srp/MailUtil.java | 18 ++
.../com/coderising/ood/srp/PromotionMail.java | 199 ++++++++++++++++++
.../coderising/ood/srp/product_promotion.txt | 4 +
129 files changed, 5624 insertions(+)
create mode 100644 students/250103158/data-structure/answer/pom.xml
create mode 100644 students/250103158/data-structure/answer/src/main/java/com/coderising/download/DownloadThread.java
create mode 100644 students/250103158/data-structure/answer/src/main/java/com/coderising/download/FileDownloader.java
create mode 100644 students/250103158/data-structure/answer/src/main/java/com/coderising/download/FileDownloaderTest.java
create mode 100644 students/250103158/data-structure/answer/src/main/java/com/coderising/download/api/Connection.java
create mode 100644 students/250103158/data-structure/answer/src/main/java/com/coderising/download/api/ConnectionException.java
create mode 100644 students/250103158/data-structure/answer/src/main/java/com/coderising/download/api/ConnectionManager.java
create mode 100644 students/250103158/data-structure/answer/src/main/java/com/coderising/download/api/DownloadListener.java
create mode 100644 students/250103158/data-structure/answer/src/main/java/com/coderising/download/impl/ConnectionImpl.java
create mode 100644 students/250103158/data-structure/answer/src/main/java/com/coderising/download/impl/ConnectionManagerImpl.java
create mode 100644 students/250103158/data-structure/answer/src/main/java/com/coderising/litestruts/LoginAction.java
create mode 100644 students/250103158/data-structure/answer/src/main/java/com/coderising/litestruts/Struts.java
create mode 100644 students/250103158/data-structure/answer/src/main/java/com/coderising/litestruts/StrutsTest.java
create mode 100644 students/250103158/data-structure/answer/src/main/java/com/coderising/litestruts/View.java
create mode 100644 students/250103158/data-structure/answer/src/main/java/com/coderising/litestruts/struts.xml
create mode 100644 students/250103158/data-structure/answer/src/main/java/com/coding/basic/Iterator.java
create mode 100644 students/250103158/data-structure/answer/src/main/java/com/coding/basic/List.java
create mode 100644 students/250103158/data-structure/answer/src/main/java/com/coding/basic/array/ArrayList.java
create mode 100644 students/250103158/data-structure/answer/src/main/java/com/coding/basic/array/ArrayUtil.java
create mode 100644 students/250103158/data-structure/answer/src/main/java/com/coding/basic/linklist/LRUPageFrame.java
create mode 100644 students/250103158/data-structure/answer/src/main/java/com/coding/basic/linklist/LRUPageFrameTest.java
create mode 100644 students/250103158/data-structure/answer/src/main/java/com/coding/basic/linklist/LinkedList.java
create mode 100644 students/250103158/data-structure/answer/src/main/java/com/coding/basic/queue/CircleQueue.java
create mode 100644 students/250103158/data-structure/answer/src/main/java/com/coding/basic/queue/CircleQueueTest.java
create mode 100644 students/250103158/data-structure/answer/src/main/java/com/coding/basic/queue/Josephus.java
create mode 100644 students/250103158/data-structure/answer/src/main/java/com/coding/basic/queue/JosephusTest.java
create mode 100644 students/250103158/data-structure/answer/src/main/java/com/coding/basic/queue/Queue.java
create mode 100644 students/250103158/data-structure/answer/src/main/java/com/coding/basic/queue/QueueWithTwoStacks.java
create mode 100644 students/250103158/data-structure/answer/src/main/java/com/coding/basic/stack/QuickMinStack.java
create mode 100644 students/250103158/data-structure/answer/src/main/java/com/coding/basic/stack/QuickMinStackTest.java
create mode 100644 students/250103158/data-structure/answer/src/main/java/com/coding/basic/stack/Stack.java
create mode 100644 students/250103158/data-structure/answer/src/main/java/com/coding/basic/stack/StackUtil.java
create mode 100644 students/250103158/data-structure/answer/src/main/java/com/coding/basic/stack/StackUtilTest.java
create mode 100644 students/250103158/data-structure/answer/src/main/java/com/coding/basic/stack/StackWithTwoQueues.java
create mode 100644 students/250103158/data-structure/answer/src/main/java/com/coding/basic/stack/StackWithTwoQueuesTest.java
create mode 100644 students/250103158/data-structure/answer/src/main/java/com/coding/basic/stack/Tail.java
create mode 100644 students/250103158/data-structure/answer/src/main/java/com/coding/basic/stack/TwoStackInOneArray.java
create mode 100644 students/250103158/data-structure/answer/src/main/java/com/coding/basic/stack/TwoStackInOneArrayTest.java
create mode 100644 students/250103158/data-structure/answer/src/main/java/com/coding/basic/stack/expr/InfixExpr.java
create mode 100644 students/250103158/data-structure/answer/src/main/java/com/coding/basic/stack/expr/InfixExprTest.java
create mode 100644 students/250103158/data-structure/answer/src/main/java/com/coding/basic/stack/expr/InfixToPostfix.java
create mode 100644 students/250103158/data-structure/answer/src/main/java/com/coding/basic/stack/expr/InfixToPostfixTest.java
create mode 100644 students/250103158/data-structure/answer/src/main/java/com/coding/basic/stack/expr/PostfixExpr.java
create mode 100644 students/250103158/data-structure/answer/src/main/java/com/coding/basic/stack/expr/PostfixExprTest.java
create mode 100644 students/250103158/data-structure/answer/src/main/java/com/coding/basic/stack/expr/PrefixExpr.java
create mode 100644 students/250103158/data-structure/answer/src/main/java/com/coding/basic/stack/expr/PrefixExprTest.java
create mode 100644 students/250103158/data-structure/answer/src/main/java/com/coding/basic/stack/expr/Token.java
create mode 100644 students/250103158/data-structure/answer/src/main/java/com/coding/basic/stack/expr/TokenParser.java
create mode 100644 students/250103158/data-structure/answer/src/main/java/com/coding/basic/stack/expr/TokenParserTest.java
create mode 100644 students/250103158/data-structure/answer/src/main/java/com/coding/basic/tree/BinarySearchTree.java
create mode 100644 students/250103158/data-structure/answer/src/main/java/com/coding/basic/tree/BinarySearchTreeTest.java
create mode 100644 students/250103158/data-structure/answer/src/main/java/com/coding/basic/tree/BinaryTreeNode.java
create mode 100644 students/250103158/data-structure/answer/src/main/java/com/coding/basic/tree/BinaryTreeUtil.java
create mode 100644 students/250103158/data-structure/answer/src/main/java/com/coding/basic/tree/BinaryTreeUtilTest.java
create mode 100644 students/250103158/data-structure/answer/src/main/java/com/coding/basic/tree/FileList.java
create mode 100644 students/250103158/data-structure/assignment/pom.xml
create mode 100644 students/250103158/data-structure/assignment/src/main/java/com/coderising/download/DownloadThread.java
create mode 100644 students/250103158/data-structure/assignment/src/main/java/com/coderising/download/FileDownloader.java
create mode 100644 students/250103158/data-structure/assignment/src/main/java/com/coderising/download/FileDownloaderTest.java
create mode 100644 students/250103158/data-structure/assignment/src/main/java/com/coderising/download/api/Connection.java
create mode 100644 students/250103158/data-structure/assignment/src/main/java/com/coderising/download/api/ConnectionException.java
create mode 100644 students/250103158/data-structure/assignment/src/main/java/com/coderising/download/api/ConnectionManager.java
create mode 100644 students/250103158/data-structure/assignment/src/main/java/com/coderising/download/api/DownloadListener.java
create mode 100644 students/250103158/data-structure/assignment/src/main/java/com/coderising/download/impl/ConnectionImpl.java
create mode 100644 students/250103158/data-structure/assignment/src/main/java/com/coderising/download/impl/ConnectionManagerImpl.java
create mode 100644 students/250103158/data-structure/assignment/src/main/java/com/coderising/litestruts/LoginAction.java
create mode 100644 students/250103158/data-structure/assignment/src/main/java/com/coderising/litestruts/Struts.java
create mode 100644 students/250103158/data-structure/assignment/src/main/java/com/coderising/litestruts/StrutsTest.java
create mode 100644 students/250103158/data-structure/assignment/src/main/java/com/coderising/litestruts/View.java
create mode 100644 students/250103158/data-structure/assignment/src/main/java/com/coderising/litestruts/struts.xml
create mode 100644 students/250103158/data-structure/assignment/src/main/java/com/coderising/ood/course/bad/Course.java
create mode 100644 students/250103158/data-structure/assignment/src/main/java/com/coderising/ood/course/bad/CourseOffering.java
create mode 100644 students/250103158/data-structure/assignment/src/main/java/com/coderising/ood/course/bad/CourseService.java
create mode 100644 students/250103158/data-structure/assignment/src/main/java/com/coderising/ood/course/bad/Student.java
create mode 100644 students/250103158/data-structure/assignment/src/main/java/com/coderising/ood/course/good/Course.java
create mode 100644 students/250103158/data-structure/assignment/src/main/java/com/coderising/ood/course/good/CourseOffering.java
create mode 100644 students/250103158/data-structure/assignment/src/main/java/com/coderising/ood/course/good/CourseService.java
create mode 100644 students/250103158/data-structure/assignment/src/main/java/com/coderising/ood/course/good/Student.java
create mode 100644 students/250103158/data-structure/assignment/src/main/java/com/coderising/ood/ocp/DateUtil.java
create mode 100644 students/250103158/data-structure/assignment/src/main/java/com/coderising/ood/ocp/Logger.java
create mode 100644 students/250103158/data-structure/assignment/src/main/java/com/coderising/ood/ocp/MailUtil.java
create mode 100644 students/250103158/data-structure/assignment/src/main/java/com/coderising/ood/ocp/SMSUtil.java
create mode 100644 students/250103158/data-structure/assignment/src/main/java/com/coderising/ood/srp/Configuration.java
create mode 100644 students/250103158/data-structure/assignment/src/main/java/com/coderising/ood/srp/ConfigurationKeys.java
create mode 100644 students/250103158/data-structure/assignment/src/main/java/com/coderising/ood/srp/DBUtil.java
create mode 100644 students/250103158/data-structure/assignment/src/main/java/com/coderising/ood/srp/MailUtil.java
create mode 100644 students/250103158/data-structure/assignment/src/main/java/com/coderising/ood/srp/PromotionMail.java
create mode 100644 students/250103158/data-structure/assignment/src/main/java/com/coderising/ood/srp/product_promotion.txt
create mode 100644 students/250103158/data-structure/assignment/src/main/java/com/coding/basic/Iterator.java
create mode 100644 students/250103158/data-structure/assignment/src/main/java/com/coding/basic/List.java
create mode 100644 students/250103158/data-structure/assignment/src/main/java/com/coding/basic/array/ArrayList.java
create mode 100644 students/250103158/data-structure/assignment/src/main/java/com/coding/basic/array/ArrayUtil.java
create mode 100644 students/250103158/data-structure/assignment/src/main/java/com/coding/basic/linklist/LRUPageFrame.java
create mode 100644 students/250103158/data-structure/assignment/src/main/java/com/coding/basic/linklist/LRUPageFrameTest.java
create mode 100644 students/250103158/data-structure/assignment/src/main/java/com/coding/basic/linklist/LinkedList.java
create mode 100644 students/250103158/data-structure/assignment/src/main/java/com/coding/basic/queue/CircleQueue.java
create mode 100644 students/250103158/data-structure/assignment/src/main/java/com/coding/basic/queue/Josephus.java
create mode 100644 students/250103158/data-structure/assignment/src/main/java/com/coding/basic/queue/JosephusTest.java
create mode 100644 students/250103158/data-structure/assignment/src/main/java/com/coding/basic/queue/Queue.java
create mode 100644 students/250103158/data-structure/assignment/src/main/java/com/coding/basic/queue/QueueWithTwoStacks.java
create mode 100644 students/250103158/data-structure/assignment/src/main/java/com/coding/basic/stack/QuickMinStack.java
create mode 100644 students/250103158/data-structure/assignment/src/main/java/com/coding/basic/stack/Stack.java
create mode 100644 students/250103158/data-structure/assignment/src/main/java/com/coding/basic/stack/StackUtil.java
create mode 100644 students/250103158/data-structure/assignment/src/main/java/com/coding/basic/stack/StackUtilTest.java
create mode 100644 students/250103158/data-structure/assignment/src/main/java/com/coding/basic/stack/StackWithTwoQueues.java
create mode 100644 students/250103158/data-structure/assignment/src/main/java/com/coding/basic/stack/TwoStackInOneArray.java
create mode 100644 students/250103158/data-structure/assignment/src/main/java/com/coding/basic/stack/expr/InfixExpr.java
create mode 100644 students/250103158/data-structure/assignment/src/main/java/com/coding/basic/stack/expr/InfixExprTest.java
create mode 100644 students/250103158/data-structure/assignment/src/main/java/com/coding/basic/stack/expr/InfixToPostfix.java
create mode 100644 students/250103158/data-structure/assignment/src/main/java/com/coding/basic/stack/expr/PostfixExpr.java
create mode 100644 students/250103158/data-structure/assignment/src/main/java/com/coding/basic/stack/expr/PostfixExprTest.java
create mode 100644 students/250103158/data-structure/assignment/src/main/java/com/coding/basic/stack/expr/PrefixExpr.java
create mode 100644 students/250103158/data-structure/assignment/src/main/java/com/coding/basic/stack/expr/PrefixExprTest.java
create mode 100644 students/250103158/data-structure/assignment/src/main/java/com/coding/basic/stack/expr/Token.java
create mode 100644 students/250103158/data-structure/assignment/src/main/java/com/coding/basic/stack/expr/TokenParser.java
create mode 100644 students/250103158/data-structure/assignment/src/main/java/com/coding/basic/stack/expr/TokenParserTest.java
create mode 100644 students/250103158/data-structure/assignment/src/main/java/com/coding/basic/tree/BinarySearchTree.java
create mode 100644 students/250103158/data-structure/assignment/src/main/java/com/coding/basic/tree/BinarySearchTreeTest.java
create mode 100644 students/250103158/data-structure/assignment/src/main/java/com/coding/basic/tree/BinaryTreeNode.java
create mode 100644 students/250103158/data-structure/assignment/src/main/java/com/coding/basic/tree/BinaryTreeUtil.java
create mode 100644 students/250103158/data-structure/assignment/src/main/java/com/coding/basic/tree/BinaryTreeUtilTest.java
create mode 100644 students/250103158/data-structure/assignment/src/main/java/com/coding/basic/tree/FileList.java
create mode 100644 students/250103158/ood/ood-assignment/pom.xml
create mode 100644 students/250103158/ood/ood-assignment/src/main/java/com/coderising/ood/srp/Configuration.java
create mode 100644 students/250103158/ood/ood-assignment/src/main/java/com/coderising/ood/srp/ConfigurationKeys.java
create mode 100644 students/250103158/ood/ood-assignment/src/main/java/com/coderising/ood/srp/DBUtil.java
create mode 100644 students/250103158/ood/ood-assignment/src/main/java/com/coderising/ood/srp/MailUtil.java
create mode 100644 students/250103158/ood/ood-assignment/src/main/java/com/coderising/ood/srp/PromotionMail.java
create mode 100644 students/250103158/ood/ood-assignment/src/main/java/com/coderising/ood/srp/product_promotion.txt
diff --git a/students/250103158/data-structure/answer/pom.xml b/students/250103158/data-structure/answer/pom.xml
new file mode 100644
index 0000000000..ac6ba882df
--- /dev/null
+++ b/students/250103158/data-structure/answer/pom.xml
@@ -0,0 +1,32 @@
+
+ 4.0.0
+
+ com.coderising
+ ds-answer
+ 0.0.1-SNAPSHOT
+ jar
+
+ ds-answer
+ http://maven.apache.org
+
+
+ UTF-8
+
+
+
+
+
+ junit
+ junit
+ 4.12
+
+
+
+
+
+ aliyunmaven
+ http://maven.aliyun.com/nexus/content/groups/public/
+
+
+
diff --git a/students/250103158/data-structure/answer/src/main/java/com/coderising/download/DownloadThread.java b/students/250103158/data-structure/answer/src/main/java/com/coderising/download/DownloadThread.java
new file mode 100644
index 0000000000..900a3ad358
--- /dev/null
+++ b/students/250103158/data-structure/answer/src/main/java/com/coderising/download/DownloadThread.java
@@ -0,0 +1,20 @@
+package com.coderising.download;
+
+import com.coderising.download.api.Connection;
+
+public class DownloadThread extends Thread{
+
+ Connection conn;
+ int startPos;
+ int endPos;
+
+ public DownloadThread( Connection conn, int startPos, int endPos){
+
+ this.conn = conn;
+ this.startPos = startPos;
+ this.endPos = endPos;
+ }
+ public void run(){
+
+ }
+}
diff --git a/students/250103158/data-structure/answer/src/main/java/com/coderising/download/FileDownloader.java b/students/250103158/data-structure/answer/src/main/java/com/coderising/download/FileDownloader.java
new file mode 100644
index 0000000000..c3c8a3f27d
--- /dev/null
+++ b/students/250103158/data-structure/answer/src/main/java/com/coderising/download/FileDownloader.java
@@ -0,0 +1,73 @@
+package com.coderising.download;
+
+import com.coderising.download.api.Connection;
+import com.coderising.download.api.ConnectionException;
+import com.coderising.download.api.ConnectionManager;
+import com.coderising.download.api.DownloadListener;
+
+
+public class FileDownloader {
+
+ String url;
+
+ DownloadListener listener;
+
+ ConnectionManager cm;
+
+
+ public FileDownloader(String _url) {
+ this.url = _url;
+
+ }
+
+ public void execute(){
+ // 在这里实现你的代码, 注意: 需要用多线程实现下载
+ // 这个类依赖于其他几个接口, 你需要写这几个接口的实现代码
+ // (1) ConnectionManager , 可以打开一个连接,通过Connection可以读取其中的一段(用startPos, endPos来指定)
+ // (2) DownloadListener, 由于是多线程下载, 调用这个类的客户端不知道什么时候结束,所以你需要实现当所有
+ // 线程都执行完以后, 调用listener的notifiedFinished方法, 这样客户端就能收到通知。
+ // 具体的实现思路:
+ // 1. 需要调用ConnectionManager的open方法打开连接, 然后通过Connection.getContentLength方法获得文件的长度
+ // 2. 至少启动3个线程下载, 注意每个线程需要先调用ConnectionManager的open方法
+ // 然后调用read方法, read方法中有读取文件的开始位置和结束位置的参数, 返回值是byte[]数组
+ // 3. 把byte数组写入到文件中
+ // 4. 所有的线程都下载完成以后, 需要调用listener的notifiedFinished方法
+
+ // 下面的代码是示例代码, 也就是说只有一个线程, 你需要改造成多线程的。
+ Connection conn = null;
+ try {
+
+ conn = cm.open(this.url);
+
+ int length = conn.getContentLength();
+
+ new DownloadThread(conn,0,length-1).start();
+
+ } catch (ConnectionException e) {
+ e.printStackTrace();
+ }finally{
+ if(conn != null){
+ conn.close();
+ }
+ }
+
+
+
+
+ }
+
+ public void setListener(DownloadListener listener) {
+ this.listener = listener;
+ }
+
+
+
+ public void setConnectionManager(ConnectionManager ucm){
+ this.cm = ucm;
+ }
+
+ public DownloadListener getListener(){
+ return this.listener;
+ }
+
+}
diff --git a/students/250103158/data-structure/answer/src/main/java/com/coderising/download/FileDownloaderTest.java b/students/250103158/data-structure/answer/src/main/java/com/coderising/download/FileDownloaderTest.java
new file mode 100644
index 0000000000..4ff7f46ae0
--- /dev/null
+++ b/students/250103158/data-structure/answer/src/main/java/com/coderising/download/FileDownloaderTest.java
@@ -0,0 +1,59 @@
+package com.coderising.download;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+import com.coderising.download.api.ConnectionManager;
+import com.coderising.download.api.DownloadListener;
+import com.coderising.download.impl.ConnectionManagerImpl;
+
+public class FileDownloaderTest {
+ boolean downloadFinished = false;
+ @Before
+ public void setUp() throws Exception {
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ }
+
+ @Test
+ public void testDownload() {
+
+ String url = "http://localhost:8080/test.jpg";
+
+ FileDownloader downloader = new FileDownloader(url);
+
+
+ ConnectionManager cm = new ConnectionManagerImpl();
+ downloader.setConnectionManager(cm);
+
+ downloader.setListener(new DownloadListener() {
+ @Override
+ public void notifyFinished() {
+ downloadFinished = true;
+ }
+
+ });
+
+
+ downloader.execute();
+
+ // 等待多线程下载程序执行完毕
+ while (!downloadFinished) {
+ try {
+ System.out.println("还没有下载完成,休眠五秒");
+ //休眠5秒
+ Thread.sleep(5000);
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+ }
+ System.out.println("下载完成!");
+
+
+
+ }
+
+}
diff --git a/students/250103158/data-structure/answer/src/main/java/com/coderising/download/api/Connection.java b/students/250103158/data-structure/answer/src/main/java/com/coderising/download/api/Connection.java
new file mode 100644
index 0000000000..0957eaf7f4
--- /dev/null
+++ b/students/250103158/data-structure/answer/src/main/java/com/coderising/download/api/Connection.java
@@ -0,0 +1,23 @@
+package com.coderising.download.api;
+
+import java.io.IOException;
+
+public interface Connection {
+ /**
+ * 给定开始和结束位置, 读取数据, 返回值是字节数组
+ * @param startPos 开始位置, 从0开始
+ * @param endPos 结束位置
+ * @return
+ */
+ public byte[] read(int startPos,int endPos) throws IOException;
+ /**
+ * 得到数据内容的长度
+ * @return
+ */
+ public int getContentLength();
+
+ /**
+ * 关闭连接
+ */
+ public void close();
+}
diff --git a/students/250103158/data-structure/answer/src/main/java/com/coderising/download/api/ConnectionException.java b/students/250103158/data-structure/answer/src/main/java/com/coderising/download/api/ConnectionException.java
new file mode 100644
index 0000000000..1551a80b3d
--- /dev/null
+++ b/students/250103158/data-structure/answer/src/main/java/com/coderising/download/api/ConnectionException.java
@@ -0,0 +1,5 @@
+package com.coderising.download.api;
+
+public class ConnectionException extends Exception {
+
+}
diff --git a/students/250103158/data-structure/answer/src/main/java/com/coderising/download/api/ConnectionManager.java b/students/250103158/data-structure/answer/src/main/java/com/coderising/download/api/ConnectionManager.java
new file mode 100644
index 0000000000..ce045393b1
--- /dev/null
+++ b/students/250103158/data-structure/answer/src/main/java/com/coderising/download/api/ConnectionManager.java
@@ -0,0 +1,10 @@
+package com.coderising.download.api;
+
+public interface ConnectionManager {
+ /**
+ * 给定一个url , 打开一个连接
+ * @param url
+ * @return
+ */
+ public Connection open(String url) throws ConnectionException;
+}
diff --git a/students/250103158/data-structure/answer/src/main/java/com/coderising/download/api/DownloadListener.java b/students/250103158/data-structure/answer/src/main/java/com/coderising/download/api/DownloadListener.java
new file mode 100644
index 0000000000..bf9807b307
--- /dev/null
+++ b/students/250103158/data-structure/answer/src/main/java/com/coderising/download/api/DownloadListener.java
@@ -0,0 +1,5 @@
+package com.coderising.download.api;
+
+public interface DownloadListener {
+ public void notifyFinished();
+}
diff --git a/students/250103158/data-structure/answer/src/main/java/com/coderising/download/impl/ConnectionImpl.java b/students/250103158/data-structure/answer/src/main/java/com/coderising/download/impl/ConnectionImpl.java
new file mode 100644
index 0000000000..36a9d2ce15
--- /dev/null
+++ b/students/250103158/data-structure/answer/src/main/java/com/coderising/download/impl/ConnectionImpl.java
@@ -0,0 +1,27 @@
+package com.coderising.download.impl;
+
+import java.io.IOException;
+
+import com.coderising.download.api.Connection;
+
+public class ConnectionImpl implements Connection{
+
+ @Override
+ public byte[] read(int startPos, int endPos) throws IOException {
+
+ return null;
+ }
+
+ @Override
+ public int getContentLength() {
+
+ return 0;
+ }
+
+ @Override
+ public void close() {
+
+
+ }
+
+}
diff --git a/students/250103158/data-structure/answer/src/main/java/com/coderising/download/impl/ConnectionManagerImpl.java b/students/250103158/data-structure/answer/src/main/java/com/coderising/download/impl/ConnectionManagerImpl.java
new file mode 100644
index 0000000000..172371dd55
--- /dev/null
+++ b/students/250103158/data-structure/answer/src/main/java/com/coderising/download/impl/ConnectionManagerImpl.java
@@ -0,0 +1,15 @@
+package com.coderising.download.impl;
+
+import com.coderising.download.api.Connection;
+import com.coderising.download.api.ConnectionException;
+import com.coderising.download.api.ConnectionManager;
+
+public class ConnectionManagerImpl implements ConnectionManager {
+
+ @Override
+ public Connection open(String url) throws ConnectionException {
+
+ return null;
+ }
+
+}
diff --git a/students/250103158/data-structure/answer/src/main/java/com/coderising/litestruts/LoginAction.java b/students/250103158/data-structure/answer/src/main/java/com/coderising/litestruts/LoginAction.java
new file mode 100644
index 0000000000..dcdbe226ed
--- /dev/null
+++ b/students/250103158/data-structure/answer/src/main/java/com/coderising/litestruts/LoginAction.java
@@ -0,0 +1,39 @@
+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/250103158/data-structure/answer/src/main/java/com/coderising/litestruts/Struts.java b/students/250103158/data-structure/answer/src/main/java/com/coderising/litestruts/Struts.java
new file mode 100644
index 0000000000..85e2e22de3
--- /dev/null
+++ b/students/250103158/data-structure/answer/src/main/java/com/coderising/litestruts/Struts.java
@@ -0,0 +1,34 @@
+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/250103158/data-structure/answer/src/main/java/com/coderising/litestruts/StrutsTest.java b/students/250103158/data-structure/answer/src/main/java/com/coderising/litestruts/StrutsTest.java
new file mode 100644
index 0000000000..b8c81faf3c
--- /dev/null
+++ b/students/250103158/data-structure/answer/src/main/java/com/coderising/litestruts/StrutsTest.java
@@ -0,0 +1,43 @@
+package com.coderising.litestruts;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+
+
+
+
+public class StrutsTest {
+
+ @Test
+ public void testLoginActionSuccess() {
+
+ 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/250103158/data-structure/answer/src/main/java/com/coderising/litestruts/View.java b/students/250103158/data-structure/answer/src/main/java/com/coderising/litestruts/View.java
new file mode 100644
index 0000000000..07df2a5dab
--- /dev/null
+++ b/students/250103158/data-structure/answer/src/main/java/com/coderising/litestruts/View.java
@@ -0,0 +1,23 @@
+package com.coderising.litestruts;
+
+import java.util.Map;
+
+public class View {
+ private String jsp;
+ private Map parameters;
+
+ public String getJsp() {
+ return jsp;
+ }
+ public View setJsp(String jsp) {
+ this.jsp = jsp;
+ return this;
+ }
+ public Map getParameters() {
+ return parameters;
+ }
+ public View setParameters(Map parameters) {
+ this.parameters = parameters;
+ return this;
+ }
+}
diff --git a/students/250103158/data-structure/answer/src/main/java/com/coderising/litestruts/struts.xml b/students/250103158/data-structure/answer/src/main/java/com/coderising/litestruts/struts.xml
new file mode 100644
index 0000000000..e5d9aebba8
--- /dev/null
+++ b/students/250103158/data-structure/answer/src/main/java/com/coderising/litestruts/struts.xml
@@ -0,0 +1,11 @@
+
+
+
+ /jsp/homepage.jsp
+ /jsp/showLogin.jsp
+
+
+ /jsp/welcome.jsp
+ /jsp/error.jsp
+
+
\ No newline at end of file
diff --git a/students/250103158/data-structure/answer/src/main/java/com/coding/basic/Iterator.java b/students/250103158/data-structure/answer/src/main/java/com/coding/basic/Iterator.java
new file mode 100644
index 0000000000..06ef6311b2
--- /dev/null
+++ b/students/250103158/data-structure/answer/src/main/java/com/coding/basic/Iterator.java
@@ -0,0 +1,7 @@
+package com.coding.basic;
+
+public interface Iterator {
+ public boolean hasNext();
+ public Object next();
+
+}
diff --git a/students/250103158/data-structure/answer/src/main/java/com/coding/basic/List.java b/students/250103158/data-structure/answer/src/main/java/com/coding/basic/List.java
new file mode 100644
index 0000000000..10d13b5832
--- /dev/null
+++ b/students/250103158/data-structure/answer/src/main/java/com/coding/basic/List.java
@@ -0,0 +1,9 @@
+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/250103158/data-structure/answer/src/main/java/com/coding/basic/array/ArrayList.java b/students/250103158/data-structure/answer/src/main/java/com/coding/basic/array/ArrayList.java
new file mode 100644
index 0000000000..4576c016af
--- /dev/null
+++ b/students/250103158/data-structure/answer/src/main/java/com/coding/basic/array/ArrayList.java
@@ -0,0 +1,35 @@
+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/250103158/data-structure/answer/src/main/java/com/coding/basic/array/ArrayUtil.java b/students/250103158/data-structure/answer/src/main/java/com/coding/basic/array/ArrayUtil.java
new file mode 100644
index 0000000000..45740e6d57
--- /dev/null
+++ b/students/250103158/data-structure/answer/src/main/java/com/coding/basic/array/ArrayUtil.java
@@ -0,0 +1,96 @@
+package com.coding.basic.array;
+
+public class ArrayUtil {
+
+ /**
+ * 给定一个整形数组a , 对该数组的值进行置换
+ 例如: a = [7, 9 , 30, 3] , 置换后为 [3, 30, 9,7]
+ 如果 a = [7, 9, 30, 3, 4] , 置换后为 [4,3, 30 , 9,7]
+ * @param origin
+ * @return
+ */
+ public void reverseArray(int[] origin){
+
+ }
+
+ /**
+ * 现在有如下的一个数组: int oldArr[]={1,3,4,5,0,0,6,6,0,5,4,7,6,7,0,5}
+ * 要求将以上数组中值为0的项去掉,将不为0的值存入一个新的数组,生成的新数组为:
+ * {1,3,4,5,6,6,5,4,7,6,7,5}
+ * @param oldArray
+ * @return
+ */
+
+ public int[] removeZero(int[] oldArray){
+ return null;
+ }
+
+ /**
+ * 给定两个已经排序好的整形数组, a1和a2 , 创建一个新的数组a3, 使得a3 包含a1和a2 的所有元素, 并且仍然是有序的
+ * 例如 a1 = [3, 5, 7,8] a2 = [4, 5, 6,7] 则 a3 为[3,4,5,6,7,8] , 注意: 已经消除了重复
+ * @param array1
+ * @param array2
+ * @return
+ */
+
+ public int[] merge(int[] array1, int[] array2){
+ return null;
+ }
+ /**
+ * 把一个已经存满数据的数组 oldArray的容量进行扩展, 扩展后的新数据大小为oldArray.length + size
+ * 注意,老数组的元素在新数组中需要保持
+ * 例如 oldArray = [2,3,6] , size = 3,则返回的新数组为
+ * [2,3,6,0,0,0]
+ * @param oldArray
+ * @param size
+ * @return
+ */
+ public int[] grow(int [] oldArray, int size){
+ return null;
+ }
+
+ /**
+ * 斐波那契数列为:1,1,2,3,5,8,13,21...... ,给定一个最大值, 返回小于该值的数列
+ * 例如, max = 15 , 则返回的数组应该为 [1,1,2,3,5,8,13]
+ * max = 1, 则返回空数组 []
+ * @param max
+ * @return
+ */
+ public int[] fibonacci(int max){
+ return null;
+ }
+
+ /**
+ * 返回小于给定最大值max的所有素数数组
+ * 例如max = 23, 返回的数组为[2,3,5,7,11,13,17,19]
+ * @param max
+ * @return
+ */
+ public int[] getPrimes(int max){
+ return null;
+ }
+
+ /**
+ * 所谓“完数”, 是指这个数恰好等于它的因子之和,例如6=1+2+3
+ * 给定一个最大值max, 返回一个数组, 数组中是小于max 的所有完数
+ * @param max
+ * @return
+ */
+ public int[] getPerfectNumbers(int max){
+ return null;
+ }
+
+ /**
+ * 用seperator 把数组 array给连接起来
+ * 例如array= [3,8,9], seperator = "-"
+ * 则返回值为"3-8-9"
+ * @param array
+ * @param s
+ * @return
+ */
+ public String join(int[] array, String seperator){
+ return null;
+ }
+
+
+}
diff --git a/students/250103158/data-structure/answer/src/main/java/com/coding/basic/linklist/LRUPageFrame.java b/students/250103158/data-structure/answer/src/main/java/com/coding/basic/linklist/LRUPageFrame.java
new file mode 100644
index 0000000000..24b9d8b155
--- /dev/null
+++ b/students/250103158/data-structure/answer/src/main/java/com/coding/basic/linklist/LRUPageFrame.java
@@ -0,0 +1,164 @@
+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) {
+
+ Node node = find(pageNum);
+ //在该队列中存在, 则提到队列头
+ if (node != null) {
+
+ moveExistingNodeToHead(node);
+
+ } else{
+
+ node = new Node();
+ node.pageNum = pageNum;
+
+ // 缓存容器是否已经超过大小.
+ if (currentSize >= capacity) {
+ removeLast();
+
+ }
+
+ addNewNodetoHead(node);
+
+
+
+
+ }
+ }
+
+ private void addNewNodetoHead(Node node) {
+
+ if(isEmpty()){
+
+ node.prev = null;
+ node.next = null;
+ first = node;
+ last = node;
+
+ } else{
+ node.prev = null;
+ node.next = first;
+ first.prev = node;
+ first = node;
+ }
+ this.currentSize ++;
+ }
+
+ private Node find(int data){
+
+ Node node = first;
+ while(node != null){
+ if(node.pageNum == data){
+ return node;
+ }
+ node = node.next;
+ }
+ return null;
+
+ }
+
+
+
+
+
+
+ /**
+ * 删除链表尾部节点 表示 删除最少使用的缓存对象
+ */
+ private void removeLast() {
+ Node prev = last.prev;
+ prev.next = null;
+ last.prev = null;
+ last = prev;
+ this.currentSize --;
+ }
+
+ /**
+ * 移动到链表头,表示这个节点是最新使用过的
+ *
+ * @param node
+ */
+ private void moveExistingNodeToHead(Node node) {
+
+ if (node == first) {
+
+ return;
+ }
+ else if(node == last){
+ //当前节点是链表尾, 需要放到链表头
+ Node prevNode = node.prev;
+ prevNode.next = null;
+ last.prev = null;
+ last = prevNode;
+
+ } else{
+ //node 在链表的中间, 把node 的前后节点连接起来
+ Node prevNode = node.prev;
+ prevNode.next = node.next;
+
+ Node nextNode = node.next;
+ nextNode.prev = prevNode;
+
+
+ }
+
+ node.prev = null;
+ node.next = first;
+ first.prev = node;
+ first = node;
+
+ }
+ private boolean isEmpty(){
+ return (first == null) && (last == null);
+ }
+
+ 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/250103158/data-structure/answer/src/main/java/com/coding/basic/linklist/LRUPageFrameTest.java b/students/250103158/data-structure/answer/src/main/java/com/coding/basic/linklist/LRUPageFrameTest.java
new file mode 100644
index 0000000000..7fd72fc2b4
--- /dev/null
+++ b/students/250103158/data-structure/answer/src/main/java/com/coding/basic/linklist/LRUPageFrameTest.java
@@ -0,0 +1,34 @@
+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/250103158/data-structure/answer/src/main/java/com/coding/basic/linklist/LinkedList.java b/students/250103158/data-structure/answer/src/main/java/com/coding/basic/linklist/LinkedList.java
new file mode 100644
index 0000000000..f4c7556a2e
--- /dev/null
+++ b/students/250103158/data-structure/answer/src/main/java/com/coding/basic/linklist/LinkedList.java
@@ -0,0 +1,125 @@
+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/250103158/data-structure/answer/src/main/java/com/coding/basic/queue/CircleQueue.java b/students/250103158/data-structure/answer/src/main/java/com/coding/basic/queue/CircleQueue.java
new file mode 100644
index 0000000000..f169d5f8e4
--- /dev/null
+++ b/students/250103158/data-structure/answer/src/main/java/com/coding/basic/queue/CircleQueue.java
@@ -0,0 +1,47 @@
+package com.coding.basic.queue;
+
+public class CircleQueue {
+
+ //用数组来保存循环队列的元素
+ private Object[] elementData ;
+ int size = 0;
+ //队头
+ private int front = 0;
+ //队尾
+ private int rear = 0;
+
+ public CircleQueue(int capacity){
+ elementData = new Object[capacity];
+ }
+ public boolean isEmpty() {
+ return (front == rear) && !isFull();
+
+ }
+
+ public boolean isFull(){
+ return size == elementData.length;
+ }
+ public int size() {
+ return size;
+ }
+
+ public void enQueue(E data) {
+ if(isFull()){
+ throw new RuntimeException("The queue is full");
+ }
+ rear = (rear+1) % elementData.length;
+ elementData[rear++] = data;
+ size++;
+ }
+
+ public E deQueue() {
+ if(isEmpty()){
+ throw new RuntimeException("The queue is empty");
+ }
+ E data = (E)elementData[front];
+ elementData[front] = null;
+ front = (front+1) % elementData.length;
+ size --;
+ return data;
+ }
+}
diff --git a/students/250103158/data-structure/answer/src/main/java/com/coding/basic/queue/CircleQueueTest.java b/students/250103158/data-structure/answer/src/main/java/com/coding/basic/queue/CircleQueueTest.java
new file mode 100644
index 0000000000..7307eb77d4
--- /dev/null
+++ b/students/250103158/data-structure/answer/src/main/java/com/coding/basic/queue/CircleQueueTest.java
@@ -0,0 +1,44 @@
+package com.coding.basic.queue;
+
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+
+
+public class CircleQueueTest {
+
+ @Before
+ public void setUp() throws Exception {
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ }
+
+ @Test
+ public void test() {
+ CircleQueue queue = new CircleQueue(5);
+ Assert.assertTrue(queue.isEmpty());
+ Assert.assertFalse(queue.isFull());
+
+ queue.enQueue("a");
+ queue.enQueue("b");
+ queue.enQueue("c");
+ queue.enQueue("d");
+ queue.enQueue("e");
+
+ Assert.assertTrue(queue.isFull());
+ Assert.assertFalse(queue.isEmpty());
+ Assert.assertEquals(5, queue.size());
+
+ Assert.assertEquals("a", queue.deQueue());
+ Assert.assertEquals("b", queue.deQueue());
+ Assert.assertEquals("c", queue.deQueue());
+ Assert.assertEquals("d", queue.deQueue());
+ Assert.assertEquals("e", queue.deQueue());
+
+ }
+
+}
diff --git a/students/250103158/data-structure/answer/src/main/java/com/coding/basic/queue/Josephus.java b/students/250103158/data-structure/answer/src/main/java/com/coding/basic/queue/Josephus.java
new file mode 100644
index 0000000000..36ec615d36
--- /dev/null
+++ b/students/250103158/data-structure/answer/src/main/java/com/coding/basic/queue/Josephus.java
@@ -0,0 +1,39 @@
+package com.coding.basic.queue;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * 用Queue来实现Josephus问题
+ * 在这个古老的问题当中, N个深陷绝境的人一致同意用这种方式减少生存人数: N个人围成一圈(位置记为0到N-1), 并且从第一个人报数, 报到M的人会被杀死, 直到最后一个人留下来
+ * @author liuxin
+ *
+ */
+public class Josephus {
+
+ public static List execute(int n, int m){
+
+ Queue queue = new Queue();
+ for (int i = 0; i < n; i++){
+ queue.enQueue(i);
+ }
+
+ List result = new ArrayList();
+ int i = 0;
+
+ while (!queue.isEmpty()) {
+
+ int x = queue.deQueue();
+
+ if (++i % m == 0){
+ result.add(x);
+ } else{
+ queue.enQueue(x);
+ }
+ }
+
+
+ return result;
+ }
+
+}
diff --git a/students/250103158/data-structure/answer/src/main/java/com/coding/basic/queue/JosephusTest.java b/students/250103158/data-structure/answer/src/main/java/com/coding/basic/queue/JosephusTest.java
new file mode 100644
index 0000000000..7d90318b51
--- /dev/null
+++ b/students/250103158/data-structure/answer/src/main/java/com/coding/basic/queue/JosephusTest.java
@@ -0,0 +1,27 @@
+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/250103158/data-structure/answer/src/main/java/com/coding/basic/queue/Queue.java b/students/250103158/data-structure/answer/src/main/java/com/coding/basic/queue/Queue.java
new file mode 100644
index 0000000000..c4c4b7325e
--- /dev/null
+++ b/students/250103158/data-structure/answer/src/main/java/com/coding/basic/queue/Queue.java
@@ -0,0 +1,61 @@
+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/250103158/data-structure/answer/src/main/java/com/coding/basic/queue/QueueWithTwoStacks.java b/students/250103158/data-structure/answer/src/main/java/com/coding/basic/queue/QueueWithTwoStacks.java
new file mode 100644
index 0000000000..bc97df0800
--- /dev/null
+++ b/students/250103158/data-structure/answer/src/main/java/com/coding/basic/queue/QueueWithTwoStacks.java
@@ -0,0 +1,55 @@
+package com.coding.basic.queue;
+
+import java.util.NoSuchElementException;
+import java.util.Stack;
+
+public class QueueWithTwoStacks {
+ private Stack stack1;
+ private Stack stack2;
+
+
+ public QueueWithTwoStacks() {
+ stack1 = new Stack();
+ stack2 = new Stack();
+ }
+
+
+ private void moveStack1ToStack2() {
+ while (!stack1.isEmpty()){
+ stack2.push(stack1.pop());
+ }
+
+ }
+
+
+ public boolean isEmpty() {
+ return stack1.isEmpty() && stack2.isEmpty();
+ }
+
+
+
+ public int size() {
+ return stack1.size() + stack2.size();
+ }
+
+
+
+ public void enQueue(E item) {
+ stack1.push(item);
+ }
+
+ public E deQueue() {
+ if (isEmpty()) {
+ throw new NoSuchElementException("Queue is empty");
+ }
+ if (stack2.isEmpty()) {
+ moveStack1ToStack2();
+ }
+
+ return stack2.pop();
+ }
+
+
+
+ }
+
diff --git a/students/250103158/data-structure/answer/src/main/java/com/coding/basic/stack/QuickMinStack.java b/students/250103158/data-structure/answer/src/main/java/com/coding/basic/stack/QuickMinStack.java
new file mode 100644
index 0000000000..faf2644ab1
--- /dev/null
+++ b/students/250103158/data-structure/answer/src/main/java/com/coding/basic/stack/QuickMinStack.java
@@ -0,0 +1,44 @@
+package com.coding.basic.stack;
+
+import java.util.Stack;
+/**
+ * 设计一个栈,支持栈的push和pop操作,以及第三种操作findMin, 它返回改数据结构中的最小元素
+ * finMin操作最坏的情形下时间复杂度应该是O(1) , 简单来讲,操作一次就可以得到最小值
+ * @author liuxin
+ *
+ */
+public class QuickMinStack {
+
+ private Stack normalStack = new Stack();
+ private Stack minNumStack = new Stack();
+
+ public void push(int data){
+
+ normalStack.push(data);
+
+ if(minNumStack.isEmpty()){
+ minNumStack.push(data);
+ } else{
+ if(minNumStack.peek() >= data) {
+ minNumStack.push(data);
+ }
+ }
+
+ }
+ public int pop(){
+ if(normalStack.isEmpty()){
+ throw new RuntimeException("the stack is empty");
+ }
+ int value = normalStack.pop();
+ if(value == minNumStack.peek()){
+ minNumStack.pop();
+ }
+ return value;
+ }
+ public int findMin(){
+ if(minNumStack.isEmpty()){
+ throw new RuntimeException("the stack is empty");
+ }
+ return minNumStack.peek();
+ }
+}
\ No newline at end of file
diff --git a/students/250103158/data-structure/answer/src/main/java/com/coding/basic/stack/QuickMinStackTest.java b/students/250103158/data-structure/answer/src/main/java/com/coding/basic/stack/QuickMinStackTest.java
new file mode 100644
index 0000000000..efe41a9f8f
--- /dev/null
+++ b/students/250103158/data-structure/answer/src/main/java/com/coding/basic/stack/QuickMinStackTest.java
@@ -0,0 +1,39 @@
+package com.coding.basic.stack;
+
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+
+public class QuickMinStackTest {
+
+ @Before
+ public void setUp() throws Exception {
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ }
+
+ @Test
+ public void test() {
+ QuickMinStack stack = new QuickMinStack();
+ stack.push(5);
+ Assert.assertEquals(5, stack.findMin());
+ stack.push(6);
+ Assert.assertEquals(5, stack.findMin());
+ stack.push(4);
+ Assert.assertEquals(4, stack.findMin());
+ stack.push(4);
+ Assert.assertEquals(4, stack.findMin());
+
+ stack.pop();
+ Assert.assertEquals(4, stack.findMin());
+ stack.pop();
+ Assert.assertEquals(5, stack.findMin());
+ stack.pop();
+ Assert.assertEquals(5, stack.findMin());
+ }
+
+}
diff --git a/students/250103158/data-structure/answer/src/main/java/com/coding/basic/stack/Stack.java b/students/250103158/data-structure/answer/src/main/java/com/coding/basic/stack/Stack.java
new file mode 100644
index 0000000000..fedb243604
--- /dev/null
+++ b/students/250103158/data-structure/answer/src/main/java/com/coding/basic/stack/Stack.java
@@ -0,0 +1,24 @@
+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/250103158/data-structure/answer/src/main/java/com/coding/basic/stack/StackUtil.java b/students/250103158/data-structure/answer/src/main/java/com/coding/basic/stack/StackUtil.java
new file mode 100644
index 0000000000..7c86d22fe7
--- /dev/null
+++ b/students/250103158/data-structure/answer/src/main/java/com/coding/basic/stack/StackUtil.java
@@ -0,0 +1,168 @@
+package com.coding.basic.stack;
+import java.util.Stack;
+public class StackUtil {
+
+ public static void bad_reverse(Stack s) {
+ if(s == null || s.isEmpty()){
+ return;
+ }
+ Stack tmpStack = new Stack();
+ while(!s.isEmpty()){
+ tmpStack.push(s.pop());
+ }
+
+ s = tmpStack;
+
+ }
+
+
+
+ public static void reverse_247565311(Stack s){
+ if(s == null || s.isEmpty()) {
+ return;
+ }
+
+ int size = s.size();
+ Stack tmpStack = new Stack();
+
+ for(int i=0;ii){
+ tmpStack.push(s.pop());
+ }
+ s.push(top);
+ while(tmpStack.size()>0){
+ s.push(tmpStack.pop());
+ }
+ }
+ }
+
+
+
+ /**
+ * 假设栈中的元素是Integer, 从栈顶到栈底是 : 5,4,3,2,1 调用该方法后, 元素次序变为: 1,2,3,4,5
+ * 注意:只能使用Stack的基本操作,即push,pop,peek,isEmpty, 可以使用另外一个栈来辅助
+ */
+ public static void reverse(Stack s) {
+ if(s == null || s.isEmpty()){
+ return;
+ }
+
+ Stack tmp = new Stack();
+ while(!s.isEmpty()){
+ tmp.push(s.pop());
+ }
+ while(!tmp.isEmpty()){
+ Integer top = tmp.pop();
+ addToBottom(s,top);
+ }
+
+
+ }
+ public static void addToBottom(Stack s, Integer value){
+ if(s.isEmpty()){
+ s.push(value);
+ } else{
+ Integer top = s.pop();
+ addToBottom(s,value);
+ s.push(top);
+ }
+
+ }
+ /**
+ * 删除栈中的某个元素 注意:只能使用Stack的基本操作,即push,pop,peek,isEmpty, 可以使用另外一个栈来辅助
+ *
+ * @param o
+ */
+ public static void remove(Stack s,Object o) {
+ if(s == null || s.isEmpty()){
+ return;
+ }
+ Stack tmpStack = new Stack();
+
+ while(!s.isEmpty()){
+ Object value = s.pop();
+ if(!value.equals(o)){
+ tmpStack.push(value);
+ }
+ }
+
+ while(!tmpStack.isEmpty()){
+ s.push(tmpStack.pop());
+ }
+ }
+
+ /**
+ * 从栈顶取得len个元素, 原来的栈中元素保持不变
+ * 注意:只能使用Stack的基本操作,即push,pop,peek,isEmpty, 可以使用另外一个栈来辅助
+ * @param len
+ * @return
+ */
+ public static Object[] getTop(Stack s,int len) {
+
+ if(s == null || s.isEmpty() || s.size() stack = new Stack();
+ for(int i=0;i s = new Stack();
+ s.push(1);
+ s.push(2);
+ s.push(3);
+
+ StackUtil.addToBottom(s, 0);
+
+ Assert.assertEquals("[0, 1, 2, 3]", s.toString());
+
+ }
+ @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 testReverse_247565311() {
+ Stack s = new Stack();
+ s.push(1);
+ s.push(2);
+ s.push(3);
+
+ Assert.assertEquals("[1, 2, 3]", s.toString());
+ StackUtil.reverse_247565311(s);
+ Assert.assertEquals("[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/250103158/data-structure/answer/src/main/java/com/coding/basic/stack/StackWithTwoQueues.java b/students/250103158/data-structure/answer/src/main/java/com/coding/basic/stack/StackWithTwoQueues.java
new file mode 100644
index 0000000000..7a58fbff56
--- /dev/null
+++ b/students/250103158/data-structure/answer/src/main/java/com/coding/basic/stack/StackWithTwoQueues.java
@@ -0,0 +1,53 @@
+package com.coding.basic.stack;
+
+import java.util.ArrayDeque;
+import java.util.Queue;
+
+public class StackWithTwoQueues {
+ Queue queue1 = new ArrayDeque<>();
+ Queue queue2 = new ArrayDeque<>();
+
+ public void push(int data) {
+ //两个栈都为空时,优先考虑queue1
+ if (queue1.isEmpty()&&queue2.isEmpty()) {
+ queue1.add(data);
+ return;
+ }
+
+ if (queue1.isEmpty()) {
+ queue2.add(data);
+ return;
+ }
+
+ if (queue2.isEmpty()) {
+ queue1.add(data);
+ return;
+ }
+
+ }
+
+ public int pop() {
+
+ if (queue1.isEmpty()&&queue2.isEmpty()) {
+ throw new RuntimeException("stack is empty");
+ }
+
+ if (queue1.isEmpty()) {
+ while (queue2.size()>1) {
+ queue1.add(queue2.poll());
+ }
+ return queue2.poll();
+ }
+
+ if (queue2.isEmpty()) {
+ while (queue1.size()>1) {
+ queue2.add(queue1.poll());
+ }
+ return queue1.poll();
+ }
+
+ throw new RuntimeException("no queue is empty, this is not allowed");
+
+
+ }
+}
diff --git a/students/250103158/data-structure/answer/src/main/java/com/coding/basic/stack/StackWithTwoQueuesTest.java b/students/250103158/data-structure/answer/src/main/java/com/coding/basic/stack/StackWithTwoQueuesTest.java
new file mode 100644
index 0000000000..4541b1f040
--- /dev/null
+++ b/students/250103158/data-structure/answer/src/main/java/com/coding/basic/stack/StackWithTwoQueuesTest.java
@@ -0,0 +1,36 @@
+package com.coding.basic.stack;
+
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+
+
+public class StackWithTwoQueuesTest {
+
+ @Before
+ public void setUp() throws Exception {
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ }
+
+ @Test
+ public void test() {
+ StackWithTwoQueues stack = new StackWithTwoQueues();
+ stack.push(1);
+ stack.push(2);
+ stack.push(3);
+ stack.push(4);
+ Assert.assertEquals(4, stack.pop());
+ Assert.assertEquals(3, stack.pop());
+
+ stack.push(5);
+ Assert.assertEquals(5, stack.pop());
+ Assert.assertEquals(2, stack.pop());
+ Assert.assertEquals(1, stack.pop());
+ }
+
+}
diff --git a/students/250103158/data-structure/answer/src/main/java/com/coding/basic/stack/Tail.java b/students/250103158/data-structure/answer/src/main/java/com/coding/basic/stack/Tail.java
new file mode 100644
index 0000000000..7f30ce55c8
--- /dev/null
+++ b/students/250103158/data-structure/answer/src/main/java/com/coding/basic/stack/Tail.java
@@ -0,0 +1,5 @@
+package com.coding.basic.stack;
+
+public class Tail {
+
+}
diff --git a/students/250103158/data-structure/answer/src/main/java/com/coding/basic/stack/TwoStackInOneArray.java b/students/250103158/data-structure/answer/src/main/java/com/coding/basic/stack/TwoStackInOneArray.java
new file mode 100644
index 0000000000..a532fd6e6c
--- /dev/null
+++ b/students/250103158/data-structure/answer/src/main/java/com/coding/basic/stack/TwoStackInOneArray.java
@@ -0,0 +1,117 @@
+package com.coding.basic.stack;
+
+import java.util.Arrays;
+
+/**
+ * 用一个数组实现两个栈
+ * 将数组的起始位置看作是第一个栈的栈底,将数组的尾部看作第二个栈的栈底,压栈时,栈顶指针分别向中间移动,直到两栈顶指针相遇,则扩容。
+ * @author liuxin
+ *
+ */
+public class TwoStackInOneArray {
+ private Object[] data = new Object[10];
+ private int size;
+ private int top1, top2;
+
+ public TwoStackInOneArray(int n){
+ data = new Object[n];
+ size = n;
+ top1 = -1;
+ top2 = data.length;
+ }
+ /**
+ * 向第一个栈中压入元素
+ * @param o
+ */
+ public void push1(Object o){
+ ensureCapacity();
+ data[++top1] = o;
+ }
+ /*
+ * 向第二个栈压入元素
+ */
+ public void push2(Object o){
+ ensureCapacity();
+ data[--top2] = o;
+ }
+ public void ensureCapacity(){
+ if(top2-top1>1){
+ return;
+ } else{
+
+ Object[] newArray = new Object[data.length*2];
+ System.arraycopy(data, 0, newArray, 0, top1+1);
+
+ int stack2Size = data.length-top2;
+ int newTop2 = newArray.length-stack2Size;
+ System.arraycopy(data, top2, newArray, newTop2, stack2Size);
+
+ top2 = newTop2;
+ data = newArray;
+ }
+ }
+ /**
+ * 从第一个栈中弹出元素
+ * @return
+ */
+ public Object pop1(){
+ if(top1 == -1){
+ throw new RuntimeException("Stack1 is empty");
+ }
+ Object o = data[top1];
+ data[top1] = null;
+ top1--;
+ return o;
+
+ }
+ /**
+ * 从第二个栈弹出元素
+ * @return
+ */
+ public Object pop2(){
+ if(top2 == data.length){
+ throw new RuntimeException("Stack2 is empty");
+ }
+ Object o = data[top2];
+ data[top2] = null;
+ top2++;
+ return o;
+ }
+ /**
+ * 获取第一个栈的栈顶元素
+ * @return
+ */
+
+ public Object peek1(){
+ if(top1 == -1){
+ throw new RuntimeException("Stack1 is empty");
+ }
+ return data[top1];
+ }
+
+
+ /**
+ * 获取第二个栈的栈顶元素
+ * @return
+ */
+
+ public Object peek2(){
+ if(top2 == data.length){
+ throw new RuntimeException("Stack2 is empty");
+ }
+ return data[top2];
+ }
+
+ public Object[] stack1ToArray(){
+ return Arrays.copyOf(data, top1+1);
+ }
+ public Object[] stack2ToArray(){
+ int size = data.length-top2;
+ Object [] stack2Data = new Object[size];
+ int j=0;
+ for(int i=data.length-1; i>=top2 ;i--){
+ stack2Data[j++] = data[i];
+ }
+ return stack2Data;
+ }
+}
diff --git a/students/250103158/data-structure/answer/src/main/java/com/coding/basic/stack/TwoStackInOneArrayTest.java b/students/250103158/data-structure/answer/src/main/java/com/coding/basic/stack/TwoStackInOneArrayTest.java
new file mode 100644
index 0000000000..b743d422c6
--- /dev/null
+++ b/students/250103158/data-structure/answer/src/main/java/com/coding/basic/stack/TwoStackInOneArrayTest.java
@@ -0,0 +1,65 @@
+package com.coding.basic.stack;
+
+import java.util.Arrays;
+
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+
+
+public class TwoStackInOneArrayTest {
+
+ @Before
+ public void setUp() throws Exception {
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ }
+
+ @Test
+ public void test1() {
+ TwoStackInOneArray stack = new TwoStackInOneArray(10);
+ stack.push1(1);
+ stack.push1(2);
+ stack.push1(3);
+ stack.push1(4);
+ stack.push1(5);
+
+ stack.push2(1);
+ stack.push2(2);
+ stack.push2(3);
+ stack.push2(4);
+ stack.push2(5);
+
+ for(int i=1;i<=5;i++){
+ Assert.assertEquals(stack.peek1(), stack.peek2());
+ Assert.assertEquals(stack.pop1(), stack.pop2());
+ }
+
+
+ }
+ @Test
+ public void test2() {
+ TwoStackInOneArray stack = new TwoStackInOneArray(5);
+ stack.push1(1);
+ stack.push1(2);
+ stack.push1(3);
+ stack.push1(4);
+ stack.push1(5);
+ stack.push1(6);
+ stack.push1(7);
+
+ stack.push2(1);
+ stack.push2(2);
+ stack.push2(3);
+ stack.push2(4);
+
+
+ Assert.assertEquals("[1, 2, 3, 4, 5, 6, 7]",Arrays.toString(stack.stack1ToArray()));
+ Assert.assertEquals("[1, 2, 3, 4]",Arrays.toString(stack.stack2ToArray()));
+ }
+
+}
diff --git a/students/250103158/data-structure/answer/src/main/java/com/coding/basic/stack/expr/InfixExpr.java b/students/250103158/data-structure/answer/src/main/java/com/coding/basic/stack/expr/InfixExpr.java
new file mode 100644
index 0000000000..cebef21fa3
--- /dev/null
+++ b/students/250103158/data-structure/answer/src/main/java/com/coding/basic/stack/expr/InfixExpr.java
@@ -0,0 +1,72 @@
+package com.coding.basic.stack.expr;
+
+import java.util.List;
+import java.util.Stack;
+
+
+public class InfixExpr {
+ String expr = null;
+
+ public InfixExpr(String expr) {
+ this.expr = expr;
+ }
+
+ public float evaluate() {
+
+
+ TokenParser parser = new TokenParser();
+ List tokens = parser.parse(this.expr);
+
+
+ Stack opStack = new Stack<>();
+ Stack numStack = new Stack<>();
+
+ for(Token token : tokens){
+
+ if (token.isOperator()){
+
+ while(!opStack.isEmpty()
+ && !token.hasHigherPriority(opStack.peek())){
+ Token prevOperator = opStack.pop();
+ Float f2 = numStack.pop();
+ Float f1 = numStack.pop();
+ Float result = calculate(prevOperator.toString(), f1,f2);
+ numStack.push(result);
+
+ }
+ opStack.push(token);
+ }
+ if(token.isNumber()){
+ numStack.push(new Float(token.getIntValue()));
+ }
+ }
+
+ while(!opStack.isEmpty()){
+ Token token = opStack.pop();
+ Float f2 = numStack.pop();
+ Float f1 = numStack.pop();
+ numStack.push(calculate(token.toString(), f1,f2));
+ }
+
+
+ return numStack.pop().floatValue();
+ }
+ private Float calculate(String op, Float f1, Float f2){
+ if(op.equals("+")){
+ return f1+f2;
+ }
+ if(op.equals("-")){
+ return f1-f2;
+ }
+ if(op.equals("*")){
+ return f1*f2;
+ }
+ if(op.equals("/")){
+ return f1/f2;
+ }
+ throw new RuntimeException(op + " is not supported");
+ }
+
+
+
+}
diff --git a/students/250103158/data-structure/answer/src/main/java/com/coding/basic/stack/expr/InfixExprTest.java b/students/250103158/data-structure/answer/src/main/java/com/coding/basic/stack/expr/InfixExprTest.java
new file mode 100644
index 0000000000..20e34e8852
--- /dev/null
+++ b/students/250103158/data-structure/answer/src/main/java/com/coding/basic/stack/expr/InfixExprTest.java
@@ -0,0 +1,52 @@
+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/250103158/data-structure/answer/src/main/java/com/coding/basic/stack/expr/InfixToPostfix.java b/students/250103158/data-structure/answer/src/main/java/com/coding/basic/stack/expr/InfixToPostfix.java
new file mode 100644
index 0000000000..9e501eda20
--- /dev/null
+++ b/students/250103158/data-structure/answer/src/main/java/com/coding/basic/stack/expr/InfixToPostfix.java
@@ -0,0 +1,43 @@
+package com.coding.basic.stack.expr;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Stack;
+
+public class InfixToPostfix {
+
+ public static List convert(String expr) {
+ List inFixTokens = new TokenParser().parse(expr);
+
+ List postFixTokens = new ArrayList<>();
+
+ Stack opStack = new Stack();
+ for(Token token : inFixTokens){
+
+ if(token.isOperator()){
+
+ while(!opStack.isEmpty()
+ && !token.hasHigherPriority(opStack.peek())){
+ postFixTokens.add(opStack.pop());
+
+ }
+ opStack.push(token);
+
+ }
+ if(token.isNumber()){
+
+ postFixTokens.add(token);
+
+ }
+ }
+
+ while(!opStack.isEmpty()){
+ postFixTokens.add(opStack.pop());
+ }
+
+ return postFixTokens;
+ }
+
+
+
+}
diff --git a/students/250103158/data-structure/answer/src/main/java/com/coding/basic/stack/expr/InfixToPostfixTest.java b/students/250103158/data-structure/answer/src/main/java/com/coding/basic/stack/expr/InfixToPostfixTest.java
new file mode 100644
index 0000000000..f879f55f14
--- /dev/null
+++ b/students/250103158/data-structure/answer/src/main/java/com/coding/basic/stack/expr/InfixToPostfixTest.java
@@ -0,0 +1,41 @@
+package com.coding.basic.stack.expr;
+
+import java.util.List;
+
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+
+
+public class InfixToPostfixTest {
+
+ @Before
+ public void setUp() throws Exception {
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ }
+
+ @Test
+ public void testConvert() {
+ {
+ List tokens = InfixToPostfix.convert("2+3");
+ Assert.assertEquals("[2, 3, +]", tokens.toString());
+ }
+ {
+
+ List tokens = InfixToPostfix.convert("2+3*4");
+ Assert.assertEquals("[2, 3, 4, *, +]", tokens.toString());
+ }
+
+ {
+
+ List tokens = InfixToPostfix.convert("2-3*4+5");
+ Assert.assertEquals("[2, 3, 4, *, -, 5, +]", tokens.toString());
+ }
+ }
+
+}
diff --git a/students/250103158/data-structure/answer/src/main/java/com/coding/basic/stack/expr/PostfixExpr.java b/students/250103158/data-structure/answer/src/main/java/com/coding/basic/stack/expr/PostfixExpr.java
new file mode 100644
index 0000000000..c54eb69e2a
--- /dev/null
+++ b/students/250103158/data-structure/answer/src/main/java/com/coding/basic/stack/expr/PostfixExpr.java
@@ -0,0 +1,46 @@
+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() {
+ TokenParser parser = new TokenParser();
+ List tokens = parser.parse(this.expr);
+
+
+ Stack numStack = new Stack<>();
+ for(Token token : tokens){
+ if(token.isNumber()){
+ numStack.push(new Float(token.getIntValue()));
+ } else{
+ Float f2 = numStack.pop();
+ Float f1 = numStack.pop();
+ numStack.push(calculate(token.toString(),f1,f2));
+ }
+ }
+ return numStack.pop().floatValue();
+ }
+
+ private Float calculate(String op, Float f1, Float f2){
+ if(op.equals("+")){
+ return f1+f2;
+ }
+ if(op.equals("-")){
+ return f1-f2;
+ }
+ if(op.equals("*")){
+ return f1*f2;
+ }
+ if(op.equals("/")){
+ return f1/f2;
+ }
+ throw new RuntimeException(op + " is not supported");
+ }
+}
diff --git a/students/250103158/data-structure/answer/src/main/java/com/coding/basic/stack/expr/PostfixExprTest.java b/students/250103158/data-structure/answer/src/main/java/com/coding/basic/stack/expr/PostfixExprTest.java
new file mode 100644
index 0000000000..c0435a2db5
--- /dev/null
+++ b/students/250103158/data-structure/answer/src/main/java/com/coding/basic/stack/expr/PostfixExprTest.java
@@ -0,0 +1,41 @@
+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/250103158/data-structure/answer/src/main/java/com/coding/basic/stack/expr/PrefixExpr.java b/students/250103158/data-structure/answer/src/main/java/com/coding/basic/stack/expr/PrefixExpr.java
new file mode 100644
index 0000000000..f811fd6d9a
--- /dev/null
+++ b/students/250103158/data-structure/answer/src/main/java/com/coding/basic/stack/expr/PrefixExpr.java
@@ -0,0 +1,52 @@
+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() {
+ TokenParser parser = new TokenParser();
+ List tokens = parser.parse(this.expr);
+
+ Stack exprStack = new Stack<>();
+ Stack numStack = new Stack<>();
+ for(Token token : tokens){
+ exprStack.push(token);
+ }
+
+ while(!exprStack.isEmpty()){
+ Token t = exprStack.pop();
+ if(t.isNumber()){
+ numStack.push(new Float(t.getIntValue()));
+ }else{
+ Float f1 = numStack.pop();
+ Float f2 = numStack.pop();
+ numStack.push(calculate(t.toString(),f1,f2));
+
+ }
+ }
+ return numStack.pop().floatValue();
+ }
+
+ private Float calculate(String op, Float f1, Float f2){
+ if(op.equals("+")){
+ return f1+f2;
+ }
+ if(op.equals("-")){
+ return f1-f2;
+ }
+ if(op.equals("*")){
+ return f1*f2;
+ }
+ if(op.equals("/")){
+ return f1/f2;
+ }
+ throw new RuntimeException(op + " is not supported");
+ }
+}
diff --git a/students/250103158/data-structure/answer/src/main/java/com/coding/basic/stack/expr/PrefixExprTest.java b/students/250103158/data-structure/answer/src/main/java/com/coding/basic/stack/expr/PrefixExprTest.java
new file mode 100644
index 0000000000..5cec210e75
--- /dev/null
+++ b/students/250103158/data-structure/answer/src/main/java/com/coding/basic/stack/expr/PrefixExprTest.java
@@ -0,0 +1,45 @@
+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/250103158/data-structure/answer/src/main/java/com/coding/basic/stack/expr/Token.java b/students/250103158/data-structure/answer/src/main/java/com/coding/basic/stack/expr/Token.java
new file mode 100644
index 0000000000..8579743fe9
--- /dev/null
+++ b/students/250103158/data-structure/answer/src/main/java/com/coding/basic/stack/expr/Token.java
@@ -0,0 +1,50 @@
+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/250103158/data-structure/answer/src/main/java/com/coding/basic/stack/expr/TokenParser.java b/students/250103158/data-structure/answer/src/main/java/com/coding/basic/stack/expr/TokenParser.java
new file mode 100644
index 0000000000..d3b0f167e1
--- /dev/null
+++ b/students/250103158/data-structure/answer/src/main/java/com/coding/basic/stack/expr/TokenParser.java
@@ -0,0 +1,57 @@
+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/250103158/data-structure/answer/src/main/java/com/coding/basic/stack/expr/TokenParserTest.java b/students/250103158/data-structure/answer/src/main/java/com/coding/basic/stack/expr/TokenParserTest.java
new file mode 100644
index 0000000000..399d3e857e
--- /dev/null
+++ b/students/250103158/data-structure/answer/src/main/java/com/coding/basic/stack/expr/TokenParserTest.java
@@ -0,0 +1,41 @@
+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/250103158/data-structure/answer/src/main/java/com/coding/basic/tree/BinarySearchTree.java b/students/250103158/data-structure/answer/src/main/java/com/coding/basic/tree/BinarySearchTree.java
new file mode 100644
index 0000000000..284e5b0011
--- /dev/null
+++ b/students/250103158/data-structure/answer/src/main/java/com/coding/basic/tree/BinarySearchTree.java
@@ -0,0 +1,189 @@
+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(){
+ if(root == null){
+ return null;
+ }
+ return findMin(root).data;
+ }
+ public T findMax(){
+ if(root == null){
+ return null;
+ }
+ return findMax(root).data;
+ }
+ public int height() {
+ return height(root);
+ }
+ public int size() {
+ return size(root);
+ }
+ public void remove(T e){
+ remove(e, root);
+ }
+
+ private BinaryTreeNode remove(T x, BinaryTreeNode t){
+ if(t == null){
+ return t;
+ }
+ int compareResult = x.compareTo(t.data);
+
+ if(compareResult< 0 ){
+ t.left = remove(x,t.left);
+
+ } else if(compareResult > 0){
+ t.right = remove(x, t.right);
+
+ } else {
+ if(t.left != null && t.right != null){
+
+ t.data = findMin(t.right).data;
+ t.right = remove(t.data,t.right);
+
+ } else{
+ t = (t.left != null) ? t.left : t.right;
+ }
+ }
+ return t;
+ }
+
+ private BinaryTreeNode findMin(BinaryTreeNode p){
+ if (p==null){
+ return null;
+ } else if (p.left == null){
+ return p;
+ } else{
+ return findMin(p.left);
+ }
+ }
+ private BinaryTreeNode findMax(BinaryTreeNode p){
+ if (p==null){
+ return null;
+ }else if (p.right==null){
+ return p;
+ } else{
+ return findMax(p.right);
+ }
+ }
+ private int height(BinaryTreeNode t){
+ if (t==null){
+ return 0;
+ }else {
+ int leftChildHeight=height(t.left);
+ int rightChildHeight=height(t.right);
+ if(leftChildHeight > rightChildHeight){
+ return leftChildHeight+1;
+ } else{
+ return rightChildHeight+1;
+ }
+ }
+ }
+ private int size(BinaryTreeNode t){
+ if (t == null){
+ return 0;
+ }
+ return size(t.left) + 1 + size(t.right);
+
+ }
+
+ public List levelVisit(){
+ List result = new ArrayList();
+ if(root == null){
+ return result;
+ }
+ Queue> queue = new Queue>();
+ BinaryTreeNode node = root;
+ queue.enQueue(node);
+ while (!queue.isEmpty()) {
+ node = queue.deQueue();
+ result.add(node.data);
+ if (node.left != null){
+ queue.enQueue(node.left);
+ }
+ if (node.right != null){
+ queue.enQueue(node.right);
+ }
+ }
+ return result;
+ }
+ public boolean isValid(){
+ return isValid(root);
+ }
+ public T getLowestCommonAncestor(T n1, T n2){
+ if (root == null){
+ return null;
+ }
+ return lowestCommonAncestor(root,n1,n2);
+
+ }
+ public List getNodesBetween(T n1, T n2){
+ List elements = new ArrayList<>();
+ getNodesBetween(elements,root,n1,n2);
+ return elements;
+ }
+
+ public void getNodesBetween(List elements ,BinaryTreeNode node, T n1, T n2){
+
+ if (node == null) {
+ return;
+ }
+
+ if (n1.compareTo(node.data) < 0) {
+ getNodesBetween(elements,node.left, n1, n2);
+ }
+
+ if ((n1.compareTo(node.data) <= 0 )
+ && (n2.compareTo(node.data) >= 0 )) {
+ elements.add(node.data);
+ }
+ if (n2.compareTo(node.data)>0) {
+ getNodesBetween(elements,node.right, n1, n2);
+ }
+ }
+ private T lowestCommonAncestor(BinaryTreeNode node,T n1, T n2){
+ if(node == null){
+ return null;
+ }
+ // 如果n1和n2都比 node的值小, LCA在左孩子
+ if (node.data.compareTo(n1) > 0 && node.data.compareTo(n2) >0){
+ return lowestCommonAncestor(node.left, n1, n2);
+ }
+
+ // 如果n1和n2都比 node的值小, LCA在右孩子
+ if (node.data.compareTo(n1) < 0 && node.data.compareTo(n2) <0)
+ return lowestCommonAncestor(node.right, n1, n2);
+
+ return node.data;
+ }
+ private boolean isValid(BinaryTreeNode t){
+ if(t == null){
+ return true;
+ }
+ if(t.left != null && findMax(t.left).data.compareTo(t.data) >0){
+ return false;
+ }
+ if(t.right !=null && findMin(t.right).data.compareTo(t.data) <0){
+ return false;
+ }
+ if(!isValid(t.left) || !isValid(t.right)){
+ return false;
+ }
+ return true;
+ }
+}
+
diff --git a/students/250103158/data-structure/answer/src/main/java/com/coding/basic/tree/BinarySearchTreeTest.java b/students/250103158/data-structure/answer/src/main/java/com/coding/basic/tree/BinarySearchTreeTest.java
new file mode 100644
index 0000000000..590e60306c
--- /dev/null
+++ b/students/250103158/data-structure/answer/src/main/java/com/coding/basic/tree/BinarySearchTreeTest.java
@@ -0,0 +1,108 @@
+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);
+ Assert.assertEquals("[3, 4, 5, 6, 8]",numbers.toString());
+ }
+}
diff --git a/students/250103158/data-structure/answer/src/main/java/com/coding/basic/tree/BinaryTreeNode.java b/students/250103158/data-structure/answer/src/main/java/com/coding/basic/tree/BinaryTreeNode.java
new file mode 100644
index 0000000000..3f6f4d2b44
--- /dev/null
+++ b/students/250103158/data-structure/answer/src/main/java/com/coding/basic/tree/BinaryTreeNode.java
@@ -0,0 +1,36 @@
+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/250103158/data-structure/answer/src/main/java/com/coding/basic/tree/BinaryTreeUtil.java b/students/250103158/data-structure/answer/src/main/java/com/coding/basic/tree/BinaryTreeUtil.java
new file mode 100644
index 0000000000..f2a6515fa6
--- /dev/null
+++ b/students/250103158/data-structure/answer/src/main/java/com/coding/basic/tree/BinaryTreeUtil.java
@@ -0,0 +1,116 @@
+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();
+ preOrderVisit(root, result);
+ return result;
+ }
+
+ /**
+ * 用递归的方式实现对二叉树的中遍历
+ *
+ * @param root
+ * @return
+ */
+ public static List inOrderVisit(BinaryTreeNode root) {
+ List result = new ArrayList();
+ inOrderVisit(root, result);
+ return result;
+ }
+
+ /**
+ * 用递归的方式实现对二叉树的后遍历
+ *
+ * @param root
+ * @return
+ */
+ public static List postOrderVisit(BinaryTreeNode root) {
+ List result = new ArrayList();
+ postOrderVisit(root, result);
+ return result;
+ }
+
+ public static List