Skip to content

Commit 5a901f2

Browse files
committed
Fixed sort to produce new list
1 parent 9fc2781 commit 5a901f2

File tree

2 files changed

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

2 files changed

+36
-18
lines changed

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

+14-16
Original file line numberDiff line numberDiff line change
@@ -192,17 +192,13 @@ public String[] search(String[] searchList, String[] searchKeyWords, ActionInjec
192192
synchronized(this) {
193193
final String[] resultList = new String[searchList.length];
194194
return Executors.callable(() -> {
195-
//format the list
196-
removeAllViews();
197195
for (int pos = 0; pos < searchList.length; pos++) {
198196
for (String keyword : searchKeyWords) {
199197
if (searchList[pos].replaceAll(" ","").trim().toLowerCase().contains(keyword.replaceAll(" ","").trim().toLowerCase())) {
200198
resultList[pos] = searchList[pos];
201-
View uiState = getChildUiStateByIndex(pos);
202199
if(injector != null){
203-
injector.execute(uiState, pos);
200+
injector.execute(getChildUiStateByIndex(pos), pos);
204201
}
205-
addView(uiState);
206202
break;
207203
}
208204
}
@@ -240,43 +236,45 @@ public void revertSearchEngine(@Nullable ActionInjector actionInjector) throws E
240236
*/
241237
public String[] sort(String[] list, int sortAlgorithm) throws Exception {
242238
synchronized(this) {
239+
//to apply the sort change as an external final change on a list copy (warning : ->Internal List change(positions or items count or items values) = Malicious Activity
240+
final String[] copy = list;
243241
return Executors.callable(() -> {
244242
String tempPointer = "";
245243
//main String List looping
246-
for (int i = 0; i < list.length; i++) {
244+
for (int i = 0; i < copy.length; i++) {
247245
//looping over the String again to compare each one String member var with the sequence of the String member vars after that item
248-
for(int j = i+1; j < list.length; j++ ){
246+
for(int j = i+1; j < copy.length; j++ ){
249247
//sort from A-Z ascendingly
250248
if(sortAlgorithm == A_Z){
251249
//compare 2 strings lexicographically based on their characters, if the (string object > the argument string) then compareTo returns 1
252-
if ( list[i].toLowerCase().compareTo(list[j].toLowerCase()) > 0 ){
250+
if ( copy[i].toLowerCase().compareTo(copy[j].toLowerCase()) > 0 ){
253251
//format the pointer
254252
tempPointer = "";
255253
//then swap list[i] & list[j] because list[i] is after the list[k]
256254
//store the list[i] inside the tempPointer for later access
257-
tempPointer = list[i];
255+
tempPointer = copy[i];
258256
//get the list[i] after
259-
list[i] = list[j];
257+
copy[i] = copy[j];
260258
//get the list[j] before
261-
list[j] = tempPointer;
259+
copy[j] = tempPointer;
262260
}
263261
}else if(sortAlgorithm == Z_A){
264262
//compare 2 strings lexicographically based on their characters, if the (string object < the argument string) then compareTo returns -1
265-
if ( list[i].toLowerCase().compareTo(list[j].toLowerCase()) < 0){
263+
if ( copy[i].toLowerCase().compareTo(copy[j].toLowerCase()) < 0){
266264
//format the pointer
267265
tempPointer = "";
268266
//then swap list[i] & list[j] because list[i] is before the list[k]
269267
//store the list[j] inside the tempPointer for later access
270-
tempPointer = list[j];
268+
tempPointer = copy[j];
271269
//get the list[j] before
272-
list[j] = list[i];
270+
copy[j] = copy[i];
273271
//get the list[i] after
274-
list[i] = tempPointer;
272+
copy[i] = tempPointer;
275273
}
276274
}
277275
}
278276
}
279-
}, list).call();
277+
}, copy).call();
280278
}
281279
}
282280
/**

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

+22-2
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ public void testPagerUiStates() throws Exception {
5252
//attach the button
5353
uiPager.attachUiState(button, UiPager.SEQUENTIAL_ADD);
5454
}
55-
System.out.println(Arrays.toString(uiPager.sort(new String[]{"199", "110", "990", "99", "222", "333", "4455",}, UiPager.A_Z)));
56-
System.out.println(Arrays.toString(uiPager.sort(new String[]{ "0?Dogy", "=Baka", "9ggBi", "D_aD", "dad", "amam", "-lolo", "\"hi", "Come", "come", "C", "F", "I", "Z", "A"}, UiPager.A_Z)));
55+
// System.out.println(Arrays.toString(uiPager.sort(new String[]{"199", "110", "990", "99", "222", "333", "4455",}, UiPager.A_Z)));
56+
// System.out.println(Arrays.toString(uiPager.sort(new String[]{ "0?Dogy", "=Baka", "9ggBi", "D_aD", "dad", "amam", "-lolo", "\"hi", "Come", "come", "C", "F", "I", "Z", "A"}, UiPager.A_Z)));
5757

5858
}
5959

@@ -90,5 +90,25 @@ public void onClick(View v) {
9090
}).start();
9191
}
9292
}
93+
private class DataModel {
94+
private int id;
95+
private String text;
96+
97+
public int getId() {
98+
return id;
99+
}
100+
101+
public void setId(int id) {
102+
this.id = id;
103+
}
104+
105+
public String getText() {
106+
return text;
107+
}
108+
109+
public void setText(String text) {
110+
this.text = text;
111+
}
112+
}
93113
}
94114

0 commit comments

Comments
 (0)