[New] Cloning without getters and setters

This commit is contained in:
Robert von Burg 2022-09-05 11:34:49 +02:00
parent 09889b6e77
commit 2e2bf893b2
Signed by: eitch
GPG Key ID: 75DB9C85C74331F7
20 changed files with 56 additions and 109 deletions

View File

@ -109,9 +109,9 @@ public abstract class AbstractStrolchElement implements StrolchElement {
* @param clone
* the clone to fill
*/
protected void fillClone(StrolchElement clone) {
clone.setId(getId());
clone.setName(getName());
protected void fillClone(AbstractStrolchElement clone) {
clone.id = this.id;
clone.name = this.name;
}
@Override

View File

@ -282,7 +282,7 @@ public abstract class GroupedParameterizedElement extends AbstractStrolchElement
*/
protected void fillClone(GroupedParameterizedElement clone) {
super.fillClone(clone);
clone.setType(getType());
clone.type = this.type;
if (this.parameterBagMap != null) {
for (ParameterBag bag : this.parameterBagMap.values())

View File

@ -231,22 +231,15 @@ public class Order extends AbstractStrolchRootElement implements StrolchRootElem
@Override
public Order getClone(boolean withVersion) {
Order clone = new Order();
super.fillClone(clone);
clone.setDate(this.date);
clone.setState(this.state);
if (this.policyDefs != null)
clone.setPolicyDefs(this.policyDefs.getClone());
if (withVersion)
clone.setVersion(this.version);
clone.date = this.date;
clone.state = this.state;
clone.locator = this.locator;
if (this.policyDefs != null)
clone.policyDefs = this.policyDefs.getClone();
if (withVersion)
clone.version = this.version;
return clone;
}

View File

@ -89,7 +89,7 @@ public abstract class ParameterizedElement extends AbstractStrolchElement {
throw new StrolchException(msg);
}
this.type = type;
this.type = type.intern();
}
///
@ -1193,14 +1193,12 @@ public abstract class ParameterizedElement extends AbstractStrolchElement {
return lb.build();
}
@Override
protected void fillClone(StrolchElement clone) {
protected void fillClone(ParameterizedElement clone) {
super.fillClone(clone);
ParameterizedElement peClone = (ParameterizedElement) clone;
peClone.setType(this.type);
clone.type = this.type;
if (this.parameterMap != null) {
for (Parameter<?> param : this.parameterMap.values()) {
peClone.addParameter(param.getClone());
clone.addParameter(param.getClone());
}
}
}

View File

@ -309,10 +309,9 @@ public class Resource extends AbstractStrolchRootElement implements StrolchRootE
@Override
public Resource getClone(boolean withVersion) {
Resource clone = new Resource();
super.fillClone(clone);
clone.locator = this.locator;
if (this.timedStateMap != null) {
for (StrolchTimedState<IValue<?>> timedState : this.timedStateMap.values()) {
@ -321,13 +320,9 @@ public class Resource extends AbstractStrolchRootElement implements StrolchRootE
}
if (this.policyDefs != null)
clone.setPolicyDefs(this.policyDefs.getClone());
clone.policyDefs = this.policyDefs.getClone();
if (withVersion)
clone.setVersion(this.version);
clone.locator = this.locator;
clone.version = this.version;
return clone;
}

View File

@ -43,6 +43,7 @@ import li.strolch.utils.dbc.DBC;
*/
public class Action extends GroupedParameterizedElement implements IActivityElement, PolicyContainer {
protected Locator locator;
protected Activity parent;
protected String resourceId;
protected String resourceType;
@ -211,10 +212,10 @@ public class Action extends GroupedParameterizedElement implements IActivityElem
public Action getClone() {
Action clone = new Action();
super.fillClone(clone);
clone.setResourceId(this.resourceId);
clone.setResourceType(this.resourceType);
clone.setState(this.state);
clone.resourceId = this.resourceId;
clone.resourceType = this.resourceType;
clone.state = this.state;
clone.locator = this.locator;
if (this.changes != null) {
for (IValueChange<? extends IValue<?>> change : getChanges()) {
@ -223,8 +224,7 @@ public class Action extends GroupedParameterizedElement implements IActivityElem
}
if (this.policyDefs != null)
clone.setPolicyDefs(this.policyDefs.getClone());
clone.policyDefs = this.policyDefs.getClone();
return clone;
}
@ -306,11 +306,14 @@ public class Action extends GroupedParameterizedElement implements IActivityElem
@Override
public Locator getLocator() {
LocatorBuilder lb = new LocatorBuilder();
if (this.parent != null)
this.parent.fillLocator(lb);
fillLocator(lb);
return lb.build();
if (this.locator == null) {
LocatorBuilder lb = new LocatorBuilder();
if (this.parent != null)
this.parent.fillLocator(lb);
fillLocator(lb);
this.locator = lb.build();
}
return this.locator;
}
@Override

View File

@ -696,27 +696,21 @@ public class Activity extends AbstractStrolchRootElement
@Override
public Activity getClone(boolean withVersion) {
Activity clone = new Activity();
clone.timeOrdering = this.timeOrdering;
super.fillClone(clone);
clone.timeOrdering = this.timeOrdering;
clone.locator = this.locator;
if (this.elements == null)
return clone;
for (IActivityElement element : this.elements.values()) {
clone.addElement(element.getClone());
if (this.elements != null) {
for (IActivityElement element : this.elements.values()) {
clone.addElement(element.getClone());
}
}
if (this.policyDefs != null)
clone.setPolicyDefs(this.policyDefs.getClone());
clone.policyDefs = this.policyDefs.getClone();
if (withVersion)
clone.setVersion(this.version);
clone.locator = this.locator;
clone.version = this.version;
return clone;
}

View File

@ -181,13 +181,13 @@ public abstract class AbstractParameter<T> extends AbstractStrolchElement implem
* @param clone
* the clone to fill
*/
protected void fillClone(Parameter<?> clone) {
protected void fillClone(AbstractParameter<?> clone) {
super.fillClone(clone);
clone.setHidden(this.hidden);
clone.setInterpretation(this.interpretation);
clone.setUom(this.uom);
clone.setIndex(this.index);
clone.hidden = this.hidden;
clone.interpretation = this.interpretation;
clone.uom = this.uom;
clone.index = this.index;
}
@SuppressWarnings("nls")

View File

@ -126,11 +126,8 @@ public class BooleanParameter extends AbstractParameter<Boolean> {
@Override
public BooleanParameter getClone() {
BooleanParameter clone = new BooleanParameter();
super.fillClone(clone);
clone.setValue(this.value);
clone.value = this.value;
return clone;
}

View File

@ -180,11 +180,8 @@ public class DateParameter extends AbstractParameter<Date> {
@Override
public DateParameter getClone() {
DateParameter clone = new DateParameter();
super.fillClone(clone);
clone.setValueFromZonedDateTime(this.value);
clone.value = this.value;
return clone;
}

View File

@ -163,11 +163,8 @@ public class DurationParameter extends AbstractParameter<PeriodDuration> {
@Override
public DurationParameter getClone() {
DurationParameter clone = new DurationParameter();
super.fillClone(clone);
clone.setValue(this.value);
clone.value = this.value;
return clone;
}

View File

@ -74,11 +74,8 @@ public class FloatListParameter extends AbstractListParameter<Double> {
@Override
public FloatListParameter getClone() {
FloatListParameter clone = new FloatListParameter();
super.fillClone(clone);
clone.setValue(this.value);
clone.value = new ArrayList<>(this.value);
return clone;
}

View File

@ -157,11 +157,8 @@ public class FloatParameter extends AbstractParameter<Double> {
@Override
public FloatParameter getClone() {
FloatParameter clone = new FloatParameter();
super.fillClone(clone);
clone.setValue(this.value);
clone.value = this.value;
return clone;
}

View File

@ -74,11 +74,8 @@ public class IntegerListParameter extends AbstractListParameter<Integer> {
@Override
public IntegerListParameter getClone() {
IntegerListParameter clone = new IntegerListParameter();
super.fillClone(clone);
clone.setValue(this.value);
clone.value = new ArrayList<>(this.value);
return clone;
}

View File

@ -150,11 +150,8 @@ public class IntegerParameter extends AbstractParameter<Integer> {
@Override
public IntegerParameter getClone() {
IntegerParameter clone = new IntegerParameter();
super.fillClone(clone);
clone.setValue(this.value);
clone.value = this.value;
return clone;
}

View File

@ -74,11 +74,8 @@ public class LongListParameter extends AbstractListParameter<Long> {
@Override
public LongListParameter getClone() {
LongListParameter clone = new LongListParameter();
super.fillClone(clone);
clone.setValue(this.value);
clone.value = new ArrayList<>(this.value);
return clone;
}

View File

@ -150,11 +150,8 @@ public class LongParameter extends AbstractParameter<Long> {
@Override
public LongParameter getClone() {
LongParameter clone = new LongParameter();
super.fillClone(clone);
clone.setValue(this.value);
clone.value = this.value;
return clone;
}

View File

@ -74,11 +74,8 @@ public class StringListParameter extends AbstractListParameter<String> {
@Override
public StringListParameter getClone() {
StringListParameter clone = new StringListParameter();
super.fillClone(clone);
clone.setValue(this.value);
clone.value = new ArrayList<>(this.value);
return clone;
}

View File

@ -149,11 +149,8 @@ public class StringParameter extends AbstractParameter<String> {
@Override
public StringParameter getClone() {
StringParameter clone = new StringParameter();
super.fillClone(clone);
clone.setValue(this.value);
clone.value = this.value;
return clone;
}

View File

@ -57,11 +57,8 @@ public class TextParameter extends StringParameter {
@Override
public TextParameter getClone() {
TextParameter clone = new TextParameter();
super.fillClone(clone);
clone.setValue(this.value);
clone.value = this.value;
return clone;
}