Skip to content

Commit

Permalink
Merge pull request #4 from onlyliuxin/master
Browse files Browse the repository at this point in the history
合并老师代码
  • Loading branch information
miniyk2012 authored Jul 3, 2017
2 parents f4f6ef8 + 35e5c7b commit a66c7ab
Show file tree
Hide file tree
Showing 40 changed files with 858 additions and 0 deletions.
32 changes: 32 additions & 0 deletions students/282692248/ood/ood-assignment/pom.xml
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>
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;
}

}
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);
}
}
}

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

}

}
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

}

}
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;
}

}
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));
}
}

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

}

}
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

}

}
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);
}
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;
}

}
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;
}

}
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);
}
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);
}

}
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);
}

}
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);
}

}
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);

}
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;
}
}
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;
}

}
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)) ;
}


}

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;
}

}
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);

}
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);
}

}
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";

}
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;
}
}
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());

}


}
Loading

0 comments on commit a66c7ab

Please sign in to comment.