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
19 public class BirthmarkContext{
20 private BirthmarkEnvironment environment;
22 private ComparisonMethod method = ComparisonMethod.ROUND_ROBIN_SAME_PAIR;
23 private ExtractionUnit unit = ExtractionUnit.CLASS;
24 private BirthmarkStoreTarget store = BirthmarkStoreTarget.MEMORY;
26 private List<String> birthmarkTypes = new ArrayList<String>();
27 private List<String> filterTypes = new ArrayList<String>();
28 private Map<String, String> nameMappings = new HashMap<String, String>();
29 private String format;
31 * properties which available on a session.
33 private Map<String, Object> properties = new HashMap<String, Object>();
38 public BirthmarkContext(BirthmarkContext context){
39 this.environment = context.getEnvironment();
40 this.method = context.getComparisonMethod();
41 this.unit = context.getExtractionUnit();
42 this.birthmarkTypes = new ArrayList<String>(context.birthmarkTypes);
43 this.filterTypes = new ArrayList<String>(context.filterTypes);
44 this.nameMappings = new HashMap<String, String>(context.nameMappings);
47 public BirthmarkContext(BirthmarkEnvironment environment){
48 this.environment = environment;
51 public BirthmarkEnvironment getEnvironment(){
55 public boolean hasNameMapping(){
56 return getNameMappingCount() > 0;
59 public int getNameMappingCount(){
60 return nameMappings.size();
63 public String getNameMapping(String key){
64 return nameMappings.get(key);
67 public void addNameMapping(String name1, String name2){
68 nameMappings.put(name1, name2);
71 public void removeNameMapping(String name1){
72 nameMappings.remove(name1);
75 public Map<String, String> getNameMappings(){
76 return Collections.unmodifiableMap(nameMappings);
79 public Iterator<Map.Entry<String, String>> nameMappingEntries(){
80 return getNameMappings().entrySet().iterator();
83 public void setNameMappings(Map<String, String> mappings){
85 for(Iterator<Map.Entry<String, String>> i = mappings.entrySet().iterator(); i.hasNext(); ){
86 Map.Entry<String, String> entry = i.next();
87 addNameMapping(entry.getKey(), entry.getValue());
91 public void setBirthmarkTypes(String[] types){
92 birthmarkTypes.clear();
93 for(int i = 0; i < types.length; i++){
94 addBirthmarkType(types[i]);
98 public void addBirthmarkType(String type){
99 if(!birthmarkTypes.contains(type)){
100 birthmarkTypes.add(type);
104 public void removeBirthmarkType(String type){
105 birthmarkTypes.remove(type);
108 public String getFormat(){
112 public void setFormat(String format){
113 this.format = format;
116 public synchronized String[] getBirthmarkTypes(){
117 return birthmarkTypes.toArray(new String[getBirthmarkTypeSize()]);
120 public int getBirthmarkTypeSize(){
121 return birthmarkTypes.size();
124 public ComparisonMethod getComparisonMethod(){
128 public void setComparisonMethod(ComparisonMethod method){
129 this.method = method;
132 public ExtractionUnit getExtractionUnit(){
136 public void setExtractionUnit(ExtractionUnit unit){
140 public BirthmarkStoreTarget getStoreTarget(){
144 public void setStoreTarget(BirthmarkStoreTarget store){
148 public boolean hasFilter(){
149 return filterTypes.size() > 0;
152 public void setFilterTypes(String[] filterTypes){
153 if(filterTypes != null){
154 for(int i = 0; i < filterTypes.length; i++){
155 addFilterType(filterTypes[i]);
160 public void addFilterType(String filterType){
161 if(filterType != null){
162 filterTypes.add(filterType);
166 public void removeFilterType(String filterType){
167 filterTypes.remove(filterType);
170 public synchronized String[] getFilterTypes(){
171 return filterTypes.toArray(new String[getFilterTypesCount()]);
174 public Iterator<String> filterTypes(){
175 return filterTypes.iterator();
178 public int getFilterTypesCount(){
179 return filterTypes.size();
182 public Object getProperty(String key){
183 return getProperty(key, null);
186 public Object getProperty(String key, Object defaultValue){
187 Object value = properties.get(key);
189 value = defaultValue;
194 public void removeProperty(String key){
195 properties.remove(key);
198 public void putProperty(String key, Object value){
199 properties.put(key, value);