MCPcopy Create free account
hub / github.com/SeleniumHQ/selenium / compare

Method compare

java/src/org/openqa/selenium/docker/Version.java:92–108  ·  view source on GitHub ↗
(String[] ours, String[] theirs, int index)

Source from the content-addressed store, hash-verified

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);

Callers 4

equalToMethod · 0.95
isLessThanMethod · 0.95
isGreaterThanMethod · 0.95
compareToMethod · 0.45

Calls 4

isNumericMethod · 0.95
parseNumberMethod · 0.95
isEmptyMethod · 0.45
compareToMethod · 0.45

Tested by

no test coverage detected