(String[] ours, String[] theirs, int index)
| 90 | // argument is less than, equal to, or greater than the second. We attempt |
| 91 | // numerical comparisons first, and then a lexical comparison |
| 92 | private int compare(String[] ours, String[] theirs, int index) { |
| 93 | String mine = index < ours.length ? ours[index] : ""; |
| 94 | String others = index < theirs.length ? theirs[index] : ""; |
| 95 | boolean mineIsNumber = isNumeric(mine) || mine.isEmpty(); |
| 96 | boolean othersIsNumber = isNumeric(others) || others.isEmpty(); |
| 97 | |
| 98 | if (mineIsNumber && othersIsNumber) { |
| 99 | return parseNumber(mine).compareTo(parseNumber(others)); |
| 100 | } |
| 101 | if (mineIsNumber) { |
| 102 | return 1; |
| 103 | } |
| 104 | if (othersIsNumber) { |
| 105 | return -1; |
| 106 | } |
| 107 | return mine.compareTo(others); |
| 108 | } |
| 109 | |
| 110 | private boolean isNumeric(String value) { |
| 111 | return value.chars().allMatch(Character::isDigit); |
no test coverage detected