ItEr33S08ValidacionEProbasFuncionaisItEr32S09: Copying mutable values in order to preserve encapsulation

This commit is contained in:
Óscar González Fernández 2009-11-03 23:25:02 +01:00
parent 194735979e
commit 984b98f317
10 changed files with 32 additions and 23 deletions

View file

@ -30,13 +30,13 @@ public class DefaultFundamentalProperties implements ITaskFundamentalProperties
private String name;
private Date beginDate = null;
private long beginDate;
private long lengthMilliseconds = 0;
private String notes;
private Date hoursAdvanceEndDate;
private long hoursAdvanceEndDate;
private Date advanceEndDate;
@ -55,10 +55,10 @@ public class DefaultFundamentalProperties implements ITaskFundamentalProperties
Date advanceEndDate,
BigDecimal hoursAdvancePercentage, BigDecimal advancePercentage) {
this.name = name;
this.beginDate = beginDate;
this.beginDate = beginDate.getTime();
this.lengthMilliseconds = lengthMilliseconds;
this.notes = notes;
this.hoursAdvanceEndDate = hoursAdvanceEndDate;
this.hoursAdvanceEndDate = hoursAdvanceEndDate.getTime();
this.advanceEndDate = advanceEndDate;
this.hoursAdvancePercentage = hoursAdvancePercentage;
this.advancePercentage = advancePercentage;
@ -74,11 +74,11 @@ public class DefaultFundamentalProperties implements ITaskFundamentalProperties
}
public Date getBeginDate() {
return beginDate;
return new Date(beginDate);
}
public long setBeginDate(Date beginDate) {
this.beginDate = beginDate;
this.beginDate = beginDate.getTime();
return lengthMilliseconds;
}
@ -105,12 +105,13 @@ public class DefaultFundamentalProperties implements ITaskFundamentalProperties
@Override
public Date getHoursAdvanceEndDate() {
return hoursAdvanceEndDate;
return new Date(hoursAdvanceEndDate);
}
@Override
public Date getAdvanceEndDate() {
return advanceEndDate;
return advanceEndDate != null ? new Date(advanceEndDate.getTime())
: null;
}
@Override
public BigDecimal getHoursAdvancePercentage() {

View file

@ -166,6 +166,9 @@ public abstract class Task implements ITaskFundamentalProperties {
}
public void setEndDate(Date value) {
if (value == null) {
return;
}
setLengthMilliseconds(value.getTime() - getBeginDate().getTime());
}

View file

@ -32,7 +32,7 @@ public class ValidationException extends RuntimeException {
private InvalidValue[] invalidValues;
public InvalidValue[] getInvalidValues() {
return invalidValues;
return invalidValues.clone();
}
public ValidationException(InvalidValue invalidValue) {

View file

@ -79,7 +79,7 @@ public class IntervalOfPartialDatesType implements CompositeUserType {
@Override
public String[] getPropertyNames() {
return PROPERTY_NAMES;
return PROPERTY_NAMES.clone();
}
@Override

View file

@ -137,11 +137,12 @@ public abstract class TaskElement extends BaseEntity {
}
public Date getStartDate() {
return startDate;
return startDate != null ? new Date(startDate.getTime()) : null;
}
public void setStartDate(Date startDate) {
this.startDate = startDate;
this.startDate = startDate != null ? new Date(startDate.getTime())
: null;
}
@ -150,6 +151,9 @@ public abstract class TaskElement extends BaseEntity {
* @param newStartDate
*/
public void moveTo(Date newStartDate) {
if (newStartDate == null) {
return;
}
long durationMilliseconds = this.endDate.getTime()
- this.startDate.getTime();
this.startDate = newStartDate;
@ -160,11 +164,11 @@ public abstract class TaskElement extends BaseEntity {
protected abstract void moveAllocations();
public Date getEndDate() {
return endDate;
return endDate != null ? new Date(endDate.getTime()) : endDate;
}
public void setEndDate(Date endDate) {
this.endDate = endDate;
this.endDate = endDate != null ? new Date(endDate.getTime()) : null;
}
void add(Dependency dependency) {

View file

@ -79,11 +79,11 @@ public class WorkReport extends BaseEntity {
}
public Date getDate() {
return date;
return date != null ? new Date(date.getTime()) : null;
}
public void setDate(Date date) {
this.date = date;
this.date = date != null ? new Date(date.getTime()) : null;
}
public String getPlace() {

View file

@ -192,7 +192,8 @@ public class BaseCalendarModel implements IBaseCalendarModel {
@Override
public Date getSelectedDay() {
return this.selectedDate;
return selectedDate != null ? new Date(this.selectedDate.getTime())
: null;
}
@Override

View file

@ -51,15 +51,15 @@ public class CalendarHighlightedDays extends HtmlMacroComponent {
}
public Date getInternalValue() {
return value;
return value != null ? new Date(value.getTime()) : null;
}
public void setValue(Date value) {
this.value = value;
this.value = value != null ? new Date(value.getTime()) : null;
}
public Date getValue() {
return value;
return value != null ? new Date(value.getTime()) : null;
}
public void setAncestorExceptionDays(String ancestorExceptionDays) {

View file

@ -86,7 +86,7 @@ public class LabelBandboxFinder extends BandboxFinder implements IBandboxFinder
@Override
public String[] getHeaders() {
return headers;
return headers.clone();
}
@Override

View file

@ -99,11 +99,11 @@ public class CriterionSatisfactionDTO implements INewObject {
}
public Date getStartDate() {
return startDate;
return new Date(startDate.getTime());
}
public Date getEndDate() {
return endDate;
return new Date(endDate.getTime());
}
public CriterionSatisfaction getCriterionSatisfaction() {