| 1 |
/* |
| 2 |
* Copyright 2015-2020 the original author or authors |
| 3 |
* |
| 4 |
* This software is licensed under the Apache License, Version 2.0, |
| 5 |
* the GNU Lesser General Public License version 2 or later ("LGPL") |
| 6 |
* and the WTFPL. |
| 7 |
* You may choose either license to govern your use of this software only |
| 8 |
* upon the condition that you accept all of the terms of either |
| 9 |
* the Apache License 2.0, the LGPL 2.1+ or the WTFPL. |
| 10 |
*/ |
| 11 |
package org.minidns.dnsserverlookup; |
| 12 |
|
| 13 |
import java.net.InetAddress; |
| 14 |
import java.util.ArrayList; |
| 15 |
import java.util.Collection; |
| 16 |
import java.util.List; |
| 17 |
import java.util.logging.Logger; |
| 18 |
|
| 19 |
public abstract class AbstractDnsServerLookupMechanism implements DnsServerLookupMechanism { |
| 20 |
|
| 21 |
protected static final Logger LOGGER = Logger.getLogger(AbstractDnsServerLookupMechanism.class.getName()); |
| 22 |
|
| 23 |
private final String name; |
| 24 |
private final int priority; |
| 25 |
|
| 26 |
protected AbstractDnsServerLookupMechanism(String name, int priority) { |
| 27 |
this.name = name; |
| 28 |
this.priority = priority; |
| 29 |
} |
| 30 |
|
| 31 |
@Override |
| 32 |
public final String getName() { |
| 33 |
return name; |
| 34 |
} |
| 35 |
|
| 36 |
@Override |
| 37 |
public final int getPriority() { |
| 38 |
return priority; |
| 39 |
} |
| 40 |
|
| 41 |
@Override |
| 42 |
public final int compareTo(DnsServerLookupMechanism other) { |
| 43 |
int myPriority = getPriority(); |
| 44 |
int otherPriority = other.getPriority(); |
| 45 |
|
| 46 |
return Integer.compare(myPriority, otherPriority); |
| 47 |
} |
| 48 |
|
| 49 |
@Override |
| 50 |
public abstract List<String> getDnsServerAddresses(); |
| 51 |
|
| 52 |
protected static List<String> toListOfStrings(Collection<? extends InetAddress> inetAddresses) { |
| 53 |
List<String> result = new ArrayList<>(inetAddresses.size()); |
| 54 |
for (InetAddress inetAddress : inetAddresses) { |
| 55 |
String address = inetAddress.getHostAddress(); |
| 56 |
result.add(address); |
| 57 |
} |
| 58 |
return result; |
| 59 |
} |
| 60 |
} |