During the development and review process of the disk health indicator we noticed that it was hard to understand. Since we learnt a lot from the first round of development we want to go through the code one more time and restructure it.
server/src/main/java/org/elasticsearch/cluster/routing/RoutingNode.java
if (states[0] == ShardRoutingState.INITIALIZING) {
                return initializingShards.size();
            } else if (states[0] == ShardRoutingState.RELOCATING) {
                return relocatingShards.size();
            } else if (states[0] == ShardRoutingState.STARTED) {
                return startedShards.size();
            }
        }
        int count = 0;
        for (ShardRouting shardEntry : this) {
            for (ShardRoutingState state : states) {
                if (shardEntry.state() == state) {
                    count++;
                }
            }
        }
        return count;
    }
    /**
     * Determine the shards with a specific state
     * @param state state which should be listed
     * @return List of shards
     */
    public List<ShardRouting> shardsWithState(ShardRoutingState state) {
        if (state == ShardRoutingState.INITIALIZING) {
            return new ArrayList<>(initializingShards);
        } else if (state == ShardRoutingState.RELOCATING) {
            return new ArrayList<>(relocatingShards);
        } else if (state == ShardRoutingState.STARTED) {
            return new ArrayList<>(startedShards);