”4635“――這三個(gè)月以來(lái)的成就。
來(lái)源:程序員人生 發(fā)布時(shí)間:2014-09-08 19:25:59 閱讀次數(shù):2952次
今天晚上突發(fā)奇想,想算一下到新公司三個(gè)月以來(lái)所寫(xiě)的代碼量。上網(wǎng)找了一下沒(méi)有現(xiàn)成的解決方案。最后找了大牛同事,同事也沒(méi)做過(guò)這個(gè)事情,不過(guò)算是找到了解決方案:利用shell去查找,不過(guò)速度真心夠慢的。最后還是自己寫(xiě)了一個(gè)java代碼去計(jì)算自己的代碼量。
計(jì)算行數(shù)代碼如下:
public static long totalCount;
//rootFile是根文件夾
public void readJava(String author,File rootFile) {
File[] files = rootFile.listFiles();
for (File file : files) {
if (file.isFile() && (file.getName().endsWith("java") || file.getName().endsWith("js"))) {
try {
getCount(author, file);
} catch (IOException e) {
e.printStackTrace();
}
}
if (file.isDirectory()) {
readJava(author,file);
}
}
}
public long getCount(String author, File file) throws IOException {
boolean belongToAuthorFlag = false;
long count = 0;
FileReader fileReader = new FileReader(file);
BufferedReader reader = new BufferedReader(fileReader);
String content = "";
while ((content = reader.readLine()) != null) {
count++;
if (!belongToAuthorFlag && content.contains(author)) {
belongToAuthorFlag = true;
}
}
reader.close();
if (belongToAuthorFlag) {
totalCount += count;
System.out.println(count + "---" + file.getName());
}
return totalCount;
}
public static void main(String[] args) {
CountCodeUtil countCode = new CountCodeUtil();
String rootPath = "/home/liubin/workspace/tz";
File rootFile = new File(rootPath);
System.out.println("startTime:" + new Date());
countCode.readJava("dingguangxian",rootFile);
System.out.println("startTime:" + new Date());
System.out.println("totalCount:" + totalCount);
}
這個(gè)代碼還是有些缺點(diǎn)的,可以不用讀取整個(gè)文件的,如果讀到public class還沒(méi)有找到符合的字符串就可以換下一個(gè)文件。然后就是沒(méi)有將空換行除去和一半的花括弧‘}’去除。
不過(guò)還是將就能用的。
我自己的結(jié)果就是4635行,同事也是比較驚訝,竟然能寫(xiě)這么多。畢竟大牛同事在公司有兩年了,代碼量是2.5W行。當(dāng)然了行數(shù)不能代表什么,我的代碼質(zhì)量當(dāng)然不能和大牛比了。但這個(gè)也算是我正式工作以來(lái)的成績(jī)吧。后面還得繼續(xù)努力。提高代碼的質(zhì)量
生活不易,碼農(nóng)辛苦
如果您覺(jué)得本網(wǎng)站對(duì)您的學(xué)習(xí)有所幫助,可以手機(jī)掃描二維碼進(jìn)行捐贈(zèng)