Add filterYears method

This commit is contained in:
misaochan 2016-10-27 16:09:47 +13:00
parent aaf91ac264
commit bff5ce96b0
2 changed files with 17 additions and 10 deletions

View file

@ -222,16 +222,7 @@ public class CategorizationFragment extends Fragment {
//Needs to be an ArrayList and not a List unless we want to modify a big portion of preexisting code
ArrayList<String> mergedItemsList = new ArrayList<String>(mergedItems);
//Copy to Iterator to prevent ConcurrentModificationException when removing item
for(Iterator<String> item = mergedItemsList.iterator(); item.hasNext();) {
String s = item.next();
//Check if s contains a 4-digit word anywhere within the string (.* is wildcard)
if(s.matches(".*(19|20)\\d{2}.*")) {
Log.d(TAG, "Filtering out year " + s);
item.remove();
}
}
Log.d(TAG, "Merged item list: " + mergedItemsList);
return mergedItemsList;

View file

@ -10,6 +10,7 @@ import org.mediawiki.api.MWApi;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Iterator;
import javax.net.ssl.SSLPeerUnverifiedException;
@ -41,6 +42,21 @@ public class PrefixUpdater extends AsyncTask<Void, Void, ArrayList<String>> {
catFragment.categoriesSkip.setVisibility(View.GONE);
}
protected ArrayList<String> filterYears(ArrayList<String> items) {
//Copy to Iterator to prevent ConcurrentModificationException when removing item
for(Iterator<String> item = items.iterator(); item.hasNext();) {
String s = item.next();
//Check if s contains a 4-digit word anywhere within the string (.* is wildcard)
if(s.matches(".*(19|20)\\d{2}.*")) {
Log.d(TAG, "Filtering out year " + s);
item.remove();
}
}
return items;
}
@Override
protected ArrayList<String> doInBackground(Void... voids) {
//If user hasn't typed anything in yet, get GPS and recent items