Simplify a few elses

Mostly just dropping them after returns.
This commit is contained in:
Daniel Martí 2015-10-12 12:37:39 +02:00
parent 603a5b25e4
commit 8d4e785185
10 changed files with 41 additions and 52 deletions

View File

@ -150,11 +150,10 @@ public class PrivilegedInstaller extends Installer {
}
boolean hasPermissions = returnBundle.getBoolean("has_permissions", false);
if (hasPermissions) {
return IS_EXTENSION_INSTALLED_YES;
} else {
if (!hasPermissions) {
return IS_EXTENSION_INSTALLED_PERMISSIONS_PROBLEM;
}
return IS_EXTENSION_INSTALLED_YES;
}
@Override

View File

@ -34,12 +34,11 @@ public final class BluetoothSwap extends SwapType {
BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
if (adapter == null) {
return new NoBluetoothType(context);
} else {
if (mInstance == null)
mInstance = new BluetoothSwap(context, adapter);
return mInstance;
}
if (mInstance == null)
mInstance = new BluetoothSwap(context, adapter);
return mInstance;
}
private BluetoothSwap(@NonNull Context context, @NonNull BluetoothAdapter adapter) {

View File

@ -344,10 +344,9 @@ public class AsyncDownloaderFromAndroid implements AsyncDownloader {
int status = c.getInt(c.getColumnIndex(DownloadManager.COLUMN_STATUS));
if (status == DownloadManager.STATUS_SUCCESSFUL) {
return 0; //Download is valid, celebrate
} else {
return c.getInt(c.getColumnIndex(DownloadManager.COLUMN_REASON));
return 0; // Download is valid, celebrate
}
return c.getInt(c.getColumnIndex(DownloadManager.COLUMN_REASON));
}
} finally {
c.close();

View File

@ -41,11 +41,11 @@ public class DownloaderFactory {
if (isBluetoothAddress(url)) {
String macAddress = url.getHost().replace("-", ":");
return new BluetoothDownloader(context, macAddress, url, destFile);
} else if (isOnionAddress(url)) {
return new TorHttpDownloader(context, url, destFile);
} else {
return new HttpDownloader(context, url, destFile);
}
if (isOnionAddress(url)) {
return new TorHttpDownloader(context, url, destFile);
}
return new HttpDownloader(context, url, destFile);
}
private static boolean isBluetoothAddress(URL url) {
@ -60,9 +60,8 @@ public class DownloaderFactory {
throws IOException {
if (canUseDownloadManager(url)) {
return new AsyncDownloaderFromAndroid(context, listener, title, id, url.toString(), destFile);
} else {
return new AsyncDownloadWrapper(create(context, url, destFile), listener);
}
return new AsyncDownloadWrapper(create(context, url, destFile), listener);
}
static boolean isOnionAddress(URL url) {

View File

@ -221,13 +221,12 @@ public class WifiStateChangeService extends Service {
private String formatIpAddress(int ipAddress) {
if (ipAddress == 0) {
return null;
} else {
return String.format(Locale.ENGLISH, "%d.%d.%d.%d",
ipAddress & 0xff,
ipAddress >> 8 & 0xff,
ipAddress >> 16 & 0xff,
ipAddress >> 24 & 0xff);
}
return String.format(Locale.ENGLISH, "%d.%d.%d.%d",
ipAddress & 0xff,
ipAddress >> 8 & 0xff,
ipAddress >> 16 & 0xff,
ipAddress >> 24 & 0xff);
}
private String printWifiState(int wifiState) {

View File

@ -234,13 +234,11 @@ public class BluetoothServer extends Thread {
if (f.canRead()) {
// No index file, list the directory if it is readable
return createResponse(NanoHTTPD.Response.Status.NOT_FOUND, NanoHTTPD.MIME_HTML, "");
} else {
return createResponse(NanoHTTPD.Response.Status.FORBIDDEN, NanoHTTPD.MIME_PLAINTEXT,
"FORBIDDEN: No directory listing.");
}
} else {
return respond(headers, uri + indexFile);
return createResponse(NanoHTTPD.Response.Status.FORBIDDEN, NanoHTTPD.MIME_PLAINTEXT,
"FORBIDDEN: No directory listing.");
}
return respond(headers, uri + indexFile);
}
Response response = serveFile(uri, headers, f, getMimeTypeForFile(uri));

View File

@ -75,11 +75,9 @@ public final class Request {
if (method.equals(Methods.HEAD)) {
Utils.debugLog(TAG, "Request was a " + Methods.HEAD + " request, not including anything other than headers and status...");
return new Response(responseCode, headers);
} else {
Utils.debugLog(TAG, "Request was a " + Methods.GET + " request, so including content stream in response...");
return new Response(responseCode, headers, connection.getInputStream());
}
Utils.debugLog(TAG, "Request was a " + Methods.GET + " request, so including content stream in response...");
return new Response(responseCode, headers, connection.getInputStream());
}
/**

View File

@ -49,11 +49,11 @@ abstract class InstallExtension {
public static InstallExtension create(final Context context) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
return new LollipopImpl(context);
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
return new KitKatToLollipopImpl(context);
} else {
return new PreKitKatImpl(context);
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
return new KitKatToLollipopImpl(context);
}
return new PreKitKatImpl(context);
}
final void runInstall(String apkPath) {

View File

@ -99,17 +99,16 @@ public class AppSecurityPermissions {
public Drawable loadGroupIcon(PackageManager pm) {
if (icon != 0) {
//return loadUnbadgedIcon(pm);
// return loadUnbadgedIcon(pm);
return loadIcon(pm);
} else {
ApplicationInfo appInfo;
try {
appInfo = pm.getApplicationInfo(packageName, 0);
//return appInfo.loadUnbadgedIcon(pm);
return appInfo.loadIcon(pm);
} catch (NameNotFoundException e) {
// ignore
}
}
ApplicationInfo appInfo;
try {
appInfo = pm.getApplicationInfo(packageName, 0);
// return appInfo.loadUnbadgedIcon(pm);
return appInfo.loadIcon(pm);
} catch (NameNotFoundException e) {
// ignore
}
return null;
}

View File

@ -28,14 +28,13 @@ public abstract class ThemeableListFragment extends ListFragment {
private View headerView;
private View getHeaderView(LayoutInflater inflater, ViewGroup container) {
if (getHeaderLayout() > 0) {
if (headerView == null) {
headerView = inflater.inflate(getHeaderLayout(), null, false);
}
return headerView;
} else {
if (getHeaderLayout() == 0) {
return null;
}
if (headerView == null) {
headerView = inflater.inflate(getHeaderLayout(), null, false);
}
return headerView;
}
private LayoutInflater getThemedInflater(Context context) {