Write Java Script Statistics total number of project code

Source: Internet
Author: User

In the new company for nearly a year, has been alone in charge of the service-side cluster operation and code writing. From one project to seven or eight project. Looking at more and more code, today suddenly want to count how much code written altogether. "Here we only count the code that was written entirely by itself, because the project is based on Springboot, so just count the number of lines in the SRC directory for all the files"

First, write a few tool classes.

Folderfind.java

import java.io.file;import java.util.arraylist;import java.util.list;/** * created  by  xiaolong  on 2016-08-05. *  Email: [Email protected] */public class  folderfind {    //lists other items in the project file, using the match parameter to filter the project name     public  static list<string> listfolder (String path,string match) {         file file = new file (PATH);         List<String> re = new ArrayList<String> ();         if (File.isdirectory ()) {             string[] list = file.list ();             if (list!=null) {                 for (StrIng item:list) {                     if  (Item.contains (match)) {                         re.add (path+ Item);                     }                 }            }         }        return re;    }     //lists all the files in a directory.     public static list<string> listfile (String path) {         file file = new file (path);         list<string> re = new arraylist< String> ();         if (File.isdirectory ()) {             file filelist[] = file.listfiles ();             if (filelist!=null) {                 for (file item:filelist) {                     if (Item.isdirectory ()) {                         list<string> temp = listfile (Item.getPath ());                          re.addall (temp);                     }else{                         re.add ( Item.getpath ());                     }                 }            }         }        return re;     }}

Countline.java

import java.io.file;import java.io.filereader;import java.io.linenumberreader;/** *  created by  xiaolong  on 2016-08-05. *  Email:[email protected] */public  Class countline {    public static int countfilelinenum (String  path) {        file file = new file (path);         if (File.isfile ()) {             try{                 filereader in = new filereader (PATH);                 linenumberreader reader =  new linenumberreader (in);                 //int nUm = reader.getlinenumber ();                 String strLine = null;                 int num = 0;                 while  (strline =  Reader.readline ())  != null)  {                     num++;                 }                 reader.close ();                 in.close ();                 return num;            }catch  ( Exception e) {                 e.printstacktrace ();            }         }        return 0;     }}

The file where the main function is located: Tongji.java

import java.util.arraylist;import java.util.hashmap;import java.util.list;import  java.util.map;/** * created by  xiaolong  on 2016-08-05. *  Email:[email  Protected] */public class tongji {    public static void  main (String[] args)  {        List<String>  Filelist = folderfind.listfolder (".. /"," Yoko ");         map<string,integer> re = new  HashMap<String, Integer> ();        int all=0;         for (string item:filelist) {             List<String> files = new ArrayList< String> ();             if (item.contains("Yoko-config")  | |  item.contains ("Config-data")) {                 files = folderfind.listfile (item+ "\");             }else{                 files = folderfind.listfile (item+ "\\src\\");             }             int num=0;            for (String  item2:files) {//                 system.out.println (ITEM2);                 num = num + countline.countfilelinenum (ITEM2);    & nbsp;        }             all = all + num;             re.put (Item,num);             SYSTEM.OUT.PRINTLN ("Project" "+item+" "# #" +num+ "line");        }   &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;SYSTEM.OUT.PRINTLN ("Total number of rows:" +all);     }}

After running, the script counted my Itellij project directory, carrying the "Yoko" string to the project, running the result as shown:

A year or so of time, unexpectedly wrote more than 2 million lines. I was shocked by myself ... All day especially tired, although wrote a lot of code, but slowly I realized, from the novice to proficiency, more important is the quality of the code and algorithmic breakthroughs. The basic work will be pushed out in the future, freeing up more time to read more and study the theoretical stuff. You can't write the same code all the time.

Original address: Write Java Script Statistics Engineering code total number of rows Similar articles:
    • Spring+hibernate WARNING: Recognized obsolete hibernate namespace solution
    • "Teach her to write code" blog home page writing
    • "Teach her to write code" Springboot's first Hello World program
    • "Teach her to write code." Use Git on your Mac to collaborate
    • "Teach her to write code" blog Architecture Design
    • "Teach her to write code" Springboot+jquery+ajax implement data paging, dynamic loading.
    • "Teach her to write code" springboot+jquery Development Blog Management Backstage (2)

Write Java Script Statistics total number of project code

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.