Atitit. . 軟體名稱空間與類名命名單詞的統計程式設計v2
1.4. 其他/-_*.$斜槓中畫線下劃線性好點號美元字元字元的拆分1
2.1. public class NamespaceUtil {3
1. 要實現的目標
1.1. Camel字串模式的分詞處理
1.2. 多個大寫的處理
最後一個大寫與後邊相連
1.3. 數字與字幕的分離
1.4. 其他/-_*.$斜槓中畫線下劃線性好點號美元字元字元的拆分
1.5. 大寫小寫的合併
1.6. 單數複數的合併
1.7. 過濾數字及單個的字母
1.8. 複數排除單詞比如access,class
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 strPath) throws 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,Map> tab=new HashMap<String, Map>();
public Map travePkgCalcNames(String strPath)
{
//final List<Map> m=new ArrayList<Map>();
//trav jar file
new dirx().traveFile_noIncDir(strPath, new Closure () {
@Override
public Object execute(Object arg0) throws Exception {
String jar=(String) arg0;
if(!jar.toLowerCase().endsWith("jar"))
return jar;//continue
JarFileView jfv=new JarFileView(jar);
jfv.travePkg(jar, jar_file_trave_executor);
return null;
}
});
return tab;
}
final Closure jar_file_trave_executor=new Closure () {
@Override
public Object execute(Object arg0) throws 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(nam2, extMultiTrimWords).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;
}
};