org.nakedobjects.example.expenses.claims.items.PrivateCarJourney Maven / Gradle / Ivy
The newest version!
package org.nakedobjects.example.expenses.claims.items;
import org.nakedobjects.applib.annotation.Disabled;
import org.nakedobjects.applib.annotation.MemberOrder;
import org.nakedobjects.applib.value.Money;
import org.nakedobjects.example.expenses.claims.ExpenseItem;
public class PrivateCarJourney extends Journey {
// {{ Total Miles field
private int totalMiles;
public void setTotalMiles(final int miles) {
this.totalMiles = miles;
objectChanged();
}
@MemberOrder(sequence="2.4")
public int getTotalMiles() {
resolve();
return totalMiles;
}
public void modifyTotalMiles(final int newMiles) {
setTotalMiles(newMiles);
checkIfComplete();
recalculateAmount();
}
public String disableTotalMiles() {
return disabledIfLocked();
}
// }}
// {{ MileageRate field;
private double mileageRate;
public void setMileageRate(final double rate) {
this.mileageRate = rate;
objectChanged();
}
@MemberOrder(sequence="2.5")
public double getMileageRate() {
resolve();
return mileageRate;
}
public void modifyMileageRate(final double newRate) {
setMileageRate(newRate);
checkIfComplete();
recalculateAmount();
}
public String disableMileageRate() {
return disabledIfLocked();
}
// }}
@Disabled
@Override
public Money getAmount() {
return super.getAmount();
}
private void recalculateAmount() {
modifyAmount(new Money(totalMiles * mileageRate, getClaim().currencyCode()));
}
// {{ Copying
@Override
protected void copyAnyEmptyFieldsSpecificToSubclassOfJourney(ExpenseItem otherItem) {
if (otherItem instanceof PrivateCarJourney) {
PrivateCarJourney carJourney = (PrivateCarJourney) otherItem;
if (totalMiles == 0) {
modifyTotalMiles(carJourney.getTotalMiles());
}
if (mileageRate == 0) {
modifyMileageRate(carJourney.getMileageRate());
}
}
}
// }}
@Override
protected boolean mandatoryJourneySubClassFieldsComplete() {
return totalMiles > 0 && mileageRate > 0;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy