forked from onlyliuxin/coding2017
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from onlyliuxin/master
合并老师代码
- Loading branch information
Showing
40 changed files
with
858 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<groupId>com.coderising</groupId> | ||
<artifactId>ood-assignment</artifactId> | ||
<version>0.0.1-SNAPSHOT</version> | ||
<packaging>jar</packaging> | ||
|
||
<name>ood-assignment</name> | ||
<url>http://maven.apache.org</url> | ||
|
||
<properties> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
</properties> | ||
|
||
<dependencies> | ||
|
||
<dependency> | ||
<groupId>junit</groupId> | ||
<artifactId>junit</artifactId> | ||
<version>4.12</version> | ||
</dependency> | ||
|
||
</dependencies> | ||
<repositories> | ||
<repository> | ||
<id>aliyunmaven</id> | ||
<url>http://maven.aliyun.com/nexus/content/groups/public/</url> | ||
</repository> | ||
</repositories> | ||
</project> |
10 changes: 10 additions & 0 deletions
10
students/282692248/ood/ood-assignment/src/main/java/com/coderising/ood/ocp/DateUtil.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package com.coderising.ood.ocp; | ||
|
||
public class DateUtil { | ||
|
||
public static String getCurrentDateAsString() { | ||
|
||
return null; | ||
} | ||
|
||
} |
38 changes: 38 additions & 0 deletions
38
students/282692248/ood/ood-assignment/src/main/java/com/coderising/ood/ocp/Logger.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package com.coderising.ood.ocp; | ||
|
||
public class Logger { | ||
|
||
public final int RAW_LOG = 1; | ||
public final int RAW_LOG_WITH_DATE = 2; | ||
public final int EMAIL_LOG = 1; | ||
public final int SMS_LOG = 2; | ||
public final int PRINT_LOG = 3; | ||
|
||
int type = 0; | ||
int method = 0; | ||
|
||
public Logger(int logType, int logMethod){ | ||
this.type = logType; | ||
this.method = logMethod; | ||
} | ||
public void log(String msg){ | ||
|
||
String logMsg = msg; | ||
|
||
if(this.type == RAW_LOG){ | ||
logMsg = msg; | ||
} else if(this.type == RAW_LOG_WITH_DATE){ | ||
String txtDate = DateUtil.getCurrentDateAsString(); | ||
logMsg = txtDate + ": " + msg; | ||
} | ||
|
||
if(this.method == EMAIL_LOG){ | ||
MailUtil.send(logMsg); | ||
} else if(this.method == SMS_LOG){ | ||
SMSUtil.send(logMsg); | ||
} else if(this.method == PRINT_LOG){ | ||
System.out.println(logMsg); | ||
} | ||
} | ||
} | ||
|
10 changes: 10 additions & 0 deletions
10
students/282692248/ood/ood-assignment/src/main/java/com/coderising/ood/ocp/MailUtil.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package com.coderising.ood.ocp; | ||
|
||
public class MailUtil { | ||
|
||
public static void send(String logMsg) { | ||
// TODO Auto-generated method stub | ||
|
||
} | ||
|
||
} |
10 changes: 10 additions & 0 deletions
10
students/282692248/ood/ood-assignment/src/main/java/com/coderising/ood/ocp/SMSUtil.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package com.coderising.ood.ocp; | ||
|
||
public class SMSUtil { | ||
|
||
public static void send(String logMsg) { | ||
// TODO Auto-generated method stub | ||
|
||
} | ||
|
||
} |
10 changes: 10 additions & 0 deletions
10
...s/282692248/ood/ood-assignment/src/main/java/com/coderising/ood/ocp/chasing/DateUtil.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package com.coderising.ood.ocp.chasing; | ||
|
||
public class DateUtil { | ||
|
||
public static String getCurrentDateAsString() { | ||
|
||
return null; | ||
} | ||
|
||
} |
19 changes: 19 additions & 0 deletions
19
...nts/282692248/ood/ood-assignment/src/main/java/com/coderising/ood/ocp/chasing/Logger.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package com.coderising.ood.ocp.chasing; | ||
|
||
import com.coderising.ood.ocp.chasing.formatter.ILogFormatter; | ||
import com.coderising.ood.ocp.chasing.sender.ILogSender; | ||
|
||
public class Logger { | ||
|
||
private ILogFormatter formatter; | ||
private ILogSender sender; | ||
|
||
public Logger(ILogFormatter formatter, ILogSender sender){ | ||
this.formatter = formatter; | ||
this.sender = sender; | ||
} | ||
public void log(String msg){ | ||
sender.send(formatter.format(msg)); | ||
} | ||
} | ||
|
10 changes: 10 additions & 0 deletions
10
...s/282692248/ood/ood-assignment/src/main/java/com/coderising/ood/ocp/chasing/MailUtil.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package com.coderising.ood.ocp.chasing; | ||
|
||
public class MailUtil { | ||
|
||
public static void send(String logMsg) { | ||
// TODO Auto-generated method stub | ||
|
||
} | ||
|
||
} |
10 changes: 10 additions & 0 deletions
10
...ts/282692248/ood/ood-assignment/src/main/java/com/coderising/ood/ocp/chasing/SMSUtil.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package com.coderising.ood.ocp.chasing; | ||
|
||
public class SMSUtil { | ||
|
||
public static void send(String logMsg) { | ||
// TODO Auto-generated method stub | ||
|
||
} | ||
|
||
} |
5 changes: 5 additions & 0 deletions
5
.../ood-assignment/src/main/java/com/coderising/ood/ocp/chasing/formatter/ILogFormatter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package com.coderising.ood.ocp.chasing.formatter; | ||
|
||
public interface ILogFormatter { | ||
String format(String txt); | ||
} |
12 changes: 12 additions & 0 deletions
12
...signment/src/main/java/com/coderising/ood/ocp/chasing/formatter/LogWithDateFormatter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.coderising.ood.ocp.chasing.formatter; | ||
|
||
import com.coderising.ood.ocp.chasing.DateUtil; | ||
|
||
public class LogWithDateFormatter implements ILogFormatter { | ||
|
||
@Override | ||
public String format(String txt) { | ||
return DateUtil.getCurrentDateAsString() + ": " + txt; | ||
} | ||
|
||
} |
10 changes: 10 additions & 0 deletions
10
...248/ood/ood-assignment/src/main/java/com/coderising/ood/ocp/chasing/formatter/RawLog.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package com.coderising.ood.ocp.chasing.formatter; | ||
|
||
public class RawLog implements ILogFormatter { | ||
|
||
@Override | ||
public String format(String txt) { | ||
return txt; | ||
} | ||
|
||
} |
5 changes: 5 additions & 0 deletions
5
...48/ood/ood-assignment/src/main/java/com/coderising/ood/ocp/chasing/sender/ILogSender.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package com.coderising.ood.ocp.chasing.sender; | ||
|
||
public interface ILogSender { | ||
void send(String msg); | ||
} |
12 changes: 12 additions & 0 deletions
12
...48/ood/ood-assignment/src/main/java/com/coderising/ood/ocp/chasing/sender/MailSender.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.coderising.ood.ocp.chasing.sender; | ||
|
||
import com.coderising.ood.ocp.chasing.MailUtil; | ||
|
||
public class MailSender implements ILogSender { | ||
|
||
@Override | ||
public void send(String msg) { | ||
MailUtil.send(msg); | ||
} | ||
|
||
} |
10 changes: 10 additions & 0 deletions
10
...248/ood/ood-assignment/src/main/java/com/coderising/ood/ocp/chasing/sender/SMSSender.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package com.coderising.ood.ocp.chasing.sender; | ||
|
||
public class SMSSender implements ILogSender { | ||
|
||
@Override | ||
public void send(String msg) { | ||
System.out.println(msg); | ||
} | ||
|
||
} |
12 changes: 12 additions & 0 deletions
12
.../ood/ood-assignment/src/main/java/com/coderising/ood/ocp/chasing/sender/StdoutSender.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.coderising.ood.ocp.chasing.sender; | ||
|
||
import com.coderising.ood.ocp.chasing.SMSUtil; | ||
|
||
public class StdoutSender implements ILogSender { | ||
|
||
@Override | ||
public void send(String msg) { | ||
SMSUtil.send(msg); | ||
} | ||
|
||
} |
7 changes: 7 additions & 0 deletions
7
...nts/282692248/ood/ood-assignment/src/main/java/com/coderising/ood/ocp/good/Formatter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.coderising.ood.ocp.good; | ||
|
||
public interface Formatter { | ||
|
||
String format(String msg); | ||
|
||
} |
13 changes: 13 additions & 0 deletions
13
...692248/ood/ood-assignment/src/main/java/com/coderising/ood/ocp/good/FormatterFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package com.coderising.ood.ocp.good; | ||
|
||
public class FormatterFactory { | ||
public static Formatter createFormatter(int type){ | ||
if(type == 1){ | ||
return new RawFormatter(); | ||
} | ||
if (type == 2){ | ||
return new HtmlFormatter(); | ||
} | ||
return null; | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
...282692248/ood/ood-assignment/src/main/java/com/coderising/ood/ocp/good/HtmlFormatter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package com.coderising.ood.ocp.good; | ||
|
||
public class HtmlFormatter implements Formatter { | ||
|
||
@Override | ||
public String format(String msg) { | ||
|
||
return null; | ||
} | ||
|
||
} |
18 changes: 18 additions & 0 deletions
18
students/282692248/ood/ood-assignment/src/main/java/com/coderising/ood/ocp/good/Logger.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package com.coderising.ood.ocp.good; | ||
|
||
public class Logger { | ||
|
||
private Formatter formatter; | ||
private Sender sender; | ||
|
||
public Logger(Formatter formatter,Sender sender){ | ||
this.formatter = formatter; | ||
this.sender = sender; | ||
} | ||
public void log(String msg){ | ||
sender.send(formatter.format(msg)) ; | ||
} | ||
|
||
|
||
} | ||
|
11 changes: 11 additions & 0 deletions
11
.../282692248/ood/ood-assignment/src/main/java/com/coderising/ood/ocp/good/RawFormatter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package com.coderising.ood.ocp.good; | ||
|
||
public class RawFormatter implements Formatter { | ||
|
||
@Override | ||
public String format(String msg) { | ||
|
||
return null; | ||
} | ||
|
||
} |
7 changes: 7 additions & 0 deletions
7
students/282692248/ood/ood-assignment/src/main/java/com/coderising/ood/ocp/good/Sender.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.coderising.ood.ocp.good; | ||
|
||
public interface Sender { | ||
|
||
void send(String msg); | ||
|
||
} |
23 changes: 23 additions & 0 deletions
23
...ents/282692248/ood/ood-assignment/src/main/java/com/coderising/ood/srp/Configuration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package com.coderising.ood.srp; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
public class Configuration { | ||
|
||
static Map<String,String> 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, "[email protected]"); | ||
} | ||
/** | ||
* 应该从配置文件读, 但是这里简化为直接从一个map 中去读 | ||
* @param key | ||
* @return | ||
*/ | ||
public String getProperty(String key) { | ||
|
||
return configurations.get(key); | ||
} | ||
|
||
} |
9 changes: 9 additions & 0 deletions
9
.../282692248/ood/ood-assignment/src/main/java/com/coderising/ood/srp/ConfigurationKeys.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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"; | ||
|
||
} |
25 changes: 25 additions & 0 deletions
25
students/282692248/ood/ood-assignment/src/main/java/com/coderising/ood/srp/DBUtil.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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", "[email protected]"); | ||
userList.add(userInfo); | ||
} | ||
|
||
return userList; | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
students/282692248/ood/ood-assignment/src/main/java/com/coderising/ood/srp/MailUtil.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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()); | ||
|
||
} | ||
|
||
|
||
} |
Oops, something went wrong.