@SuppressWarnings("ReferenceEquality")
  public RegionLocations mergeLocations(RegionLocations other) {
    assert other != null;

    HRegionLocation[] newLocations = null;

    // Use the length from other, since it is coming from meta. Otherwise,
    // in case of region replication going down, we might have a leak here.
    int max = other.locations.length;

    RegionInfo regionInfo = null;
    for (int i = 0; i < max; i++) {
      HRegionLocation thisLoc = this.getRegionLocation(i);
      HRegionLocation otherLoc = other.getRegionLocation(i);
      if (regionInfo == null && otherLoc != null && otherLoc.getRegion() != null) {
        // regionInfo is the first non-null HRI from other RegionLocations. We use it to ensure that
        // all replica region infos belong to the same region with same region id.
        regionInfo = otherLoc.getRegion();
      }

      HRegionLocation selectedLoc = selectRegionLocation(thisLoc, otherLoc, true, false);

      if (selectedLoc != thisLoc) {
        if (newLocations == null) {
          newLocations = new HRegionLocation[max];
          System.arraycopy(locations, 0, newLocations, 0, i);
        }
      }
      if (newLocations != null) {
        newLocations[i] = selectedLoc;
      }
    }

    // ensure that all replicas share the same start code. Otherwise delete them
    if (newLocations != null && regionInfo != null) {
      for (int i = 0; i < newLocations.length; i++) {
        if (newLocations[i] != null) {
          if (!RegionReplicaUtil.isReplicasForSameRegion(regionInfo, newLocations[i].getRegion())) {
            newLocations[i] = null;
          }
        }
      }
    }

    return newLocations == null ? this : new RegionLocations(newLocations);
  }
Merges this RegionLocations list with the given list assuming same range, and keeping the most
up to date version of the HRegionLocation entries from either list according to seqNum. If
seqNums are equal, the location from the argument (other) is taken.
@param other the locations to merge with
@return an RegionLocations object with merged locations or the same object if nothing is merged
hbase-client/src/main/java/org/apache/hadoop/hbase/RegionLocations.java