Yuta HIGUCHI

Add copy constructor

Change-Id: If9b50a8e5db29e4bae2c93b51f34c5e043563094
...@@ -31,6 +31,7 @@ import org.onlab.onos.net.MastershipRole; ...@@ -31,6 +31,7 @@ import org.onlab.onos.net.MastershipRole;
31 31
32 import com.google.common.base.MoreObjects; 32 import com.google.common.base.MoreObjects;
33 import com.google.common.base.MoreObjects.ToStringHelper; 33 import com.google.common.base.MoreObjects.ToStringHelper;
34 +import com.google.common.collect.Lists;
34 35
35 /** 36 /**
36 * A structure that holds node mastership roles associated with a 37 * A structure that holds node mastership roles associated with a
...@@ -40,12 +41,26 @@ final class RoleValue { ...@@ -40,12 +41,26 @@ final class RoleValue {
40 41
41 protected final Map<MastershipRole, List<NodeId>> value = new EnumMap<>(MastershipRole.class); 42 protected final Map<MastershipRole, List<NodeId>> value = new EnumMap<>(MastershipRole.class);
42 43
44 + /**
45 + * Constructs empty RoleValue.
46 + */
43 public RoleValue() { 47 public RoleValue() {
44 value.put(MastershipRole.MASTER, new LinkedList<NodeId>()); 48 value.put(MastershipRole.MASTER, new LinkedList<NodeId>());
45 value.put(MastershipRole.STANDBY, new LinkedList<NodeId>()); 49 value.put(MastershipRole.STANDBY, new LinkedList<NodeId>());
46 value.put(MastershipRole.NONE, new LinkedList<NodeId>()); 50 value.put(MastershipRole.NONE, new LinkedList<NodeId>());
47 } 51 }
48 52
53 + /**
54 + * Constructs copy of specified RoleValue.
55 + *
56 + * @param original original to create copy from
57 + */
58 + public RoleValue(final RoleValue original) {
59 + value.put(MASTER, Lists.newLinkedList(original.value.get(MASTER)));
60 + value.put(STANDBY, Lists.newLinkedList(original.value.get(STANDBY)));
61 + value.put(NONE, Lists.newLinkedList(original.value.get(NONE)));
62 + }
63 +
49 // exposing internals for serialization purpose only 64 // exposing internals for serialization purpose only
50 Map<MastershipRole, List<NodeId>> value() { 65 Map<MastershipRole, List<NodeId>> value() {
51 return Collections.unmodifiableMap(value); 66 return Collections.unmodifiableMap(value);
......