use ImmutableList.Builder instead of ArrayList
This commit is contained in:
parent
2ed6ea25cc
commit
e347a626da
|
@ -64,9 +64,9 @@ public class IndexShardRoutingTable implements Iterable<ShardRouting> {
|
||||||
this.counter = new AtomicInteger(ThreadLocalRandom.current().nextInt(shards.size()));
|
this.counter = new AtomicInteger(ThreadLocalRandom.current().nextInt(shards.size()));
|
||||||
|
|
||||||
ShardRouting primary = null;
|
ShardRouting primary = null;
|
||||||
List<ShardRouting> replicas = new ArrayList<ShardRouting>();
|
ImmutableList.Builder<ShardRouting> replicas = ImmutableList.builder();
|
||||||
List<ShardRouting> activeShards = new ArrayList<ShardRouting>();
|
ImmutableList.Builder<ShardRouting> activeShards = ImmutableList.builder();
|
||||||
List<ShardRouting> assignedShards = new ArrayList<ShardRouting>();
|
ImmutableList.Builder<ShardRouting> assignedShards = ImmutableList.builder();
|
||||||
|
|
||||||
for (ShardRouting shard : shards) {
|
for (ShardRouting shard : shards) {
|
||||||
if (shard.primary()) {
|
if (shard.primary()) {
|
||||||
|
@ -88,9 +88,9 @@ public class IndexShardRoutingTable implements Iterable<ShardRouting> {
|
||||||
} else {
|
} else {
|
||||||
this.primaryAsList = ImmutableList.of();
|
this.primaryAsList = ImmutableList.of();
|
||||||
}
|
}
|
||||||
this.replicas = ImmutableList.copyOf(replicas);
|
this.replicas = replicas.build();
|
||||||
this.activeShards = ImmutableList.copyOf(activeShards);
|
this.activeShards = activeShards.build();
|
||||||
this.assignedShards = ImmutableList.copyOf(assignedShards);
|
this.assignedShards = assignedShards.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -137,6 +137,7 @@ public class IndexShardRoutingTable implements Iterable<ShardRouting> {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the shards id
|
* Returns the shards id
|
||||||
|
*
|
||||||
* @return id of the shard
|
* @return id of the shard
|
||||||
*/
|
*/
|
||||||
public ShardId shardId() {
|
public ShardId shardId() {
|
||||||
|
@ -145,6 +146,7 @@ public class IndexShardRoutingTable implements Iterable<ShardRouting> {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the shards id
|
* Returns the shards id
|
||||||
|
*
|
||||||
* @return id of the shard
|
* @return id of the shard
|
||||||
*/
|
*/
|
||||||
public ShardId getShardId() {
|
public ShardId getShardId() {
|
||||||
|
@ -162,7 +164,7 @@ public class IndexShardRoutingTable implements Iterable<ShardRouting> {
|
||||||
public int size() {
|
public int size() {
|
||||||
return shards.size();
|
return shards.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the number of this shards instances.
|
* Returns the number of this shards instances.
|
||||||
*/
|
*/
|
||||||
|
@ -172,6 +174,7 @@ public class IndexShardRoutingTable implements Iterable<ShardRouting> {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a {@link ImmutableList} of shards
|
* Returns a {@link ImmutableList} of shards
|
||||||
|
*
|
||||||
* @return a {@link ImmutableList} of shards
|
* @return a {@link ImmutableList} of shards
|
||||||
*/
|
*/
|
||||||
public ImmutableList<ShardRouting> shards() {
|
public ImmutableList<ShardRouting> shards() {
|
||||||
|
@ -180,6 +183,7 @@ public class IndexShardRoutingTable implements Iterable<ShardRouting> {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a {@link ImmutableList} of shards
|
* Returns a {@link ImmutableList} of shards
|
||||||
|
*
|
||||||
* @return a {@link ImmutableList} of shards
|
* @return a {@link ImmutableList} of shards
|
||||||
*/
|
*/
|
||||||
public ImmutableList<ShardRouting> getShards() {
|
public ImmutableList<ShardRouting> getShards() {
|
||||||
|
@ -188,6 +192,7 @@ public class IndexShardRoutingTable implements Iterable<ShardRouting> {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a {@link ImmutableList} of active shards
|
* Returns a {@link ImmutableList} of active shards
|
||||||
|
*
|
||||||
* @return a {@link ImmutableList} of shards
|
* @return a {@link ImmutableList} of shards
|
||||||
*/
|
*/
|
||||||
public ImmutableList<ShardRouting> activeShards() {
|
public ImmutableList<ShardRouting> activeShards() {
|
||||||
|
@ -196,6 +201,7 @@ public class IndexShardRoutingTable implements Iterable<ShardRouting> {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a {@link ImmutableList} of active shards
|
* Returns a {@link ImmutableList} of active shards
|
||||||
|
*
|
||||||
* @return a {@link ImmutableList} of shards
|
* @return a {@link ImmutableList} of shards
|
||||||
*/
|
*/
|
||||||
public ImmutableList<ShardRouting> getActiveShards() {
|
public ImmutableList<ShardRouting> getActiveShards() {
|
||||||
|
@ -204,6 +210,7 @@ public class IndexShardRoutingTable implements Iterable<ShardRouting> {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a {@link ImmutableList} of assigned shards
|
* Returns a {@link ImmutableList} of assigned shards
|
||||||
|
*
|
||||||
* @return a {@link ImmutableList} of shards
|
* @return a {@link ImmutableList} of shards
|
||||||
*/
|
*/
|
||||||
public ImmutableList<ShardRouting> assignedShards() {
|
public ImmutableList<ShardRouting> assignedShards() {
|
||||||
|
@ -212,6 +219,7 @@ public class IndexShardRoutingTable implements Iterable<ShardRouting> {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a {@link ImmutableList} of assigned shards
|
* Returns a {@link ImmutableList} of assigned shards
|
||||||
|
*
|
||||||
* @return a {@link ImmutableList} of shards
|
* @return a {@link ImmutableList} of shards
|
||||||
*/
|
*/
|
||||||
public ImmutableList<ShardRouting> getAssignedShards() {
|
public ImmutableList<ShardRouting> getAssignedShards() {
|
||||||
|
@ -220,6 +228,7 @@ public class IndexShardRoutingTable implements Iterable<ShardRouting> {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the number of shards in a specific state
|
* Returns the number of shards in a specific state
|
||||||
|
*
|
||||||
* @param state state of the shards to count
|
* @param state state of the shards to count
|
||||||
* @return number of shards in <code>state</code>
|
* @return number of shards in <code>state</code>
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Reference in New Issue