Skip to content
This repository has been archived by the owner on Mar 3, 2020. It is now read-only.

Commit

Permalink
change digit checking to use idiomatic Character.isDigit()
Browse files Browse the repository at this point in the history
  • Loading branch information
trevor-e committed Mar 28, 2015
1 parent ceb7647 commit 269f1c8
Showing 1 changed file with 9 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public boolean accept(File pathname) {
//regex is slow, so checking char by char.
if (path.startsWith("cpu")) {
for (int i = 3; i < path.length(); i++) {
if (path.charAt(i) < '0' || path.charAt(i) > '9') {
if (!Character.isDigit(path.charAt(i))) {
return false;
}
}
Expand Down Expand Up @@ -85,11 +85,14 @@ public static int getCPUMaxFreqKHz() {
stream.read(buffer);
int endIndex = 0;
//Trim the first number out of the byte buffer.
while (buffer[endIndex] >= '0' && buffer[endIndex] <= '9'
&& endIndex < buffer.length) endIndex++;
while (Character.isDigit(buffer[endIndex]) && endIndex < buffer.length) {
endIndex++;
}
String str = new String(buffer, 0, endIndex);
Integer freqBound = Integer.parseInt(str);
if (freqBound > maxFreq) maxFreq = freqBound;
if (freqBound > maxFreq) {
maxFreq = freqBound;
}
} catch (NumberFormatException e) {
//Fall through and use /proc/cpuinfo.
} finally {
Expand Down Expand Up @@ -191,10 +194,10 @@ private static int parseFileForValue(String textToMatch, FileInputStream stream)
*/
private static int extractValue(byte[] buffer, int index) {
while (index < buffer.length && buffer[index] != '\n') {
if (buffer[index] >= '0' && buffer[index] <= '9') {
if (Character.isDigit(buffer[index])) {
int start = index;
index++;
while (index < buffer.length && buffer[index] >= '0' && buffer[index] <= '9') {
while (index < buffer.length && Character.isDigit(buffer[index])) {
index++;
}
String str = new String(buffer, 0, start, index - start);
Expand Down

0 comments on commit 269f1c8

Please sign in to comment.