← Back to team overview

sikuli-driver team mailing list archive

Re: [Question #160030]: String returned from findAll() function are not in order of their occurrence in Screen

 

Question #160030 on Sikuli changed:
https://answers.launchpad.net/sikuli/+question/160030

RaiMan posted a new comment:
How to sort matches returned by findAll() in Java?

Step 1:
collect the matches into an array (aMatches in this example) with a for loop using hasNext()/next()

Step 2:
define a comparator function based on the Comparator interface (example for sorting by the y coordinates):

public class MatchComparatorY implements Comparator<Match>{
    public int compare( Match a, Match b ) {
        if( a.y < b.y )
            return -1;
        if( a.y > b.y )
            return 1;          
        return 0;
    }

Step 3:
sort the array of matches (aMatches in this example):

Comparator<Match> comparator = new MatchComparatorY();
java.util.Collections.sort( aMatches, comparator );

-- 
You received this question notification because you are a member of
Sikuli Drivers, which is an answer contact for Sikuli.