Created
August 6, 2015 17:56
-
-
Save money4honey/f3f86e7f7778f00e8b76 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package ru.moneyhoney.tester.util; | |
import java.util.ArrayList; | |
public class ListMaster { | |
public static String[] findMatches(String query, String[] array){ | |
ArrayList<String> list = new ArrayList<String>(); | |
for (String item : array){ | |
if (item.toLowerCase().contains(query.toLowerCase())) list.add(item); | |
} | |
return (String[])list.toArray(); | |
} | |
public static ArrayList<String> findMatches(String query, ArrayList<String> arrayList){ | |
ArrayList<String> list = new ArrayList<String>(); | |
for (String item : arrayList){ | |
if (item.toLowerCase().contains(query.toLowerCase())) list.add(item); | |
} | |
return list; | |
} | |
public static void deleteIfNoMatches(String query, ArrayList<String> arrayList){ | |
String item; | |
for (int i = 0; i < arrayList.size(); i++){ | |
item = arrayList.get(i); | |
if (!item.toLowerCase().contains(query.toLowerCase())) { | |
deleteItemFromArrayList(item, arrayList); | |
i--; | |
} | |
} | |
} | |
public static void deleteItemFromArrayList(String item, ArrayList<String> arrayList){ | |
int index = 0; | |
for (String i : arrayList){ | |
if (i == item) { | |
arrayList.remove(index); | |
return; | |
} | |
index++; | |
} | |
} | |
public static ArrayList<String> addArrayToArrayList(ArrayList<String> arrayList, String[] array){ | |
for (String item : array){ | |
arrayList.add(item); | |
} | |
return arrayList; | |
} | |
public static ArrayList<String> addArrayToArrayListWithSplit(ArrayList<String> arrayList, String[] array, String delimiter, int position){ | |
for (String item : array){ | |
String[] mas = item.split(delimiter); | |
arrayList.add(mas[position]); | |
} | |
return arrayList; | |
} | |
public static String getItemFromArrayWithSplit(int arrayCount, int positionCount, String delimiter, String[] array){ | |
String[] mas = array[arrayCount].split(delimiter); | |
return mas[positionCount]; | |
} | |
public static String getItemFromArrayListWithSplit(int arrayListCount, int positionCount, String delimiter, ArrayList<String> arrayList){ | |
String[] mas = arrayList.get(arrayListCount).split(delimiter); | |
return mas[positionCount]; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment