Skip to content

Commit

Permalink
Merge pull request #5 from onlyliuxin/master
Browse files Browse the repository at this point in the history
2017/07/15合并
  • Loading branch information
lorcx authored Jul 15, 2017
2 parents ede72d4 + 2a2be7c commit b7e6dc5
Show file tree
Hide file tree
Showing 510 changed files with 22,194 additions and 70 deletions.
Binary file added dicegame.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 13 additions & 1 deletion liuxin/ood/ood-assignment/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,19 @@
<groupId>com.coderising</groupId>
<artifactId>ood-assignment</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
</plugins>
</build>
<packaging>jar</packaging>

<name>ood-assignment</name>
<url>http://maven.apache.org</url>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.coderising.dp.builder;

public class TagBuilder {

public TagBuilder(String rootTagName){

}

public TagBuilder addChild(String childTagName){

return null;
}
public TagBuilder addSibling(String siblingTagName){


return null;

}
public TagBuilder setAttribute(String name, String value){

return null;
}
public TagBuilder setText(String value){

return null;
}
public String toXML(){
return null;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package com.coderising.dp.builder;

import static org.junit.Assert.*;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

public class TagBuilderTest {

@Before
public void setUp() throws Exception {
}

@After
public void tearDown() throws Exception {
}

@Test
public void testToXML() {

TagBuilder builder = new TagBuilder("order");

String xml = builder.addChild("line-items")
.addChild("line-item").setAttribute("pid", "P3677").setAttribute("qty", "3")
.addSibling("line-item").setAttribute("pid", "P9877").setAttribute("qty", "10")
.toXML();

String expected = "<order>"
+ "<line-items>"
+ "<line-item pid=\"P3677\" qty=\"3\"/>"
+ "<line-item pid=\"P9877\" qty=\"10\"/>"
+ "</line-items>"
+ "</order>";

System.out.println(xml);
assertEquals(expected, xml);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
package com.coderising.dp.builder;

import java.util.ArrayList;
import java.util.List;

public class TagNode {
private String tagName;
private String tagValue;
private List<TagNode> children = new ArrayList<>();
private List<Attribute> attributes = new ArrayList<>();

public TagNode(String name){
this.tagName = name;
}
public void add(TagNode child){
this.children.add(child);
}
public void setAttribute(String name, String value) {
Attribute attr = findAttribute(name);
if(attr != null){
attr.value = value;
}

attributes.add(new Attribute(name,value));
}
private Attribute findAttribute(String name){
for(Attribute attr : attributes){
if(attr.name.equals(name)){
return attr;
}
}
return null;
}
public void setValue(String value) {
this.tagValue = value;

}
public String getTagName() {
return tagName;
}
public List<TagNode> getChildren() {
return children;
}

private static class Attribute{
public Attribute(String name, String value) {
this.name = name;
this.value = value;
}
String name;
String value;

}
public String toXML(){
return toXML(this);
}
private String toXML(TagNode node){
StringBuilder buffer = new StringBuilder();
buffer.append("<").append(node.tagName);
if(node.attributes.size()> 0){
for(int i=0;i<node.attributes.size();i++){
Attribute attr = node.attributes.get(i);
buffer.append(" ").append(toXML(attr));
}
}
if(node.children.size()== 0){
buffer.append("/>");
return buffer.toString();
}
buffer.append(">");
for(TagNode childNode : node.children){
buffer.append(toXML(childNode));
}
buffer.append("</").append(node.tagName).append(">");


return buffer.toString();
}
private String toXML(Attribute attr){
return attr.name+"=\""+attr.value + "\"";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.coderising.dp.decorator;

public interface Email {
public String getContent();
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.coderising.dp.decorator;

public abstract class EmailDecorator implements Email{

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.coderising.dp.decorator;

public class EmailImpl implements Email {
private String content;

public EmailImpl(String content) {
this.content = content;
}
public String getContent() {
return content;
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.coderising.ood.srp.good1;


public class MailSender {

private String fromAddress ;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@





P8756 iPhone8
P3946 XiaoMi10
P8904 Oppo_R15
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package com.coderising.payroll;

import java.util.List;

import com.coderising.payroll.classification.CommissionedClassification;
import com.coderising.payroll.classification.HourlyClassification;
import com.coderising.payroll.classification.SalariedClassification;
import com.coderising.payroll.domain.Employee;
import com.coderising.payroll.domain.HoldMethod;
import com.coderising.payroll.domain.Paycheck;
import com.coderising.payroll.schedule.BiweeklySchedule;
import com.coderising.payroll.schedule.MonthlySchedule;
import com.coderising.payroll.schedule.WeeklySchedule;

public class PayrollService {
public List<Employee> getAllEmployees(){
return null;
}
public void savePaycheck(Paycheck pc){

}

public Employee addHourlyEmployee(String name, String address, double hourlyRate){
Employee e = new Employee(name, address);
e.setClassification(new HourlyClassification(hourlyRate));
e.setSchedule(new WeeklySchedule());
e.setPaymentMethod(new HoldMethod());
//保存员工到数据库.. 略
return e;
}

public Employee addSalariedEmployee(String name, String address, double salary){
Employee e = new Employee(name, address);
e.setClassification(new SalariedClassification(salary));
e.setSchedule(new MonthlySchedule());
e.setPaymentMethod(new HoldMethod());
//保存员工到数据库.. 略
return e;
}

public Employee addCommissionedEmployee(String name, String address, double salary, double saleRate){
Employee e = new Employee(name, address);
e.setClassification(new CommissionedClassification(salary, saleRate));
e.setSchedule(new BiweeklySchedule());
e.setPaymentMethod(new HoldMethod());
//保存员工到数据库.. 略
return e;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.coderising.payroll.affiliation;

import com.coderising.payroll.domain.Affiliation;
import com.coderising.payroll.domain.Paycheck;

public class NonAffiliation implements Affiliation{
public double calculateDeductions(Paycheck pc){
return 0.0;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.coderising.payroll.affiliation;

import com.coderising.payroll.domain.Affiliation;
import com.coderising.payroll.domain.Paycheck;

public class UnionAffiliation implements Affiliation {

@Override
public double calculateDeductions(Paycheck pc) {

return 0;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.coderising.payroll.classification;

import java.util.Date;
import java.util.Map;

import com.coderising.payroll.domain.Paycheck;
import com.coderising.payroll.domain.PaymentClassification;
import com.coderising.payroll.domain.SalesReceipt;
import com.coderising.payroll.util.DateUtil;

public class CommissionedClassification implements PaymentClassification {
double salary;
double rate;
public CommissionedClassification(double salary , double rate){
this.salary = salary;
this.rate = rate;
}
Map<Date, SalesReceipt> receipts;
@Override
public double calculatePay(Paycheck pc) {
double commission = 0.0;
for(SalesReceipt sr : receipts.values()){
if(DateUtil.between(sr.getSaleDate(), pc.getPayPeriodStartDate(),
pc.getPayPeriodEndDate())){
commission += sr.getAmount() * rate;
}
}
return salary + commission;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package com.coderising.payroll.classification;

import java.util.Date;
import java.util.Map;

import com.coderising.payroll.domain.Paycheck;
import com.coderising.payroll.domain.PaymentClassification;
import com.coderising.payroll.domain.TimeCard;
import com.coderising.payroll.util.DateUtil;

public class HourlyClassification implements PaymentClassification {
private double rate;
private Map<Date, TimeCard> timeCards;

public HourlyClassification(double hourlyRate) {
this.rate = hourlyRate;
}
public void addTimeCard(TimeCard tc){
timeCards.put(tc.getDate(), tc);
}
@Override
public double calculatePay(Paycheck pc) {
double totalPay = 0;
for(TimeCard tc : timeCards.values()){
if(DateUtil.between(tc.getDate(), pc.getPayPeriodStartDate(),
pc.getPayPeriodEndDate())){
totalPay += calculatePayForTimeCard(tc);
}
}
return totalPay;

}
private double calculatePayForTimeCard(TimeCard tc) {
int hours = tc.getHours();

if(hours > 8){
return 8*rate + (hours-8) * rate * 1.5;
} else{
return 8*rate;
}
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.coderising.payroll.classification;

import com.coderising.payroll.domain.Paycheck;
import com.coderising.payroll.domain.PaymentClassification;

public class SalariedClassification implements PaymentClassification {
private double salary;
public SalariedClassification(double salary){
this.salary = salary;
}
@Override
public double calculatePay(Paycheck pc) {
return salary;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.coderising.payroll.domain;

public interface Affiliation {
public double calculateDeductions(Paycheck pc);
}
Loading

0 comments on commit b7e6dc5

Please sign in to comment.