Skip to content

Commit 4a4fa48

Browse files
committed
Quickstart PMD analysis
./run.sh pmd -d /home/anit/work/codechallenge-java-pom/src/main/java/hackerrank/api -f text -R rulesets/java/quickstart.xml --cache /tmp/codechallenge-pmd-analysis | more PMD violation messages can be suppressed with @SuppressWarnings("PMD.VIOLATION_CLASS")
1 parent 1c707e9 commit 4a4fa48

File tree

4 files changed

+15
-19
lines changed

4 files changed

+15
-19
lines changed

src/main/java/hackerrank/api/BarcodeReader.java

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,10 @@
1212

1313
public class BarcodeReader {
1414

15-
private static final String TAG = HttpHandler.class.getSimpleName();
15+
private final static String TAG = HttpHandler.class.getSimpleName();
1616
private final static Logger logger =
1717
Logger.getLogger(Logger.GLOBAL_LOGGER_NAME);
18-
private final String barcodeURI = "https://jsonmock.hackerrank.com/api/inventory?barcode=";
19-
private Inventory inventory;
18+
private final static String barcodeURI = "https://jsonmock.hackerrank.com/api/inventory?barcode=";
2019

2120
public Inventory read(int barcode)
2221
throws BarcodeNotFoundException {
@@ -30,15 +29,22 @@ public Inventory read(int barcode)
3029
inventories = getInventories(inventoryJSONString);
3130

3231
} catch (MalformedURLException e) {
33-
logger.log(Level.WARNING, TAG + " MalformedURLException: " + e.getMessage());
32+
if (logger.isLoggable(Level.SEVERE)) {
33+
logger.log(Level.SEVERE, TAG + " MalformedURLException: " + e.getMessage());
34+
}
3435
} catch (IOException e) {
35-
logger.log(Level.WARNING, TAG + " IOException: " + e.getMessage());
36+
if (logger.isLoggable(Level.SEVERE)) {
37+
logger.severe(TAG + " IOException: " + e.getMessage());
38+
}
3639
} catch (Exception e) {
37-
logger.log(Level.WARNING, TAG + " Exception: " + e.getMessage());
40+
if (logger.isLoggable(Level.SEVERE)) {
41+
logger.severe(TAG + " Exception: " + e.getMessage());
42+
}
3843
}
3944

40-
if ( inventories.length == 0 )
45+
if ( inventories.length == 0 ) {
4146
throw new BarcodeNotFoundException("Barcode Not Found!");
47+
}
4248

4349
return inventories[0];
4450
}

src/main/java/hackerrank/api/HttpRequests.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@
55
import java.net.HttpURLConnection;
66
import java.net.URL;
77

8-
class HttpRequests {
9-
8+
public abstract class HttpRequests {
109
public static InputStream get(String url)
1110
throws IOException {
1211
InputStream inputStream = null;

src/main/java/hackerrank/api/InputStreamConverter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import java.io.InputStream;
99
import java.io.InputStreamReader;
1010

11-
class InputStreamConverter {
11+
public abstract class InputStreamConverter {
1212

1313
public static String toString(InputStream is) {
1414

src/main/java/hackerrank/api/Inventory.java

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,6 @@
11
package hackerrank.api;
22

3-
import com.sun.net.httpserver.HttpHandler;
4-
5-
import java.util.logging.Logger;
6-
73
public class Inventory {
8-
private final static Logger logger =
9-
Logger.getLogger(Logger.GLOBAL_LOGGER_NAME);
10-
private static final String TAG = HttpHandler.class.getSimpleName();
11-
12-
private final String URL = "https://jsonmock.hackerrank.com/api/inventory?barcode=";
134

145
String item;
156
int price;

0 commit comments

Comments
 (0)