Is this possible?
I have a function which accepts a user string and then splits into an array of words. I’m going to sort the array and de-duplicate it.
However, it will be used in a function which is called in an iterative step. It actually iterates over a database and checks for each word in the user defines string in each field.
I would like to only sort and de-dup the array once but call the function many for that particular instance of the class. Should I just store the sorted array in a static instance variable?
Thanks for your time
My code is something like this (pseudo-code):
public class searchAssistant{
private float mScores[][];
private Cursor mCursor;
public searchAssistant(Cursor c){
mCursor = c;
}
private float scoreType1(String typeFromCursor, String typeFromUser){
if (typeFromCursor == typeFromUser) {return 1}
else {return 0}
}
//similar method for type scoreType2 but sorting an array
private int[] scoreAll(){
int 1 = 0;
do {
mScores = ScoreType1(mCursor.getString(), smomeString) + scoreType2(...);
itr++;
} while(cursor.moveToNext)
return mScores;
}
}
is this the wrong way to be doing things?
No. Change the signature of the method called multiple times to make it accept the array, and compute the array before calling the method:
Instead of
Use something like this: