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
}
        assert invariant();
    }
    void remove(ShardRouting shard) {
        ShardRouting previousValue = shards.remove(shard.shardId());
        assert previousValue == shard : "expected shard " + previousValue + " but was " + shard;
        if (shard.initializing()) {
            boolean exist = initializingShards.remove(shard);
            assert exist : "expected shard " + shard + " to exist in initializingShards";
        } else if (shard.relocating()) {
            boolean exist = relocatingShards.remove(shard);
            assert exist : "expected shard " + shard + " to exist in relocatingShards";
        } else if (shard.started()) {
            boolean exist = startedShards.remove(shard);
            assert exist : "expected shard " + shard + " to exist in startedShards";
        }
        final Set<ShardRouting> byIndex = shardsByIndex.get(shard.index());
        byIndex.remove(shard);
        if (byIndex.isEmpty()) {
            shardsByIndex.remove(shard.index());
        }
        assert invariant();
    }
    /**
     * Determine the number of shards with a specific state
     * @param states set of states which should be counted
     * @return number of shards
     */
    public int numberOfShardsWithState(ShardRoutingState... states) {
        if (states.length == 1) {