Counting clicks

Report a typo

There is a LogEntry class for monitoring user activity on your site. The class has three fields:

  • created: Date is the date of creating log entry;
  • login: String is a user login;
  • url: String is a url that the user clicked.

and getter for url field: getUrl().

Write a collector that calculates how many times each url was clicked by users. The collector will be applied to a stream of log entries for creating a map: url -> click count.

Write a program in Java 17
import java.util.*;

class Monitor {

public static Map<String, Long> getUrlToNumberOfVisited(List<LogEntry> logs) {
return logs.stream()
.collect(
// Write a collector here
);
}

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;
}
___

Create a free account to access the full topic