-
Notifications
You must be signed in to change notification settings - Fork 101
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0cc1833
commit f6789c8
Showing
6 changed files
with
268 additions
and
177 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
30 changes: 0 additions & 30 deletions
30
...a/org/mobilitydata/gtfsvalidator/outputcomparator/io/MemoryUsageUsedMemoryComparator.java
This file was deleted.
Oops, something went wrong.
57 changes: 57 additions & 0 deletions
57
...ava/org/mobilitydata/gtfsvalidator/outputcomparator/io/UsedMemoryIncreasedComparator.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,57 @@ | ||
package org.mobilitydata.gtfsvalidator.outputcomparator.io; | ||
|
||
import java.util.Comparator; | ||
import java.util.HashSet; | ||
import java.util.Map; | ||
import java.util.Set; | ||
|
||
/** | ||
* Comparator to compare two {@link DatasetMemoryUsage} objects based on the difference between the | ||
* used memory of the two objects. The difference is calculated by comparing the used memory of the | ||
* two objects for each key present in both objects. If a key is present in one object but not in | ||
* the other, the key it is ignored. This comparator is used to sort DatasetMemoryUsage by the | ||
* minimum difference between the used memory of the two. This means the order is by the dataset | ||
* validation that increased the memory. | ||
*/ | ||
public class UsedMemoryIncreasedComparator implements Comparator<DatasetMemoryUsage> { | ||
|
||
@Override | ||
public int compare(DatasetMemoryUsage o1, DatasetMemoryUsage o2) { | ||
if (o1 == o2) { | ||
return 0; | ||
} | ||
if (o1 == null || o2 == null) { | ||
return o1 == null ? -1 : 1; | ||
} | ||
if (o1.getReferenceMemoryUsage() == null && o2.getLatestMemoryUsage() == null) { | ||
return 0; | ||
} | ||
if (o1.getReferenceMemoryUsage() == null || o2.getLatestMemoryUsage() == null) { | ||
return o1.getReferenceMemoryUsage() == null ? -1 : 1; | ||
} | ||
|
||
long o1MinDiff = | ||
getMinimumDifferenceByKey(o1.getReferenceUsedMemoryByKey(), o1.getLatestUsedMemoryByKey()); | ||
long o2MinDiff = | ||
getMinimumDifferenceByKey(o2.getReferenceUsedMemoryByKey(), o2.getLatestUsedMemoryByKey()); | ||
return Long.compare(o1MinDiff, o2MinDiff); | ||
} | ||
|
||
private long getMinimumDifferenceByKey( | ||
Map<String, Long> referenceMemoryUsage, Map<String, Long> latestMemoryUsage) { | ||
Set<String> keys = new HashSet<>(); | ||
keys.addAll(latestMemoryUsage.keySet()); | ||
keys.addAll(referenceMemoryUsage.keySet()); | ||
return keys.stream() | ||
.filter(key -> latestMemoryUsage.containsKey(key) && referenceMemoryUsage.containsKey(key)) | ||
.filter(key -> latestMemoryUsage.get(key) - referenceMemoryUsage.get(key) != 0) | ||
.mapToLong(key -> referenceMemoryUsage.get(key) - latestMemoryUsage.get(key)) | ||
.min() | ||
.orElse(Long.MAX_VALUE); | ||
} | ||
|
||
@Override | ||
public Comparator<DatasetMemoryUsage> reversed() { | ||
return Comparator.super.reversed(); | ||
} | ||
} |
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
Oops, something went wrong.