1
|
// $Id$
|
2
|
/**
|
3
|
* Copyright (C) 2007 EDIT
|
4
|
* European Distributed Institute of Taxonomy
|
5
|
* http://www.e-taxonomy.eu
|
6
|
*
|
7
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
8
|
* See LICENSE.TXT at the top of this package for the full license terms.
|
9
|
*/
|
10
|
|
11
|
package eu.etaxonomy.cdm.strategy.match;
|
12
|
|
13
|
import java.util.ArrayList;
|
14
|
import java.util.List;
|
15
|
import java.util.SortedMap;
|
16
|
import java.util.TreeMap;
|
17
|
|
18
|
import org.apache.log4j.Logger;
|
19
|
|
20
|
/**
|
21
|
* @author a.mueller
|
22
|
* @created 07.08.2009
|
23
|
* @version 1.0
|
24
|
*/
|
25
|
public class Matching {
|
26
|
@SuppressWarnings("unused")
|
27
|
private static final Logger logger = Logger.getLogger(Matching.class);
|
28
|
|
29
|
private SortedMap<String, FieldMatcher> fieldMatchers = new TreeMap<String, FieldMatcher>();
|
30
|
private SortedMap<String, FieldMatcher> tmpFieldMatchers = new TreeMap<String, FieldMatcher>();
|
31
|
private List<CacheMatcher> cacheMatchers = new ArrayList<CacheMatcher>();
|
32
|
|
33
|
|
34
|
public Matching setFieldMatcher(FieldMatcher fieldMatcher){
|
35
|
return setFieldMatcher(fieldMatcher, false);
|
36
|
}
|
37
|
|
38
|
public Matching setFieldMatcher(FieldMatcher fieldMatcher,boolean temporary){
|
39
|
String propertyName = fieldMatcher.getPropertyName();
|
40
|
if (temporary && ! fieldMatchers.containsKey(propertyName)){
|
41
|
tmpFieldMatchers.put(propertyName, fieldMatcher);
|
42
|
}else{
|
43
|
fieldMatchers.put(propertyName, fieldMatcher);
|
44
|
}
|
45
|
return this;
|
46
|
}
|
47
|
|
48
|
public Matching addCacheMatcher(CacheMatcher cacheMatcher){
|
49
|
cacheMatchers.add(cacheMatcher);
|
50
|
return this;
|
51
|
}
|
52
|
|
53
|
/**
|
54
|
* @return the fieldMatchers
|
55
|
*/
|
56
|
public List<FieldMatcher> getFieldMatchers(boolean includeTemporary) {
|
57
|
List<FieldMatcher> result = new ArrayList<FieldMatcher>();
|
58
|
for (FieldMatcher fieldMatcher : fieldMatchers.values()){
|
59
|
result.add(fieldMatcher);
|
60
|
}
|
61
|
if (includeTemporary){
|
62
|
for (FieldMatcher fieldMatcher : tmpFieldMatchers.values()){
|
63
|
result.add(fieldMatcher);
|
64
|
}
|
65
|
}
|
66
|
return result;
|
67
|
}
|
68
|
|
69
|
/**
|
70
|
* @return the fieldMatchers
|
71
|
*/
|
72
|
public FieldMatcher getFieldMatcher(String propertyName) {
|
73
|
return fieldMatchers.get(propertyName);
|
74
|
}
|
75
|
|
76
|
public boolean exists(String propertyName){
|
77
|
return getFieldMatcher(propertyName) != null;
|
78
|
}
|
79
|
|
80
|
/**
|
81
|
* @return the groupMatchers
|
82
|
*/
|
83
|
public List<CacheMatcher> getCacheMatchers() {
|
84
|
return cacheMatchers;
|
85
|
}
|
86
|
|
87
|
public void deleteTemporaryMatchers(){
|
88
|
tmpFieldMatchers = new TreeMap<String, FieldMatcher>();
|
89
|
}
|
90
|
|
91
|
|
92
|
}
|