Skip to content

Commit

Permalink
Improved maintainability and reduced logical complexity (#1136)
Browse files Browse the repository at this point in the history
* Improved maintainability and reduced logical complexity.
  • Loading branch information
dukbong authored Apr 11, 2024
1 parent cc98249 commit dfbdda2
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 17 deletions.
41 changes: 24 additions & 17 deletions openpdf/src/main/java/com/lowagie/text/pdf/events/IndexEvents.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,26 +83,33 @@ public class IndexEvents extends PdfPageEventHelper {
* Comparator for sorting the index
*/
private Comparator<Entry> comparator = (en1, en2) -> {

int rt = 0;
if (en1.getIn1() != null && en2.getIn1() != null) {
if ((rt = en1.getIn1().compareToIgnoreCase(en2.getIn1())) == 0) {
// in1 equals
if (en1.getIn2() != null && en2.getIn2() != null) {
if ((rt = en1.getIn2()
.compareToIgnoreCase(en2.getIn2())) == 0) {
// in2 equals
if (en1.getIn3() != null && en2.getIn3() != null) {
rt = en1.getIn3().compareToIgnoreCase(
en2.getIn3());
}
}
}
}

int rt = compareStringsIgnoreCase(en1.getIn1(), en2.getIn1());

if (rt != 0) {
return rt;
}

rt = compareStringsIgnoreCase(en1.getIn2(), en2.getIn2());

if (rt != 0) {
return rt;
}
return rt;

// in2 equals
return compareStringsIgnoreCase(en1.getIn3(), en2.getIn3());
};

private int compareStringsIgnoreCase(String str1, String str2) {

if (str1 == null || str2 == null) {
return 0;
}

return str1.compareToIgnoreCase(str2);
}


/**
* All the text that is passed to this event, gets registered in the indexentry.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
*
*
*/

package com.lowagie.examples.fonts;

import com.lowagie.text.pdf.BaseFont;
Expand Down

0 comments on commit dfbdda2

Please sign in to comment.