Created
December 13, 2020 22:29
-
-
Save LeoPFreitas/a354d5c0c7c0b55468ea3969e0bc9b9b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.*; | |
import java.util.stream.Collectors; | |
class Monitor { | |
public static Map<String, Long> getUrlToNumberOfVisited(List<LogEntry> logs) { | |
return logs.stream() | |
.collect(Collectors.groupingBy(LogEntry::getUrl, Collectors.summingLong(a -> 1L))); | |
} | |
static class LogEntry { | |
private Date created; | |
private String login; | |
private String url; | |
public LogEntry(Date created, String login, String url) { | |
this.created = created; | |
this.login = login; | |
this.url = url; | |
} | |
public String getUrl() { | |
return url; | |
} | |
public void setUrl(String url) { | |
this.url = url; | |
} | |
@Override | |
public boolean equals(Object o) { | |
if (this == o) { | |
return true; | |
} | |
if (!(o instanceof LogEntry)) { | |
return false; | |
} | |
LogEntry logEntry = (LogEntry) o; | |
if (!login.equals(logEntry.login)) { | |
return false; | |
} | |
return url.equals(logEntry.url); | |
} | |
@Override | |
public int hashCode() { | |
int result = login.hashCode(); | |
result = 31 * result + url.hashCode(); | |
return result; | |
} | |
@Override | |
public String toString() { | |
return "LogEntry{" + | |
", created=" + created + | |
", login='" + login + '\'' + | |
", url='" + url + '\'' + | |
'}'; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment