I have a recipe, a list of Strings and int, which they are been recognized from an image.
String elementText = "";
for (Text.Element element : line.getElements()) {
elementText = element.getText();
Point[] elementCornerPoints = element.getCornerPoints();
Rect elementFrame = element.getBoundingBox();
checkObject(elementText);
But, when i do Log.d, i get only strings:
private void checkObject(Object obj) {
if(obj instanceof Integer){
Log.d("log int", String.valueOf(obj));
Log.d("log int", "it's a number");
}
else if(obj instanceof String){
Log.d("log string", (String)obj);
Log.d("log string", "it's a string");
}
}
10:21:40.532 D oil
10:21:40.532 D it's a string
10:21:40.534 D garlic
10:21:40.534 D it's a string
10:21:40.537 D oregan
10:21:40.537 D it's a string
10:21:40.545 D 50
10:21:40.545 D it's a string
10:21:40.545 D g
10:21:40.545 D it's a string
10:21:40.545 D 120
10:21:40.545 D it's a string
I was looking to separate them in 1 arraylist with 2 parameters, (string, int).
Do you think i need to create an arraylist instead of declaring elementText
as string?
Update
I also tried this, first part of code works great check()
with output:
22:25:56.675 D List [1, 2, 120, 50]
function IsInt_ByRegex
is still giving int as string:
private void check(String elementText){
try{
int num = Integer.parseInt(this.elementText);
// is an integer!
Log.d("LOG int", "int " + num);
list.add(num);
Log.d("LOG int", "List " + list); //List [1, 2, 120, 50]
} catch (NumberFormatException e) {
// not an integer!
}
}
private void IsInt_ByRegex(String elementText) {
try{
elementText.matches("/\\{[a-zA-Z]+\\}/");
Log.d("LOG string", "string " + elementText);
}catch (Exception e){
}
}
Output:
22:25:56.674 D string 50
22:25:56.649 D string red
22:25:56.649 D string peppers
22:25:56.654 D string 120