001package org.hl7.fhir.r5.utils;
002
003import java.util.Comparator;
004
005import org.hl7.fhir.r5.model.CanonicalResource;
006
007public class ResourceSorters {
008
009  public static class CanonicalResourceSortByUrl implements Comparator<CanonicalResource> {
010
011    @Override
012    public int compare(CanonicalResource arg0, CanonicalResource arg1) {
013      if (arg0.getUrl() != null) {
014        return arg0.getUrl().compareTo(arg1.getUrl());        
015      } else if (arg1.getUrl() != null) {
016        return -arg1.getUrl().compareTo(arg0.getUrl());        
017      } else {
018        return 0;
019      }
020    }
021
022  }
023
024  public static class CanonicalResourceSortByTypeId implements Comparator<CanonicalResource> {
025
026    @Override
027    public int compare(CanonicalResource arg0, CanonicalResource arg1) {
028      int ret = arg0.fhirType().compareTo(arg1.fhirType());
029      if (ret == 0) {
030        ret = arg0.getId().compareTo(arg1.getId());
031      }
032      return ret;
033    }
034
035  }
036
037
038}