In short: I have to build the iPsForDays method, which has no parameters. This method returns a HashMap> that uses records and maps days from web logs to an ArrayList of IP addresses that occurred on that day (including repeated IP addresses). For example, Sep 14 maps to one IP address, Sep 21 maps to four IP addresses, and Sep 30 maps to five IP addresses. My issue is that to every key(date) the value(ArrayList) is the same (contains the same values). How can I have different values? Here's the code:
public HashMap<String, ArrayList<String>> iPsForDays(){
HashMap<String, ArrayList<String>> mapDatesToIPs = new HashMap<String,ArrayList<String>>();
ArrayList<String> ips = new ArrayList<String>();
for(LogEntry le : records){
Date d = le.getAccessTime();
String dates = d.toString().substring(4, 10);//date is a diff format
if(!mapDatesToIPs.containsKey(dates)){
ips.add(le.getIpAddress());
mapDatesToIPs.put(dates, ips);
}
else if(mapDatesToIPs.containsKey(dates)){
String ip = le.getIpAddress();
if(!ips.contains(ip)){
ips.add(ip);
}
}
}
return mapDatesToIPs;
}