org.nakedobjects.example.expenses.claims.items.Journey 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.annotation.Optional;
import org.nakedobjects.example.expenses.claims.ExpenseItem;
public abstract class Journey extends AbstractExpenseItem {
// {{ Description
@Disabled
public String getDescription() {
return super.getDescription();
}
private void createDescription() {
String description = getOrigin() + " - " + getDestination();
if (getReturnJourney() != null && getReturnJourney().booleanValue()) {
description += " (return)";
}
setDescription(description);
}
// }}
// {{ Origin
private String origin;
public void setOrigin(final String origin) {
this.origin = origin;
objectChanged();
}
@MemberOrder(sequence="2.1")
public String getOrigin() {
resolve(origin);
return origin;
}
public void modifyOrigin(final String newOrigin) {
setOrigin(newOrigin);
checkIfComplete();
createDescription();
}
public String disableOrigin() {
return disabledIfLocked();
}
// }}
// {{ Destination
private String destination;
public void setDestination(final String destination) {
this.destination = destination;
objectChanged();
}
@MemberOrder(sequence="2.2")
public String getDestination() {
resolve(destination);
return destination;
}
public void modifyDestination(final String newDestination) {
setDestination(newDestination);
checkIfComplete();
createDescription();
}
public String disableDestination() {
return disabledIfLocked();
}
// }}
// {{ Return journey
private Boolean returnJourney;
@MemberOrder(sequence="2.3")
@Optional
public Boolean getReturnJourney() {
return returnJourney;
}
public void setReturnJourney(final Boolean returnJourney) {
this.returnJourney = returnJourney;
objectChanged();
}
public void modifyReturnJourney(final Boolean newReturnJourney) {
setReturnJourney(newReturnJourney);
checkIfComplete();
createDescription();
}
public String disableReturnJourney() {
return disabledIfLocked();
}
// }}
// {{ Copying
@Override
protected void copyAnyEmptyFieldsSpecificToSubclassOfAbstractExpenseItem(ExpenseItem otherItem) {
if (otherItem instanceof Journey) {
Journey journey = (Journey) otherItem;
if (origin == null || origin.length() == 0) {
modifyOrigin(journey.getOrigin());
}
if (destination == null || destination.length() == 0) {
modifyDestination(journey.getDestination());
}
if (returnJourney == null) {
modifyReturnJourney(journey.getReturnJourney());
}
}
copyAnyEmptyFieldsSpecificToSubclassOfJourney(otherItem);
}
protected abstract void copyAnyEmptyFieldsSpecificToSubclassOfJourney(ExpenseItem otherItem);
// }}
// {{ Fields complete
protected boolean mandatorySubClassFieldsComplete() {
return origin != null && !origin.equals("") &&
destination != null && !destination.equals("") &&
mandatoryJourneySubClassFieldsComplete();
}
protected abstract boolean mandatoryJourneySubClassFieldsComplete();
// }}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy