private void initialize() {
        if (shards == null || algorithm == null) {
            shardedNodes = null;
            return;
        }

        Set<String> nodesId = new HashSet<String>(shards.size());
        for (Shard node : shards) {
            if(node.getShardId() == null) {
                throw new RedisException("Sharded node must have unique shard id and must not be null");
            }
            nodesId.add(node.getShardId());
        }

        if(shards.size() != nodesId.size()) {
            throw new RedisException("Sharded node must have unique shard id");
        }

        nodes = new ArrayList<T>(shards.size());
        for (Shard<T> shard : shards) {
            nodes.add(shard.getNode());
        }

        shardedNodes = new TreeMap<Long, Shard<T>>();

        for (Shard<T> node : shards) {
            for (int n = 0; n < 160 * node.getWeight(); n++) {
                this.shardedNodes.put(this.algorithm.hash(node.getShardId() + n), node);
            }
        }
    }