Commit 63532094 authored by monireh sanaei's avatar monireh sanaei

Some minor changes

parent fd4415a6
......@@ -12,19 +12,6 @@ public class DBParserOpenFoodFacts implements DBParser {
if(!entry.contains(NO_PRODUCTS)) {
int nbProductsStart = entry.indexOf(PARAGRAPH) + PARAGRAPH.length();
int nbProductsEnd = entry.indexOf(" ");
String nbProductsString = entry.substring(nbProductsStart, nbProductsEnd);
int nbProducts = 0;
try {
nbProducts = Integer.parseInt(nbProductsString);
} catch(NumberFormatException e){
System.out.println(e.getStackTrace());
}
System.out.println("Number of products : " + nbProducts);
int codeSearchIndex = 0;
int codeStartIndex = 0;
int codeEndIndex = 0;
......@@ -62,4 +49,4 @@ public class DBParserOpenFoodFacts implements DBParser {
}
return productResults;
}
}
\ No newline at end of file
}
public class CDBParserOpenFoodFacts implements DBParser {
/*
* This class parses the response to Get requests from the OpenFoodFacts database.
*/
public class CDBParserOpenFoodFacts implements DBParserInterface {
public static final String Const_NO_PRODUCTS = "No products";
public static final String Const_CODE = "code";
......@@ -12,19 +15,6 @@ public class CDBParserOpenFoodFacts implements DBParser {
if(!inString.contains(Const_NO_PRODUCTS)) {
int iNbProductsStart = inString.indexOf(Const_PARAGRAPH) + Const_PARAGRAPH.length();
int iNbProductsEnd = inString.indexOf(" ");
String sNbProductsString = inString.substring(iNbProductsStart, iNbProductsEnd);
int iNbProducts = 0;
try {
iNbProducts = Integer.parseInt(sNbProductsString);
} catch(NumberFormatException e){
System.out.println(e.getStackTrace());
}
System.out.println("Number of products : " + iNbProducts);
int iCodeSearchIndex = 0;
int iCodeStartIndex = 0;
int iCodeEndIndex = 0;
......@@ -36,8 +26,10 @@ public class CDBParserOpenFoodFacts implements DBParser {
int indexOfCode = -1;
int indexOfTitle = -1;
//To search for the occurrence of "code" and "title"
while (indexOfCode != inString.lastIndexOf(Const_CODE) && indexOfTitle != inString.lastIndexOf(Const_TITLE)) {
//To parse the bar codes
indexOfCode = inString.indexOf(Const_CODE, iCodeSearchIndex);
iCodeStartIndex = indexOfCode + Const_CODE.length() + 1;
......@@ -45,8 +37,10 @@ public class CDBParserOpenFoodFacts implements DBParser {
String sBarcode = inString.substring(iCodeStartIndex, iCodeEndIndex);
//To update the "code" search index
iCodeSearchIndex = iCodeEndIndex + 1;
//To parse the titles
indexOfTitle = inString.indexOf(Const_TITLE, iTitleSearchIndex);
iTitleStartIndex = indexOfTitle + Const_TITLE.length() + 3;
......@@ -57,9 +51,10 @@ public class CDBParserOpenFoodFacts implements DBParser {
productHashMap.put(sBarcode, new Product(sBarcode, sProductName, title));
//To update the "title" search index
iTitleSearchIndex = iTitleEndIndex + 1;
}
}
return productHashMap;
}
}
\ No newline at end of file
}
/*
* This class initializes a thread poolService with a fixed size in order to
* execute http connections to communicate with a given database.
*/
public class LkpCli {
public static final int PL_SZ = 100;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment