Project

General

Profile

Download (2.39 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
* Copyright (C) 2007 EDIT
3
* European Distributed Institute of Taxonomy 
4
* http://www.e-taxonomy.eu
5
* 
6
* The contents of this file are subject to the Mozilla Public License Version 1.1
7
* See LICENSE.TXT at the top of this package for the full license terms.
8
*/
9

    
10
package eu.etaxonomy.cdm.strategy.match;
11

    
12
import java.util.ArrayList;
13
import java.util.List;
14
import java.util.SortedMap;
15
import java.util.TreeMap;
16

    
17
import org.apache.log4j.Logger;
18

    
19
/**
20
 * @author a.mueller
21
 * @created 07.08.2009
22
 * @version 1.0
23
 */
24
public class Matching {
25
	@SuppressWarnings("unused")
26
	private static final Logger logger = Logger.getLogger(Matching.class);
27
	
28
	private SortedMap<String, FieldMatcher> fieldMatchers = new TreeMap<String, FieldMatcher>();
29
	private SortedMap<String, FieldMatcher> tmpFieldMatchers = new TreeMap<String, FieldMatcher>();
30
	private List<CacheMatcher> cacheMatchers = new ArrayList<CacheMatcher>();
31
	
32

    
33
	public Matching setFieldMatcher(FieldMatcher fieldMatcher){
34
		return setFieldMatcher(fieldMatcher, false);
35
	}
36
	
37
	public Matching setFieldMatcher(FieldMatcher fieldMatcher,boolean temporary){
38
		String propertyName = fieldMatcher.getPropertyName();
39
		if (temporary && ! fieldMatchers.containsKey(propertyName)){
40
			tmpFieldMatchers.put(propertyName, fieldMatcher);	
41
		}else{
42
			fieldMatchers.put(propertyName, fieldMatcher);
43
		}
44
		return this;
45
	}
46

    
47
	public Matching addCacheMatcher(CacheMatcher cacheMatcher){
48
		cacheMatchers.add(cacheMatcher);
49
		return this;
50
	}
51

    
52
	/**
53
	 * @return the fieldMatchers
54
	 */
55
	public List<FieldMatcher> getFieldMatchers(boolean includeTemporary) {
56
		List<FieldMatcher> result = new ArrayList<FieldMatcher>();
57
		for (FieldMatcher fieldMatcher : fieldMatchers.values()){
58
			result.add(fieldMatcher);
59
		}
60
		if (includeTemporary){
61
			for (FieldMatcher fieldMatcher : tmpFieldMatchers.values()){
62
				result.add(fieldMatcher);
63
			}	
64
		}
65
		return result;
66
	}
67
	
68
	/**
69
	 * @return the fieldMatchers
70
	 */
71
	public FieldMatcher getFieldMatcher(String propertyName) {
72
		return fieldMatchers.get(propertyName);
73
	}
74
	
75
	public boolean exists(String propertyName){
76
		return getFieldMatcher(propertyName) != null;
77
	}
78

    
79
	/**
80
	 * @return the groupMatchers
81
	 */
82
	public List<CacheMatcher> getCacheMatchers() {
83
		return cacheMatchers;
84
	}
85

    
86
	public void deleteTemporaryMatchers(){
87
		tmpFieldMatchers = new TreeMap<String, FieldMatcher>();
88
	}
89
	
90
	
91
}
(11-11/11)