Related To ISSUE-42787:Apply new HQL formatting/style in
authorAtul Gaware <atul.gaware@openbravo.com>
Tue, 14 Jan 2020 09:21:40 +0530
changeset 36941 23dacd16acaa
parent 36940 c84c0562635a
child 36942 d18ec79bbbf2
Related To ISSUE 42787:Apply new HQL formatting/style in
ManageVariantsDS, apply SonarLint suggestions

**Constant names to match reg. exp ^[A-Z][A-Z0-9]*(_[A-Z0-9]+)*$
**Use StringBuilder for few String variables like strChDesc,
searchKey and strKeyId
**Rename method parameters to match reg exp
^[a-z][a-zA-Z0-9]*$
** Use primitive type boolean instead of Boolean when using
condition part in ternary operator in return statement
src/org/openbravo/materialmgmt/ManageVariantsDS.java
--- a/src/org/openbravo/materialmgmt/ManageVariantsDS.java	Mon Jan 13 14:25:28 2020 +0530
+++ b/src/org/openbravo/materialmgmt/ManageVariantsDS.java	Tue Jan 14 09:21:40 2020 +0530
@@ -58,7 +58,7 @@
 public class ManageVariantsDS extends ReadOnlyDataSourceService {
 
   private static final Logger log = LogManager.getLogger();
-  private static final int searchKeyLength = getSearchKeyColumnLength();
+  private static final int SEARCH_KEY_LENGTH = getSearchKeyColumnLength();
   private static final String MANAGE_VARIANTS_TABLE_ID = "147D4D709FAC4AF0B611ABFED328FA12";
   private static final String ID_REFERENCE_ID = "13";
 
@@ -149,7 +149,7 @@
         throw new OBException("HighRecords");
       }
       totalMaxLength += Long.toString(variantNumber).length();
-      boolean useCodes = totalMaxLength <= searchKeyLength;
+      boolean useCodes = totalMaxLength <= SEARCH_KEY_LENGTH;
 
       boolean hasNext = true;
       int productNo = 0;
@@ -169,7 +169,7 @@
         variantMap.put("variantCreated", false);
         variantMap.put("obSelected", false);
 
-        String searchKey = product.getSearchKey();
+        StringBuilder searchKey = new StringBuilder().append(product.getSearchKey());
         for (i = 0; i < chNumber; i++) {
           ProductCharacteristicConf prChConf = currentValues[i];
           ProductCharacteristicAux prChConfAux = prChUseCode.get(prChs.get(i));
@@ -181,33 +181,33 @@
 
           if (useCodes && prChConfAux.isUseCode() && prChConf != null
               && StringUtils.isNotBlank(prChConf.getCode())) {
-            searchKey += "_" + prChConf.getCode() + "_";
+            searchKey.append("_" + prChConf.getCode() + "_");
           }
         }
         for (int j = 0; j < (Long.toString(variantNumber).length()
             - Integer.toString(productNo).length()); j++) {
-          searchKey += "0";
+          searchKey.append("0");
         }
-        searchKey += productNo;
+        searchKey.append(productNo);
         variantMap.put("searchKey", searchKey);
         //@formatter:off
         String hql = " as p "
                    + " where p.genericProduct = :product ";
         //@formatter:on
 
-        String strChDesc = "";
-        String strKeyId = "";
+        StringBuilder strChDesc = new StringBuilder();
+        StringBuilder strKeyId = new StringBuilder();
         JSONArray valuesArray = new JSONArray();
         for (i = 0; i < chNumber; i++) {
           ProductCharacteristicConf prChConf = currentValues[i];
           Characteristic characteristic = prChConf.getCharacteristicOfProduct().getCharacteristic();
           hql += buildExistsClause(i);
-          if (StringUtils.isNotBlank(strChDesc)) {
-            strChDesc += ", ";
+          if (StringUtils.isNotBlank(strChDesc.toString())) {
+            strChDesc.append(", ");
           }
-          strChDesc += characteristic.getName() + ":";
-          strChDesc += " " + prChConf.getCharacteristicValue().getName();
-          strKeyId += prChConf.getCharacteristicValue().getId();
+          strChDesc.append(characteristic.getName() + ":");
+          strChDesc.append(" " + prChConf.getCharacteristicValue().getName());
+          strKeyId.append(prChConf.getCharacteristicValue().getId());
           JSONObject value = new JSONObject();
           value.put("characteristic", characteristic.getId());
           value.put("characteristicValue", prChConf.getCharacteristicValue().getId());
@@ -382,17 +382,17 @@
     private String sortByField;
     private boolean ascending;
 
-    public ResultComparator(String _sortByField, boolean _ascending) {
-      sortByField = _sortByField;
-      ascending = _ascending;
+    public ResultComparator(String sortbyfield, boolean isascending) {
+      sortByField = sortbyfield;
+      ascending = isascending;
     }
 
     @Override
     public int compare(Map<String, Object> map1, Map<String, Object> map2) {
       boolean sortByChanged = false;
       if ("variantCreated".equals(sortByField)) {
-        Boolean o1 = (Boolean) map1.get(sortByField);
-        Boolean o2 = (Boolean) map2.get(sortByField);
+        boolean o1 = (boolean) map1.get(sortByField);
+        boolean o2 = (boolean) map2.get(sortByField);
         if (o1 == o2) {
           sortByField = "characteristicDescription";
           sortByChanged = true;
@@ -427,11 +427,11 @@
     private List<CharacteristicValue> filteredValues;
     private Iterator<ProductCharacteristicConf> iterator;
 
-    ProductCharacteristicAux(boolean _useCode, List<ProductCharacteristicConf> _values,
-        List<CharacteristicValue> _filteredValues) {
-      useCode = _useCode;
-      values = _values;
-      filteredValues = _filteredValues;
+    ProductCharacteristicAux(boolean usecode, List<ProductCharacteristicConf> valueslist,
+        List<CharacteristicValue> filteredvalues) {
+      useCode = usecode;
+      values = valueslist;
+      filteredValues = filteredvalues;
     }
 
     public boolean isUseCode() {