-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #21 from MeasureAuthoringTool/MAT-7897_FhirOrderin…
…gDuplicates MAT-7897: Fixing equals check so that libraries aren't discarded when…
- Loading branch information
Showing
10 changed files
with
422 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
src/main/java/gov/cms/madie/cql_elm_translator/dto/CqlBuilderLookupComparator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<T> implements Comparator<CqlBuilderLookup.Lookup> { | ||
|
||
/*** | ||
* 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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
85 changes: 85 additions & 0 deletions
85
src/test/java/gov/cms/madie/cql_elm_translator/dto/CqlBuilderLookupComparatorTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
package gov.cms.madie.cql_elm_translator.dto; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
import java.util.Set; | ||
import java.util.TreeSet; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
class CqlBuilderLookupComparatorTest { | ||
|
||
@Test | ||
void testAddOne() { | ||
|
||
CqlBuilderLookup.Lookup lookup = | ||
CqlBuilderLookup.Lookup.builder() | ||
.name("SDE Race") | ||
.libraryAlias("SDE") | ||
.libraryName("Supplemental Data") | ||
.startLine(11) | ||
.build(); | ||
|
||
Set<CqlBuilderLookup.Lookup> definitions = | ||
new TreeSet<CqlBuilderLookup.Lookup>( | ||
new CqlBuilderLookupComparator<CqlBuilderLookup.Lookup>()); | ||
|
||
definitions.add(lookup); | ||
assertEquals(definitions.size(), 1); | ||
} | ||
|
||
@Test | ||
void testAddTwoIdentical() { | ||
|
||
CqlBuilderLookup.Lookup lookup = | ||
CqlBuilderLookup.Lookup.builder() | ||
.name("SDE Race") | ||
.libraryAlias("SDE") | ||
.libraryName("Supplemental Data") | ||
.startLine(11) | ||
.build(); | ||
|
||
CqlBuilderLookup.Lookup lookup2 = | ||
CqlBuilderLookup.Lookup.builder() | ||
.name("SDE Race") | ||
.libraryAlias("SDE") | ||
.libraryName("Supplemental Data") | ||
.startLine(11) | ||
.build(); | ||
|
||
Set<CqlBuilderLookup.Lookup> definitions = | ||
new TreeSet<CqlBuilderLookup.Lookup>( | ||
new CqlBuilderLookupComparator<CqlBuilderLookup.Lookup>()); | ||
|
||
definitions.add(lookup); | ||
definitions.add(lookup2); | ||
assertEquals(definitions.size(), 1); | ||
} | ||
|
||
@Test | ||
void testSameNameDifferentAlias() { | ||
|
||
CqlBuilderLookup.Lookup lookup = | ||
CqlBuilderLookup.Lookup.builder() | ||
.name("SDE Race") | ||
.libraryAlias("SDE") | ||
.libraryName("Supplemental Data") | ||
.startLine(11) | ||
.build(); | ||
|
||
CqlBuilderLookup.Lookup lookup2 = | ||
CqlBuilderLookup.Lookup.builder() | ||
.name("SDE Race") | ||
.libraryName("Supplemental Data") | ||
.startLine(11) | ||
.build(); | ||
|
||
Set<CqlBuilderLookup.Lookup> definitions = | ||
new TreeSet<CqlBuilderLookup.Lookup>( | ||
new CqlBuilderLookupComparator<CqlBuilderLookup.Lookup>()); | ||
|
||
definitions.add(lookup); | ||
definitions.add(lookup2); | ||
assertEquals(2, definitions.size()); | ||
} | ||
} |
Oops, something went wrong.