@@ -152,27 +152,14 @@ private RoutingNodes(RoutingNodes routingNodes) {
152
152
// instance
153
153
assert routingNodes .readOnly : "tried to create a mutable copy from a mutable instance" ;
154
154
this .readOnly = false ;
155
- this .nodesToShards = Maps .newMapWithExpectedSize (routingNodes .nodesToShards .size ());
156
- for (Map .Entry <String , RoutingNode > entry : routingNodes .nodesToShards .entrySet ()) {
157
- this .nodesToShards .put (entry .getKey (), entry .getValue ().copy ());
158
- }
159
- this .assignedShards = Maps .newMapWithExpectedSize (routingNodes .assignedShards .size ());
160
- for (Map .Entry <ShardId , List <ShardRouting >> entry : routingNodes .assignedShards .entrySet ()) {
161
- this .assignedShards .put (entry .getKey (), new ArrayList <>(entry .getValue ()));
162
- }
155
+ this .nodesToShards = Maps .copyOf (routingNodes .nodesToShards , RoutingNode ::copy );
156
+ this .assignedShards = Maps .copyOf (routingNodes .assignedShards , ArrayList ::new );
163
157
this .unassignedShards = routingNodes .unassignedShards .copyFor (this );
164
-
165
158
this .inactivePrimaryCount = routingNodes .inactivePrimaryCount ;
166
159
this .inactiveShardCount = routingNodes .inactiveShardCount ;
167
160
this .relocatingShards = routingNodes .relocatingShards ;
168
- this .attributeValuesByAttribute = Maps .newMapWithExpectedSize (routingNodes .attributeValuesByAttribute .size ());
169
- for (Map .Entry <String , Set <String >> entry : routingNodes .attributeValuesByAttribute .entrySet ()) {
170
- this .attributeValuesByAttribute .put (entry .getKey (), new HashSet <>(entry .getValue ()));
171
- }
172
- this .recoveriesPerNode = Maps .newMapWithExpectedSize (routingNodes .recoveriesPerNode .size ());
173
- for (Map .Entry <String , Recoveries > entry : routingNodes .recoveriesPerNode .entrySet ()) {
174
- this .recoveriesPerNode .put (entry .getKey (), entry .getValue ().copy ());
175
- }
161
+ this .attributeValuesByAttribute = Maps .copyOf (routingNodes .attributeValuesByAttribute , HashSet ::new );
162
+ this .recoveriesPerNode = Maps .copyOf (routingNodes .recoveriesPerNode , Recoveries ::copy );
176
163
}
177
164
178
165
/**
0 commit comments