diff --git a/src/main/java/gov/cms/madie/cql_elm_translator/dto/CqlBuilderLookup.java b/src/main/java/gov/cms/madie/cql_elm_translator/dto/CqlBuilderLookup.java index 59985c4..b30b82e 100644 --- a/src/main/java/gov/cms/madie/cql_elm_translator/dto/CqlBuilderLookup.java +++ b/src/main/java/gov/cms/madie/cql_elm_translator/dto/CqlBuilderLookup.java @@ -5,6 +5,8 @@ import java.util.Set; +import org.apache.commons.lang3.StringUtils; + @Data @Builder public class CqlBuilderLookup { @@ -21,5 +23,20 @@ public static class Lookup { private String libraryAlias; private String logic; private int startLine; + + @Override + public boolean equals(Object o) { + if (o == this) { + return true; + } + CqlBuilderLookup.Lookup lookup = (CqlBuilderLookup.Lookup) o; + + if (StringUtils.equals(lookup.getName(), this.getName()) + && StringUtils.equals(lookup.getLibraryAlias(), this.getLibraryAlias()) + && lookup.getLibraryName().equals(this.getLibraryName())) { + return true; + } + return false; + } } } diff --git a/src/main/java/gov/cms/madie/cql_elm_translator/dto/CqlBuilderLookupComparator.java b/src/main/java/gov/cms/madie/cql_elm_translator/dto/CqlBuilderLookupComparator.java new file mode 100644 index 0000000..3350987 --- /dev/null +++ b/src/main/java/gov/cms/madie/cql_elm_translator/dto/CqlBuilderLookupComparator.java @@ -0,0 +1,32 @@ +package gov.cms.madie.cql_elm_translator.dto; + +import java.util.Comparator; + +import org.apache.commons.lang3.StringUtils; + +import lombok.extern.slf4j.Slf4j; + +@Slf4j +public class CqlBuilderLookupComparator implements Comparator { + + /*** + * This is required because the name/line numbers can conflict between line + * numbers + */ + public int compare(CqlBuilderLookup.Lookup lookup1, CqlBuilderLookup.Lookup lookup2) { + + int result; + + if (StringUtils.equalsIgnoreCase(lookup1.getName(), lookup2.getName()) + && StringUtils.equalsIgnoreCase(lookup1.getLibraryAlias(), lookup2.getLibraryAlias())) { + result = 0; + } else if (lookup1.getStartLine() == lookup2.getStartLine()) { + // if the names are different but the lines are the same + result = lookup1.getStartLine() - lookup2.getStartLine() + 1; + } else { + result = lookup1.getStartLine() - lookup2.getStartLine(); + } + + return result; + } +}