Atitit. . 软件命名空间与类名命名单词的统计程序设计v2 1. 要实现的目标 2. Code----

Atitit. . 软件命名空间与类名命名单词的统计程序设计v2

 

 

1要实现的目标1

1.1. Camel字符串模式的分词处理1

1.2. 多个大写的处理1

1.3. 数字与字幕的分离1

1.4. 其他/-_*.$斜杠中画线下划线性好点号美元字符字符的拆分1

1.5. 大写小写的合并2

1.6. 单数复数的合并2

1.7. 过滤数字及单个的字母2

1.8. 复数排除单词比如accessclass2

1.9. 类要截取主类名,去除路径与扩展名2

2Code----2

2.1. public class NamespaceUtil {3

 

 

 

1.1. Camel字符串模式的分词处理

1.2. 多个大写的处理

最后一个大写与后边相连

1.3. 数字与字幕的分离

 

1.4. 其他/-_*.$斜杠中画线下划线性好点号美元字符字符的拆分

 

1.5. 大写小写的合并

1.6. 单数复数的合并

1.7. 过滤数字及单个的字母

1.8. 复数排除单词比如accessclass

1.9. 类要截取主类名,去除路径与扩展名

 

 作者:: 老哇的爪子 Attilax 艾龙,  EMAIL:1466519819@qq.com

转载请注明来源: http://blog.csdn.net/attilax

 

 

 

 

 

2. Code----

package com.attilax.namespace;

 

import java.util.ArrayList;

import java.util.Collection;

import java.util.HashMap;

import java.util.List;

import java.util.Map;

 

import net.sf.json.JSONArray;

 

import com.attilax.coll.ListX;

import com.attilax.collection.listUtil;

import com.attilax.io.dirx;

import com.attilax.io.filex;

import com.attilax.jar.JarFileView;

import com.attilax.json.JSONObject;

import com.attilax.lang.Closure;

import com.attilax.lang.MapX;

import com.attilax.lang.text.RegExpChar4splitor;

import com.attilax.lang.text.strUtil;

import com.attilax.office.excelUtil;

import com.attilax.text.CamelStrUtil;

import com.attilax.util.numUtil;

 

2.1. public class NamespaceUtil {

 

public static void main(String[] args) throws Exception {

//["com.attilax","camel","Gbnfm","hhh","comm"]

String s="com.attilax_camelXGbnfm-hhh/comm$123";

     //s="CamelGbnfm";

List<String> li=toList_byDotByCase(s);

System.out.println( JSONObject.fromObject(li).toString(2));

  String strPath = "D:\workspace 空格\AtiBrow\lib";

//calcPkg(strPath);

calcCls(strPath);

System.out.println("--f");

 

}

 

 

 

private static void calcPkg(String strPaththrows Exception {

Map m=new NamespaceUtil().travePkgCalcNames(strPath);

List Li_table=listUtil.addAll(m); 

 System.out.println( com.attilax.json.JSONArray.fromObject(Li_table).toString(2));

 excelUtil.toExcel("名字,计数""name,count"Li_table"c:\calc_pkg_"+filex.getUUidName()+".xls");

}

 

 

final Map<String,Maptab=new  HashMap<String, Map>();

public Map travePkgCalcNames(String strPath)

{

//final List<Map> m=new ArrayList<Map>();

//trav  jar file

new dirx().traveFile_noIncDir(strPathnew Closure () {

 

@Override

public Object execute(Object arg0throws Exception {

String jar=(String) arg0;

if(!jar.toLowerCase().endsWith("jar"))

return jar;//continue

JarFileView jfv=new JarFileView(jar);

jfv.travePkg(jarjar_file_trave_executor);

return null;

}

 

 

});

return tab;

}

 

 

final Closure jar_file_trave_executor=new Closure () {

 

@Override

public Object execute(Object arg0throws Exception {

String pkg=arg0.toString(); 

if("META-INF/".toLowerCase().equals(pkg.toLowerCase()))

return null;

if(pkg.startsWith("META-INF"))return null;

pkg=pkg.replace("/"".");

System.out.println(pkg);

List<String> nams=new ClassNameSplitor().split(pkg)

for ( String nam : nams) {

final String nam2=nam;

final String nam_key=strUtil.getSingleFmt(nam2extMultiTrimWords).toLowerCase().trim();

if(filted(nam_key))

continue;

Map row=tab.get(nam_key);

if(row==null)

{

tab.put(nam_key,new HashMap (){{

 

this.put("name"nam_key);

this.put("count", 0);

}});//add new row

}

row=tab.get(nam_key);

//new HashMap<String,Integer>();

row.put( "count",MapX.get(row,"count",0)+1);

//m.putm.get(nam)

}

return null;

}

};