OSDN Git Service

change package name. jp.naist.se.stigmata -> jp.sourceforge.stigmata
[stigmata/stigmata.git] / src / main / java / jp / sourceforge / stigmata / ui / swing / ClassNameObfuscator.java
1 package jp.sourceforge.stigmata.ui.swing;
2
3 /*
4  * $Id$
5  */
6
7 import java.io.File;
8 import java.io.FileWriter;
9 import java.io.IOException;
10 import java.io.PrintWriter;
11 import java.util.HashMap;
12 import java.util.Map;
13
14 import jp.sourceforge.stigmata.Birthmark;
15 import jp.sourceforge.stigmata.BirthmarkSet;
16
17 /**
18  * 
19  * @author Haruaki TAMADA
20  * @version $Revision$ $Date$
21  */
22 public class ClassNameObfuscator{
23     private Map<String, String> nameMapping = new HashMap<String, String>();
24
25     public void outputNameMappings(File file) throws IOException{
26         PrintWriter out = null;
27         try{
28             out = new PrintWriter(new FileWriter(file));
29             for(String oldName: nameMapping.keySet()){
30                 String newName = nameMapping.get(oldName);
31                 out.print(oldName);
32                 out.print(",");
33                 out.println(newName);
34             }
35
36         }finally{
37             if(out != null){
38                 out.close();
39             }
40         }
41     }
42
43     public BirthmarkSet obfuscateClassName(BirthmarkSet orig){
44         String newName = nameMapping.get(orig.getName());
45         if(newName == null){
46             newName = String.format("C%04d", new Object[] { new Integer(nameMapping.size() + 1), });
47             nameMapping.put(orig.getName(), newName);
48         }
49
50         BirthmarkSet newSet = new BirthmarkSet(newName, orig.getLocation());
51         for(Birthmark birthmark: orig){
52             newSet.addBirthmark(birthmark);
53         }
54         return newSet;
55     }
56
57 }