日期:2014-05-20 浏览次数:20695 次
HashMap<String, Server> hostname2server = new HashMap<String, Server>();
HashMap<Integer, Server> id2server = new HashMap<Integer, Server>();
HashMap<String, Server> ip2server = new HashMap<String, Server>();
//没看出来多么麻烦
public class MapTest {
public static class Server{
private int id;
private String ip;
private String name;
}
public static class ServerFactory{
private ServerFactory(){}
private static List<Server> servers = new ArrayList<Server>();
public static Server getById(int id){
return null;
}
public static Server getByName(String name){
return null;
}
public static Server getByIp(String ip){
return null;
}
}
public static void main(String[] args) {
Server server = ServerFactory.getById(1);
}
}