Skip to content

Commit b0b930d

Browse files
committed
fix6 for search to include all the meets
1 parent 2162ec9 commit b0b930d

File tree

2 files changed

+45
-32
lines changed
  • SuperiorPlugin/src/main/java/com/scrappers/superiorExtendedEngine/menuStates/uiPager
  • demoApp/src/main/java/com/myGame/JMESurfaceViewExampleActivity

2 files changed

+45
-32
lines changed

SuperiorPlugin/src/main/java/com/scrappers/superiorExtendedEngine/menuStates/uiPager/UiPager.java

+33-24
Original file line numberDiff line numberDiff line change
@@ -180,40 +180,49 @@ public void forEachUiState(UiStatesLooper.Modifiable.Looper uiStatesLooper){
180180
}
181181

182182
/**
183-
* Runs an anonymous asynchronous searching task function for some items inside a searchList based on a list of searchKeyWords.
183+
* Runs a searching task function for some items inside a searchList based on a list of searchKeyWords.
184184
* @param searchList the search list you want to traverse through, it should be parallel to the UiStates you want to update.
185185
* @param searchKeyWords the keywords you want to look for inside this search list.
186186
* @param injector injects what you want to do when an item is returned by the search engine.
187187
* @return a list of the founded strings from the searchList based on the search keywords.
188-
* @throws Exception throws an exception if the search custom thread fails.
189-
* @apiNote <b> <T extends Object> synchronized(T)</b> marks a thread-safe function by the dead locking other threads synchronized on the same object scheduled or started by the thread factory.
190188
*/
191-
public String[] search(String[] searchList, String[] searchKeyWords, ActionInjector injector) throws Exception {
192-
synchronized(this) {
193-
final String[][] resultList = {new String[0]};
194-
return Executors.callable(() -> {
195-
String[] temp;
196-
for (int i = 0; i < searchKeyWords.length; i++) {
197-
for (int j = 0; j < searchList.length; j++) {
198-
if (searchList[j].replaceAll(" ","").trim().toLowerCase().contains(
199-
searchKeyWords[i].replaceAll(" ","").trim().toLowerCase())) {
200-
//dynamic array conception
201-
if(i > resultList[0].length-1){
202-
temp = resultList[0];
203-
resultList[0] = new String[temp.length+1];
204-
for(int position=0; position < temp.length; position++){
205-
resultList[0][position] = temp[position];
189+
public String[] search(String[] searchList, String[] searchKeyWords, ActionInjector injector) {
190+
String[] resultList = new String[0];
191+
String[] temp;
192+
int index = 0;
193+
//loop over the main list items
194+
for (int i = 0; i < searchList.length; i++) {
195+
//loop over the search keywords
196+
for (String searchKeyWord : searchKeyWords) {
197+
if ( searchList[i].replaceAll(" ", "").trim().toLowerCase().contains(
198+
searchKeyWord.replaceAll(" ", "").trim().toLowerCase()) ){
199+
//dynamic array conception (expandable by 1 array) & index to keep track of the successful matched string literals
200+
if ( index > resultList.length - 1 ){
201+
//creating temp pointer producing a deep copy of resultList[0] array
202+
temp = resultList;
203+
//expanding the array through a new wider in size pointer
204+
resultList = new String[temp.length + 1];
205+
//copy the values of the old contacted array to the new expanded one
206+
int position = 0;
207+
while (position < temp.length) {
208+
resultList[position] = temp[position];
209+
position++;
206210
}
207211
}
208-
resultList[0][i] = searchKeyWords[i];
209-
if(injector != null){
210-
injector.execute(getChildUiStateByIndex(j), j, resultList[0][i]);
212+
//fill a new item after expanding the pointer
213+
resultList[index] = searchList[i];
214+
//inject users' actions to execute
215+
if ( injector != null ){
216+
injector.execute(getChildUiStateByIndex(i), i, resultList[index]);
211217
}
212-
}
218+
//add 1 to keep track of successful values
219+
index++;
220+
//terminate when a successful condition search has met in the list of search keywords
221+
break;
213222
}
214223
}
215-
}, resultList[0]).call();
216-
}
224+
}
225+
return resultList;
217226
}
218227

219228
/**

demoApp/src/main/java/com/myGame/JMESurfaceViewExampleActivity/UiTestCase.java

+12-8
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import com.scrappers.superiorExtendedEngine.menuStates.uiPager.UiPager;
1212

1313
import java.util.Arrays;
14+
import java.util.concurrent.Executors;
1415

1516
/**
1617
* Test case for UiPager #{@link UiPager}.
@@ -61,18 +62,21 @@ public void testPagerUiStates() throws Exception {
6162
public void onClick(View v) {
6263
if(v.getId() == 'S'){
6364
Toast.makeText(uiPager.getContext(), "Search Button Clicked", Toast.LENGTH_LONG).show();
65+
uiPager.removeAllViews();
6466
try {
65-
uiPager.removeAllViews();
66-
uiPager.search(sortedList, new String[]{"Search", "PAvlY", "Thomas"}, (uiState, position, currentItem) -> {
67-
uiPager.addView(uiState);
68-
uiState.setBackgroundColor(Color.MAGENTA);
69-
if(uiState.getId() == 'P'){
70-
uiState.setBackgroundColor(Color.RED);
71-
}
72-
});
67+
Executors.callable(()->{
68+
System.out.println(Arrays.toString(uiPager.search(sortedList, new String[]{"Search", "PAvlY", "Thomas"}, (uiState, position, currentItem) -> {
69+
uiPager.addView(uiState);
70+
uiState.setBackgroundColor(Color.MAGENTA);
71+
if ( uiState.getId() == 'P' ){
72+
uiState.setBackgroundColor(Color.RED);
73+
}
74+
})));
75+
}).call();
7376
} catch (Exception e) {
7477
e.printStackTrace();
7578
}
79+
7680
}else if(v.getId() == 'R'){
7781
Toast.makeText(uiPager.getContext(), "Revert Search clicked", Toast.LENGTH_LONG).show();
7882

0 commit comments

Comments
 (0)