1
|
/**
|
2
|
* Copyright (C) 2017 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
|
package eu.etaxonomy.cdm.persistence.dao.common;
|
10
|
|
11
|
import java.util.ArrayList;
|
12
|
import java.util.Arrays;
|
13
|
import java.util.EnumSet;
|
14
|
import java.util.List;
|
15
|
|
16
|
import eu.etaxonomy.cdm.persistence.query.MatchMode;
|
17
|
|
18
|
/**
|
19
|
* See <code>NameServiceImplTest.testFindByTitle()</code> for usage examples.
|
20
|
*
|
21
|
* @author a.kohlbecker
|
22
|
* @since May 8, 2017
|
23
|
*/
|
24
|
public class Restriction<T extends Object> {
|
25
|
|
26
|
public enum Operator {
|
27
|
AND,
|
28
|
OR,
|
29
|
AND_NOT,
|
30
|
OR_NOT;
|
31
|
}
|
32
|
|
33
|
private static final EnumSet<Operator> NOT_OPERATORS = EnumSet.of(Operator.AND_NOT, Operator.OR_NOT);
|
34
|
|
35
|
private String propertyName;
|
36
|
|
37
|
private MatchMode matchMode;
|
38
|
|
39
|
private Operator operator = Operator.AND;
|
40
|
|
41
|
private List<T> values = null;
|
42
|
|
43
|
public Restriction(){
|
44
|
super();
|
45
|
}
|
46
|
|
47
|
/**
|
48
|
* @param propertyName
|
49
|
* @param matchMode is only applied if the <code>value</code> is a <code>String</code> object
|
50
|
*/
|
51
|
public Restriction(String propertyName, MatchMode matchMode, T ... values ) {
|
52
|
this(propertyName, Operator.AND, matchMode, values);
|
53
|
}
|
54
|
|
55
|
public Restriction(String propertyName, Operator operator, MatchMode matchMode, T ... values ) {
|
56
|
this.propertyName = propertyName;
|
57
|
this.operator = operator;
|
58
|
if(values.length > 0){
|
59
|
this.setValues(Arrays.asList(values));
|
60
|
if(values[0] != null && values[0] instanceof String){
|
61
|
this.matchMode = matchMode;
|
62
|
}
|
63
|
}
|
64
|
}
|
65
|
|
66
|
public String getPropertyName() {
|
67
|
return propertyName;
|
68
|
}
|
69
|
public void setPropertyName(String propertyName) {
|
70
|
this.propertyName = propertyName;
|
71
|
}
|
72
|
|
73
|
public MatchMode getMatchMode() {
|
74
|
return matchMode;
|
75
|
}
|
76
|
public void setMatchMode(MatchMode matchMode) {
|
77
|
this.matchMode = matchMode;
|
78
|
}
|
79
|
|
80
|
/**
|
81
|
* @return the values, never <code>null</code>
|
82
|
*/
|
83
|
public List<T> getValues() {
|
84
|
if(values == null){
|
85
|
values = new ArrayList<>();
|
86
|
}
|
87
|
return values;
|
88
|
}
|
89
|
public void setValues(List<T> values) {
|
90
|
this.values = values;
|
91
|
}
|
92
|
public void addValue(T value){
|
93
|
getValues().add(value);
|
94
|
}
|
95
|
|
96
|
public Operator getOperator() {
|
97
|
return operator;
|
98
|
}
|
99
|
public void setOperator(Operator operator) {
|
100
|
this.operator = operator;
|
101
|
}
|
102
|
|
103
|
public boolean isNot() {
|
104
|
return NOT_OPERATORS.contains(operator);
|
105
|
}
|
106
|
}
|