PSP2.1 |
Personal Software Process Stages |
Estimated time consuming (minutes) |
The actual time-consuming (minutes) |
Planning |
plan |
|
|
· Estimate |
• Estimate how much time this task requires |
|
|
Development |
Develop |
|
|
· Analysis |
· Needs analysis (including learning new technologies) |
|
|
· Design Spec |
Generate design documents |
|
|
· Design Review |
· Design Review (and his colleagues reviewed the design documents) |
|
|
· Coding Standard |
· Code specifications (development of appropriate norms for the current development) |
|
|
· Design |
· Specific design |
|
|
· Coding |
· Specific coding |
|
|
· Code Review |
· Code Review |
|
|
· Test |
· Test (self-test, modify the code, submit modifications) |
|
|
Reporting |
report |
|
|
· Test Report |
· testing report |
|
|
· Size Measurement |
· Computing workload |
|
|
· Postmortem & Process Improvement Plan |
· Hindsight, and propose process improvement plan |
|
|
total |
|
1895 |
|
1.1 WC project requirements
Blank line:
Line:
Comment lines:
public enum CountImpl implements Count { OP_C{ @Override public int op(byte[] fileByte) { if(fileByte==null) return 0; //文件为空 String fileStr = new String(fileByte); String pattern = "\\S"; return FileUtil.searchStr(pattern, fileStr); } }, OP_W{ @Override public int op(byte[] fileByte){ if(fileByte==null) return 0; String fileStr = new String(fileByte); String REGEX = "[a-zA-Z]+\\W"; return FileUtil.searchStr(REGEX, fileStr); } }, OP_L{ @Override public int op(byte[] fileByte){ if(fileByte==null) return 0; String REGEX = "\\n"; FileStr String= New new String (fileByte); return FileUtil.searchStr (REGEX, fileStr) + 1'd; // last line usually without the transport } }; }
/ ** * batch processing document * @param processing mode selected submodel * @param filePath file absolute path * @throws IOException file does not exist * / public static void batchProCount (submodel String, String filePath) throws IOException { File File = new new File (filePath); int NUM = 0 ; IF (file.isFile ()) { // if the file byte [] = fileByte FileUtil.fileToByte (filePath); NUM = CountImpl.valueOf (submodel) .OP (fileByte); / / which function is used depending on the mode of automatically distinguish System.out.println ( "File Path:" + file.getAbsolutePath ()); System.out.println ( "Calculation Results:" NUM + + "\ n-" ); } the else IF (file.isDirectory ()) { // If the directory file [] = the fileList File.listFiles (); IF (the fileList == null ) { // If there is no file in the directory System.out.println ( "file does not exist" ); return ; } for ( value File: the fileList) { batchProCount (submodel, value.getAbsolutePath ()); // recursive process } } } / ** * calculated number of lines of code file, comment number of rows, the number of blank lines * @param filePath file path * @return num [0] is the number of lines of code [1] is the number of comment lines num, num [2] is number of blank lines * @throws IOException file does not exist * / public static int [] Procount (String filePath) throws IOException { int [] NUM = new new int [. 3 ]; file file = new new file (filePath); IF (! file. eXISTS ()) { System.out.println ( "file does not exist" ); return NUM; // file exists } BufferedReader bufferedReader = new BufferedReader(new FileReader(file)); int codeLineNum=0; int noteLineNum=0; int blankLineNum=0; String fileLine; while ((fileLine=bufferedReader.readLine())!=null){ fileLine = fileLine.trim(); //计算注释行 if(fileLine.startsWith("/") || fileLine.startsWith("*")){ noteLineNum++; } //计算空行 else if(fileLine.trim().isEmpty() || fileLine.trim().length()==1){ blankLineNum++; } //计算代码行 else { codeLineNum++; } } bufferedReader.close(); num[0] = codeLineNum; num[1] = noteLineNum; num[2] = blankLineNum; return num; }
@FXML public void open(ActionEvent actionEvent) throws IOException { File file = OpenUtil.chooseFile(); long start = System.currentTimeMillis(); if(file==null){ warn.setText("你没有打开任何文件噢~"); return; }else{ path.setText(file.getAbsolutePath()); int[] num; num = WordCount.wc("-c", file.getAbsolutePath()); charNum.setText(String.valueOf(num[0])); num = WordCount.wc("-w", file.getAbsolutePath()); wordNum.setText(String.valueOf(num[0])); num = WordCount.wc("-l", file.getAbsolutePath()); lineNum.setText(String.valueOf(num[0])); num = ProWordCount.proCount(file.getAbsolutePath()); codeNum.setText(String.valueOf(num[0])); noteNum.setText(String.valueOf(num[1])); blankNum.setText(String.valueOf(num[2])); } long runTime = TimeUtil.getRunTime(start); runtime.setText(runTime +"ms"); }
package com.demo; import java.io.*; import java.util.Scanner; import java.util.regex.Matcher; import java.util.regex.Pattern; public class WordCounter { public static void main(String[] args) throws IOException { /* Scanner scan = new Scanner(System.in); String model = ""; String filePath = ""; WordCounter.wc(model, filePath); */ System.out.println(wc("-l", "C:\\Users\\15191\\Desktop\\imageTest\\testBrunch\\test\\C_language_Class2_1_utf8.txt")); }