Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I966 results compare fixes #998

Merged
merged 6 commits into from
Aug 27, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
182 changes: 132 additions & 50 deletions src/edu/csus/ecs/pc2/core/StringUtilities.java

Large diffs are not rendered by default.

17 changes: 10 additions & 7 deletions src/edu/csus/ecs/pc2/core/imports/clics/FieldCompareRecord.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (C) 1989-2023 PC2 Development Team: John Clevenger, Douglas Lane, Samir Ashoo, and Troy Boudreau.
// Copyright (C) 1989-2024 PC2 Development Team: John Clevenger, Douglas Lane, Samir Ashoo, and Troy Boudreau.
package edu.csus.ecs.pc2.core.imports.clics;

import java.util.logging.Level;
Expand All @@ -13,7 +13,7 @@

/**
* Information about a comparison of two fields.
*
*
* @author Douglas A. Lane, PC^2 team [email protected]
*/
public class FieldCompareRecord {
Expand All @@ -39,7 +39,7 @@ public class FieldCompareRecord {
public FieldCompareRecord(String fieldName, String valueOne, String valueTwo, String details) {
this(fieldName, valueOne, valueTwo, details, null);
}

public FieldCompareRecord(String fieldName, String valueOne, String valueTwo, String details, String key) {
super();
this.fieldName = fieldName;
Expand All @@ -48,6 +48,9 @@ public FieldCompareRecord(String fieldName, String valueOne, String valueTwo, St
this.details = details;
this.key = key;

if(key == null) {
this.key = "any";
}
createComparisonState(valueOne, valueTwo);
}

Expand Down Expand Up @@ -106,18 +109,18 @@ public String getDetails() {
public void setDetails(String details) {
this.details = details;
}

public String getKey() {
return key;
}

public void setKey(String key) {
this.key = key;
}

/**
* Returns a JSON string representation of this SerializedFile object.
*
*
* @return a String containing a JSON representation of this object, or null if an error occurs during creation of the JSON string
*/
// TODO REFACTOR Move into a JSON Utility class
Expand All @@ -137,7 +140,7 @@ public String toJSON() {
return null;
}
}

@Override
public String toString() {
return toJSON();
Expand Down
31 changes: 24 additions & 7 deletions src/edu/csus/ecs/pc2/core/report/FieldCompareRecordComparator.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (C) 1989-2023 PC2 Development Team: John Clevenger, Douglas Lane, Samir Ashoo, and Troy Boudreau.
// Copyright (C) 1989-2024 PC2 Development Team: John Clevenger, Douglas Lane, Samir Ashoo, and Troy Boudreau.
package edu.csus.ecs.pc2.core.report;

import java.util.Comparator;
Expand All @@ -7,20 +7,37 @@
import edu.csus.ecs.pc2.core.imports.clics.FieldCompareRecord;

/**
* Compare by key then by fieldName.
*
* Compare by State (type of error), then key then by fieldName.
*
* @author Douglas A. Lane, PC^2 team [email protected]
*/
public class FieldCompareRecordComparator implements Comparator<FieldCompareRecord> {

@Override
public int compare(FieldCompareRecord o1, FieldCompareRecord o2) {

if (o1.getKey().equals(o2.getKey())) {
return StringUtilities.nullSafeCompareTo(o1.getFieldName(), o2.getFieldName());
} else {
return StringUtilities.nullSafeCompareTo(o1.getKey(), o2.getKey());
// Reverse sort by state number, since we want the non-matches first, then the missings.
int cmpResult = o2.getState().ordinal() - o1.getState().ordinal();
if(cmpResult == 0) {
String k1 = o1.getKey();
String k2 = o2.getKey();

// Paranoia with the keys
if(k1 == null){
if(k2 == null) {
return(0);
}
return(-1);
} else if(k2 == null) {
return(1);
}
if (o1.getKey().equals(o2.getKey())) {
cmpResult = StringUtilities.nullSafeNaturalCompareTo(o1.getFieldName(), o2.getFieldName(), false);
} else {
cmpResult = StringUtilities.nullSafeNaturalCompareTo(o1.getKey(), o2.getKey(), false);
}
}
return(cmpResult);
}

}
Loading
Loading