Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.BufferedReader;
- import java.io.IOException;
- import java.io.InputStreamReader;
- import java.util.ArrayList;
- import java.util.Map;
- import java.util.TreeMap;
- import java.util.regex.Matcher;
- import java.util.regex.Pattern;
- public class p08_Commits {
- public static void main(String[] args) throws IOException {
- BufferedReader scanner = new BufferedReader(new InputStreamReader(System.in));
- String inputLine = scanner.readLine();
- Map<String, Map<String, ArrayList<Commit>>> gitUsers = new TreeMap<>();
- Pattern pattern = Pattern.compile("^https://github\\.com/(?<user>[A-Za-z0-9\\-]+)/" +
- "(?<repo>[a-zA-Z\\-_]+)/commit/" +
- "(?<hash>[0-9a-f]{40})," +
- "(?<message>[^\\n]*)," +
- "(?<additions>\\d*)," +
- "(?<deletions>\\d*)$");
- while (!"git push".equals(inputLine)) {
- Matcher matcher = pattern.matcher(inputLine);
- if (matcher.find()) {
- String username = matcher.group("user");
- String repo = matcher.group("repo");
- String hash = matcher.group("hash");
- String message = matcher.group("message");
- long additions = Long.parseLong(matcher.group("additions"));
- long deletions = Long.parseLong(matcher.group("deletions"));
- Commit commit = new Commit(hash, message, additions, deletions);
- gitUsers.putIfAbsent(username, new TreeMap<>());
- gitUsers.get(username).putIfAbsent(repo, new ArrayList<>());
- gitUsers.get(username).get(repo).add(commit);
- }
- inputLine = scanner.readLine();
- }
- // Printing the data
- gitUsers.forEach((key, value) -> {
- System.out.printf("%s:%n", key);
- value.forEach((key1, value1) -> {
- System.out.printf(" %s:%n", key1);
- value1.forEach(c -> {
- System.out.printf(" commit %s: %s (%s additions, %s deletions)%n",
- c.getHash(), c.getMessage(), c.getAdditions(), c.getDeletions());
- });
- long totalAdditions = value1
- .stream()
- .mapToLong(Commit::getAdditions)
- .sum();
- long totalDeletions = value1
- .stream()
- .mapToLong(Commit::getDeletions)
- .sum();
- System.out.printf(" Total: %s additions, %s deletions%n", totalAdditions, totalDeletions);
- });
- });
- }
- }
- class Commit {
- private String hash;
- private String message;
- private long additions;
- private long deletions;
- // Creating constructor
- public Commit(String hash, String message, long additions, long deletions) {
- this.hash = hash;
- this.message = message;
- this.additions = additions;
- this.deletions = deletions;
- }
- public String getHash() {
- return this.hash;
- }
- public String getMessage() {
- return this.message;
- }
- public long getAdditions() {
- return this.additions;
- }
- public long getDeletions() {
- return this.deletions;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement