From e347a626dabab889ddd7700e5e5d3df149aa314e Mon Sep 17 00:00:00 2001 From: Shay Banon Date: Sun, 17 Mar 2013 21:55:07 +0100 Subject: [PATCH] use ImmutableList.Builder instead of ArrayList --- .../routing/IndexShardRoutingTable.java | 23 +++++++++++++------ 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/src/main/java/org/elasticsearch/cluster/routing/IndexShardRoutingTable.java b/src/main/java/org/elasticsearch/cluster/routing/IndexShardRoutingTable.java index 1df26510d56..79fc193a37f 100644 --- a/src/main/java/org/elasticsearch/cluster/routing/IndexShardRoutingTable.java +++ b/src/main/java/org/elasticsearch/cluster/routing/IndexShardRoutingTable.java @@ -64,9 +64,9 @@ public class IndexShardRoutingTable implements Iterable { this.counter = new AtomicInteger(ThreadLocalRandom.current().nextInt(shards.size())); ShardRouting primary = null; - List replicas = new ArrayList(); - List activeShards = new ArrayList(); - List assignedShards = new ArrayList(); + ImmutableList.Builder replicas = ImmutableList.builder(); + ImmutableList.Builder activeShards = ImmutableList.builder(); + ImmutableList.Builder assignedShards = ImmutableList.builder(); for (ShardRouting shard : shards) { if (shard.primary()) { @@ -88,9 +88,9 @@ public class IndexShardRoutingTable implements Iterable { } else { this.primaryAsList = ImmutableList.of(); } - this.replicas = ImmutableList.copyOf(replicas); - this.activeShards = ImmutableList.copyOf(activeShards); - this.assignedShards = ImmutableList.copyOf(assignedShards); + this.replicas = replicas.build(); + this.activeShards = activeShards.build(); + this.assignedShards = assignedShards.build(); } /** @@ -137,6 +137,7 @@ public class IndexShardRoutingTable implements Iterable { /** * Returns the shards id + * * @return id of the shard */ public ShardId shardId() { @@ -145,6 +146,7 @@ public class IndexShardRoutingTable implements Iterable { /** * Returns the shards id + * * @return id of the shard */ public ShardId getShardId() { @@ -162,7 +164,7 @@ public class IndexShardRoutingTable implements Iterable { public int size() { return shards.size(); } - + /** * Returns the number of this shards instances. */ @@ -172,6 +174,7 @@ public class IndexShardRoutingTable implements Iterable { /** * Returns a {@link ImmutableList} of shards + * * @return a {@link ImmutableList} of shards */ public ImmutableList shards() { @@ -180,6 +183,7 @@ public class IndexShardRoutingTable implements Iterable { /** * Returns a {@link ImmutableList} of shards + * * @return a {@link ImmutableList} of shards */ public ImmutableList getShards() { @@ -188,6 +192,7 @@ public class IndexShardRoutingTable implements Iterable { /** * Returns a {@link ImmutableList} of active shards + * * @return a {@link ImmutableList} of shards */ public ImmutableList activeShards() { @@ -196,6 +201,7 @@ public class IndexShardRoutingTable implements Iterable { /** * Returns a {@link ImmutableList} of active shards + * * @return a {@link ImmutableList} of shards */ public ImmutableList getActiveShards() { @@ -204,6 +210,7 @@ public class IndexShardRoutingTable implements Iterable { /** * Returns a {@link ImmutableList} of assigned shards + * * @return a {@link ImmutableList} of shards */ public ImmutableList assignedShards() { @@ -212,6 +219,7 @@ public class IndexShardRoutingTable implements Iterable { /** * Returns a {@link ImmutableList} of assigned shards + * * @return a {@link ImmutableList} of shards */ public ImmutableList getAssignedShards() { @@ -220,6 +228,7 @@ public class IndexShardRoutingTable implements Iterable { /** * Returns the number of shards in a specific state + * * @param state state of the shards to count * @return number of shards in state */