From 269f1c8ab03799001de952512462ddd7d8e38adb Mon Sep 17 00:00:00 2001 From: Trevor Elkins Date: Sat, 28 Mar 2015 03:27:27 -0400 Subject: [PATCH] change digit checking to use idiomatic Character.isDigit() --- .../com/facebook/device/yearclass/DeviceInfo.java | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/yearclass/src/main/java/com/facebook/device/yearclass/DeviceInfo.java b/yearclass/src/main/java/com/facebook/device/yearclass/DeviceInfo.java index cd2932e..66714e3 100644 --- a/yearclass/src/main/java/com/facebook/device/yearclass/DeviceInfo.java +++ b/yearclass/src/main/java/com/facebook/device/yearclass/DeviceInfo.java @@ -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; } } @@ -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 { @@ -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);