2010年4月6日!值得纪念的一天,100000!!!

来源:互联网 发布:正义的伙伴 知乎 编辑:程序博客网 时间:2024/04/29 11:56

今天终于来临了,今天可算到来了,今天已经实现了!三年的辛苦与汗水,无数的欢歌与笑语.2010年4月6日,是我值得纪念的一天,因为今天我突破100000行代码了,我等了好久了,2010年最初磕磕碰碰的我,现在有回到从前了,并且更加自信!2010年目标320000行代码,李开复说过微软应聘大学生要求100000行代码,我基本满足了,我用我自己编的代码统计小工具测得我的代码量。100%正确率,因为它用到了正则表达式,文件等一些概念,要说出错,那只有电脑出错的那亿万分之一得几率了。现在有汇编语言写过的100多行程序,C语言写过的3000行左右程序,C++写过的20000行左右的程序,Java写过的60000行左右的程序,还有现在的HTML,JSP,JavaScript, J2ME, Android写过的10000行左右的程序,再加上数据结构,编译原理,VC++等10000行左右的程序。总数>100000行,代码数已经是六位数了,但我知道今天只是个开始,今天只是个起步,总有那么一天我会自豪的说,我写过的程序就像冬天的雪花那样,让人眼红缭乱,让人数不胜数。

import java.util.regex.*;
import java.io.File;
import java.io.FileReader;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.BufferedReader;
import java.awt.*;
import java.awt.event.*;

public class CodeCount
{
    //定义统计空行、正常、注释的变量
 static long whitelines   = 0;
 static long normallines  = 0;
 static long commentlines = 0;
 Frame  frame = new Frame("代码统计小工具");
 FileDialog open = new FileDialog(frame, "选择需要打开的文件夹",  FileDialog.LOAD);
 Button bt = new Button("打开要统计的文件夹中的一个文件");
 TextArea ta = new TextArea(5, 30);
 //存放要统计文件夹得路径
 String str = null;
 public void init()
 {
     ta.setBackground(new Color(255, 134, 100));
     ta.setEditable(false);
    
     bt.addActionListener(new ActionListener()
     {
         public void actionPerformed(ActionEvent e)
         {
             open.setVisible(true);
             str = open.getDirectory();
             File f = new File(str);
             File[] codeFiles = f.listFiles();
          for(File child : codeFiles)
          {
           //只对后缀名为java的文件进行分析
              if(child.getName().matches(".*//.java$"))
              {
               parse(child);
              }
          }
          String ss = "空行个数: " + whitelines +                   
                            "/n正常代码行个数: " + normallines +          
                            "/n注释行个数: " + commentlines;              
                ta.setText(ss); 
            }  
     });
    
     frame.addWindowListener(new WindowAdapter()
        {
            public void windowClosing(WindowEvent we)
            {
                System.exit(0);
            }
        });
           
     frame.setBounds(20, 30, 200, 300);
  frame.add(ta, BorderLayout.EAST);
     frame.add(bt, BorderLayout.WEST);
     frame.pack();
     frame.setVisible(true);
 }
 
 public  void parse(File f)
 {
  BufferedReader br = null;
  boolean comment = false;
  try
  {
   //BuffeedReader 构造函数用的是Reader类型的,所以用FileReader
   br = new BufferedReader(new FileReader(f));
   String line = "";
   while((line = br.readLine())!=null)
   {
    line = line.trim();
    //由于readline已经把结尾的换行符给抹掉了所以求空白符的正则表达式不能以换行符结束了
    if(line.matches("^[//s&&[^//n]]*$")) 
    {
        whitelines++;
    }
    else if(line.startsWith("/*") && !line.endsWith("*/"))
    {
        commentlines++;
        comment = true;
    }
    else if(line.startsWith("/*") && line.endsWith("*/"))
    {
        commentlines++;
    }      
    else if(true == comment)
             {
                 commentlines++;
                 if(line.endsWith("*/") || line.startsWith("*/"))
                     comment = false;
             }
             else if(line.startsWith("//"))
             {
                 commentlines++;
             }   
             else
             {
                 normallines++;
              }
          }
      }
         catch(FileNotFoundException e)
         {
             e.printStackTrace();       
         }
         catch(IOException c)
         {
             c.printStackTrace();
         }
         finally
         {
             if(br != null)
             {
             try
             {
                 br.close();
                 br = null;
             }
             catch(IOException e)
             {
                 e.printStackTrace();
             }
            }
     
        }
    
 }
 
 public static void main(String[] args)
 {
     CodeCount cc = new CodeCount();
     cc.init();    
    }
}
      
  
          
       
    
  
     

我,安树峰,对自己的前途负责,写下今天的收获,告诉世界我在进步!The road ahead will be long. However, I want to go  ahead. Today I have to make a choice. I must forget somthing and I need to follow my heart!

:2010年我命运的转折点儿。

 

原创粉丝点击