diff --git a/base/uk.ac.stfc.isis.ibex.synoptic.tests/src/uk/ac/stfc/isis/ibex/synoptic/tests/model/desc/TargetDescriptionTest.java b/base/uk.ac.stfc.isis.ibex.synoptic.tests/src/uk/ac/stfc/isis/ibex/synoptic/tests/model/desc/TargetDescriptionTest.java index 96b7509852..cd3f12a6ee 100644 --- a/base/uk.ac.stfc.isis.ibex.synoptic.tests/src/uk/ac/stfc/isis/ibex/synoptic/tests/model/desc/TargetDescriptionTest.java +++ b/base/uk.ac.stfc.isis.ibex.synoptic.tests/src/uk/ac/stfc/isis/ibex/synoptic/tests/model/desc/TargetDescriptionTest.java @@ -122,6 +122,23 @@ public void copied_object_has_target_type_that_is_not_linked_to_source_object() assertEquals(TargetType.OPI, source.type()); assertEquals(TargetType.COMPONENT, copied.type()); } + + @Test + public void copied_object_has_macros_that_are_not_linked_to_source_object() { + final String sourcePropertyValue = "SOURCE"; + final String copiedPropertyValue = "COPIED"; + + // Arrange + source.getProperties().get(0).setValue(sourcePropertyValue); + TargetDescription copied = new TargetDescription(source); + + // Act (should not affect property of source). + copied.getProperties().get(0).setValue(copiedPropertyValue); + + // Assert + assertEquals(source.getProperties().get(0).getValue(), sourcePropertyValue); + assertEquals(copied.getProperties().get(0).getValue(), copiedPropertyValue); + } @Test public void copied_object_has_same_properties_as_source_object_with_no_name_changes() { diff --git a/base/uk.ac.stfc.isis.ibex.synoptic/src/uk/ac/stfc/isis/ibex/synoptic/model/desc/ComponentDescription.java b/base/uk.ac.stfc.isis.ibex.synoptic/src/uk/ac/stfc/isis/ibex/synoptic/model/desc/ComponentDescription.java index f818afdb0b..ed56a33247 100644 --- a/base/uk.ac.stfc.isis.ibex.synoptic/src/uk/ac/stfc/isis/ibex/synoptic/model/desc/ComponentDescription.java +++ b/base/uk.ac.stfc.isis.ibex.synoptic/src/uk/ac/stfc/isis/ibex/synoptic/model/desc/ComponentDescription.java @@ -21,6 +21,7 @@ import java.util.ArrayList; import java.util.List; +import java.util.stream.Collectors; import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; @@ -98,10 +99,7 @@ private ComponentDescription(ComponentDescription other, boolean isTopLevelCopy, this.type = other.type; this.target = other.target != null ? new TargetDescription(other.target) : null; - this.pvs = new ArrayList<>(); - for (PV pv : other.pvs) { - this.pvs.add(new PV(pv)); - } + this.pvs = other.pvs().stream().map(PV::new).collect(Collectors.toList()); this.components = new ArrayList<>(); for (ComponentDescription cd : other.components) { diff --git a/base/uk.ac.stfc.isis.ibex.synoptic/src/uk/ac/stfc/isis/ibex/synoptic/model/desc/Property.java b/base/uk.ac.stfc.isis.ibex.synoptic/src/uk/ac/stfc/isis/ibex/synoptic/model/desc/Property.java index 4f2e194fcc..52489f1b22 100644 --- a/base/uk.ac.stfc.isis.ibex.synoptic/src/uk/ac/stfc/isis/ibex/synoptic/model/desc/Property.java +++ b/base/uk.ac.stfc.isis.ibex.synoptic/src/uk/ac/stfc/isis/ibex/synoptic/model/desc/Property.java @@ -43,6 +43,15 @@ public class Property extends ModelObject { public Property() { } + /** + * Clones an existing property. + * + * @param other the property to clone + */ + public Property(Property other) { + this(other.key, other.value); + } + /** * Instantiates a new property. * diff --git a/base/uk.ac.stfc.isis.ibex.synoptic/src/uk/ac/stfc/isis/ibex/synoptic/model/desc/TargetDescription.java b/base/uk.ac.stfc.isis.ibex.synoptic/src/uk/ac/stfc/isis/ibex/synoptic/model/desc/TargetDescription.java index 7902410fec..88742f56a0 100644 --- a/base/uk.ac.stfc.isis.ibex.synoptic/src/uk/ac/stfc/isis/ibex/synoptic/model/desc/TargetDescription.java +++ b/base/uk.ac.stfc.isis.ibex.synoptic/src/uk/ac/stfc/isis/ibex/synoptic/model/desc/TargetDescription.java @@ -22,6 +22,7 @@ import java.util.ArrayList; import java.util.Collections; import java.util.List; +import java.util.stream.Collectors; import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; @@ -41,7 +42,7 @@ public class TargetDescription { @XmlElementWrapper(name = "properties") @XmlElement(name = "property", type = Property.class) - private ArrayList properties = new ArrayList<>(); + private List properties = new ArrayList<>(); /** * Default constructor, required due to existence of copy constructor. @@ -69,7 +70,7 @@ public TargetDescription(String name, TargetType type) { public TargetDescription(TargetDescription other) { this.name = other.name; this.type = other.type; - this.properties = new ArrayList<>(other.getProperties()); + this.properties = other.getProperties().stream().map(Property::new).collect(Collectors.toList()); } /**