private boolean isParentOf()

in dataenum-processor/src/main/java/com/spotify/dataenum/processor/AccessSelector.java [95:109]


  private boolean isParentOf(String maybeParentPackage, String packageName) {
    // check the easy case first
    if (!packageName.startsWith(maybeParentPackage)) {
      return false;
    }

    // even if they start with the same string, there might be a mismatch in the last package name
    // in the possible parent. For instance, "com.spot" is not a parent package of "com.spotify".
    String[] parentParts = maybeParentPackage.split("\\.");
    String[] packageParts = packageName.split("\\.");

    String lastParentPackagePart = parentParts[parentParts.length - 1];

    return packageParts[parentParts.length - 1].equals(lastParentPackagePart);
  }