Project

General

Profile

1 26600 sandro.lab
package eu.dnetlib.data.mapreduce.util;
2
3
import com.google.common.collect.ImmutableList;
4
import com.google.common.collect.Ordering;
5
6
import eu.dnetlib.data.proto.OafProtos.Oaf;
7
import eu.dnetlib.data.proto.SpecialTrustProtos.SpecialTrust;
8
9
public class TrustOrdering extends Ordering<Oaf> {
10
11
	@Override
12
	public int compare(Oaf left, Oaf right) {
13
		String lTrust = left.getDataInfo().getTrust();
14
		String rTrust = right.getDataInfo().getTrust();
15
16
		if (lTrust.equals(rTrust)) return 0;
17
18
		if (lTrust.equals(SpecialTrust.INFINITE.toString())) return 1;
19
		if (rTrust.equals(SpecialTrust.INFINITE.toString())) return -1;
20
21
		if (lTrust.equals(SpecialTrust.NEUTRAL.toString())) return 1;
22
		if (rTrust.equals(SpecialTrust.NEUTRAL.toString())) return -1;
23
24
		return Float.compare(Float.parseFloat(lTrust), Float.parseFloat(rTrust));
25
	}
26
27
	public static ImmutableList<Oaf> sort(Iterable<Oaf> entities) {
28
		return new TrustOrdering().immutableSortedCopy(entities);
29
	}
30
31
}