1
|
package eu.dnetlib.pace.condition;
|
2
|
|
3
|
import java.util.List;
|
4
|
|
5
|
import com.google.common.collect.Iterables;
|
6
|
|
7
|
import eu.dnetlib.pace.model.Field;
|
8
|
import eu.dnetlib.pace.model.FieldDef;
|
9
|
|
10
|
/**
|
11
|
* Returns true if the number of values in the fields is the same.
|
12
|
*
|
13
|
* @author claudio
|
14
|
*/
|
15
|
public class SizeMatch extends AbstractCondition {
|
16
|
|
17
|
/**
|
18
|
* Instantiates a new size match.
|
19
|
*
|
20
|
* @param fields
|
21
|
* the fields
|
22
|
*/
|
23
|
public SizeMatch(final List<FieldDef> fields) {
|
24
|
super(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 int verify(final FieldDef fd, final Field a, final Field b) {
|
34
|
|
35
|
// if (a.isEmpty() & b.isEmpty()) return 1;
|
36
|
//
|
37
|
// if (a.isEmpty()) return -1;
|
38
|
// if (b.isEmpty()) return -1;
|
39
|
|
40
|
return Iterables.size(a) == Iterables.size(b) ? 1 : -1;
|
41
|
}
|
42
|
|
43
|
/**
|
44
|
* Checks if is empty.
|
45
|
*
|
46
|
* @param a
|
47
|
* the a
|
48
|
* @return true, if is empty
|
49
|
*/
|
50
|
protected boolean isEmpty(final Iterable<?> a) {
|
51
|
return (a == null) || Iterables.isEmpty(a);
|
52
|
}
|
53
|
|
54
|
}
|