Merge branch 'hotfix/4.5.1'
[taxeditor.git] / eu.etaxonomy.taxeditor.bulkeditor / src / main / java / eu / etaxonomy / taxeditor / bulkeditor / input / sortprovider / TitleCacheComparator.java
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 * @version 1.0
22 */
23 public class TitleCacheComparator<T extends IIdentifiableEntity> implements Comparator<T> {
24
25 private boolean fIgnoreCase;
26
27 private String getTitleCache(T o) {
28 return o == null ? null : o.getTitleCache();
29 }
30
31 /* (non-Javadoc)
32 * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object)
33 */
34 /** {@inheritDoc} */
35 public int compare(T o1, T o2) {
36 String titleCache1 = getTitleCache(o1);
37 String titleCache2 = getTitleCache(o2);
38 if (titleCache1 == null && titleCache2 == null) {
39 return 0;
40 }
41 if (titleCache1 == null) {
42 return -1;
43 }
44 if (titleCache2 == null) {
45 return 1;
46 }
47 return fIgnoreCase ? titleCache1.compareToIgnoreCase(titleCache2) :
48 titleCache1.compareTo(titleCache2);
49 }
50 }