Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chapter 05 후반의 리팩토링 과정을 따라하라 #5

Merged
merged 3 commits into from
Mar 21, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
isDiscountable, isSatisfiedBy 메소드를 DiscountCondition으로 옮겨라
  • Loading branch information
johngrib committed Mar 21, 2020
commit a311f447119c16147bc1dde36c6ac5984f02295d
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,21 @@ public class DiscountCondition {
@Getter
@Setter
private LocalTime endTime;

public boolean isDiscountable(Screening screening) {
if (type == DiscountConditionType.PERIOD) {
return isSatisfiedByPeriod(screening);
}
return isSatisfiedBySequence(screening);
}

private boolean isSatisfiedByPeriod(Screening screening) {
return screening.getWhenScreened().getDayOfWeek().equals(dayOfWeek)
&& startTime.isBefore(screening.getWhenScreened().toLocalTime())
&& endTime.isAfter(screening.getWhenScreened().toLocalTime());
}

private boolean isSatisfiedBySequence(Screening screening) {
return sequence == screening.getSequence();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,7 @@ public Reservation reserve(Screening screening, Customer customer, int audienceC

private boolean checkDiscountable(Screening screening) {
return screening.getMovie().getDiscountConditions().stream()
.anyMatch(condition -> isDiscountable(condition, screening));
}

private boolean isDiscountable(DiscountCondition condition, Screening screening) {
if (condition.getType() == DiscountConditionType.PERIOD) {
return isSatisfiedByPeriod(condition, screening);
}
return isSatisfiedBySequence(condition, screening);
}

private boolean isSatisfiedByPeriod(DiscountCondition condition, Screening screening) {
return screening.getWhenScreened().getDayOfWeek().equals(condition.getDayOfWeek())
&& condition.getStartTime().isBefore(screening.getWhenScreened().toLocalTime())
&& condition.getEndTime().isAfter(screening.getWhenScreened().toLocalTime());
}

private boolean isSatisfiedBySequence(DiscountCondition condition, Screening screening) {
return condition.getSequence() == screening.getSequence();
.anyMatch(condition -> condition.isDiscountable(screening));
}

private Money calculateFee(Screening screening, boolean discountable, int audienceCount) {
Expand Down