@Test(expected = IllegalArgumentException.class) public void testGetPublicSuffixWithNegativeAdditionalPartCountThrows() { PublicSuffix.getPublicSuffix(RuntimeEnvironment.application, "whatever-doesnt-matter", -1); }
@NonNull @WorkerThread public static String getPublicSuffix(@NonNull final Context context, @NonNull final String domain, final int additionalPartCount) { if (context == null) { throw new NullPointerException("Expected non-null Context argument"); } if (domain == null) { throw new NullPointerException("Expected non-null domain argument"); } if (additionalPartCount < 0) { throw new IllegalArgumentException("Expected additionalPartCount > 0. Got: " + additionalPartCount); } final int publicSuffixCombinedIndex = findPublicSuffixIndex(context, domain); if (publicSuffixCombinedIndex < 0) { return ""; } final String publicSuffix = domain.substring(publicSuffixCombinedIndex + 1); final int nextPartIndex = publicSuffix.indexOf('.'); final String publicSuffixFirstPart = nextPartIndex < 0 ? publicSuffix : publicSuffix.substring(0, nextPartIndex); final List<String> domainParts = normalizeAndSplit(domain); final int publicSuffixPartsIndex = domainParts.indexOf(publicSuffixFirstPart); final int returnedPartsIndex = Math.max(0, publicSuffixPartsIndex - additionalPartCount); return TextUtils.join(".", domainParts.subList(returnedPartsIndex, domainParts.size())); }
PublicSuffix { @NonNull @WorkerThread public static String getPublicSuffix(@NonNull final Context context, @NonNull final String domain, final int additionalPartCount) { if (context == null) { throw new NullPointerException("Expected non-null Context argument"); } if (domain == null) { throw new NullPointerException("Expected non-null domain argument"); } if (additionalPartCount < 0) { throw new IllegalArgumentException("Expected additionalPartCount > 0. Got: " + additionalPartCount); } final int publicSuffixCombinedIndex = findPublicSuffixIndex(context, domain); if (publicSuffixCombinedIndex < 0) { return ""; } final String publicSuffix = domain.substring(publicSuffixCombinedIndex + 1); final int nextPartIndex = publicSuffix.indexOf('.'); final String publicSuffixFirstPart = nextPartIndex < 0 ? publicSuffix : publicSuffix.substring(0, nextPartIndex); final List<String> domainParts = normalizeAndSplit(domain); final int publicSuffixPartsIndex = domainParts.indexOf(publicSuffixFirstPart); final int returnedPartsIndex = Math.max(0, publicSuffixPartsIndex - additionalPartCount); return TextUtils.join(".", domainParts.subList(returnedPartsIndex, domainParts.size())); } }
PublicSuffix { @NonNull @WorkerThread public static String getPublicSuffix(@NonNull final Context context, @NonNull final String domain, final int additionalPartCount) { if (context == null) { throw new NullPointerException("Expected non-null Context argument"); } if (domain == null) { throw new NullPointerException("Expected non-null domain argument"); } if (additionalPartCount < 0) { throw new IllegalArgumentException("Expected additionalPartCount > 0. Got: " + additionalPartCount); } final int publicSuffixCombinedIndex = findPublicSuffixIndex(context, domain); if (publicSuffixCombinedIndex < 0) { return ""; } final String publicSuffix = domain.substring(publicSuffixCombinedIndex + 1); final int nextPartIndex = publicSuffix.indexOf('.'); final String publicSuffixFirstPart = nextPartIndex < 0 ? publicSuffix : publicSuffix.substring(0, nextPartIndex); final List<String> domainParts = normalizeAndSplit(domain); final int publicSuffixPartsIndex = domainParts.indexOf(publicSuffixFirstPart); final int returnedPartsIndex = Math.max(0, publicSuffixPartsIndex - additionalPartCount); return TextUtils.join(".", domainParts.subList(returnedPartsIndex, domainParts.size())); }  }
PublicSuffix { @NonNull @WorkerThread public static String getPublicSuffix(@NonNull final Context context, @NonNull final String domain, final int additionalPartCount) { if (context == null) { throw new NullPointerException("Expected non-null Context argument"); } if (domain == null) { throw new NullPointerException("Expected non-null domain argument"); } if (additionalPartCount < 0) { throw new IllegalArgumentException("Expected additionalPartCount > 0. Got: " + additionalPartCount); } final int publicSuffixCombinedIndex = findPublicSuffixIndex(context, domain); if (publicSuffixCombinedIndex < 0) { return ""; } final String publicSuffix = domain.substring(publicSuffixCombinedIndex + 1); final int nextPartIndex = publicSuffix.indexOf('.'); final String publicSuffixFirstPart = nextPartIndex < 0 ? publicSuffix : publicSuffix.substring(0, nextPartIndex); final List<String> domainParts = normalizeAndSplit(domain); final int publicSuffixPartsIndex = domainParts.indexOf(publicSuffixFirstPart); final int returnedPartsIndex = Math.max(0, publicSuffixPartsIndex - additionalPartCount); return TextUtils.join(".", domainParts.subList(returnedPartsIndex, domainParts.size())); }  static void init(Context context); @NonNull @WorkerThread // This method might need to load data from disk static String stripPublicSuffix(Context context, @NonNull String domain); @NonNull @WorkerThread // This method might need to load data from disk static String getPublicSuffix(@NonNull final Context context, @NonNull final String domain, final int additionalPartCount); }
PublicSuffix { @NonNull @WorkerThread public static String getPublicSuffix(@NonNull final Context context, @NonNull final String domain, final int additionalPartCount) { if (context == null) { throw new NullPointerException("Expected non-null Context argument"); } if (domain == null) { throw new NullPointerException("Expected non-null domain argument"); } if (additionalPartCount < 0) { throw new IllegalArgumentException("Expected additionalPartCount > 0. Got: " + additionalPartCount); } final int publicSuffixCombinedIndex = findPublicSuffixIndex(context, domain); if (publicSuffixCombinedIndex < 0) { return ""; } final String publicSuffix = domain.substring(publicSuffixCombinedIndex + 1); final int nextPartIndex = publicSuffix.indexOf('.'); final String publicSuffixFirstPart = nextPartIndex < 0 ? publicSuffix : publicSuffix.substring(0, nextPartIndex); final List<String> domainParts = normalizeAndSplit(domain); final int publicSuffixPartsIndex = domainParts.indexOf(publicSuffixFirstPart); final int returnedPartsIndex = Math.max(0, publicSuffixPartsIndex - additionalPartCount); return TextUtils.join(".", domainParts.subList(returnedPartsIndex, domainParts.size())); }  static void init(Context context); @NonNull @WorkerThread // This method might need to load data from disk static String stripPublicSuffix(Context context, @NonNull String domain); @NonNull @WorkerThread // This method might need to load data from disk static String getPublicSuffix(@NonNull final Context context, @NonNull final String domain, final int additionalPartCount);  }