MCPcopy Index your code
hub / github.com/arduino/Arduino / compare

Method compare

arduino-core/src/processing/app/SerialPortList.java:80–121  ·  view source on GitHub ↗
(String valueA, String valueB)

Source from the content-addressed store, hash-verified

78 private static final Comparator<String> PORTNAMES_COMPARATOR = new Comparator<String>() {
79
80 @Override
81 public int compare(String valueA, String valueB) {
82
83 if(valueA.equalsIgnoreCase(valueB)){
84 return valueA.compareTo(valueB);
85 }
86
87 int minLength = Math.min(valueA.length(), valueB.length());
88
89 int shiftA = 0;
90 int shiftB = 0;
91
92 for(int i = 0; i < minLength; i++){
93 char charA = valueA.charAt(i - shiftA);
94 char charB = valueB.charAt(i - shiftB);
95 if(charA != charB){
96 if(Character.isDigit(charA) && Character.isDigit(charB)){
97 int[] resultsA = getNumberAndLastIndex(valueA, i - shiftA);
98 int[] resultsB = getNumberAndLastIndex(valueB, i - shiftB);
99
100 if(resultsA[0] != resultsB[0]){
101 return resultsA[0] - resultsB[0];
102 }
103
104 if(valueA.length() < valueB.length()){
105 i = resultsA[1];
106 shiftB = resultsA[1] - resultsB[1];
107 }
108 else {
109 i = resultsB[1];
110 shiftA = resultsB[1] - resultsA[1];
111 }
112 }
113 else {
114 if(Character.toLowerCase(charA) - Character.toLowerCase(charB) != 0){
115 return Character.toLowerCase(charA) - Character.toLowerCase(charB);
116 }
117 }
118 }
119 }
120 return valueA.compareToIgnoreCase(valueB);
121 }
122
123 /**
124 * Evaluate port <b>index/number</b> from <b>startIndex</b> to the number end. For example:

Callers

nothing calls this directly

Calls 3

getNumberAndLastIndexMethod · 0.95
compareToMethod · 0.80
minMethod · 0.80

Tested by

no test coverage detected