@SuppressWarnings("ReferenceEquality")
  public RegionLocations updateLocation(HRegionLocation location, boolean checkForEquals,
    boolean force) {
    assert location != null;

    int replicaId = location.getRegion().getReplicaId();

    HRegionLocation oldLoc = getRegionLocation(location.getRegion().getReplicaId());
    HRegionLocation selectedLoc = selectRegionLocation(oldLoc, location, checkForEquals, force);

    if (selectedLoc == oldLoc) {
      return this;
    }
    HRegionLocation[] newLocations = new HRegionLocation[Math.max(locations.length, replicaId + 1)];
    System.arraycopy(locations, 0, newLocations, 0, locations.length);
    newLocations[replicaId] = location;
    // ensure that all replicas share the same start code. Otherwise delete them
    for (int i = 0; i < newLocations.length; i++) {
      if (newLocations[i] != null) {
        if (
          !RegionReplicaUtil.isReplicasForSameRegion(location.getRegion(),
            newLocations[i].getRegion())
        ) {
          newLocations[i] = null;
        }
      }
    }
    return new RegionLocations(newLocations);
  }
Updates the location with new only if the new location has a higher seqNum than the old one or
force is true.
@param location       the location to add or update
@param checkForEquals whether to update the location if seqNums for the HRegionLocations for
                      the old and new location are the same
@param force          whether to force update
@return an RegionLocations object with updated locations or the same object if nothing is
        updated
hbase-client/src/main/java/org/apache/hadoop/hbase/RegionLocations.java