Project

General

Profile

Download (1.43 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.annotatedlineeditor;
12

    
13
import java.util.Comparator;
14

    
15
import org.apache.log4j.Logger;
16

    
17
import eu.etaxonomy.cdm.model.common.IdentifiableEntity;
18

    
19
/**
20
 * <p>IdentifiableEntityComparator class.</p>
21
 *
22
 * @author p.ciardelli
23
 * @created 19.08.2009
24
 * @version 1.0
25
 */
26
public class IdentifiableEntityComparator implements Comparator {
27
	private static final Logger logger = Logger
28
			.getLogger(IdentifiableEntityComparator.class);
29
	
30
    private boolean fIgnoreCase;
31

    
32
	private String getTitleCache(Object o) {
33
		return o == null || !(o instanceof IdentifiableEntity) ? 
34
				null : ((IdentifiableEntity) o).getTitleCache();
35
	}
36
	
37
	/* (non-Javadoc)
38
	 * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object)
39
	 */
40
	/** {@inheritDoc} */
41
	public int compare(Object o1, Object o2) {
42
		String titleCache1 = getTitleCache(o1);
43
		String titleCache2 = getTitleCache(o2);
44
		if (titleCache1 == null && titleCache2 == null) {
45
			return 0;
46
		}
47
		if (titleCache1 == null) {
48
			return -1;
49
		}
50
		if (titleCache2 == null) {
51
			return 1;
52
		}				
53
        return fIgnoreCase ? titleCache1.compareToIgnoreCase(titleCache2) : 
54
        						titleCache1.compareTo(titleCache2);
55
	}
56
}
(13-13/18)