1 package jp.sourceforge.stigmata;
7 import java.util.ArrayList;
8 import java.util.Collections;
9 import java.util.HashMap;
10 import java.util.Iterator;
11 import java.util.List;
15 * Birthmark runtime context.
17 * @author Haruaki Tamada
20 public class BirthmarkContext{
21 private BirthmarkEnvironment environment;
23 private ComparisonMethod method = ComparisonMethod.ROUND_ROBIN_SAME_PAIR;
24 private ExtractionUnit unit = ExtractionUnit.CLASS;
25 private BirthmarkStoreTarget store = BirthmarkStoreTarget.MEMORY;
27 private List<String> birthmarkTypes = new ArrayList<String>();
28 private List<String> filterTypes = new ArrayList<String>();
29 private Map<String, String> nameMappings = new HashMap<String, String>();
30 private String format;
32 * properties which available on a session.
34 private Map<String, Object> properties = new HashMap<String, Object>();
39 public BirthmarkContext(BirthmarkContext context){
40 this.environment = context.getEnvironment();
41 this.method = context.getComparisonMethod();
42 this.unit = context.getExtractionUnit();
43 this.birthmarkTypes = new ArrayList<String>(context.birthmarkTypes);
44 this.filterTypes = new ArrayList<String>(context.filterTypes);
45 this.nameMappings = new HashMap<String, String>(context.nameMappings);
48 public BirthmarkContext(BirthmarkEnvironment environment){
49 this.environment = environment;
52 public BirthmarkEnvironment getEnvironment(){
56 public boolean hasNameMapping(){
57 return getNameMappingCount() > 0;
60 public int getNameMappingCount(){
61 return nameMappings.size();
64 public String getNameMapping(String key){
65 return nameMappings.get(key);
68 public void addNameMapping(String name1, String name2){
69 nameMappings.put(name1, name2);
72 public void removeNameMapping(String name1){
73 nameMappings.remove(name1);
76 public Map<String, String> getNameMappings(){
77 return Collections.unmodifiableMap(nameMappings);
80 public Iterator<Map.Entry<String, String>> nameMappingEntries(){
81 return getNameMappings().entrySet().iterator();
84 public void setNameMappings(Map<String, String> mappings){
86 for(Iterator<Map.Entry<String, String>> i = mappings.entrySet().iterator(); i.hasNext(); ){
87 Map.Entry<String, String> entry = i.next();
88 addNameMapping(entry.getKey(), entry.getValue());
92 public void setBirthmarkTypes(String[] types){
93 birthmarkTypes.clear();
94 for(int i = 0; i < types.length; i++){
95 addBirthmarkType(types[i]);
99 public void addBirthmarkType(String type){
100 if(!birthmarkTypes.contains(type)){
101 birthmarkTypes.add(type);
105 public void removeBirthmarkType(String type){
106 birthmarkTypes.remove(type);
109 public String getFormat(){
113 public void setFormat(String format){
114 this.format = format;
117 public synchronized String[] getBirthmarkTypes(){
118 return birthmarkTypes.toArray(new String[getBirthmarkTypeSize()]);
121 public int getBirthmarkTypeSize(){
122 return birthmarkTypes.size();
125 public ComparisonMethod getComparisonMethod(){
129 public void setComparisonMethod(ComparisonMethod method){
130 this.method = method;
133 public ExtractionUnit getExtractionUnit(){
137 public void setExtractionUnit(ExtractionUnit unit){
141 public BirthmarkStoreTarget getStoreTarget(){
145 public void setStoreTarget(BirthmarkStoreTarget store){
149 public boolean hasFilter(){
150 return filterTypes.size() > 0;
153 public void setFilterTypes(String[] filterTypes){
154 if(filterTypes != null){
155 for(int i = 0; i < filterTypes.length; i++){
156 addFilterType(filterTypes[i]);
161 public void addFilterType(String filterType){
162 if(filterType != null){
163 filterTypes.add(filterType);
167 public void removeFilterType(String filterType){
168 filterTypes.remove(filterType);
171 public synchronized String[] getFilterTypes(){
172 return filterTypes.toArray(new String[getFilterTypesCount()]);
175 public Iterator<String> filterTypes(){
176 return filterTypes.iterator();
179 public int getFilterTypesCount(){
180 return filterTypes.size();
183 public Object getProperty(String key){
184 return getProperty(key, null);
187 public Object getProperty(String key, Object defaultValue){
188 Object value = properties.get(key);
190 value = defaultValue;
195 public void removeProperty(String key){
196 properties.remove(key);
199 public void putProperty(String key, Object value){
200 properties.put(key, value);