Skip to content

Commit

Permalink
Remove overlapping entries in the sorting stage
Browse files Browse the repository at this point in the history
The html exporter used substrings to apply rules to the html output. If there was an overlap then the parts of the substring may repeat. No matter what the exporter, there would always be a need to handle overlaps. Overlaps happen frequently with ghunna vs idghaam vs meem idghaam see issue #11. In this workaround, overlaps are removed all together. Also, ghunna is given the least preference and is always removed. Doing this at the sorting level will help remove the need of handling this in any future exporters. .
  • Loading branch information
asimmohiuddin committed Jan 16, 2016
1 parent 4edc989 commit d6a2397
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/main/java/com/quran/tajweed/model/ResultUtil.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.quran.tajweed.model;

import java.util.ArrayList;
import java.util.List;

public class ResultUtil {
Expand All @@ -16,5 +17,22 @@ private ResultUtil() {
public void sort(List<Result> results) {
// note that this Comparator imposes an order inconsistent with equals
results.sort((o1, o2) -> o1.getMinimumStartingPosition() - o2.getMinimumStartingPosition());
// the following will delete portions of overlapping rules
List<Result> removeMe = new ArrayList<>();
for (int index = 1; index < results.size(); index++) {
Result result = results.get(index);
Result previousResult = results.get(index - 1);
int min = result.getMinimumStartingPosition();
int previousMax = previousResult.getMaximumEndingPosition();
if(previousMax > min){
if(previousResult.resultType.equals(ResultType.GHUNNA) || previousMax - min <= 0) {
removeMe.add(previousResult);
}
else {
previousResult.setMaximumEndingPosition(previousMax - (previousMax - min));
}
}
}
results.removeAll(removeMe);
}
}

0 comments on commit d6a2397

Please sign in to comment.