private int getMatchingPoint ( String pattern , String itemName ) { int index = pattern . indexOf ( ' ' ) ; if ( index == - 1 ) { return - 1 ; } String firstPart = pattern . substring ( 0 , index ) ; if ( ! itemName . startsWith ( firstPart ) ) { return - 1 ; } String secondPart = pattern . substring ( index + 1 ) ; if ( ! itemName . endsWith ( secondPart ) ) { return - 1 ; } return firstPart . length ( ) + secondPart . length ( ) ; }
This method returns the higher value the better the matching is .