2019-08-09 15:41:49 +02:00
|
|
|
package eu.dnetlib.pace.tree;
|
|
|
|
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
import com.google.common.collect.Iterables;
|
|
|
|
|
2019-10-29 16:38:42 +01:00
|
|
|
import eu.dnetlib.pace.config.Config;
|
2019-08-09 15:41:49 +02:00
|
|
|
import eu.dnetlib.pace.model.Field;
|
|
|
|
import eu.dnetlib.pace.tree.support.AbstractComparator;
|
|
|
|
import eu.dnetlib.pace.tree.support.ComparatorClass;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns true if the number of values in the fields is the same.
|
|
|
|
*
|
|
|
|
* @author claudio
|
|
|
|
*/
|
|
|
|
@ComparatorClass("sizeMatch")
|
|
|
|
public class SizeMatch extends AbstractComparator {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Instantiates a new size match.
|
|
|
|
*
|
|
|
|
* @param params
|
|
|
|
* the parameters
|
|
|
|
*/
|
2019-11-21 09:37:56 +01:00
|
|
|
public SizeMatch(final Map<String, String> params) {
|
2019-08-09 15:41:49 +02:00
|
|
|
super(params);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-10-29 16:38:42 +01:00
|
|
|
public double compare(final Field a, final Field b, final Config conf) {
|
2019-08-09 15:41:49 +02:00
|
|
|
|
|
|
|
if (a.isEmpty() || b.isEmpty())
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
return Iterables.size(a) == Iterables.size(b) ? 1 : 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks if is empty.
|
|
|
|
*
|
|
|
|
* @param a
|
|
|
|
* the a
|
|
|
|
* @return true, if is empty
|
|
|
|
*/
|
|
|
|
protected boolean isEmpty(final Iterable<?> a) {
|
|
|
|
return (a == null) || Iterables.isEmpty(a);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|