View Javadoc
1   /*
2    * Copyright 2018-2022 Medical Information Systems Research Group (https://medical.zcu.cz),
3    * Department of Computer Science and Engineering, University of West Bohemia.
4    * Address: Univerzitni 8, 306 14 Plzen, Czech Republic.
5    *
6    * Author Petr Vcelak (vcelak@kiv.zcu.cz).
7    *
8    * This file is part of MRECore project.
9    *
10   * MRECore is free software: you can redistribute it and/or modify
11   * it under the terms of the GNU General Public License as published by
12   * the Free Software Foundation, either version 3 of the License.
13   *
14   * MRECore is distributed in the hope that it will be useful,
15   * but WITHOUT ANY WARRANTY; without even the implied warranty of
16   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17   * GNU General Public License for more details.
18   *
19   * You should have received a copy of the GNU General Public License
20   * along with MRECore. If not, see <http://www.gnu.org/licenses/>.
21   */
22  package cz.zcu.mre.data.rdf;
23  
24  import java.io.Serializable;
25  import java.util.Comparator;
26  
27  /**
28   * Sort vocabulary items by it's annotation of property IBDT.ITEM_ID.
29   *
30   * @author Petr Vcelak (vcelak@kiv.zcu.cz)
31   */
32  public class ResourceWrapperComparator implements Comparator<ResourceWrapper>, Serializable {
33  
34      @Override
35      public int compare(ResourceWrapper rw1, ResourceWrapper rw2) {
36  
37          int compared = Integer.compare(rw1.getIntOrder(), rw2.getIntOrder());
38          if (compared != 0) {
39              return compared;
40          }
41  
42          if (rw1.getStringOrder() != null) {
43  
44              compared = rw1.getStringOrder().compareTo(rw2.getStringOrder());
45              if (compared != 0) {
46                  return compared;
47              }
48          } else {
49              return -1;
50          }
51  
52          if (rw1.getLabel() != null) {
53              compared = rw1.getLabel().compareTo(rw2.getLabel());
54              if (compared != 0) {
55                  return compared;
56              }
57          } else {
58              return -1;
59          }
60  
61          return rw1.getURI().compareTo(rw2.getURI());
62      }
63  }