HostNameStartupAddressChecker.java
package com.ziesemer.utils.web.addressFilter.conditions;
import java.net.InetAddress;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* @author Mark A. Ziesemer
* <a href="http://www.ziesemer.com."><www.ziesemer.com></a>
*/
public class HostNameStartupAddressChecker implements IAddressChecker{
protected static final Logger LOGGER = LoggerFactory.getLogger(HostNameStartupAddressChecker.class);
protected final Set<InetAddress> addresses;
public HostNameStartupAddressChecker(final String hostName) throws Exception{
addresses = new HashSet<InetAddress>();
for(final InetAddress address : InetAddress.getAllByName(hostName)){
addresses.add(address);
}
}
public boolean matches(final InetAddress ip, final String hostName) throws Exception{
return addresses.contains(ip);
}
/**
* <p>
* Returns a read-only view of the addresses checked against, primarily for unit testing.
* </p>
*/
public Set<InetAddress> getAddresses(){
return Collections.unmodifiableSet(addresses);
}
}