Skip to content

Commit b841070

Browse files
author
Rory Potter
authored
Merge pull request #822 from ISISComputingGroup/Ticket3697_fix_synoptic_copy
Ticket3697 fix synoptic copy
2 parents 20f60ac + e3fac53 commit b841070

File tree

4 files changed

+31
-6
lines changed

4 files changed

+31
-6
lines changed

base/uk.ac.stfc.isis.ibex.synoptic.tests/src/uk/ac/stfc/isis/ibex/synoptic/tests/model/desc/TargetDescriptionTest.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,23 @@ public void copied_object_has_target_type_that_is_not_linked_to_source_object()
122122
assertEquals(TargetType.OPI, source.type());
123123
assertEquals(TargetType.COMPONENT, copied.type());
124124
}
125+
126+
@Test
127+
public void copied_object_has_macros_that_are_not_linked_to_source_object() {
128+
final String sourcePropertyValue = "SOURCE";
129+
final String copiedPropertyValue = "COPIED";
130+
131+
// Arrange
132+
source.getProperties().get(0).setValue(sourcePropertyValue);
133+
TargetDescription copied = new TargetDescription(source);
134+
135+
// Act (should not affect property of source).
136+
copied.getProperties().get(0).setValue(copiedPropertyValue);
137+
138+
// Assert
139+
assertEquals(source.getProperties().get(0).getValue(), sourcePropertyValue);
140+
assertEquals(copied.getProperties().get(0).getValue(), copiedPropertyValue);
141+
}
125142

126143
@Test
127144
public void copied_object_has_same_properties_as_source_object_with_no_name_changes() {

base/uk.ac.stfc.isis.ibex.synoptic/src/uk/ac/stfc/isis/ibex/synoptic/model/desc/ComponentDescription.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
import java.util.ArrayList;
2323
import java.util.List;
24+
import java.util.stream.Collectors;
2425

2526
import javax.xml.bind.annotation.XmlAccessType;
2627
import javax.xml.bind.annotation.XmlAccessorType;
@@ -98,10 +99,7 @@ private ComponentDescription(ComponentDescription other, boolean isTopLevelCopy,
9899
this.type = other.type;
99100
this.target = other.target != null ? new TargetDescription(other.target) : null;
100101

101-
this.pvs = new ArrayList<>();
102-
for (PV pv : other.pvs) {
103-
this.pvs.add(new PV(pv));
104-
}
102+
this.pvs = other.pvs().stream().map(PV::new).collect(Collectors.toList());
105103

106104
this.components = new ArrayList<>();
107105
for (ComponentDescription cd : other.components) {

base/uk.ac.stfc.isis.ibex.synoptic/src/uk/ac/stfc/isis/ibex/synoptic/model/desc/Property.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,15 @@ public class Property extends ModelObject {
4343
public Property() {
4444
}
4545

46+
/**
47+
* Clones an existing property.
48+
*
49+
* @param other the property to clone
50+
*/
51+
public Property(Property other) {
52+
this(other.key, other.value);
53+
}
54+
4655
/**
4756
* Instantiates a new property.
4857
*

base/uk.ac.stfc.isis.ibex.synoptic/src/uk/ac/stfc/isis/ibex/synoptic/model/desc/TargetDescription.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import java.util.ArrayList;
2323
import java.util.Collections;
2424
import java.util.List;
25+
import java.util.stream.Collectors;
2526

2627
import javax.xml.bind.annotation.XmlAccessType;
2728
import javax.xml.bind.annotation.XmlAccessorType;
@@ -41,7 +42,7 @@ public class TargetDescription {
4142

4243
@XmlElementWrapper(name = "properties")
4344
@XmlElement(name = "property", type = Property.class)
44-
private ArrayList<Property> properties = new ArrayList<>();
45+
private List<Property> properties = new ArrayList<>();
4546

4647
/**
4748
* Default constructor, required due to existence of copy constructor.
@@ -69,7 +70,7 @@ public TargetDescription(String name, TargetType type) {
6970
public TargetDescription(TargetDescription other) {
7071
this.name = other.name;
7172
this.type = other.type;
72-
this.properties = new ArrayList<>(other.getProperties());
73+
this.properties = other.getProperties().stream().map(Property::new).collect(Collectors.toList());
7374
}
7475

7576
/**

0 commit comments

Comments
 (0)