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 #5 from onlyliuxin/master
2017/07/15合并
- Loading branch information
Showing
510 changed files
with
22,194 additions
and
70 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
30 changes: 30 additions & 0 deletions
30
liuxin/ood/ood-assignment/src/main/java/com/coderising/dp/builder/TagBuilder.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,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; | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
liuxin/ood/ood-assignment/src/main/java/com/coderising/dp/builder/TagBuilderTest.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,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); | ||
} | ||
|
||
} |
82 changes: 82 additions & 0 deletions
82
liuxin/ood/ood-assignment/src/main/java/com/coderising/dp/builder/TagNode.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,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 + "\""; | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
liuxin/ood/ood-assignment/src/main/java/com/coderising/dp/decorator/Email.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,6 @@ | ||
package com.coderising.dp.decorator; | ||
|
||
public interface Email { | ||
public String getContent(); | ||
} | ||
|
5 changes: 5 additions & 0 deletions
5
liuxin/ood/ood-assignment/src/main/java/com/coderising/dp/decorator/EmailDecorator.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.dp.decorator; | ||
|
||
public abstract class EmailDecorator implements Email{ | ||
|
||
} |
12 changes: 12 additions & 0 deletions
12
liuxin/ood/ood-assignment/src/main/java/com/coderising/dp/decorator/EmailImpl.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.dp.decorator; | ||
|
||
public class EmailImpl implements Email { | ||
private String content; | ||
|
||
public EmailImpl(String content) { | ||
this.content = content; | ||
} | ||
public String getContent() { | ||
return content; | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
liuxin/ood/ood-assignment/src/main/java/com/coderising/ood/srp/good1/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 |
---|---|---|
@@ -1,5 +1,6 @@ | ||
package com.coderising.ood.srp.good1; | ||
|
||
|
||
public class MailSender { | ||
|
||
private String fromAddress ; | ||
|
5 changes: 5 additions & 0 deletions
5
liuxin/ood/ood-assignment/src/main/java/com/coderising/ood/srp/product_promotion.txt
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 |
---|---|---|
@@ -1,3 +1,8 @@ | ||
|
||
|
||
|
||
|
||
|
||
P8756 iPhone8 | ||
P3946 XiaoMi10 | ||
P8904 Oppo_R15 | ||
|
49 changes: 49 additions & 0 deletions
49
liuxin/ood/ood-assignment/src/main/java/com/coderising/payroll/PayrollService.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,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; | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
...n/ood/ood-assignment/src/main/java/com/coderising/payroll/affiliation/NonAffiliation.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.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; | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
...ood/ood-assignment/src/main/java/com/coderising/payroll/affiliation/UnionAffiliation.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,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; | ||
} | ||
|
||
} |
31 changes: 31 additions & 0 deletions
31
...nment/src/main/java/com/coderising/payroll/classification/CommissionedClassification.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,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; | ||
} | ||
|
||
} |
43 changes: 43 additions & 0 deletions
43
...-assignment/src/main/java/com/coderising/payroll/classification/HourlyClassification.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,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; | ||
} | ||
} | ||
} | ||
|
16 changes: 16 additions & 0 deletions
16
...ssignment/src/main/java/com/coderising/payroll/classification/SalariedClassification.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,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; | ||
} | ||
|
||
} |
5 changes: 5 additions & 0 deletions
5
liuxin/ood/ood-assignment/src/main/java/com/coderising/payroll/domain/Affiliation.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.payroll.domain; | ||
|
||
public interface Affiliation { | ||
public double calculateDeductions(Paycheck pc); | ||
} |
Oops, something went wrong.