in locales-utils/src/main/java/com/spotify/i18n/locales/utils/hierarchy/LocalesHierarchyUtils.java [134:156]
public static boolean isDescendantLocale(final ULocale underTest, final ULocale ancestorLocale) {
Preconditions.checkNotNull(underTest);
Preconditions.checkNotNull(ancestorLocale);
// Both locales are the same
if (isSameLocale(underTest, ancestorLocale)) {
return false;
}
// We start from the underTest locale position and go up in the hierarchy
Optional<ULocale> currentOpt = getParentLocale(underTest);
while (true) {
// We have gone up all the way in the hierarchy and didn't find a match.
if (!currentOpt.isPresent()) {
return false;
}
// If the current locale is the parent one that we seek, it is a bingo.
if (isSameLocale(currentOpt.get(), ancestorLocale)) {
return true;
}
currentOpt = getParentLocale(currentOpt.get());
}
}