From 943a47187dbb1393d720b2fdf0019d48270edb4d Mon Sep 17 00:00:00 2001 From: PawelSzalapski Date: Thu, 21 Jun 2018 12:12:30 +0200 Subject: Remove dead code from VESCollector Many things there are unused or have inproper modifiers, spelling etc. I run static analysis tool (Intellij code inspect) and clear those things up. It will be easier to maintain now. No actual behavior changes were done. Issue-ID: DCAEGEN2-526 Signed-off-by: PawelSzalapski Change-Id: I1a4ad0c896bd32165cba654344ffc5245648c615 --- .../onap/dcae/commonFunction/ConfigProcessors.java | 40 +++++++++------------- 1 file changed, 16 insertions(+), 24 deletions(-) (limited to 'src/main/java/org/onap/dcae/commonFunction/ConfigProcessors.java') diff --git a/src/main/java/org/onap/dcae/commonFunction/ConfigProcessors.java b/src/main/java/org/onap/dcae/commonFunction/ConfigProcessors.java index 80a65f08..a6de0fc8 100644 --- a/src/main/java/org/onap/dcae/commonFunction/ConfigProcessors.java +++ b/src/main/java/org/onap/dcae/commonFunction/ConfigProcessors.java @@ -29,7 +29,7 @@ import org.slf4j.LoggerFactory; public class ConfigProcessors { - private static Logger log = LoggerFactory.getLogger(ConfigProcessors.class); + private static final Logger log = LoggerFactory.getLogger(ConfigProcessors.class); private static final String FIELD = "field"; private static final String OLD_FIELD = "oldField"; private static final String FILTER = "filter"; @@ -39,7 +39,7 @@ public class ConfigProcessors { private static final String FILTER_NOT_MET = "Filter not met"; private static final String COMP_FALSE = "==false"; - private JSONObject event; + private final JSONObject event; public ConfigProcessors(JSONObject eventJson) { event = eventJson; @@ -170,7 +170,7 @@ public class ConfigProcessors { private String performOperation(String operation, String value) { log.info("performOperation"); - if (operation != null && "convertMBtoKB".equals(operation)) { + if ("convertMBtoKB".equals(operation)) { float kbValue = Float.parseFloat(value) * 1024; value = String.valueOf(kbValue); } @@ -184,7 +184,7 @@ public class ConfigProcessors { final String oldField = jsonObject.getString(OLD_FIELD); final JSONObject filter = jsonObject.optJSONObject(FILTER); final String operation = jsonObject.optString("operation"); - String value = ""; + String value; if (filter == null || isFilterMet(filter)) { value = getEventObjectVal(oldField).toString(); @@ -267,19 +267,19 @@ public class ConfigProcessors { final JSONArray values = jsonObject.getJSONArray("concatenate"); final JSONObject filter = jsonObject.optJSONObject(FILTER); if (filter == null || isFilterMet(filter)) { - String value = ""; + StringBuilder value = new StringBuilder(); for (int i = 0; i < values.length(); i++) { String tempVal = evaluate(values.getString(i)); if (!tempVal.equals(OBJECT_NOT_FOUND)) { if (i == 0) - value = value + tempVal; + value.append(tempVal); else - value = value + delimiter + tempVal; + value.append(delimiter).append(tempVal); } } - setEventObjectVal(field, value); + setEventObjectVal(field, value.toString()); } else log.info(FILTER_NOT_MET); } @@ -323,8 +323,6 @@ public class ConfigProcessors { private boolean checkFilter(JSONObject jo, String key, String logicKey) { String filterValue = jo.getString(key); - boolean retVal = true; - if (filterValue.contains(":")) { String[] splitVal = filterValue.split(":"); if ("matches".equals(splitVal[0])) { @@ -368,26 +366,21 @@ public class ConfigProcessors { } } } - return retVal; + return true; } public boolean isFilterMet(JSONObject jo) { - boolean retval = true; - for (String key : jo.keySet()) { if ("not".equals(key)) { JSONObject njo = jo.getJSONObject(key); for (String njoKey : njo.keySet()) { - - retval = checkFilter(njo, njoKey, key); - if (!retval) - return retval; + if (!checkFilter(njo, njoKey, key)) + return false; } } else { - retval = checkFilter(jo, key, key); - if (!retval) - return retval; + if (!checkFilter(jo, key, key)) + return false; } } return true; @@ -407,17 +400,16 @@ public class ConfigProcessors { keySeriesStr = keySeriesStr.substring(0, keySeriesStr.length() - 1); String[] keySet = keySeriesStr.split("\\.", keySeriesStr.length()); Object keySeriesObj = event; - for (int i = 0; i < (keySet.length); i++) { - + for (String aKeySet : keySet) { if (keySeriesObj != null) { if (keySeriesObj instanceof String) { log.info("STRING==" + keySeriesObj); } else if (keySeriesObj instanceof JSONArray) { - keySeriesObj = ((JSONArray) keySeriesObj).optJSONObject(Integer.parseInt(keySet[i])); + keySeriesObj = ((JSONArray) keySeriesObj).optJSONObject(Integer.parseInt(aKeySet)); } else if (keySeriesObj instanceof JSONObject) { - keySeriesObj = ((JSONObject) keySeriesObj).opt(keySet[i]); + keySeriesObj = ((JSONObject) keySeriesObj).opt(aKeySet); } else { log.info("unknown object==" + keySeriesObj); -- cgit 1.2.3-korg