Refactor Fee class to support EAP fee

Currently EapFee is a separate class that has no inheritance from either
BaseFee and Fee. With this CL its functionality is merged into the Fee class
and the type of the fee can be identified by the FeeType enum in the Fee class.
Future custom fees can follow the same pattern.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=133627570
This commit is contained in:
jianglai 2016-09-19 13:53:38 -07:00 committed by Ben McIlwain
parent 0518f63aad
commit 77571e2063
9 changed files with 121 additions and 131 deletions

View file

@ -17,6 +17,7 @@ package google.registry.model.domain.fee;
import static com.google.common.base.MoreObjects.firstNonNull;
import static com.google.common.base.Preconditions.checkState;
import com.google.common.collect.Range;
import google.registry.model.ImmutableObject;
import google.registry.xml.PeriodAdapter;
import java.math.BigDecimal;
@ -25,6 +26,7 @@ import javax.xml.bind.annotation.XmlEnumValue;
import javax.xml.bind.annotation.XmlTransient;
import javax.xml.bind.annotation.XmlValue;
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
import org.joda.time.DateTime;
import org.joda.time.Period;
/** Base class for the fee and credit types. */
@ -75,9 +77,12 @@ public abstract class BaseFee extends ImmutableObject {
@XmlValue
BigDecimal cost;
@XmlTransient
FeeType type;
@XmlTransient
Range<DateTime> validDateRange;
public String getDescription() {
return description;
@ -109,11 +114,19 @@ public abstract class BaseFee extends ImmutableObject {
public FeeType getType() {
return type;
}
public boolean hasValidDateRange() {
return validDateRange != null;
}
protected void generateDescription(Object... args) {
checkState(type != null);
description = type.renderDescription(args);
}
public boolean hasZeroCost() {
return cost.signum() == 0;
}
public boolean hasDefaultAttributes() {
return getGracePeriod().equals(Period.ZERO)