Re: using TreeMap how to return the Object ?
On 06/27/2013 11:19 AM, Jeff Higgins wrote:
On 06/27/2013 01:30 AM, moonhkt wrote:
Hi All
public class HostsTest {
private final Hosts hosts;
{ hosts = new Hosts(); }
public static void main(String[] args) {
HostsTest test = new HostsTest();
test.fillHosts("\\etc\\hosts");
}
public boolean fillHosts(String filename) {
/*
* TODO
*/
return false;
}
public Host getHost(IPAddress address) {
/*
* TODO
*/
return null;
}
}
public class IPAddress implements Comparable<IPAddress> {
/*
* IPV4 addresses are 32 bit values
* IPV6 addresses are 128 bit values
* (non-Javadoc)
* @see java.lang.Comparable#compareTo(java.lang.Object)
*/
// some private final field to hold your address value.
// some constructor(s)
@Override
public int compareTo(IPAddress address) {
// TODO Auto-generated method stub
return 0;
}
@Override
public int hashCode() {
// TODO Auto-generated method stub
return super.hashCode();
}
@Override
public boolean equals(Object obj) {
// TODO Auto-generated method stub
return super.equals(obj);
}
@Override
public String toString() {
// TODO Auto-generated method stub
return super.toString();
}
}
import java.util.ArrayList;
import java.util.List;
public class Host {
private final String hostName;
private final List<String> aliases;
{ aliases = new ArrayList<String>(); }
public Host(String hostname) {
hostName = hostname;
}
/*
* TODO
*/
}
import java.util.Map;
import java.util.TreeMap;
public class Hosts {
private final Map<IPAddress, Host> map;
{ map = new TreeMap<IPAddress, Host>(); }
public Host getHostFromIPAddress(IPAddress address) {
/*
* TODO
*/
return null;
}
}