Skip to content

Commit

Permalink
[New] Extend builders
Browse files Browse the repository at this point in the history
  • Loading branch information
eitch committed Jun 16, 2024
1 parent caeb904 commit 4ae05d1
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 7 deletions.
26 changes: 20 additions & 6 deletions model/src/main/java/li/strolch/model/builder/ActivityBuilder.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package li.strolch.model.builder;

import java.util.ArrayList;
import java.util.List;

import li.strolch.model.activity.Activity;
import li.strolch.model.activity.TimeOrdering;
import li.strolch.utils.dbc.DBC;

import static li.strolch.model.builder.BuilderHelper.*;
import java.util.ArrayList;
import java.util.List;

import static li.strolch.model.builder.BuilderHelper.buildParamName;

public class ActivityBuilder extends RootElementBuilder<ActivityBuilder> implements ActivityElementBuilder {

Expand Down Expand Up @@ -86,13 +86,27 @@ public StrolchElementBuilder endActivity() {
return this.builder;
}

@Override
public Activity build(String id) {
Activity activity = new Activity(id, getName(), getType(), this.timeOrdering);
return applyBuilder(activity);
}

@Override
public Activity build(String id, String name) {
Activity activity = new Activity(id, name, getType(), this.timeOrdering);
return applyBuilder(activity);
}

@Override
public Activity build() {
Activity activity = new Activity(getId(), getName(), getType(), this.timeOrdering);
super.applyRootElement(activity);
return applyBuilder(activity);
}

private Activity applyBuilder(Activity activity) {
super.applyRootElement(activity);
this.builders.forEach(b -> activity.addElement(b.build()));

return activity;
}
}
18 changes: 17 additions & 1 deletion model/src/main/java/li/strolch/model/builder/OrderBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import li.strolch.utils.dbc.DBC;
import li.strolch.utils.iso8601.ISO8601;

import static li.strolch.model.builder.BuilderHelper.*;
import static li.strolch.model.builder.BuilderHelper.buildParamName;

public class OrderBuilder extends RootElementBuilder<OrderBuilder> {

Expand Down Expand Up @@ -34,9 +34,25 @@ public StrolchElementBuilder endOrder() {
return this.builder;
}

@Override
public Order build(String id) {
Order order = new Order(id, getName(), getType());
return applyBuilder(order);
}

@Override
public Order build(String id, String name) {
Order order = new Order(id, name, getType());
return applyBuilder(order);
}

@Override
public Order build() {
Order order = new Order(getId(), getName(), getType());
return applyBuilder(order);
}

private Order applyBuilder(Order order) {
super.applyRootElement(order);
order.setDate(ISO8601.EMPTY_VALUE_ZONED_DATE);
order.setState(State.CREATED);
Expand Down
16 changes: 16 additions & 0 deletions model/src/main/java/li/strolch/model/builder/ResourceBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,25 @@ public StrolchElementBuilder endResource() {
return this.builder;
}

@Override
public Resource build(String id) {
Resource resource = new Resource(id, getName(), getType());
return applyBuilder(resource);
}

@Override
public Resource build(String id, String name) {
Resource resource = new Resource(id, name, getType());
return applyBuilder(resource);
}

@Override
public Resource build() {
Resource resource = new Resource(getId(), getName(), getType());
return applyBuilder(resource);
}

protected Resource applyBuilder(Resource resource) {
super.applyRootElement(resource);
this.timedStates.forEach(b -> resource.addTimedState(b.build()));
return resource;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,8 @@ protected void applyRootElement(StrolchRootElement element) {
}

public abstract StrolchRootElement build();

public abstract StrolchRootElement build(String id);

public abstract StrolchRootElement build(String id, String name);
}

0 comments on commit 4ae05d1

Please sign in to comment.