Count the number of pictures

Asked by Ju1+i-我.

        while (true) {
            s.wait(1.1);
            if (s.exists(s1.prop("sm378")) != null) {
                s.wait(1.1);
                List<Match> a378 = (List<Match>) s.findAll(s1.prop("sm378"));
                count = count + a378.size() ;
            }
            else{
                count = count + 0;
                s.wait(1.1);
            }
            if (s.exists(s1.prop("summary")) != null) {
                break;
            }else {
                s.wait(1.1);
                s.type(Key.F11,Key.SHIFT);
                s.wait(1.1) ;
            }
        }

Exception in thread "main" java.lang.ClassCastException: org.sikuli.script.Finder cannot be cast to java.util.List

how to solve this problem?

Question information

Language:
English Edit question
Status:
Solved
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Solved by:
Ju1+i-我.
Solved:
Last query:
Last reply:
Revision history for this message
RaiMan (raimund-hocke) said :
#1

Your Java IDE should have told you, that Region::findAll() returns java.util.Iterator<Match> and not List<Match>.

Revision history for this message
Ju1+i-我. (1ju2+i-a.) said :
#2

     if (s.exists(s1.prop("sm37")) != null) {
      System.out.println("Blank");
      }
     else{
         int count = 0;
         while (true) {
             if (s.exists(s1.prop("sm378")) != null) {
                 s.wait(0.5);
                 Iterator<Match> a = s.findAll(s1.prop("sm378"));
                 count = count + fu.getsizeofIterator(a);
                 System.out.println("continue");
             }
             else{
                 count = count + 0;
             }
             if (s.exists(s1.prop("sm379")) != null) {
              System.out.println("Not find");
                 break;
             }
             else {
                 System.out.println("True");
                 s.type(Key.F11,Key.SHIFT);
             }
         }

i need to count the number of pictures :s1.prop("sm378")

count = count + fu.getsizeofIterator(a); ----- This sentence is not carried out

could you please tell me how to solve this ?

Revision history for this message
RaiMan (raimund-hocke) said :
#3

--- fu.getsizeofIterator(a)
it looks like
int getsizeofIterator(Iterator<Match> a) {}
is some method in class/object fu to evaluate and return the count

like this:
public int getsizeofIterator(Iterator<Match> a) {
  int count = 0;
  if (null != a && a.hasNext()) {
    while (a.hasNext()) {
      a.next()
      count++;
    }
  }
  return count;
}

Revision history for this message
Ju1+i-我. (1ju2+i-a.) said :
#4

thx for your answer ,

public int getsizeofIterator(Iterator<Match> a) {
  int count = 0;
  if (null != a && a.hasNext()) {
    while (a.hasNext()) {
      a.next()
      count++;
    }
  }
  return count;
}

Pattern st = new Pattern(s1.prop("sm378")).similar((float) 0.99);
     if (s.exists(s1.prop("sm37")) != null) {
      System.out.println("Blank");
      }
     else{
         int count = 0;
         while (true) {
             if (s.exists(st) != null) {
                 s.wait(0.5);
                 Iterator<Match> a = s.findAll(s1.prop("sm378"));
                 count = count + fu.getsizeofIterator(a);

             }
             else{
                 count = count + 0;
             }
             if (s.exists(s1.prop("sm379")) != null) {
                 break;
             }
             else {
                 s.type(Key.F11,Key.SHIFT);
             }
         }

i used this , but result is not ideal . the actual number is 2, but the result of the execution is 10, could you please help to look further ?

Revision history for this message
RaiMan (raimund-hocke) said :
#5

It finds more then the 2 you expect, because of standard similarity score of 0.7.

Either use:
s.findAll(new Pattern(s1.prop("sm378")).similar(0.99)) //adjust as needed

or filter the matches in the def:

    while (a.hasNext()) {
      Match match = a.next();
      if (match.getScore() < 0.95) break;
      count++;
    }

Revision history for this message
Ju1+i-我. (1ju2+i-a.) said :
#6

thx a lot !!!