Skip to content

Commit 12769d2

Browse files
authored
Merge pull request onlyliuxin#440 from yangzhm/master
push request
2 parents 209c893 + e01d178 commit 12769d2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+878
-0
lines changed
59.5 KB
Loading
Loading
72.5 KB
Loading
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
P8756 iPhone8
2+
P3946 XiaoMi10
3+
P8904 Oppo_R15
4+
P4955 Vivo_X20
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
5+
<groupId>com.coderising</groupId>
6+
<artifactId>ood-assignment</artifactId>
7+
<version>0.0.1-SNAPSHOT</version>
8+
<packaging>jar</packaging>
9+
10+
<name>ood-assignment</name>
11+
<url>http://maven.apache.org</url>
12+
13+
<properties>
14+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
15+
</properties>
16+
17+
<dependencies>
18+
19+
<dependency>
20+
<groupId>junit</groupId>
21+
<artifactId>junit</artifactId>
22+
<version>4.12</version>
23+
</dependency>
24+
25+
</dependencies>
26+
<repositories>
27+
<repository>
28+
<id>aliyunmaven</id>
29+
<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
30+
</repository>
31+
</repositories>
32+
</project>
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package com.coderising.ood.ocp;
2+
3+
public class ComSender implements Sender {
4+
public void send(String msg) {
5+
System.out.println(msg);
6+
}
7+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package com.coderising.ood.ocp;
2+
3+
public class DateUtil {
4+
5+
public static String getCurrentDateAsString() {
6+
7+
return null;
8+
}
9+
10+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package com.coderising.ood.ocp;
2+
3+
public class LogType {
4+
public static final int RAW_LOG = 1;
5+
public static final int RAW_LOG_WITH_DATE = 2;
6+
public static final int EMAIL_LOG = 1;
7+
public static final int SMS_LOG = 2;
8+
public static final int PRINT_LOG = 3;
9+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package com.coderising.ood.ocp;
2+
3+
public class Logger {
4+
int type = 0;
5+
int method = 0;
6+
7+
public Logger(int logType, int logMethod){
8+
this.type = logType;
9+
this.method = logMethod;
10+
}
11+
public void log(String msg){
12+
13+
String logMsg = msg;
14+
15+
if(this.type == LogType.RAW_LOG){
16+
logMsg = msg;
17+
} else if(this.type == LogType.RAW_LOG_WITH_DATE){
18+
String txtDate = DateUtil.getCurrentDateAsString();
19+
logMsg = txtDate + ": " + msg;
20+
}
21+
22+
SenderFactory.createSender(type).send(logMsg);
23+
}
24+
}
25+
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package com.coderising.ood.ocp;
2+
3+
public class MailUtil implements Sender{
4+
5+
public void send(String logMsg) {
6+
// TODO Auto-generated method stub
7+
8+
}
9+
10+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package com.coderising.ood.ocp;
2+
3+
public class SMSUtil implements Sender {
4+
5+
public void send(String logMsg) {
6+
// TODO Auto-generated method stub
7+
8+
}
9+
10+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package com.coderising.ood.ocp;
2+
3+
public interface Sender {
4+
public void send(String msg);
5+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package com.coderising.ood.ocp;
2+
3+
public class SenderFactory {
4+
public static Sender createSender(int type) {
5+
if(type == LogType.EMAIL_LOG){
6+
return new MailUtil();
7+
} else if(type == LogType.SMS_LOG){
8+
return new SMSUtil();
9+
} else if(type == LogType.PRINT_LOG){
10+
return new ComSender();
11+
}
12+
13+
return new ComSender();
14+
}
15+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package com.coderising.ood.ocp.good;
2+
3+
public interface Formatter {
4+
5+
String format(String msg);
6+
7+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package com.coderising.ood.ocp.good;
2+
3+
public class FormatterFactory {
4+
public static Formatter createFormatter(int type){
5+
if(type == 1){
6+
return new RawFormatter();
7+
}
8+
if (type == 2){
9+
return new HtmlFormatter();
10+
}
11+
return null;
12+
}
13+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package com.coderising.ood.ocp.good;
2+
3+
public class HtmlFormatter implements Formatter {
4+
5+
@Override
6+
public String format(String msg) {
7+
8+
return null;
9+
}
10+
11+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package com.coderising.ood.ocp.good;
2+
3+
public class Logger {
4+
5+
private Formatter formatter;
6+
private Sender sender;
7+
8+
public Logger(Formatter formatter,Sender sender){
9+
this.formatter = formatter;
10+
this.sender = sender;
11+
}
12+
public void log(String msg){
13+
sender.send(formatter.format(msg)) ;
14+
}
15+
16+
17+
}
18+
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package com.coderising.ood.ocp.good;
2+
3+
public class RawFormatter implements Formatter {
4+
5+
@Override
6+
public String format(String msg) {
7+
8+
return null;
9+
}
10+
11+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package com.coderising.ood.ocp.good;
2+
3+
public interface Sender {
4+
5+
void send(String msg);
6+
7+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package com.coderising.ood.srp;
2+
3+
public class CommonKeys {
4+
5+
public static final String SMTP_SERVER = "smtp.server";
6+
public static final String ALT_SMTP_SERVER = "alt.smtp.server";
7+
public static final String EMAIL_ADMIN = "email.admin";
8+
public static final String NAME_KEY = "NAME";
9+
public static final String EMAIL_KEY = "EMAIL";
10+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package com.coderising.ood.srp;
2+
import java.util.HashMap;
3+
import java.util.Map;
4+
5+
public class Configuration {
6+
7+
static Map<String,String> configurations = new HashMap<>();
8+
static{
9+
configurations.put(CommonKeys.SMTP_SERVER, "smtp.163.com");
10+
configurations.put(CommonKeys.ALT_SMTP_SERVER, "smtp1.163.com");
11+
configurations.put(CommonKeys.EMAIL_ADMIN, "admin@company.com");
12+
}
13+
/**
14+
* 应该从配置文件读, 但是这里简化为直接从一个map 中去读
15+
* @param key
16+
* @return
17+
*/
18+
public String getProperty(String key) {
19+
20+
return configurations.get(key);
21+
}
22+
23+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package com.coderising.ood.srp;
2+
import java.util.ArrayList;
3+
import java.util.HashMap;
4+
import java.util.List;
5+
6+
public class DBUtil {
7+
8+
/**
9+
* 应该从数据库读, 但是简化为直接生成。
10+
* @param sql
11+
* @return
12+
*/
13+
public static List query(String sql){
14+
15+
List userList = new ArrayList();
16+
for (int i = 1; i <= 3; i++) {
17+
HashMap userInfo = new HashMap();
18+
userInfo.put(CommonKeys.NAME_KEY, "User" + i);
19+
userInfo.put(CommonKeys.EMAIL_KEY, "aa@bb.com");
20+
userList.add(userInfo);
21+
}
22+
23+
return userList;
24+
}
25+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package com.coderising.ood.srp;
2+
3+
public class MailAddr {
4+
protected String smtpHost = null;
5+
protected String altSmtpHost = null;
6+
protected String fromAddress = null;
7+
protected String toAddress = null;
8+
9+
public MailAddr(Configuration config) {
10+
reloadconfig(config);
11+
}
12+
13+
public void reloadconfig(Configuration config) {
14+
smtpHost = config.getProperty(CommonKeys.SMTP_SERVER);
15+
altSmtpHost = config.getProperty(CommonKeys.ALT_SMTP_SERVER);
16+
fromAddress = config.getProperty(CommonKeys.EMAIL_ADMIN);
17+
}
18+
19+
public void setToAddress(String address) {
20+
toAddress = address;
21+
}
22+
23+
public String getToAddress() {
24+
return toAddress;
25+
}
26+
27+
public boolean checkToAddress() {
28+
return toAddress.length() > 0;
29+
}
30+
31+
public String getSmtpHost() {
32+
return smtpHost;
33+
}
34+
35+
public String getAltSmtpHost() {
36+
return altSmtpHost;
37+
}
38+
39+
public String getFromAddress() {
40+
return fromAddress;
41+
}
42+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package com.coderising.ood.srp;
2+
3+
public class MailMsg {
4+
protected String subject = null;
5+
protected String message = null;
6+
7+
public MailMsg(String sub, String msg) {
8+
this.subject = sub;
9+
this.message = msg;
10+
}
11+
12+
public String getSubject() {
13+
return subject;
14+
}
15+
16+
public String getMessage() {
17+
return message;
18+
}
19+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package com.coderising.ood.srp;
2+
3+
public class MailUtil {
4+
5+
public static void sendEmail(MailAddr mailAddr, MailMsg mailMsg, boolean debug) {
6+
//假装发了一封邮件
7+
StringBuilder buffer = new StringBuilder();
8+
buffer.append("From:").append(mailAddr.getFromAddress()).append("\n");
9+
buffer.append("To:").append(mailAddr.getToAddress()).append("\n");
10+
buffer.append("Subject:").append(mailMsg.getSubject()).append("\n");
11+
buffer.append("Content:").append(mailMsg.getMessage()).append("\n");
12+
System.out.println(buffer.toString());
13+
}
14+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
package com.coderising.ood.srp;
2+
3+
import java.io.BufferedReader;
4+
import java.io.File;
5+
import java.io.FileReader;
6+
import java.io.IOException;
7+
8+
public class ProductInfo {
9+
protected String productID = null;
10+
protected String productDesc = null;
11+
12+
public ProductInfo(String path) {
13+
try {
14+
readFile(path);
15+
} catch (IOException e) {
16+
e.printStackTrace();
17+
}
18+
}
19+
20+
protected void readFile(String path) throws IOException
21+
{
22+
File f = new File(path);
23+
BufferedReader br = null;
24+
try {
25+
br = new BufferedReader(new FileReader(f));
26+
String temp = br.readLine();
27+
String[] data = temp.split(" ");
28+
29+
this.productID = data[0];
30+
this.productDesc = data[1];
31+
32+
System.out.println("产品ID = " + productID + "\n");
33+
System.out.println("产品描述 = " + productDesc + "\n");
34+
35+
} catch (IOException e) {
36+
throw new IOException(e.getMessage());
37+
} finally {
38+
br.close();
39+
}
40+
}
41+
42+
public String getProductID() {
43+
return productID;
44+
}
45+
46+
public String getProductDesc() {
47+
return productDesc;
48+
}
49+
}

0 commit comments

Comments
 (0)