@Override
        public boolean hasNext() {
            if (next != null) return true;
            while (true) {
                if (offset >= replicas.length) {
                    if (!iterator.hasNext()) return false;
                    offset = 0;
                    Entry<Uuid, int[]> entry = iterator.next();
                    uuid = entry.getKey();
                    replicas = entry.getValue();
                }
                int replica = replicas[offset++];
                if ((!leaderOnly) || (replica & LEADER_FLAG) != 0) {
                    next = new TopicIdPartition(uuid, replica & REPLICA_MASK);
                    return true;
                }
            }
        }
Associates brokers with their in-sync partitions.

This is useful when we need to remove a broker from all the ISRs, or move all leaders
away from a broker.

We also track all the partitions that currently have no leader.

The core data structure is a map from broker IDs to topic maps.  Each topic map relates
topic UUIDs to arrays of partition IDs.

Each entry in the array has a high bit which indicates that the broker is the leader
for the given partition, as well as 31 low bits which contain the partition id.  This
works because partition IDs cannot be negative.
metadata/src/main/java/org/apache/kafka/controller/BrokersToIsrs.java