public Builder addReplica() {
   for (IntCursor cursor : shards.keys()) {
     int shardId = cursor.value;
     // version 0, will get updated when reroute will happen
     ImmutableShardRouting shard =
         new ImmutableShardRouting(index, shardId, null, false, ShardRoutingState.UNASSIGNED, 0);
     shards.put(
         shardId,
         new IndexShardRoutingTable.Builder(shards.get(shard.id())).addShard(shard).build());
   }
   return this;
 }
 public Builder removeReplica() {
   for (IntCursor cursor : shards.keys()) {
     int shardId = cursor.value;
     IndexShardRoutingTable indexShard = shards.get(shardId);
     if (indexShard.replicaShards().isEmpty()) {
       // nothing to do here!
       return this;
     }
     // re-add all the current ones
     IndexShardRoutingTable.Builder builder =
         new IndexShardRoutingTable.Builder(
             indexShard.shardId(), indexShard.primaryAllocatedPostApi());
     for (ShardRouting shardRouting : indexShard) {
       builder.addShard(new ImmutableShardRouting(shardRouting));
     }
     // first check if there is one that is not assigned to a node, and remove it
     boolean removed = false;
     for (ShardRouting shardRouting : indexShard) {
       if (!shardRouting.primary() && !shardRouting.assignedToNode()) {
         builder.removeShard(shardRouting);
         removed = true;
         break;
       }
     }
     if (!removed) {
       for (ShardRouting shardRouting : indexShard) {
         if (!shardRouting.primary()) {
           builder.removeShard(shardRouting);
           removed = true;
           break;
         }
       }
     }
     shards.put(shardId, builder.build());
   }
   return this;
 }