Project

General

Profile

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

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

    
13
import java.util.Comparator;
14

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

    
17
/**
18
 * <p>IdentifiableEntityComparator class.</p>
19
 *
20
 * @author p.ciardelli
21
 * @created 19.08.2009
22
 * @version 1.0
23
 */
24
public class TitleCacheComparator<T extends IIdentifiableEntity> implements Comparator<T> {
25
	
26
    private boolean fIgnoreCase;
27

    
28
	private String getTitleCache(T o) {
29
		return o == null ? null : o.getTitleCache();
30
	}
31
	
32
	/* (non-Javadoc)
33
	 * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object)
34
	 */
35
	/** {@inheritDoc} */
36
	public int compare(T o1, T o2) {
37
		String titleCache1 = getTitleCache(o1);
38
		String titleCache2 = getTitleCache(o2);
39
		if (titleCache1 == null && titleCache2 == null) {
40
			return 0;
41
		}
42
		if (titleCache1 == null) {
43
			return -1;
44
		}
45
		if (titleCache2 == null) {
46
			return 1;
47
		}				
48
        return fIgnoreCase ? titleCache1.compareToIgnoreCase(titleCache2) : 
49
        						titleCache1.compareTo(titleCache2);
50
	}
51
}
(6-6/6)