Prefer unsynchronized ArrayList over Vector

This commit is contained in:
Andrew Gaul 2012-12-11 19:42:39 -08:00
parent 8dd337f345
commit 716b1c802b
9 changed files with 49 additions and 47 deletions

View File

@ -22,7 +22,6 @@ import java.io.File;
import java.security.NoSuchAlgorithmException; import java.security.NoSuchAlgorithmException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Vector;
import android.support.v4.view.MenuItemCompat; import android.support.v4.view.MenuItemCompat;
import org.xml.sax.XMLReader; import org.xml.sax.XMLReader;
@ -302,7 +301,7 @@ public class AppDetails extends ListActivity {
Log.d("FDroid", "Getting application details for " + appid); Log.d("FDroid", "Getting application details for " + appid);
app = null; app = null;
Vector<DB.App> apps = ((FDroidApp) getApplication()).getApps(); List<DB.App> apps = ((FDroidApp) getApplication()).getApps();
for (DB.App tapp : apps) { for (DB.App tapp : apps) {
if (tapp.id.equals(appid)) { if (tapp.id.equals(appid)) {
app = tapp; app = tapp;

View File

@ -15,7 +15,7 @@ import java.util.*;
*/ */
public class AppListManager { public class AppListManager {
private Vector<DB.App> allApps = null; private List<DB.App> allApps = null;
private FDroid fdroidActivity; private FDroid fdroidActivity;
@ -55,7 +55,7 @@ public class AppListManager {
// Needs to be created before createViews(), because that will use the // Needs to be created before createViews(), because that will use the
// getCategoriesAdapter() accessor which expects this object... // getCategoriesAdapter() accessor which expects this object...
categories = new ArrayAdapter<String>(activity, categories = new ArrayAdapter<String>(activity,
android.R.layout.simple_spinner_item, new Vector<String>()); android.R.layout.simple_spinner_item, new ArrayList<String>());
categories categories
.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); .setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
} }
@ -185,7 +185,7 @@ public class AppListManager {
Date recentDate = calcMaxHistory(); Date recentDate = calcMaxHistory();
AppFilter appFilter = new AppFilter(fdroidActivity); AppFilter appFilter = new AppFilter(fdroidActivity);
Vector<DB.App> availApps = new Vector<DB.App>(); List<DB.App> availApps = new ArrayList<DB.App>();
for (DB.App app : allApps) { for (DB.App app : allApps) {
boolean isInCategory = isInCategory(app, currentCategory, recentDate); boolean isInCategory = isInCategory(app, currentCategory, recentDate);

View File

@ -21,6 +21,7 @@ package org.fdroid.fdroid;
import java.io.File; import java.io.File;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.Date; import java.util.Date;
import java.util.HashMap; import java.util.HashMap;
@ -28,7 +29,6 @@ import java.util.HashSet;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Vector;
import java.util.concurrent.Semaphore; import java.util.concurrent.Semaphore;
import android.annotation.TargetApi; import android.annotation.TargetApi;
@ -116,7 +116,7 @@ public class DB {
updated = false; updated = false;
added = null; added = null;
lastUpdated = null; lastUpdated = null;
apks = new Vector<Apk>(); apks = new ArrayList<Apk>();
detail_Populated = false; detail_Populated = false;
compatible = false; compatible = false;
} }
@ -181,7 +181,7 @@ public class DB {
public boolean updated; public boolean updated;
// List of apks. // List of apks.
public Vector<Apk> apks; public List<Apk> apks;
// Get the current version - this will be one of the Apks from 'apks'. // Get the current version - this will be one of the Apks from 'apks'.
// Can return null if there are no available versions. // Can return null if there are no available versions.
@ -413,7 +413,7 @@ public class DB {
// Migrate repo list to new structure. (No way to change primary // Migrate repo list to new structure. (No way to change primary
// key in sqlite - table must be recreated) // key in sqlite - table must be recreated)
if (oldVersion < 20) { if (oldVersion < 20) {
Vector<Repo> oldrepos = new Vector<Repo>(); List<Repo> oldrepos = new ArrayList<Repo>();
Cursor c = db.rawQuery("select address, inuse, pubkey from " Cursor c = db.rawQuery("select address, inuse, pubkey from "
+ TABLE_REPO, null); + TABLE_REPO, null);
c.moveToFirst(); c.moveToFirst();
@ -504,7 +504,7 @@ public class DB {
// Get the number of apps that have updates available. This can be a // Get the number of apps that have updates available. This can be a
// time consuming operation. // time consuming operation.
public int getNumUpdates() { public int getNumUpdates() {
Vector<App> apps = getApps(true); List<App> apps = getApps(true);
int count = 0; int count = 0;
for (App app : apps) { for (App app : apps) {
if (app.hasUpdates) if (app.hasUpdates)
@ -513,8 +513,8 @@ public class DB {
return count; return count;
} }
public Vector<String> getCategories() { public List<String> getCategories() {
Vector<String> result = new Vector<String>(); List<String> result = new ArrayList<String>();
Cursor c = null; Cursor c = null;
try { try {
c = db.rawQuery("select distinct category from " + TABLE_APP c = db.rawQuery("select distinct category from " + TABLE_APP
@ -592,7 +592,7 @@ public class DB {
// Return a list of apps matching the given criteria. Filtering is // Return a list of apps matching the given criteria. Filtering is
// also done based on compatibility and anti-features according to // also done based on compatibility and anti-features according to
// the user's current preferences. // the user's current preferences.
public Vector<App> getApps(boolean getinstalledinfo) { public List<App> getApps(boolean getinstalledinfo) {
// If we're going to need it, get info in what's currently installed // If we're going to need it, get info in what's currently installed
Map<String, PackageInfo> systemApks = null; Map<String, PackageInfo> systemApks = null;
@ -697,7 +697,7 @@ public class DB {
+ (System.currentTimeMillis() - startTime) + " ms)"); + (System.currentTimeMillis() - startTime) + " ms)");
} }
Vector<App> result = new Vector<App>(apps.values()); List<App> result = new ArrayList<App>(apps.values());
Collections.sort(result); Collections.sort(result);
// Fill in the hasUpdates fields if we have the necessary information... // Fill in the hasUpdates fields if we have the necessary information...
@ -721,9 +721,9 @@ public class DB {
return result; return result;
} }
public Vector<String> doSearch(String query) { public List<String> doSearch(String query) {
Vector<String> ids = new Vector<String>(); List<String> ids = new ArrayList<String>();
Cursor c = null; Cursor c = null;
try { try {
String filter = "%" + query + "%"; String filter = "%" + query + "%";
@ -771,11 +771,11 @@ public class DB {
} }
} }
private Vector<App> updateApps = null; private List<App> updateApps = null;
// Called before a repo update starts. Returns the number of updates // Called before a repo update starts. Returns the number of updates
// available beforehand. // available beforehand.
public int beginUpdate(Vector<DB.App> apps) { public int beginUpdate(List<DB.App> apps) {
// Get a list of all apps. All the apps and apks in this list will // Get a list of all apps. All the apps and apks in this list will
// have 'updated' set to false at this point, and we will only set // have 'updated' set to false at this point, and we will only set
// it to true when we see the app/apk in a repository. Thus, at the // it to true when we see the app/apk in a repository. Thus, at the
@ -866,7 +866,7 @@ public class DB {
// compatible apk - if it's not, leave it out) // compatible apk - if it's not, leave it out)
// Also keep a list of which were compatible, because they're the // Also keep a list of which were compatible, because they're the
// only ones we'll add, unless the showIncompatible preference is set. // only ones we'll add, unless the showIncompatible preference is set.
Vector<Apk> compatibleapks = new Vector<Apk>(); List<Apk> compatibleapks = new ArrayList<Apk>();
for (Apk apk : upapp.apks) { for (Apk apk : upapp.apks) {
if (compatChecker.isCompatible(apk)) { if (compatChecker.isCompatible(apk)) {
apk.compatible = true; apk.compatible = true;
@ -1017,8 +1017,8 @@ public class DB {
} }
// Get a list of the configured repositories. // Get a list of the configured repositories.
public Vector<Repo> getRepos() { public List<Repo> getRepos() {
Vector<Repo> repos = new Vector<Repo>(); List<Repo> repos = new ArrayList<Repo>();
Cursor c = null; Cursor c = null;
try { try {
c = db.rawQuery( c = db.rawQuery(
@ -1079,7 +1079,7 @@ public class DB {
db.insert(TABLE_REPO, null, values); db.insert(TABLE_REPO, null, values);
} }
public void removeServers(Vector<String> addresses) { public void removeServers(List<String> addresses) {
db.beginTransaction(); db.beginTransaction();
try { try {
for (String address : addresses) { for (String address : addresses) {

View File

@ -23,8 +23,9 @@ import android.app.ActionBar;
import java.util.Calendar; import java.util.Calendar;
import java.util.Collections; import java.util.Collections;
import java.util.Comparator; import java.util.Comparator;
import java.util.ArrayList;
import java.util.Date; import java.util.Date;
import java.util.Vector; import java.util.List;
import android.support.v4.view.MenuItemCompat; import android.support.v4.view.MenuItemCompat;
import org.fdroid.fdroid.DB.App; import org.fdroid.fdroid.DB.App;

View File

@ -19,7 +19,8 @@
package org.fdroid.fdroid; package org.fdroid.fdroid;
import java.io.File; import java.io.File;
import java.util.Vector; import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.Semaphore; import java.util.concurrent.Semaphore;
import android.app.Application; import android.app.Application;
@ -47,7 +48,7 @@ public class FDroidApp extends Application {
} }
// Global list of all known applications. // Global list of all known applications.
private Vector<DB.App> apps; private List<DB.App> apps;
// Set when something has changed (database or installed apps) so we know // Set when something has changed (database or installed apps) so we know
// we should invalidate the apps. // we should invalidate the apps.
@ -70,7 +71,7 @@ public class FDroidApp extends Application {
// Get a list of all known applications. Should not be called when the // Get a list of all known applications. Should not be called when the
// database is locked (i.e. between DB.getDB() and db.releaseDB(). The // database is locked (i.e. between DB.getDB() and db.releaseDB(). The
// contents should never be modified, it's for reading only. // contents should never be modified, it's for reading only.
public Vector<DB.App> getApps() { public List<DB.App> getApps() {
boolean invalid = false; boolean invalid = false;
try { try {
@ -95,7 +96,7 @@ public class FDroidApp extends Application {
} }
} }
if (apps == null) if (apps == null)
return new Vector<DB.App>(); return new ArrayList<DB.App>();
return apps; return apps;
} }

View File

@ -26,7 +26,6 @@ import java.util.Formatter;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Vector;
import android.app.AlertDialog; import android.app.AlertDialog;
import android.app.AlertDialog.Builder; import android.app.AlertDialog.Builder;
@ -55,7 +54,7 @@ public class ManageRepo extends ListActivity {
private boolean changed = false; private boolean changed = false;
private Vector<DB.Repo> repos; private List<DB.Repo> repos;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
@ -201,7 +200,7 @@ public class ManageRepo extends ListActivity {
return true; return true;
case REM_REPO: case REM_REPO:
final Vector<String> rem_lst = new Vector<String>(); final List<String> rem_lst = new ArrayList<String>();
CharSequence[] b = new CharSequence[repos.size()]; CharSequence[] b = new CharSequence[repos.size()];
for (int i = 0; i < repos.size(); i++) { for (int i = 0; i < repos.size(); i++) {
b[i] = repos.get(i).address; b[i] = repos.get(i).address;
@ -215,9 +214,9 @@ public class ManageRepo extends ListActivity {
public void onClick(DialogInterface dialog, public void onClick(DialogInterface dialog,
int whichButton, boolean isChecked) { int whichButton, boolean isChecked) {
if (isChecked) { if (isChecked) {
rem_lst.addElement(repos.get(whichButton).address); rem_lst.add(repos.get(whichButton).address);
} else { } else {
rem_lst.removeElement(repos.get(whichButton).address); rem_lst.remove(repos.get(whichButton).address);
} }
} }
}); });

View File

@ -33,7 +33,7 @@ import java.net.URL;
import java.security.cert.Certificate; import java.security.cert.Certificate;
import java.text.ParseException; import java.text.ParseException;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.Vector; import java.util.List;
import java.util.jar.JarEntry; import java.util.jar.JarEntry;
import java.util.jar.JarFile; import java.util.jar.JarFile;
@ -57,7 +57,7 @@ public class RepoXMLHandler extends DefaultHandler {
// The ID of the repo we're processing. // The ID of the repo we're processing.
private int repo; private int repo;
private Vector<DB.App> apps; private List<DB.App> apps;
private DB.App curapp = null; private DB.App curapp = null;
private DB.Apk curapk = null; private DB.Apk curapk = null;
@ -69,7 +69,7 @@ public class RepoXMLHandler extends DefaultHandler {
// The date format used in the repo XML file. // The date format used in the repo XML file.
private SimpleDateFormat mXMLDateFormat = new SimpleDateFormat("yyyy-MM-dd"); private SimpleDateFormat mXMLDateFormat = new SimpleDateFormat("yyyy-MM-dd");
public RepoXMLHandler(int repo, Vector<DB.App> apps) { public RepoXMLHandler(int repo, List<DB.App> apps) {
this.repo = repo; this.repo = repo;
this.apps = apps; this.apps = apps;
pubkey = null; pubkey = null;
@ -293,7 +293,7 @@ public class RepoXMLHandler extends DefaultHandler {
// value for the index that was successfully processed, or it may contain // value for the index that was successfully processed, or it may contain
// null if none was available. // null if none was available.
public static String doUpdate(Context ctx, DB.Repo repo, public static String doUpdate(Context ctx, DB.Repo repo,
Vector<DB.App> apps, StringBuilder newetag, Vector<Integer> keeprepos) { List<DB.App> apps, StringBuilder newetag, List<Integer> keeprepos) {
try { try {
int code = 0; int code = 0;

View File

@ -18,7 +18,8 @@
package org.fdroid.fdroid; package org.fdroid.fdroid;
import java.util.Vector; import java.util.ArrayList;
import java.util.List;
import android.app.ListActivity; import android.app.ListActivity;
import android.app.SearchManager; import android.app.SearchManager;
@ -68,7 +69,7 @@ public class SearchResults extends ListActivity {
private void updateView() { private void updateView() {
Vector<String> matchingids = new Vector<String>(); List<String> matchingids = new ArrayList<String>();
try { try {
DB db = DB.getDB(); DB db = DB.getDB();
matchingids = db.doSearch(mQuery); matchingids = db.doSearch(mQuery);
@ -78,9 +79,9 @@ public class SearchResults extends ListActivity {
DB.releaseDB(); DB.releaseDB();
} }
Vector<DB.App> apps = new Vector<DB.App>(); List<DB.App> apps = new ArrayList<DB.App>();
AppFilter appfilter = new AppFilter(this); AppFilter appfilter = new AppFilter(this);
Vector<DB.App> tapps = ((FDroidApp) getApplication()).getApps(); List<DB.App> tapps = ((FDroidApp) getApplication()).getApps();
for (DB.App tapp : tapps) { for (DB.App tapp : tapps) {
boolean include = false; boolean include = false;
for (String tid : matchingids) { for (String tid : matchingids) {

View File

@ -24,7 +24,8 @@ import java.io.InputStream;
import java.io.OutputStream; import java.io.OutputStream;
import java.net.HttpURLConnection; import java.net.HttpURLConnection;
import java.net.URL; import java.net.URL;
import java.util.Vector; import java.util.ArrayList;
import java.util.List;
import android.app.AlarmManager; import android.app.AlarmManager;
import android.app.IntentService; import android.app.IntentService;
@ -110,7 +111,7 @@ public class UpdateService extends IntentService {
// database while we do all the downloading, etc... // database while we do all the downloading, etc...
int prevUpdates = 0; int prevUpdates = 0;
int newUpdates = 0; int newUpdates = 0;
Vector<DB.Repo> repos; List<DB.Repo> repos;
try { try {
DB db = DB.getDB(); DB db = DB.getDB();
repos = db.getRepos(); repos = db.getRepos();
@ -119,8 +120,8 @@ public class UpdateService extends IntentService {
} }
// Process each repo... // Process each repo...
Vector<DB.App> apps = new Vector<DB.App>(); List<DB.App> apps = new ArrayList<DB.App>();
Vector<Integer> keeprepos = new Vector<Integer>(); List<Integer> keeprepos = new ArrayList<Integer>();
boolean success = true; boolean success = true;
for (DB.Repo repo : repos) { for (DB.Repo repo : repos) {
if (repo.inuse) { if (repo.inuse) {
@ -142,8 +143,8 @@ public class UpdateService extends IntentService {
} }
if (success) { if (success) {
Vector<DB.App> acceptedapps = new Vector<DB.App>(); List<DB.App> acceptedapps = new ArrayList<DB.App>();
Vector<DB.App> prevapps = ((FDroidApp) getApplication()) List<DB.App> prevapps = ((FDroidApp) getApplication())
.getApps(); .getApps();
DB db = DB.getDB(); DB db = DB.getDB();
@ -272,7 +273,7 @@ public class UpdateService extends IntentService {
} }
private void getIcon(DB.App app, Vector<DB.Repo> repos) { private void getIcon(DB.App app, List<DB.Repo> repos) {
try { try {
File f = new File(DB.getIconsPath(), app.icon); File f = new File(DB.getIconsPath(), app.icon);