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.logging.log4j.LogManager;import org.apache.logging.log4j.Logger;
|
18
|
|
19
|
/**
|
20
|
* @author a.mueller
|
21
|
* @since 07.08.2009
|
22
|
*/
|
23
|
public class Matching {
|
24
|
@SuppressWarnings("unused")
|
25
|
private static final Logger logger = LogManager.getLogger(Matching.class);
|
26
|
|
27
|
private SortedMap<String, FieldMatcher> fieldMatchers = new TreeMap<>();
|
28
|
private SortedMap<String, FieldMatcher> tmpFieldMatchers = new TreeMap<>();
|
29
|
private List<CacheMatcher> cacheMatchers = new ArrayList<>();
|
30
|
|
31
|
|
32
|
public Matching addFieldMatcher(FieldMatcher fieldMatcher){
|
33
|
return addFieldMatcher(fieldMatcher, false);
|
34
|
}
|
35
|
|
36
|
public Matching addFieldMatcher(FieldMatcher fieldMatcher, boolean temporary){
|
37
|
String propertyName = fieldMatcher.getPropertyName();
|
38
|
if (temporary && ! fieldMatchers.containsKey(propertyName)){
|
39
|
tmpFieldMatchers.put(propertyName, fieldMatcher);
|
40
|
}else{
|
41
|
fieldMatchers.put(propertyName, fieldMatcher);
|
42
|
}
|
43
|
return this;
|
44
|
}
|
45
|
|
46
|
public Matching addCacheMatcher(CacheMatcher cacheMatcher){
|
47
|
cacheMatchers.add(cacheMatcher);
|
48
|
return this;
|
49
|
}
|
50
|
|
51
|
/**
|
52
|
* @return the fieldMatchers
|
53
|
*/
|
54
|
public List<FieldMatcher> getFieldMatchers(boolean includeTemporary) {
|
55
|
List<FieldMatcher> result = new ArrayList<>();
|
56
|
for (FieldMatcher fieldMatcher : fieldMatchers.values()){
|
57
|
result.add(fieldMatcher);
|
58
|
}
|
59
|
if (includeTemporary){
|
60
|
for (FieldMatcher fieldMatcher : tmpFieldMatchers.values()){
|
61
|
result.add(fieldMatcher);
|
62
|
}
|
63
|
}
|
64
|
return result;
|
65
|
}
|
66
|
|
67
|
/**
|
68
|
* @return the fieldMatchers
|
69
|
*/
|
70
|
public FieldMatcher getFieldMatcher(String propertyName) {
|
71
|
return fieldMatchers.get(propertyName);
|
72
|
}
|
73
|
|
74
|
public boolean exists(String propertyName){
|
75
|
return getFieldMatcher(propertyName) != null;
|
76
|
}
|
77
|
|
78
|
/**
|
79
|
* @return the groupMatchers
|
80
|
*/
|
81
|
public List<CacheMatcher> getCacheMatchers() {
|
82
|
return cacheMatchers;
|
83
|
}
|
84
|
|
85
|
public void deleteTemporaryMatchers(){
|
86
|
tmpFieldMatchers = new TreeMap<>();
|
87
|
}
|
88
|
|
89
|
|
90
|
}
|