Project

General

Profile

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.config.Cond;
8
import eu.dnetlib.pace.distance.eval.ConditionEval;
9
import eu.dnetlib.pace.model.Field;
10
import eu.dnetlib.pace.model.FieldDef;
11

    
12
/**
13
 * Returns true if the number of values in the fields is the same.
14
 *
15
 * @author claudio
16
 */
17
public class SizeMatch extends AbstractCondition {
18

    
19
	/**
20
	 * Instantiates a new size match.
21
	 *
22
	 * @param fields
23
	 *            the fields
24
	 */
25
	public SizeMatch(final Cond cond, final List<FieldDef> fields) {
26
		super(cond, fields);
27
	}
28

    
29
	/*
30
	 * (non-Javadoc)
31
	 *
32
	 * @see eu.dnetlib.pace.condition.AbstractCondition#verify(eu.dnetlib.pace.model.FieldDef, java.util.List, java.util.List)
33
	 */
34
	@Override
35
	protected ConditionEval verify(final FieldDef fd, final Field a, final Field b) {
36

    
37
		// if (a.isEmpty() & b.isEmpty()) return 1;
38
		//
39
		// if (a.isEmpty()) return -1;
40
		// if (b.isEmpty()) return -1;
41

    
42
		return new ConditionEval(cond, a, b, Iterables.size(a) == Iterables.size(b) ? 1 : -1);
43
	}
44

    
45
	/**
46
	 * Checks if is empty.
47
	 *
48
	 * @param a
49
	 *            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
}
(9-9/11)