code: @Nullable public GeoTarget getCanonAncestor(GeoTarget.Type type) {
      for (GeoTarget target = this; target != null; target = target.canonParent()) {
        if (target.key.type == type) {
          return target;
        }
      }
  
      return null;
    }
docs: Finds an ancestor of a specific type, if possible.
  
  <p>Example: (New York city target, {@link Type#COUNTRY}) returns (US country target)