Infer more types taking advantage of java 1.7 to simplify code
This commit is contained in:
parent
d9590743d9
commit
3eddb1402c
@ -34,7 +34,7 @@ public class CompatibilityChecker extends Compatibility {
|
||||
PackageManager pm = ctx.getPackageManager();
|
||||
StringBuilder logMsg = new StringBuilder();
|
||||
logMsg.append("Available device features:");
|
||||
features = new HashSet<String>();
|
||||
features = new HashSet<>();
|
||||
if (pm != null) {
|
||||
final FeatureInfo[] featureArray = pm.getSystemAvailableFeatures();
|
||||
if (featureArray != null)
|
||||
@ -71,7 +71,7 @@ public class CompatibilityChecker extends Compatibility {
|
||||
|
||||
public List<String> getIncompatibleReasons(final Apk apk) {
|
||||
|
||||
List<String> incompatibleReasons = new ArrayList<String>();
|
||||
List<String> incompatibleReasons = new ArrayList<>();
|
||||
|
||||
if (!hasApi(apk.minSdkVersion) || !upToApi(apk.maxSdkVersion)) {
|
||||
incompatibleReasons.add(
|
||||
|
@ -49,7 +49,7 @@ public class FDroidCertPins {
|
||||
|
||||
public static String[] getPinList() {
|
||||
if (PINLIST == null) {
|
||||
List<String> pinlist = new ArrayList<String>();
|
||||
List<String> pinlist = new ArrayList<>();
|
||||
pinlist.addAll(Arrays.asList(DEFAULT_PINS));
|
||||
PINLIST = pinlist;
|
||||
}
|
||||
|
@ -78,14 +78,14 @@ public class Preferences implements SharedPreferences.OnSharedPreferenceChangeLi
|
||||
private boolean compactLayout = DEFAULT_COMPACT_LAYOUT;
|
||||
private boolean filterAppsRequiringRoot = DEFAULT_ROOTED;
|
||||
|
||||
private Map<String,Boolean> initialized = new HashMap<String,Boolean>();
|
||||
private Map<String,Boolean> initialized = new HashMap<>();
|
||||
|
||||
private List<ChangeListener> compactLayoutListeners = new ArrayList<ChangeListener>();
|
||||
private List<ChangeListener> filterAppsRequiringRootListeners = new ArrayList<ChangeListener>();
|
||||
private List<ChangeListener> updateHistoryListeners = new ArrayList<ChangeListener>();
|
||||
private List<ChangeListener> localRepoBonjourListeners = new ArrayList<ChangeListener>();
|
||||
private List<ChangeListener> localRepoNameListeners = new ArrayList<ChangeListener>();
|
||||
private List<ChangeListener> localRepoHttpsListeners = new ArrayList<ChangeListener>();
|
||||
private List<ChangeListener> compactLayoutListeners = new ArrayList<>();
|
||||
private List<ChangeListener> filterAppsRequiringRootListeners = new ArrayList<>();
|
||||
private List<ChangeListener> updateHistoryListeners = new ArrayList<>();
|
||||
private List<ChangeListener> localRepoBonjourListeners = new ArrayList<>();
|
||||
private List<ChangeListener> localRepoNameListeners = new ArrayList<>();
|
||||
private List<ChangeListener> localRepoHttpsListeners = new ArrayList<>();
|
||||
|
||||
private boolean isInitialized(String key) {
|
||||
return initialized.containsKey(key) && initialized.get(key);
|
||||
|
@ -38,8 +38,8 @@ public class RepoXMLHandler extends DefaultHandler {
|
||||
// The repo we're processing.
|
||||
private Repo repo;
|
||||
|
||||
private List<App> apps = new ArrayList<App>();
|
||||
private List<Apk> apksList = new ArrayList<Apk>();
|
||||
private List<App> apps = new ArrayList<>();
|
||||
private List<Apk> apksList = new ArrayList<>();
|
||||
|
||||
private App curapp = null;
|
||||
private Apk curapk = null;
|
||||
|
@ -399,7 +399,7 @@ public class UpdateService extends IntentService implements ProgressListener {
|
||||
} else {
|
||||
sendStatus(STATUS_INFO, getString(R.string.status_checking_compatibility));
|
||||
|
||||
List<App> listOfAppsToUpdate = new ArrayList<App>();
|
||||
List<App> listOfAppsToUpdate = new ArrayList<>();
|
||||
listOfAppsToUpdate.addAll(appsToUpdate.values());
|
||||
|
||||
calcApkCompatibilityFlags(this, apksToUpdate);
|
||||
@ -554,7 +554,7 @@ public class UpdateService extends IntentService implements ProgressListener {
|
||||
}
|
||||
|
||||
private List<String> getKnownAppIds(List<App> apps) {
|
||||
List<String> knownAppIds = new ArrayList<String>();
|
||||
List<String> knownAppIds = new ArrayList<>();
|
||||
if (apps.size() == 0) {
|
||||
// Do nothing
|
||||
} else if (apps.size() > AppProvider.MAX_APPS_TO_QUERY) {
|
||||
@ -581,7 +581,7 @@ public class UpdateService extends IntentService implements ProgressListener {
|
||||
Cursor cursor = getContentResolver().query(uri, fields, null, null, null);
|
||||
|
||||
int knownIdCount = cursor != null ? cursor.getCount() : 0;
|
||||
List<String> knownIds = new ArrayList<String>(knownIdCount);
|
||||
List<String> knownIds = new ArrayList<>(knownIdCount);
|
||||
if (cursor != null) {
|
||||
if (knownIdCount > 0) {
|
||||
cursor.moveToFirst();
|
||||
@ -615,7 +615,7 @@ public class UpdateService extends IntentService implements ProgressListener {
|
||||
|
||||
private void updateOrInsertApps(List<App> appsToUpdate, int totalUpdateCount, int currentCount) {
|
||||
|
||||
List<ContentProviderOperation> operations = new ArrayList<ContentProviderOperation>();
|
||||
List<ContentProviderOperation> operations = new ArrayList<>();
|
||||
List<String> knownAppIds = getKnownAppIds(appsToUpdate);
|
||||
for (final App a : appsToUpdate) {
|
||||
boolean known = false;
|
||||
@ -651,7 +651,7 @@ public class UpdateService extends IntentService implements ProgressListener {
|
||||
int i = 0;
|
||||
while (i < operations.size()) {
|
||||
int count = Math.min(operations.size() - i, 100);
|
||||
ArrayList<ContentProviderOperation> o = new ArrayList<ContentProviderOperation>(operations.subList(i, i + count));
|
||||
ArrayList<ContentProviderOperation> o = new ArrayList<>(operations.subList(i, i + count));
|
||||
sendStatus(STATUS_INFO, getString(
|
||||
R.string.status_inserting,
|
||||
(int)((double)(currentCount + i) / totalUpdateCount * 100)));
|
||||
@ -664,7 +664,7 @@ public class UpdateService extends IntentService implements ProgressListener {
|
||||
* Return list of apps from the "apks" argument which are already in the database.
|
||||
*/
|
||||
private List<Apk> getKnownApks(List<Apk> apks) {
|
||||
List<Apk> knownApks = new ArrayList<Apk>();
|
||||
List<Apk> knownApks = new ArrayList<>();
|
||||
if (apks.size() > ApkProvider.MAX_APKS_TO_QUERY) {
|
||||
int middle = apks.size() / 2;
|
||||
List<Apk> apks1 = apks.subList(0, middle);
|
||||
@ -679,7 +679,7 @@ public class UpdateService extends IntentService implements ProgressListener {
|
||||
|
||||
private void updateOrInsertApks(List<Apk> apksToUpdate, int totalApksAppsCount, int currentCount) {
|
||||
|
||||
List<ContentProviderOperation> operations = new ArrayList<ContentProviderOperation>();
|
||||
List<ContentProviderOperation> operations = new ArrayList<>();
|
||||
|
||||
List<Apk> knownApks = getKnownApks(apksToUpdate);
|
||||
for (final Apk apk : apksToUpdate) {
|
||||
@ -747,7 +747,7 @@ public class UpdateService extends IntentService implements ProgressListener {
|
||||
private void removeApksNoLongerInRepo(List<Apk> apksToUpdate, List<Repo> updatedRepos) {
|
||||
|
||||
long startTime = System.currentTimeMillis();
|
||||
List<Apk> toRemove = new ArrayList<Apk>();
|
||||
List<Apk> toRemove = new ArrayList<>();
|
||||
|
||||
String[] fields = {
|
||||
ApkProvider.DataColumns.APK_ID,
|
||||
|
@ -135,7 +135,7 @@ public class TabManager {
|
||||
}
|
||||
|
||||
private List<Spinner> traverseViewChildren(ViewGroup parent) {
|
||||
List<Spinner> spinners = new ArrayList<Spinner>();
|
||||
List<Spinner> spinners = new ArrayList<>();
|
||||
for (int i = 0; i < parent.getChildCount(); i++) {
|
||||
View child = parent.getChildAt(i);
|
||||
if (child instanceof Spinner) {
|
||||
|
@ -35,7 +35,7 @@ public class ApkProvider extends FDroidProvider {
|
||||
|
||||
public static List<Apk> cursorToList(Cursor cursor) {
|
||||
int knownApkCount = cursor != null ? cursor.getCount() : 0;
|
||||
List<Apk> apks = new ArrayList<Apk>(knownApkCount);
|
||||
List<Apk> apks = new ArrayList<>(knownApkCount);
|
||||
if (cursor != null) {
|
||||
if (knownApkCount > 0) {
|
||||
cursor.moveToFirst();
|
||||
@ -106,7 +106,7 @@ public class ApkProvider extends FDroidProvider {
|
||||
public static List<Apk> knownApks(Context context,
|
||||
List<Apk> apks, String[] fields) {
|
||||
if (apks.size() == 0) {
|
||||
return new ArrayList<Apk>();
|
||||
return new ArrayList<>();
|
||||
}
|
||||
ContentResolver resolver = context.getContentResolver();
|
||||
Uri uri = getContentUri(apks);
|
||||
@ -185,7 +185,7 @@ public class ApkProvider extends FDroidProvider {
|
||||
|
||||
private static final UriMatcher matcher = new UriMatcher(-1);
|
||||
|
||||
public static Map<String,String> REPO_FIELDS = new HashMap<String,String>();
|
||||
public static Map<String,String> REPO_FIELDS = new HashMap<>();
|
||||
|
||||
static {
|
||||
REPO_FIELDS.put(DataColumns.REPO_VERSION, RepoProvider.DataColumns.VERSION);
|
||||
|
@ -244,7 +244,7 @@ public class App extends ValueObject implements Comparable<App> {
|
||||
FeatureInfo[] features = packageInfo.reqFeatures;
|
||||
|
||||
if (features != null && features.length > 0) {
|
||||
List<String> featureNames = new ArrayList<String>(features.length);
|
||||
List<String> featureNames = new ArrayList<>(features.length);
|
||||
|
||||
for (int i = 0; i < features.length; i++)
|
||||
featureNames.add(features[i].name);
|
||||
|
@ -50,7 +50,7 @@ public class AppProvider extends FDroidProvider {
|
||||
|
||||
private static List<App> cursorToList(Cursor cursor) {
|
||||
int knownAppCount = cursor != null ? cursor.getCount() : 0;
|
||||
List<App> apps = new ArrayList<App>(knownAppCount);
|
||||
List<App> apps = new ArrayList<>(knownAppCount);
|
||||
if (cursor != null) {
|
||||
if (knownAppCount > 0) {
|
||||
cursor.moveToFirst();
|
||||
@ -81,7 +81,7 @@ public class AppProvider extends FDroidProvider {
|
||||
Uri uri = getContentUri();
|
||||
String[] projection = { DataColumns.CATEGORIES };
|
||||
Cursor cursor = resolver.query(uri, projection, null, null, null);
|
||||
Set<String> categorySet = new HashSet<String>();
|
||||
Set<String> categorySet = new HashSet<>();
|
||||
if (cursor != null) {
|
||||
if (cursor.getCount() > 0) {
|
||||
cursor.moveToFirst();
|
||||
@ -97,7 +97,7 @@ public class AppProvider extends FDroidProvider {
|
||||
}
|
||||
cursor.close();
|
||||
}
|
||||
List<String> categories = new ArrayList<String>(categorySet);
|
||||
List<String> categories = new ArrayList<>(categorySet);
|
||||
Collections.sort(categories);
|
||||
|
||||
// Populate the category list with the real categories, and the
|
||||
@ -537,7 +537,7 @@ public class AppProvider extends FDroidProvider {
|
||||
};
|
||||
|
||||
// Remove duplicates, surround in % for case insensitive searching
|
||||
Set<String> keywordSet = new HashSet<String>(Arrays.asList(query.split("\\s")));
|
||||
Set<String> keywordSet = new HashSet<>(Arrays.asList(query.split("\\s")));
|
||||
String[] keywords = new String[keywordSet.size()];
|
||||
int iKeyword = 0;
|
||||
for (String keyword : keywordSet) {
|
||||
|
@ -283,7 +283,7 @@ public class DBHelper extends SQLiteOpenHelper {
|
||||
*/
|
||||
private void migrateRepoTable(SQLiteDatabase db, int oldVersion) {
|
||||
if (oldVersion < 20) {
|
||||
List<Repo> oldrepos = new ArrayList<Repo>();
|
||||
List<Repo> oldrepos = new ArrayList<>();
|
||||
Cursor cursor = db.query(TABLE_REPO,
|
||||
new String[] { "address", "inuse", "pubkey" },
|
||||
null, null, null, null, null);
|
||||
@ -358,7 +358,7 @@ public class DBHelper extends SQLiteOpenHelper {
|
||||
if (oldVersion < 44) {
|
||||
if (!columnExists(db, TABLE_REPO, "fingerprint"))
|
||||
db.execSQL("alter table " + TABLE_REPO + " add column fingerprint text");
|
||||
List<Repo> oldrepos = new ArrayList<Repo>();
|
||||
List<Repo> oldrepos = new ArrayList<>();
|
||||
Cursor cursor = db.query(TABLE_REPO,
|
||||
new String[] { "address", "pubkey" },
|
||||
null, null, null, null, null);
|
||||
|
@ -116,7 +116,7 @@ public abstract class FDroidProvider extends ContentProvider {
|
||||
return values.keySet();
|
||||
}
|
||||
|
||||
Set<String> keySet = new HashSet<String>();
|
||||
Set<String> keySet = new HashSet<>();
|
||||
for (Entry<String, Object> item : values.valueSet()) {
|
||||
String key = item.getKey();
|
||||
keySet.add(key);
|
||||
|
@ -26,8 +26,8 @@ public class InstalledAppCacheUpdater {
|
||||
|
||||
private Context context;
|
||||
|
||||
private List<PackageInfo> toInsert = new ArrayList<PackageInfo>();
|
||||
private List<String> toDelete = new ArrayList<String>();
|
||||
private List<PackageInfo> toInsert = new ArrayList<>();
|
||||
private List<String> toDelete = new ArrayList<>();
|
||||
|
||||
protected InstalledAppCacheUpdater(Context context) {
|
||||
this.context = context;
|
||||
@ -89,7 +89,7 @@ public class InstalledAppCacheUpdater {
|
||||
|
||||
private void updateCache() {
|
||||
|
||||
ArrayList<ContentProviderOperation> ops = new ArrayList<ContentProviderOperation>();
|
||||
ArrayList<ContentProviderOperation> ops = new ArrayList<>();
|
||||
ops.addAll(deleteFromCache(toDelete));
|
||||
ops.addAll(insertIntoCache(toInsert));
|
||||
|
||||
@ -126,7 +126,7 @@ public class InstalledAppCacheUpdater {
|
||||
}
|
||||
|
||||
private List<ContentProviderOperation> insertIntoCache(List<PackageInfo> appsToInsert) {
|
||||
List<ContentProviderOperation> ops = new ArrayList<ContentProviderOperation>(appsToInsert.size());
|
||||
List<ContentProviderOperation> ops = new ArrayList<>(appsToInsert.size());
|
||||
if (appsToInsert.size() > 0) {
|
||||
Log.d(TAG, "Preparing to cache installed info for " + appsToInsert.size() + " new apps.");
|
||||
Uri uri = InstalledAppProvider.getContentUri();
|
||||
@ -145,7 +145,7 @@ public class InstalledAppCacheUpdater {
|
||||
}
|
||||
|
||||
private List<ContentProviderOperation> deleteFromCache(List<String> appIds) {
|
||||
List<ContentProviderOperation> ops = new ArrayList<ContentProviderOperation>(appIds.size());
|
||||
List<ContentProviderOperation> ops = new ArrayList<>(appIds.size());
|
||||
if (appIds.size() > 0) {
|
||||
Log.d(TAG, "Preparing to remove " + appIds.size() + " apps from the installed app cache.");
|
||||
for (String appId : appIds) {
|
||||
|
@ -28,7 +28,7 @@ public class InstalledAppProvider extends FDroidProvider {
|
||||
*/
|
||||
public static Map<String, Integer> all(Context context) {
|
||||
|
||||
Map<String, Integer> cachedInfo = new HashMap<String, Integer>();
|
||||
Map<String, Integer> cachedInfo = new HashMap<>();
|
||||
|
||||
Uri uri = InstalledAppProvider.getContentUri();
|
||||
String[] projection = InstalledAppProvider.DataColumns.ALL;
|
||||
|
@ -5,7 +5,7 @@ import java.util.List;
|
||||
|
||||
abstract class QueryBuilder {
|
||||
|
||||
private List<String> fields = new ArrayList<String>();
|
||||
private List<String> fields = new ArrayList<>();
|
||||
private StringBuilder tables = new StringBuilder(getRequiredTables());
|
||||
private String selection = null;
|
||||
private String orderBy = null;
|
||||
|
@ -63,7 +63,7 @@ public class QuerySelection {
|
||||
|
||||
int thisNumArgs = this.hasArgs() ? this.args.length : 0;
|
||||
int queryNumArgs = query.hasArgs() ? query.args.length : 0;
|
||||
List<String> a = new ArrayList<String>(thisNumArgs + queryNumArgs);
|
||||
List<String> a = new ArrayList<>(thisNumArgs + queryNumArgs);
|
||||
|
||||
if (this.hasArgs()) {
|
||||
Collections.addAll(a, this.args);
|
||||
|
@ -76,7 +76,7 @@ public class RepoProvider extends FDroidProvider {
|
||||
|
||||
private static List<Repo> cursorToList(Cursor cursor) {
|
||||
int knownRepoCount = cursor != null ? cursor.getCount() : 0;
|
||||
List<Repo> repos = new ArrayList<Repo>(knownRepoCount);
|
||||
List<Repo> repos = new ArrayList<>(knownRepoCount);
|
||||
if (cursor != null) {
|
||||
if (knownRepoCount > 0) {
|
||||
cursor.moveToFirst();
|
||||
|
@ -160,7 +160,7 @@ public class RootInstaller extends Installer {
|
||||
}
|
||||
|
||||
private void addInstallCommand(List<File> apkFiles) {
|
||||
List<String> commands = new ArrayList<String>();
|
||||
List<String> commands = new ArrayList<>();
|
||||
String pm = "pm install -r ";
|
||||
for (File apkFile : apkFiles) {
|
||||
// see addInstallCommand()
|
||||
|
@ -263,7 +263,7 @@ public class LocalRepoService extends Service {
|
||||
if (pairService != null || jmdns != null)
|
||||
clearCurrentMDNSService();
|
||||
String repoName = Preferences.get().getLocalRepoName();
|
||||
HashMap<String, String> values = new HashMap<String, String>();
|
||||
HashMap<String, String> values = new HashMap<>();
|
||||
values.put("path", "/fdroid/repo");
|
||||
values.put("name", repoName);
|
||||
values.put("fingerprint", FDroidApp.repo.fingerprint);
|
||||
|
@ -129,7 +129,7 @@ public class MDnsHelper implements ServiceListener {
|
||||
public static class RepoScanListAdapter extends BaseAdapter {
|
||||
private Context mContext;
|
||||
private LayoutInflater mLayoutInflater;
|
||||
private List<DiscoveredRepo> mEntries = new ArrayList<DiscoveredRepo>();
|
||||
private List<DiscoveredRepo> mEntries = new ArrayList<>();
|
||||
|
||||
public RepoScanListAdapter(Context context) {
|
||||
mContext = context;
|
||||
|
@ -48,8 +48,8 @@ abstract public class RepoUpdater {
|
||||
|
||||
protected final Context context;
|
||||
protected final Repo repo;
|
||||
private List<App> apps = new ArrayList<App>();
|
||||
private List<Apk> apks = new ArrayList<Apk>();
|
||||
private List<App> apps = new ArrayList<>();
|
||||
private List<Apk> apks = new ArrayList<>();
|
||||
private RepoUpdateRememberer rememberer = null;
|
||||
protected boolean usePubkeyInJar = false;
|
||||
protected boolean hasChanged = false;
|
||||
|
@ -111,7 +111,7 @@ public class AvailableAppsFragment extends AppListFragment implements
|
||||
List<String> categories = AppProvider.Helper.categories(getActivity());
|
||||
|
||||
// attempt to translate category names with fallback to default name
|
||||
List<String> translatedCategories = new ArrayList<String>(categories.size());
|
||||
List<String> translatedCategories = new ArrayList<>(categories.size());
|
||||
Resources res = getResources();
|
||||
for (String category : categories) {
|
||||
int id = res.getIdentifier(category.replace(" & ", "_"), "string", getActivity().getPackageName());
|
||||
@ -135,7 +135,7 @@ public class AvailableAppsFragment extends AppListFragment implements
|
||||
}
|
||||
}
|
||||
|
||||
ArrayAdapter<String> adapter = new ArrayAdapter<String>(
|
||||
ArrayAdapter<String> adapter = new ArrayAdapter<>(
|
||||
getActivity(), android.R.layout.simple_spinner_item, translatedCategories);
|
||||
adapter.setDropDownViewResource(
|
||||
android.R.layout.simple_spinner_dropdown_item);
|
||||
|
@ -113,7 +113,7 @@ public class SelectLocalAppsFragment extends ListFragment
|
||||
|
||||
// build list of existing apps from what is on the file system
|
||||
if (FDroidApp.selectedApps == null) {
|
||||
Set<String> selectedApps = new HashSet<String>();
|
||||
Set<String> selectedApps = new HashSet<>();
|
||||
for (String filename : LocalRepoManager.get(selectLocalAppsActivity).repoDir.list()) {
|
||||
if (filename.matches(".*\\.apk")) {
|
||||
String packageName = filename.substring(0, filename.indexOf("_"));
|
||||
|
Loading…
x
Reference in New Issue
Block a user