Project

General

Profile

1
package eu.dnetlib.data.transform;
2

    
3
import com.google.common.collect.ImmutableList;
4
import com.google.common.collect.Ordering;
5

    
6
import eu.dnetlib.data.proto.DNGFProtos.DNGF;
7
import eu.dnetlib.data.proto.SpecialTrustProtos.SpecialTrust;
8

    
9
public class TrustOrdering extends Ordering<DNGF> {
10

    
11
	@Override
12
	public int compare(DNGF left, DNGF 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<DNGF> sort(Iterable<DNGF> entities) {
28
		return new TrustOrdering().immutableSortedCopy(entities);
29
	}
30

    
31
}
(11-11/13)