Skip to content

Commit a8f6a2d

Browse files
committed
Extract out domain concepts
1 parent fe7f1e0 commit a8f6a2d

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

src/warranty/ClaimsAdjudication.java

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
import warranty.Contract.Status;
44

5+
import java.util.Date;
6+
57
/**
68
* Adjudicate/adjudication - a judgment made on a claim to determine whether
79
* we are legally obligated to process the claim against the warranty. From
@@ -14,12 +16,21 @@
1416
public class ClaimsAdjudication {
1517

1618
public void Adjudicate(Contract contract, Claim newClaim) {
17-
double claimTotal = contract.getClaims().stream().mapToDouble(c -> c.amount).sum();
18-
if (((contract.purchasePrice - claimTotal) * 0.8 > newClaim.amount) &&
19-
(contract.status == Status.ACTIVE) &&
20-
(newClaim.failureDate.compareTo(contract.effectiveDate) >= 0) &&
21-
(newClaim.failureDate.compareTo(contract.expirationDate) <= 0)) {
19+
if ((LimitOfLiability(contract) > newClaim.amount) &&
20+
InEffectFor(contract, newClaim.failureDate)) {
2221
contract.add(newClaim);
2322
}
2423
}
24+
25+
// These two new methods we've added seem to be responsibilities of Contract. Let's move them...
26+
public double LimitOfLiability(Contract contract) {
27+
double claimTotal = contract.getClaims().stream().mapToDouble(c -> c.amount).sum();
28+
return (contract.purchasePrice - claimTotal) * 0.8;
29+
}
30+
31+
public boolean InEffectFor(Contract contract, Date failureDate) {
32+
return (contract.status == Status.ACTIVE) &&
33+
(failureDate.compareTo(contract.effectiveDate) >= 0) &&
34+
(failureDate.compareTo(contract.expirationDate) <= 0);
35+
}
2536
}

0 commit comments

Comments
 (0)