Added documentation
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / model / DefaultTermComparator.java
1 // $Id$
2 /**
3 * Copyright (C) 2009 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 package eu.etaxonomy.taxeditor.model;
11
12 import java.util.Comparator;
13
14 import eu.etaxonomy.cdm.model.common.DefinedTermBase;
15 import eu.etaxonomy.taxeditor.store.CdmStore;
16
17 /**
18 * Implements a {@link Comparator} for {@link DefinedTermBase} objects based on the term's label.
19 * The compare algorithm compares a term's label. Example: If used on an unsorted list of terms, the
20 * list will be alphabetically sorted by label afterwards.
21 *
22 * @author n.hoffmann
23 * @date Jan 18, 2012
24 *
25 */
26 public class DefaultTermComparator<T extends DefinedTermBase> implements Comparator<T> {
27 @Override
28 public int compare(T o1, T o2) {
29 String label1 = o1.getLabel(CdmStore.getDefaultLanguage()) != null ? o1.getLabel(CdmStore.getDefaultLanguage()) : o1.getTitleCache();
30 String label2 = o2.getLabel(CdmStore.getDefaultLanguage()) != null ? o2.getLabel(CdmStore.getDefaultLanguage()) : o2.getTitleCache();
31 return label1.compareTo(label2);
32 }
33 };