Project

General

Profile

Download (1.25 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
* Copyright (C) 2007 EDIT
3
* European Distributed Institute of Taxonomy
4
* http://www.e-taxonomy.eu
5
*
6
* The contents of this file are subject to the Mozilla Public License Version 1.1
7
* See LICENSE.TXT at the top of this package for the full license terms.
8
*/
9

    
10
package eu.etaxonomy.taxeditor.bulkeditor.input.sortprovider;
11

    
12
import java.util.Comparator;
13

    
14
import eu.etaxonomy.cdm.model.common.IIdentifiableEntity;
15

    
16
/**
17
 * <p>IdentifiableEntityComparator class.</p>
18
 *
19
 * @author p.ciardelli
20
 * @created 19.08.2009
21
 */
22
public class TitleCacheComparator<T extends IIdentifiableEntity> implements Comparator<T> {
23

    
24
    private boolean fIgnoreCase;
25

    
26
	private String getTitleCache(T o) {
27
		return o == null ? null : o.getTitleCache();
28
	}
29

    
30
	@Override
31
    public int compare(T o1, T o2) {
32
		String titleCache1 = getTitleCache(o1);
33
		String titleCache2 = getTitleCache(o2);
34
		if (titleCache1 == null && titleCache2 == null) {
35
			return 0;
36
		}
37
		if (titleCache1 == null) {
38
			return -1;
39
		}
40
		if (titleCache2 == null) {
41
			return 1;
42
		}
43
        int result =  fIgnoreCase ? titleCache1.compareToIgnoreCase(titleCache2) :
44
        						titleCache1.compareTo(titleCache2);
45

    
46
        if (result == 0){
47
            result = o1.getUuid().compareTo(o2.getUuid());
48
        }
49
        return result;
50
	}
51
}
(7-7/8)