001/* 002 * Copyright 2015-2024 the original author or authors 003 * 004 * This software is licensed under the Apache License, Version 2.0, 005 * the GNU Lesser General Public License version 2 or later ("LGPL") 006 * and the WTFPL. 007 * You may choose either license to govern your use of this software only 008 * upon the condition that you accept all of the terms of either 009 * the Apache License 2.0, the LGPL 2.1+ or the WTFPL. 010 */ 011 package org.minidns.dnsserverlookup; 012 013import java.net.InetAddress; 014import java.util.ArrayList; 015import java.util.Collection; 016import java.util.List; 017import java.util.logging.Logger; 018 019public abstract class AbstractDnsServerLookupMechanism implements DnsServerLookupMechanism { 020 021 protected static final Logger LOGGER = Logger.getLogger(AbstractDnsServerLookupMechanism.class.getName()); 022 023 private final String name; 024 private final int priority; 025 026 protected AbstractDnsServerLookupMechanism(String name, int priority) { 027 this.name = name; 028 this.priority = priority; 029 } 030 031 @Override 032 public final String getName() { 033 return name; 034 } 035 036 @Override 037 public final int getPriority() { 038 return priority; 039 } 040 041 @Override 042 public final int compareTo(DnsServerLookupMechanism other) { 043 int myPriority = getPriority(); 044 int otherPriority = other.getPriority(); 045 046 return Integer.compare(myPriority, otherPriority); 047 } 048 049 @Override 050 public abstract List<String> getDnsServerAddresses(); 051 052 protected static List<String> toListOfStrings(Collection<? extends InetAddress> inetAddresses) { 053 List<String> result = new ArrayList<>(inetAddresses.size()); 054 for (InetAddress inetAddress : inetAddresses) { 055 String address = inetAddress.getHostAddress(); 056 result.add(address); 057 } 058 return result; 059 } 060}