ArrayList<MXRecord> list = new ArrayList<MXRecord>(records.length);
for (int i=0;i<records.length;i++) {
if ( records[i] instanceof ARecord ) {
ARecord rec = (ARecord) records[i];
MXRecord mx = new MXRecord(
rec.getName(),
rec.getDClass(),
rec.getTTL(),
100,
rec.getName()
);
list.add(mx);
} else {
list.add((MXRecord)records[i]);
}
}
Collections.sort(list, new MXPriorityComparator());
String answers[] = new String[list.size()];
for (int i = 0; i < list.size(); i++) {
MXRecord mx = list.get(i);
answers[i] = mx.getTarget().toString();
// System.out.println("host="+mx.getTarget()+" priority="+mx.getPriority());
}
return new MXLookupResult(answers);
} catch (TextParseException e) {
throw new MXResolverException("Can only get this if you used the wrong constants in your code.");