1
|
package eu.dnetlib.pace.condition;
|
2
|
|
3
|
import java.util.List;
|
4
|
|
5
|
import com.google.common.collect.Iterables;
|
6
|
import eu.dnetlib.pace.config.Cond;
|
7
|
import eu.dnetlib.pace.distance.eval.ConditionEval;
|
8
|
import eu.dnetlib.pace.model.Field;
|
9
|
import eu.dnetlib.pace.model.FieldDef;
|
10
|
|
11
|
/**
|
12
|
* Returns true if the field values are different.
|
13
|
*
|
14
|
* @author claudio
|
15
|
*/
|
16
|
public class MustBeDifferent extends AbstractCondition {
|
17
|
|
18
|
/**
|
19
|
* Instantiates a new size match.
|
20
|
*
|
21
|
* @param fields the fields
|
22
|
*/
|
23
|
public MustBeDifferent(final Cond cond, final List<FieldDef> fields) {
|
24
|
super(cond, fields);
|
25
|
}
|
26
|
|
27
|
/*
|
28
|
* (non-Javadoc)
|
29
|
*
|
30
|
* @see eu.dnetlib.pace.condition.AbstractCondition#verify(eu.dnetlib.pace.model.FieldDef, java.util.List, java.util.List)
|
31
|
*/
|
32
|
@Override
|
33
|
protected ConditionEval verify(final FieldDef fd, final Field a, final Field b) {
|
34
|
|
35
|
final String fa = getValue(a);
|
36
|
final String fb = getValue(b);
|
37
|
|
38
|
return new ConditionEval(cond, a, b, fa.equals(fb) ? -1 : 1);
|
39
|
|
40
|
}
|
41
|
|
42
|
protected String getValue(final Field f) {
|
43
|
return getFirstValue(f);
|
44
|
}
|
45
|
|
46
|
/**
|
47
|
* Checks if is empty.
|
48
|
*
|
49
|
* @param a the a
|
50
|
* @return true, if is empty
|
51
|
*/
|
52
|
protected boolean isEmpty(final Iterable<?> a) {
|
53
|
return (a == null) || Iterables.isEmpty(a);
|
54
|
}
|
55
|
|
56
|
}
|