OSDN Git Service

Delete Subversion Tags (Revision, Id)
[stigmata/stigmata.git] / src / main / java / jp / sourceforge / stigmata / BirthmarkContext.java
1 package jp.sourceforge.stigmata;
2
3 import java.util.ArrayList;
4 import java.util.Collections;
5 import java.util.HashMap;
6 import java.util.Iterator;
7 import java.util.List;
8 import java.util.Map;
9
10 /**
11  * Birthmark runtime context.
12  * 
13  * @author Haruaki Tamada
14  */
15 public class BirthmarkContext{
16     private BirthmarkEnvironment environment;
17
18     private ComparisonMethod method = ComparisonMethod.ROUND_ROBIN_SAME_PAIR;
19     private ExtractionUnit unit = ExtractionUnit.CLASS;
20     private BirthmarkStoreTarget store = BirthmarkStoreTarget.MEMORY;
21
22     private List<String> birthmarkTypes = new ArrayList<String>();
23     private List<String> filterTypes = new ArrayList<String>();
24     private Map<String, String> nameMappings = new HashMap<String, String>();
25     private String format;
26     /**
27      * properties which available on a session.
28      */
29     private Map<String, Object> properties = new HashMap<String, Object>();
30
31     /**
32      * self constructor.
33      */
34     public BirthmarkContext(BirthmarkContext context){
35         this.environment = context.getEnvironment();
36         this.method = context.getComparisonMethod();
37         this.unit = context.getExtractionUnit();
38         this.birthmarkTypes = new ArrayList<String>(context.birthmarkTypes);
39         this.filterTypes = new ArrayList<String>(context.filterTypes);
40         this.nameMappings = new HashMap<String, String>(context.nameMappings);
41     }
42
43     public BirthmarkContext(BirthmarkEnvironment environment){
44         this.environment = environment;
45     }
46
47     public BirthmarkEnvironment getEnvironment(){
48         return environment;
49     }
50
51     public boolean hasNameMapping(){
52         return getNameMappingCount() > 0;
53     }
54
55     public int getNameMappingCount(){
56         return nameMappings.size();
57     }
58
59     public String getNameMapping(String key){
60         return nameMappings.get(key);
61     }
62
63     public void addNameMapping(String name1, String name2){
64         nameMappings.put(name1, name2);
65     }
66
67     public void removeNameMapping(String name1){
68         nameMappings.remove(name1);
69     }
70
71     public Map<String, String> getNameMappings(){
72         return Collections.unmodifiableMap(nameMappings);
73     }
74
75     public Iterator<Map.Entry<String, String>> nameMappingEntries(){
76         return getNameMappings().entrySet().iterator();
77     }
78
79     public void setNameMappings(Map<String, String> mappings){
80         nameMappings.clear();
81         for(Iterator<Map.Entry<String, String>> i = mappings.entrySet().iterator(); i.hasNext(); ){
82             Map.Entry<String, String> entry = i.next();
83             addNameMapping(entry.getKey(), entry.getValue());
84         }
85     }
86
87     public void setBirthmarkTypes(String[] types){
88         birthmarkTypes.clear();
89         for(int i = 0; i < types.length; i++){
90             addBirthmarkType(types[i]);
91         }
92     }
93
94     public void addBirthmarkType(String type){
95         if(!birthmarkTypes.contains(type)){
96             birthmarkTypes.add(type);
97         }
98     }
99
100     public void removeBirthmarkType(String type){
101         birthmarkTypes.remove(type);
102     }
103
104     public String getFormat(){
105         return format;
106     }
107
108     public void setFormat(String format){
109         this.format = format;
110     }
111
112     public synchronized String[] getBirthmarkTypes(){
113         return birthmarkTypes.toArray(new String[getBirthmarkTypeSize()]);
114     }
115
116     public int getBirthmarkTypeSize(){
117         return birthmarkTypes.size();
118     }
119
120     public ComparisonMethod getComparisonMethod(){
121         return method;
122     }
123
124     public void setComparisonMethod(ComparisonMethod method){
125         this.method = method;
126     }
127
128     public ExtractionUnit getExtractionUnit(){
129         return unit;
130     }
131
132     public void setExtractionUnit(ExtractionUnit unit){
133         this.unit = unit;
134     }
135
136     public BirthmarkStoreTarget getStoreTarget(){
137         return store;
138     }
139
140     public void setStoreTarget(BirthmarkStoreTarget store){
141         this.store = store;
142     }
143
144     public boolean hasFilter(){
145         return filterTypes.size() > 0;
146     }
147
148     public void setFilterTypes(String[] filterTypes){
149         if(filterTypes != null){
150             for(int i = 0; i < filterTypes.length; i++){
151                 addFilterType(filterTypes[i]);
152             }
153         }
154     }
155
156     public void addFilterType(String filterType){
157         if(filterType != null){
158             filterTypes.add(filterType);
159         }
160     }
161
162     public void removeFilterType(String filterType){
163         filterTypes.remove(filterType);
164     }
165
166     public synchronized String[] getFilterTypes(){
167         return filterTypes.toArray(new String[getFilterTypesCount()]);
168     }
169
170     public Iterator<String> filterTypes(){
171         return filterTypes.iterator();
172     }
173
174     public int getFilterTypesCount(){
175         return filterTypes.size();
176     }
177
178     public Object getProperty(String key){
179         return getProperty(key, null);
180     }
181
182     public Object getProperty(String key, Object defaultValue){
183         Object value = properties.get(key);
184         if(value == null){
185             value = defaultValue;
186         }
187         return value;
188     }
189
190     public void removeProperty(String key){
191         properties.remove(key);
192     }
193
194     public void putProperty(String key, Object value){
195         properties.put(key, value);
196     }
197 }