1 package jp.sourceforge.stigmata;
3 import java.util.ArrayList;
4 import java.util.Collections;
5 import java.util.HashMap;
6 import java.util.Iterator;
11 * Birthmark runtime context.
13 * @author Haruaki Tamada
15 public class BirthmarkContext{
16 private BirthmarkEnvironment environment;
18 private ComparisonMethod method = ComparisonMethod.ROUND_ROBIN_SAME_PAIR;
19 private ExtractionUnit unit = ExtractionUnit.CLASS;
20 private BirthmarkStoreTarget store = BirthmarkStoreTarget.MEMORY;
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;
27 * properties which available on a session.
29 private Map<String, Object> properties = new HashMap<String, Object>();
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);
43 public BirthmarkContext(BirthmarkEnvironment environment){
44 this.environment = environment;
47 public BirthmarkEnvironment getEnvironment(){
51 public boolean hasNameMapping(){
52 return getNameMappingCount() > 0;
55 public int getNameMappingCount(){
56 return nameMappings.size();
59 public String getNameMapping(String key){
60 return nameMappings.get(key);
63 public void addNameMapping(String name1, String name2){
64 nameMappings.put(name1, name2);
67 public void removeNameMapping(String name1){
68 nameMappings.remove(name1);
71 public Map<String, String> getNameMappings(){
72 return Collections.unmodifiableMap(nameMappings);
75 public Iterator<Map.Entry<String, String>> nameMappingEntries(){
76 return getNameMappings().entrySet().iterator();
79 public void setNameMappings(Map<String, String> mappings){
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());
87 public void setBirthmarkTypes(String[] types){
88 birthmarkTypes.clear();
89 for(int i = 0; i < types.length; i++){
90 addBirthmarkType(types[i]);
94 public void addBirthmarkType(String type){
95 if(!birthmarkTypes.contains(type)){
96 birthmarkTypes.add(type);
100 public void removeBirthmarkType(String type){
101 birthmarkTypes.remove(type);
104 public String getFormat(){
108 public void setFormat(String format){
109 this.format = format;
112 public synchronized String[] getBirthmarkTypes(){
113 return birthmarkTypes.toArray(new String[getBirthmarkTypeSize()]);
116 public int getBirthmarkTypeSize(){
117 return birthmarkTypes.size();
120 public ComparisonMethod getComparisonMethod(){
124 public void setComparisonMethod(ComparisonMethod method){
125 this.method = method;
128 public ExtractionUnit getExtractionUnit(){
132 public void setExtractionUnit(ExtractionUnit unit){
136 public BirthmarkStoreTarget getStoreTarget(){
140 public void setStoreTarget(BirthmarkStoreTarget store){
144 public boolean hasFilter(){
145 return filterTypes.size() > 0;
148 public void setFilterTypes(String[] filterTypes){
149 if(filterTypes != null){
150 for(int i = 0; i < filterTypes.length; i++){
151 addFilterType(filterTypes[i]);
156 public void addFilterType(String filterType){
157 if(filterType != null){
158 filterTypes.add(filterType);
162 public void removeFilterType(String filterType){
163 filterTypes.remove(filterType);
166 public synchronized String[] getFilterTypes(){
167 return filterTypes.toArray(new String[getFilterTypesCount()]);
170 public Iterator<String> filterTypes(){
171 return filterTypes.iterator();
174 public int getFilterTypesCount(){
175 return filterTypes.size();
178 public Object getProperty(String key){
179 return getProperty(key, null);
182 public Object getProperty(String key, Object defaultValue){
183 Object value = properties.get(key);
185 value = defaultValue;
190 public void removeProperty(String key){
191 properties.remove(key);
194 public void putProperty(String key, Object value){
195 properties.put(key, value);