List<Link> matching = new ArrayList<Link>();
for (Range range : ranges) {
for (Link link : links) {
String hreflang = link.getHrefLang();
if (hreflang != null) {
Lang lang = new Lang(hreflang);
Range basic = range.toBasicRange();
Lang blang = !basic.toString().equals("*") ? new Lang(basic.toString()) : null;
if (range.matches(lang) || (blang != null && lang.isParentOf(blang)))
matching.add(link);
}
}
Collections.sort(matching, new Comparator<Link>() {
public int compare(Link o1, Link o2) {
Lang l1 = new Lang(o1.getHrefLang());
Lang l2 = new Lang(o2.getHrefLang());
return l1.compareTo(l2);
}
});
}
return matching.toArray(new Link[matching.size()]);