-
Notifications
You must be signed in to change notification settings - Fork 0
/
P3A2_Yellajosyula_ryellajo.java
123 lines (86 loc) · 3.67 KB
/
P3A2_Yellajosyula_ryellajo.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
import java.io.*;
import java.util.*;
import java.text.DateFormatSymbols;
import com.opencsv.CSVWriter;
/**
Author's Name: Rajya Laxmi Yellajosyula
Creation day: July 31st 2017
Last modification day: August 4th 2017
This program processes the log file emacs.log,
fetches the name of every file changed,Number of commits made to it,
First date of commit and Last date of commit.
All the results are stored in Details.csv of the current execution folder.
*/
public class P3A2_Yellajosyula_ryellajo
{
public static void main(String[] args) throws FileNotFoundException,IOException
{ String csv = "Details.csv";
CSVWriter writer = new CSVWriter(new FileWriter(csv));
//Creates header record
String [] record = "File,Number of Commits,First Date of commit,Last Date of commit".split(",");
//Write the record to file
writer.writeNext(record);
//Fetching fileName from user using Activity1 public static function
String fileName = P3A1_Yellajosyula_ryellajo.getFileName();
P3A1_Yellajosyula_ryellajo x = new P3A1_Yellajosyula_ryellajo(fileName);
Map<String,Date> result2,result3;
Map<String,Integer> result4;
try{
result2 = x.earliestCommits();
result3 = x.LastCommits();
result4 = getTotalCommits(fileName);
//List that stores the final results
List<String[]> details = new ArrayList<String[]>();
for(Map.Entry<String,Date> m1:result2.entrySet())
{
for(Map.Entry<String,Date> m2:result3.entrySet())
{
if(m1.getKey().equals(m2.getKey()))
{
for(Map.Entry<String,Integer> m3:result4.entrySet())
{
if(m1.getKey().equals(m3.getKey()))
{
String[] temp ={m1.getKey(),m3.getValue().toString(),m1.getValue().toString(),m2.getValue().toString()};
details.add(temp);
}
}
}
}
}
//Writes all the records to CSV
writer.writeAll(details);
//close the writer
writer.close();
}
catch(Exception e){
System.out.println(e.getMessage()+"Exception caused while parsing the field");
}
System.out.println("File creation Successful.Look for Details.csv for Results.");
}
//Method that finds number of commits made to each file and return as HashMap of filename and number of commits
public static Map<String,Integer> getTotalCommits(String fileName) throws FileNotFoundException,IOException
{
Map<String,Integer> fileContents = new HashMap<>();
BufferedReader br = new BufferedReader(new FileReader(fileName));
String line,file = new String();
int commit = 0,users =0;
String maxFile = new String();
int userMax =0;
while ((line = br.readLine()) != null)
{
if(line.contains("RCS file:"))
{
//Fetches filenames
String lines[] = line.split(":");
file = lines[1];
commit = 0;
}
//Counting the commits
if(line.contains("author:"))
commit++;
fileContents.put(file,commit);
}
return fileContents;
}
}