java文本牛逼代码 java代码怎么写

java 源代码 基础点的谢谢package com.regex;
import java.io.*;
import java.net.URLDecoder;
import java.util.regex.*;
public class Regex {
private int REMARK=0;
private int LOGIC=0;
private int PHYSIC=0;
boolean start=false;
/**
* @param args
*/
public static void main(String[] args) { //测试方法
// TODO Auto-generated method stub
Regex re=new Regex();
re.regCount("Regex.java");
System.out.println("remark Line: "+re.REMARK);
System.out.println("logic Line: "+re.LOGIC);
System.out.println("physic Line: "+re.PHYSIC);
}/**
* @author BlueDance
* @param s
* @deprecated count
*/
public void regCount(String s){
String url=null;
try {
url=URLDecoder.decode(this.getClass().getResource(s).getPath(),"UTF-8");
} catch (Exception e) {
e.printStackTrace();
// TODO: handle exception
}
try {
BufferedReader br=new BufferedReader(new FileReader(new File(url)));
String s1=null;
while((s1=br.readLine())!=null){
PHYSIC++;
if(CheckChar(s1)==1){
REMARK++;
System.out.println("纯注释行:"+s1);
}
if(CheckChar(s1)==2){
LOGIC++;
REMARK++;
System.out.println("非纯注释行:"+s1);
}
if(CheckChar(s1)==3)
LOGIC++;
}
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}catch(IOException e){
e.printStackTrace();
}
}
/**
*
* @param s
* @return int
* @version check s
*/
public int CheckChar(String s){
String s1=null;
if(s!=null)
s1=s.trim();
//System.out.println(regCheck(s1,re));
if(regCheck(s1,"(//.*)"))//判断//开头的为纯注释行
return 1;
if(regCheck(s1,"(.*[;{})] *//.*)"))//判断不是//开头的非纯注释行
return 2;
if(regCheck(s1,"(//*.*)")){//判断/*开头的纯注释行
start=true;
return 1;
}
if(regCheck(s1,"(.*[;{})]//*.*)")){//判断不是/*开头的非纯注释行
start=true;
return 2;
}
if(regCheck(s1,"(.* */*/)")){//判断*/结尾的纯注释行
start=false;
return 1;
}
if(regCheck(s1,"(.* */*/.*)")!strCheck(s1)){ //判断不是*/结尾的非纯注释行
if(strCheck(s1)){
start=false;
return 2;
}
}
if(start==true)//状态代码,start即/*开始时start=true*/结束时为false
return 1;
return 3;//ssssllll
}//aeee
/**
*
* @param s
* @param re
* @return boolean
*/
public boolean regCheck(String s,String re){//正则表达试判断方法
return Pattern.matches(re,s);
}
public boolean strCheck(String s){//中间有*/的字符判断 此方法最关键
if(s.indexOf("*/")0){
int count=0;
String y[]=s.split("/*/");
boolean boo[]=new boolean[y.length];
for (int i = 0; iy.length-1; i++) {
char c[]=y[i].toCharArray();
for (int j = 0; jc.length; j++) {
if(c[j]=='\\'c[j+1]=='"'){
count++;
}
}
if(count%2==0){
if(countNumber("\"",y[i])%2!=0){
boo[i]=true;
}else{
boo[i]=false;
}
}else{
if(countNumber("\"",y[i])%2==0){
boo[i]=true;
}else{
boo[i]=false;
}
}
}
for(int i=0;iboo.length;i++){
if(!boo[i])
return false;
}
return true;
}
return false;
}
public int countNumber(String s,String y){//此方法为我前面写的字符串出现次数统计方法,不懂的可以看我前面的文章
int count=0;
String [] k=y.split(s);
if(y.lastIndexOf(s)==(y.length()-s.length()))
count=k.length;
else
count=k.length-1;

推荐阅读