Merge pull request #363 from veyndan/diamond

Replace explicit type with diamond operator
This commit is contained in:
Josephine Lim 2017-03-02 18:37:14 +10:00 committed by GitHub
commit 9a6dd2e97e
16 changed files with 43 additions and 43 deletions

View file

@ -122,7 +122,7 @@ public class CommonsApplication extends Application {
if (maxMem < 48L * 1024L * 1024L) { if (maxMem < 48L * 1024L * 1024L) {
// Cache only one bitmap if VM memory is too small (such as Nexus One); // Cache only one bitmap if VM memory is too small (such as Nexus One);
Log.d("Commons", "Skipping bitmap cache; max mem is: " + maxMem); Log.d("Commons", "Skipping bitmap cache; max mem is: " + maxMem);
imageCache = new LruCache<String, Bitmap>(1); imageCache = new LruCache<>(1);
} else { } else {
int cacheSize = (int) (maxMem / (1024 * 8)); int cacheSize = (int) (maxMem / (1024 * 8));
Log.d("Commons", "Bitmap cache size " + cacheSize + " from max mem " + maxMem); Log.d("Commons", "Bitmap cache size " + cacheSize + " from max mem " + maxMem);

View file

@ -11,7 +11,7 @@ import java.util.Map;
import java.util.Set; import java.util.Set;
public class LicenseList { public class LicenseList {
Map<String, fr.free.nrw.commons.License> licenses = new HashMap<String, fr.free.nrw.commons.License>(); Map<String, fr.free.nrw.commons.License> licenses = new HashMap<>();
Resources res; Resources res;
private static String XMLNS_LICENSE = "https://www.mediawiki.org/wiki/Extension:UploadWizard/xmlns/licenses"; private static String XMLNS_LICENSE = "https://www.mediawiki.org/wiki/Extension:UploadWizard/xmlns/licenses";

View file

@ -27,11 +27,11 @@ public class Media implements Parcelable {
}; };
protected Media() { protected Media() {
this.categories = new ArrayList<String>(); this.categories = new ArrayList<>();
this.descriptions = new HashMap<String, String>(); this.descriptions = new HashMap<>();
} }
private HashMap<String, Object> tags = new HashMap<String, Object>(); private HashMap<String, Object> tags = new HashMap<>();
public Object getTag(String key) { public Object getTag(String key) {
return tags.get(key); return tags.get(key);

View file

@ -46,8 +46,8 @@ public class MediaDataExtractor {
*/ */
public MediaDataExtractor(String filename, LicenseList licenseList) { public MediaDataExtractor(String filename, LicenseList licenseList) {
this.filename = filename; this.filename = filename;
categories = new ArrayList<String>(); categories = new ArrayList<>();
descriptions = new HashMap<String, String>(); descriptions = new HashMap<>();
fetched = false; fetched = false;
processed = false; processed = false;
this.licenseList = licenseList; this.licenseList = licenseList;
@ -251,7 +251,7 @@ public class MediaDataExtractor {
// Texts are wrapped in things like {{en|foo} or {{en|1=foo bar}}. // Texts are wrapped in things like {{en|foo} or {{en|1=foo bar}}.
// Text outside those wrappers is stuffed into a 'default' faux language key if present. // Text outside those wrappers is stuffed into a 'default' faux language key if present.
private Map<String, String> getMultilingualText(Node parentNode) throws IOException { private Map<String, String> getMultilingualText(Node parentNode) throws IOException {
Map<String, String> texts = new HashMap<String, String>(); Map<String, String> texts = new HashMap<>();
StringBuilder localText = new StringBuilder(); StringBuilder localText = new StringBuilder();
NodeList nodes = parentNode.getChildNodes(); NodeList nodes = parentNode.getChildNodes();

View file

@ -33,7 +33,7 @@ public class CacheController {
} }
public void cacheCategory() { public void cacheCategory() {
List<String> pointCatList = new ArrayList<String>(); List<String> pointCatList = new ArrayList<>();
if (MwVolleyApi.GpsCatExists.getGpsCatExists() == true) { if (MwVolleyApi.GpsCatExists.getGpsCatExists() == true) {
pointCatList.addAll(MwVolleyApi.getGpsCat()); pointCatList.addAll(MwVolleyApi.getGpsCat());
Log.d(TAG, "Categories being cached: " + pointCatList); Log.d(TAG, "Categories being cached: " + pointCatList);
@ -47,7 +47,7 @@ public class CacheController {
//Convert decLatitude and decLongitude to a coordinate offset range //Convert decLatitude and decLongitude to a coordinate offset range
convertCoordRange(); convertCoordRange();
pointsFound = quadTree.searchWithin(xMinus, yMinus, xPlus, yPlus); pointsFound = quadTree.searchWithin(xMinus, yMinus, xPlus, yPlus);
List<String> displayCatList = new ArrayList<String>(); List<String> displayCatList = new ArrayList<>();
Log.d(TAG, "Points found in quadtree: " + Arrays.asList(pointsFound)); Log.d(TAG, "Points found in quadtree: " + Arrays.asList(pointsFound));
if (pointsFound.length != 0) { if (pointsFound.length != 0) {

View file

@ -66,14 +66,14 @@ public class CategorizationFragment extends Fragment {
protected HashMap<String, ArrayList<String>> categoriesCache; protected HashMap<String, ArrayList<String>> categoriesCache;
private ArrayList<String> selectedCategories = new ArrayList<String>(); private ArrayList<String> selectedCategories = new ArrayList<>();
// LHS guarantees ordered insertions, allowing for prioritized method A results // LHS guarantees ordered insertions, allowing for prioritized method A results
private final Set<String> results = new LinkedHashSet<String>(); private final Set<String> results = new LinkedHashSet<>();
PrefixUpdater prefixUpdaterSub; PrefixUpdater prefixUpdaterSub;
MethodAUpdater methodAUpdaterSub; MethodAUpdater methodAUpdaterSub;
private final ArrayList<String> titleCatItems = new ArrayList<String>(); private final ArrayList<String> titleCatItems = new ArrayList<>();
final CountDownLatch mergeLatch = new CountDownLatch(1); final CountDownLatch mergeLatch = new CountDownLatch(1);
private ContentProviderClient client; private ContentProviderClient client;
@ -161,7 +161,7 @@ public class CategorizationFragment extends Fragment {
* @return a list containing recent categories * @return a list containing recent categories
*/ */
protected ArrayList<String> recentCatQuery() { protected ArrayList<String> recentCatQuery() {
ArrayList<String> items = new ArrayList<String>(); ArrayList<String> items = new ArrayList<>();
try { try {
Cursor cursor = client.query( Cursor cursor = client.query(
@ -189,16 +189,16 @@ public class CategorizationFragment extends Fragment {
*/ */
protected ArrayList<String> mergeItems() { protected ArrayList<String> mergeItems() {
Set<String> mergedItems = new LinkedHashSet<String>(); Set<String> mergedItems = new LinkedHashSet<>();
Log.d(TAG, "Calling APIs for GPS cats, title cats and recent cats..."); Log.d(TAG, "Calling APIs for GPS cats, title cats and recent cats...");
List<String> gpsItems = new ArrayList<String>(); List<String> gpsItems = new ArrayList<>();
if (MwVolleyApi.GpsCatExists.getGpsCatExists()) { if (MwVolleyApi.GpsCatExists.getGpsCatExists()) {
gpsItems.addAll(MwVolleyApi.getGpsCat()); gpsItems.addAll(MwVolleyApi.getGpsCat());
} }
List<String> titleItems = new ArrayList<String>(titleCatQuery()); List<String> titleItems = new ArrayList<>(titleCatQuery());
List<String> recentItems = new ArrayList<String>(recentCatQuery()); List<String> recentItems = new ArrayList<>(recentCatQuery());
//Await results of titleItems, which is likely to come in last //Await results of titleItems, which is likely to come in last
try { try {
@ -216,7 +216,7 @@ public class CategorizationFragment extends Fragment {
Log.d(TAG, "Adding recent items: " + recentItems); Log.d(TAG, "Adding recent items: " + recentItems);
//Needs to be an ArrayList and not a List unless we want to modify a big portion of preexisting code //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); ArrayList<String> mergedItemsList = new ArrayList<>(mergedItems);
Log.d(TAG, "Merged item list: " + mergedItemsList); Log.d(TAG, "Merged item list: " + mergedItemsList);
return mergedItemsList; return mergedItemsList;
@ -230,8 +230,8 @@ public class CategorizationFragment extends Fragment {
protected void setCatsAfterAsync(ArrayList<String> categories, String filter) { protected void setCatsAfterAsync(ArrayList<String> categories, String filter) {
if (getActivity() != null) { if (getActivity() != null) {
ArrayList<CategoryItem> items = new ArrayList<CategoryItem>(); ArrayList<CategoryItem> items = new ArrayList<>();
HashSet<String> existingKeys = new HashSet<String>(); HashSet<String> existingKeys = new HashSet<>();
for (CategoryItem item : categoriesAdapter.getItems()) { for (CategoryItem item : categoriesAdapter.getItems()) {
if (item.selected) { if (item.selected) {
items.add(item); items.add(item);
@ -279,7 +279,7 @@ public class CategorizationFragment extends Fragment {
prefixUpdaterSub = new PrefixUpdater(this) { prefixUpdaterSub = new PrefixUpdater(this) {
@Override @Override
protected ArrayList<String> doInBackground(Void... voids) { protected ArrayList<String> doInBackground(Void... voids) {
ArrayList<String> result = new ArrayList<String>(); ArrayList<String> result = new ArrayList<>();
try { try {
result = super.doInBackground(); result = super.doInBackground();
latch.await(); latch.await();
@ -299,7 +299,7 @@ public class CategorizationFragment extends Fragment {
Log.d(TAG, "Prefix result: " + result); Log.d(TAG, "Prefix result: " + result);
String filter = categoriesFilter.getText().toString(); String filter = categoriesFilter.getText().toString();
ArrayList<String> resultsList = new ArrayList<String>(results); ArrayList<String> resultsList = new ArrayList<>(results);
categoriesCache.put(filter, resultsList); categoriesCache.put(filter, resultsList);
Log.d(TAG, "Final results List: " + resultsList); Log.d(TAG, "Final results List: " + resultsList);
@ -421,8 +421,8 @@ public class CategorizationFragment extends Fragment {
ArrayList<CategoryItem> items; ArrayList<CategoryItem> items;
if(savedInstanceState == null) { if(savedInstanceState == null) {
items = new ArrayList<CategoryItem>(); items = new ArrayList<>();
categoriesCache = new HashMap<String, ArrayList<String>>(); categoriesCache = new HashMap<>();
} else { } else {
items = savedInstanceState.getParcelableArrayList("currentCategories"); items = savedInstanceState.getParcelableArrayList("currentCategories");
categoriesCache = (HashMap<String, ArrayList<String>>) savedInstanceState.getSerializable("categoriesCache"); categoriesCache = (HashMap<String, ArrayList<String>>) savedInstanceState.getSerializable("categoriesCache");

View file

@ -82,7 +82,7 @@ public class MethodAUpdater extends AsyncTask<Void, Void, ArrayList<String>> {
//otherwise if user has typed something in that isn't in cache, search API for matching categories //otherwise if user has typed something in that isn't in cache, search API for matching categories
MWApi api = CommonsApplication.createMWApi(); MWApi api = CommonsApplication.createMWApi();
ApiResult result; ApiResult result;
ArrayList<String> categories = new ArrayList<String>(); ArrayList<String> categories = new ArrayList<>();
//URL https://commons.wikimedia.org/w/api.php?action=query&format=xml&list=search&srwhat=text&srenablerewrites=1&srnamespace=14&srlimit=10&srsearch= //URL https://commons.wikimedia.org/w/api.php?action=query&format=xml&list=search&srwhat=text&srenablerewrites=1&srnamespace=14&srlimit=10&srsearch=
try { try {
@ -109,7 +109,7 @@ public class MethodAUpdater extends AsyncTask<Void, Void, ArrayList<String>> {
} }
Log.d(TAG, "Found categories from Method A search, waiting for filter"); Log.d(TAG, "Found categories from Method A search, waiting for filter");
ArrayList<String> filteredItems = new ArrayList<String>(filterYears(categories)); ArrayList<String> filteredItems = new ArrayList<>(filterYears(categories));
return filteredItems; return filteredItems;
} }
} }

View file

@ -82,17 +82,17 @@ public class PrefixUpdater extends AsyncTask<Void, Void, ArrayList<String>> {
protected ArrayList<String> doInBackground(Void... voids) { protected ArrayList<String> doInBackground(Void... voids) {
//If user hasn't typed anything in yet, get GPS and recent items //If user hasn't typed anything in yet, get GPS and recent items
if(TextUtils.isEmpty(filter)) { if(TextUtils.isEmpty(filter)) {
ArrayList<String> mergedItems = new ArrayList<String>(catFragment.mergeItems()); ArrayList<String> mergedItems = new ArrayList<>(catFragment.mergeItems());
Log.d(TAG, "Merged items, waiting for filter"); Log.d(TAG, "Merged items, waiting for filter");
ArrayList<String> filteredItems = new ArrayList<String>(filterYears(mergedItems)); ArrayList<String> filteredItems = new ArrayList<>(filterYears(mergedItems));
return filteredItems; return filteredItems;
} }
//if user types in something that is in cache, return cached category //if user types in something that is in cache, return cached category
if(catFragment.categoriesCache.containsKey(filter)) { if(catFragment.categoriesCache.containsKey(filter)) {
ArrayList<String> cachedItems = new ArrayList<String>(catFragment.categoriesCache.get(filter)); ArrayList<String> cachedItems = new ArrayList<>(catFragment.categoriesCache.get(filter));
Log.d(TAG, "Found cache items, waiting for filter"); Log.d(TAG, "Found cache items, waiting for filter");
ArrayList<String> filteredItems = new ArrayList<String>(filterYears(cachedItems)); ArrayList<String> filteredItems = new ArrayList<>(filterYears(cachedItems));
return filteredItems; return filteredItems;
} }
@ -100,7 +100,7 @@ public class PrefixUpdater extends AsyncTask<Void, Void, ArrayList<String>> {
//URL: https://commons.wikimedia.org/w/api.php?action=query&list=allcategories&acprefix=filter&aclimit=25 //URL: https://commons.wikimedia.org/w/api.php?action=query&list=allcategories&acprefix=filter&aclimit=25
MWApi api = CommonsApplication.createMWApi(); MWApi api = CommonsApplication.createMWApi();
ApiResult result; ApiResult result;
ArrayList<String> categories = new ArrayList<String>(); ArrayList<String> categories = new ArrayList<>();
try { try {
result = api.action("query") result = api.action("query")
.param("list", "allcategories") .param("list", "allcategories")
@ -120,7 +120,7 @@ public class PrefixUpdater extends AsyncTask<Void, Void, ArrayList<String>> {
} }
Log.d(TAG, "Found categories from Prefix search, waiting for filter"); Log.d(TAG, "Found categories from Prefix search, waiting for filter");
ArrayList<String> filteredItems = new ArrayList<String>(filterYears(categories)); ArrayList<String> filteredItems = new ArrayList<>(filterYears(categories));
return filteredItems; return filteredItems;
} }
} }

View file

@ -45,7 +45,7 @@ public class ContributionsActivity
private MediaDetailPagerFragment mediaDetails; private MediaDetailPagerFragment mediaDetails;
private UploadService uploadService; private UploadService uploadService;
private boolean isUploadServiceConnected; private boolean isUploadServiceConnected;
private ArrayList<DataSetObserver> observersWaitingForLoad = new ArrayList<DataSetObserver>(); private ArrayList<DataSetObserver> observersWaitingForLoad = new ArrayList<>();
private String CONTRIBUTION_SELECTION = ""; private String CONTRIBUTION_SELECTION = "";
/* /*
This sorts in the following order: This sorts in the following order:

View file

@ -92,7 +92,7 @@ public class ContributionsSyncAdapter extends AbstractThreadedSyncAdapter {
ArrayList<ApiResult> uploads = result.getNodes("/api/query/logevents/item"); ArrayList<ApiResult> uploads = result.getNodes("/api/query/logevents/item");
Log.d("Commons", uploads.size() + " results!"); Log.d("Commons", uploads.size() + " results!");
ArrayList<ContentValues> imageValues = new ArrayList<ContentValues>(); ArrayList<ContentValues> imageValues = new ArrayList<>();
for(ApiResult image: uploads) { for(ApiResult image: uploads) {
String filename = image.getString("@title"); String filename = image.getString("@title");
if(fileExists(contentProviderClient, filename)) { if(fileExists(contentProviderClient, filename)) {

View file

@ -32,7 +32,7 @@ public class CategoryImagesLoader extends AsyncTaskLoader<List<Media>>{
@Override @Override
public List<Media> loadInBackground() { public List<Media> loadInBackground() {
ArrayList<Media> mediaList = new ArrayList<Media>(); ArrayList<Media> mediaList = new ArrayList<>();
ApiResult result; ApiResult result;
try { try {
result = app.getApi().action("query") result = app.getApi().action("query")

View file

@ -108,7 +108,7 @@ public class MediaDetailFragment extends Fragment {
index = getArguments().getInt("index"); index = getArguments().getInt("index");
initialListTop = 0; initialListTop = 0;
} }
categoryNames = new ArrayList<String>(); categoryNames = new ArrayList<>();
categoryNames.add(getString(R.string.detail_panel_cats_loading)); categoryNames.add(getString(R.string.detail_panel_cats_loading));
final View view = inflater.inflate(R.layout.fragment_media_detail, container, false); final View view = inflater.inflate(R.layout.fragment_media_detail, container, false);

View file

@ -21,7 +21,7 @@ public class ModifierSequence {
public ModifierSequence(Uri mediaUri) { public ModifierSequence(Uri mediaUri) {
this.mediaUri = mediaUri; this.mediaUri = mediaUri;
modifiers = new ArrayList<PageModifier>(); modifiers = new ArrayList<>();
} }
public ModifierSequence(Uri mediaUri, JSONObject data) { public ModifierSequence(Uri mediaUri, JSONObject data) {

View file

@ -21,7 +21,7 @@ public class NearbyPlaces {
} }
else { else {
try { try {
places = new ArrayList<Place>(); places = new ArrayList<>();
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build(); StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy); StrictMode.setThreadPolicy(policy);

View file

@ -249,7 +249,7 @@ public class MultipleShareActivity
if(intent.getAction().equals(Intent.ACTION_SEND_MULTIPLE)) { if(intent.getAction().equals(Intent.ACTION_SEND_MULTIPLE)) {
if(photosList == null) { if(photosList == null) {
photosList = new ArrayList<Contribution>(); photosList = new ArrayList<>();
ArrayList<Uri> urisList = intent.getParcelableArrayListExtra(Intent.EXTRA_STREAM); ArrayList<Uri> urisList = intent.getParcelableArrayListExtra(Intent.EXTRA_STREAM);
for(int i=0; i < urisList.size(); i++) { for(int i=0; i < urisList.size(); i++) {
Contribution up = new Contribution(); Contribution up = new Contribution();

View file

@ -42,7 +42,7 @@ public class MwVolleyApi {
public MwVolleyApi(Context context) { public MwVolleyApi(Context context) {
this.context = context; this.context = context;
categorySet = new HashSet<String>(); categorySet = new HashSet<>();
} }
public static List<String> getGpsCat() { public static List<String> getGpsCat() {
@ -50,7 +50,7 @@ public class MwVolleyApi {
} }
public static void setGpsCat(List cachedList) { public static void setGpsCat(List cachedList) {
categoryList = new ArrayList<String>(); categoryList = new ArrayList<>();
categoryList.addAll(cachedList); categoryList.addAll(cachedList);
Log.d(TAG, "Setting GPS cats from cache: " + categoryList.toString()); Log.d(TAG, "Setting GPS cats from cache: " + categoryList.toString());
} }
@ -236,7 +236,7 @@ public class MwVolleyApi {
} }
} }
categoryList = new ArrayList<String>(categorySet); categoryList = new ArrayList<>(categorySet);
builder.replace(builder.length() - 1, builder.length(), ""); builder.replace(builder.length() - 1, builder.length(), "");
return builder.toString(); return builder.toString();
} }