cleanup
[cdm-vaadin.git] / src / main / java / eu / etaxonomy / cdm / vaadin / debug / CdmEntityInfoSorter.java
1 /**
2 * Copyright (C) 2018 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 package eu.etaxonomy.cdm.vaadin.debug;
10
11 import com.vaadin.data.Container.Sortable;
12 import com.vaadin.data.util.ItemSorter;
13
14 import eu.etaxonomy.cdm.cache.EntityCacherDebugResult.CdmEntityInfo;
15
16 /**
17 * @author a.kohlbecker
18 * @since Jan 23, 2018
19 *
20 */
21 public class CdmEntityInfoSorter implements ItemSorter {
22
23 private static final long serialVersionUID = 1008554008146041297L;
24
25 private Object[] propertyId;
26 private boolean[] ascending;
27
28 @Override
29 public void setSortProperties(Sortable container, Object[] propertyId, boolean[] ascending) {
30 this.propertyId = propertyId;
31 this.ascending = ascending;
32
33 }
34
35 @Override
36 public int compare(Object itemId1, Object itemId2) {
37 if(! (itemId1 instanceof CdmEntityInfo && itemId2 instanceof CdmEntityInfo) ){
38 throw new RuntimeException("Objects must be CdmEntityInfo");
39 }
40 CdmEntityInfo infoItem1 = (CdmEntityInfo)itemId1;
41 CdmEntityInfo infoItem2 = (CdmEntityInfo)itemId2;
42
43 return infoItem1.getField().getName().compareToIgnoreCase(infoItem2.getField().getName());
44 }
45 }