package lect2_hierarchy; import java.lang.String; import static utils.DomainConstraint.ZERO_PLUS; import utils.DomainConstraint; import utils.NotPossibleException; import utils.OptType; import utils.AttrRef; import utils.DOpt; /** * @overview A projectile that can be fired by tank unit in the game * * @attributes * damage Integer int * angle Integer int * radius Integer int * * @object * A typical Projectile is
pt =, where *
damage(d), angle(ang), radius(r)* * @abstract_property * mutable(damage) = true /\ optional(damage) = false /\ min(damage) = 1 * mutable(angle) = false /\ optional(angle) = false /\ min(angle) = 0 * mutable(radius) = false /\ optional(radius) = false /\ min(radius) = 0+ * * @author namhv */ public class Projectile { @DomainConstraint(type="Integer", mutable=true, optional=false, min=1) private int damage; @DomainConstraint(type="Integer", mutable=false, optional=false, min=0) private int angle; @DomainConstraint(type="Integer", mutable=false, optional=false, min=ZERO_PLUS) private int radius; /** * @effects * if d, ang, r are valid * initialize this as
* if this satisfies abstract properties
* return true
* else
* return false
*
*/
public boolean repOK() {
if (!validateDamage(damage) || !validateAngle(angle) || !validateRadius(radius)) {
return false;
}
return true;
}
/**
* @effects
* if d is valid
* return true
* else
* return false
*
*/
private boolean validateDamage(int d) {
if (d < 1) {
return false;
}
return true;
}
/**
* @effects
* if ang is valid
* return true
* else
* return false
*
*/
private boolean validateAngle(int ang) {
if (ang < 0) {
return false;
}
return true;
}
/**
* @effects
* if r is valid
* return true
* else
* return false
*
*/
protected boolean validateRadius(int r) {
if (r <= 0) {
return false;
}
return true;
}
}