Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Plugin data builders now reset their states after build #97

Merged
merged 1 commit into from
Apr 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions gcm4/src/main/java/plugins/groups/GroupsPluginData.java
Original file line number Diff line number Diff line change
Expand Up @@ -254,11 +254,15 @@ private Builder(Data data) {
*
*/
public GroupsPluginData build() {
try {
if (!data.locked) {
validateData();
}
ensureImmutability();
return new GroupsPluginData(data);
}finally {
data = new Data();
}
}

/**
Expand Down
4 changes: 4 additions & 0 deletions gcm4/src/main/java/plugins/materials/MaterialsPluginData.java
Original file line number Diff line number Diff line change
Expand Up @@ -247,11 +247,15 @@ public Builder addStage(final StageId stageId, final boolean offered, final Mate
*/

public MaterialsPluginData build() {
try {
if (!data.locked) {
validateData();
}
ensureImmutability();
return new MaterialsPluginData(data);
}finally {
data = new Data();
}

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,12 @@ private void ensureImmutability() {
* Returns the {@linkplain AttributesPluginData} from the collected data
*/
public AttributesPluginData build() {
ensureImmutability();
return new AttributesPluginData(data);
try {
ensureImmutability();
return new AttributesPluginData(data);
} finally {
data = new Data();
}
}

/**
Expand Down
20 changes: 12 additions & 8 deletions gcm4/src/main/java/plugins/people/PeoplePluginData.java
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ private void ensureImmutability() {
a = low;
b = high;
} else {
if (low > b+1) {
if (low > b + 1) {
count += (b - a + 1);
list2.add(new PersonRange(a, b));
a = low;
Expand All @@ -179,11 +179,11 @@ private void ensureImmutability() {

data.personRanges = list2;
data.personIds = new ArrayList<>(count);
if(data.personCount<0) {

if (data.personCount < 0) {
data.personCount = 0;
if(!data.personRanges.isEmpty()) {
data.personCount = data.personRanges.get(data.personRanges.size()-1).getHighPersonId()+1;
if (!data.personRanges.isEmpty()) {
data.personCount = data.personRanges.get(data.personRanges.size() - 1).getHighPersonId() + 1;
}
}

Expand Down Expand Up @@ -215,9 +215,13 @@ private Builder(Data data) {
*
*/
public PeoplePluginData build() {
validate();
ensureImmutability();
return new PeoplePluginData(data);
try {
validate();
ensureImmutability();
return new PeoplePluginData(data);
} finally {
data = new Data();
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,11 +135,15 @@ private Builder(Data data) {
*
*/
public PersonPropertiesPluginData build() {
try {
if (!data.locked) {
validateData();
}
ensureImmutability();
return new PersonPropertiesPluginData(data);
}finally {
data = new Data();
}
}

/**
Expand Down
28 changes: 19 additions & 9 deletions gcm4/src/main/java/plugins/regions/RegionsPluginData.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,14 @@ public Data(Data data) {

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof Data)) return false;
if (this == o)
return true;
if (!(o instanceof Data))
return false;
Data data = (Data) o;
return locked == data.locked && regionPropertyDefinitions.equals(data.regionPropertyDefinitions) && regionIds.equals(data.regionIds) && regionArrivalTimeTrackingPolicy == data.regionArrivalTimeTrackingPolicy && regionPropertyValues.equals(data.regionPropertyValues) && emptyRegionPropertyMap.equals(data.emptyRegionPropertyMap) && personRegions.equals(data.personRegions);
return locked == data.locked && regionPropertyDefinitions.equals(data.regionPropertyDefinitions) && regionIds.equals(data.regionIds)
&& regionArrivalTimeTrackingPolicy == data.regionArrivalTimeTrackingPolicy && regionPropertyValues.equals(data.regionPropertyValues)
&& emptyRegionPropertyMap.equals(data.emptyRegionPropertyMap) && personRegions.equals(data.personRegions);
}

@Override
Expand Down Expand Up @@ -171,11 +175,15 @@ private Builder(Data data) {
*
*/
public RegionsPluginData build() {
if (!data.locked) {
validateData();
try {
if (!data.locked) {
validateData();
}
ensureImmutability();
return new RegionsPluginData(data);
} finally {
data = new Data();
}
ensureImmutability();
return new RegionsPluginData(data);

}

Expand Down Expand Up @@ -454,8 +462,10 @@ public PluginDataBuilder getEmptyBuilder() {

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof RegionsPluginData)) return false;
if (this == o)
return true;
if (!(o instanceof RegionsPluginData))
return false;
RegionsPluginData that = (RegionsPluginData) o;
return data.equals(that.data);
}
Expand Down
12 changes: 8 additions & 4 deletions gcm4/src/main/java/plugins/resources/ResourcesPluginData.java
Original file line number Diff line number Diff line change
Expand Up @@ -252,11 +252,15 @@ private Builder(Data data) {
*
*/
public ResourcesPluginData build() {
if (!data.locked) {
validateData();
try {
if (!data.locked) {
validateData();
}
ensureImmutability();
return new ResourcesPluginData(data);
} finally {
data = new Data();
}
ensureImmutability();
return new ResourcesPluginData(data);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,11 +152,15 @@ private void validateData() {
*
*/
public StochasticsPluginData build() {
try {
if (!data.locked) {
validateData();
}
ensureImmutability();
return new StochasticsPluginData(data);
}finally {
data = new Data();
}
}

/**
Expand Down