More static imports.

This commit is contained in:
akwizgran
2018-12-20 16:51:10 +00:00
parent ad9191b076
commit 8ecec8bcf5
83 changed files with 313 additions and 288 deletions

View File

@@ -25,7 +25,6 @@ import java.security.cert.CertificateFactory;
import java.security.cert.X509Certificate;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
@@ -46,6 +45,9 @@ import static android.content.pm.PackageInfo.REQUESTED_PERMISSION_GRANTED;
import static android.content.pm.PackageManager.GET_PERMISSIONS;
import static android.content.pm.PackageManager.GET_SIGNATURES;
import static android.os.Build.VERSION.SDK_INT;
import static java.util.Collections.emptySet;
import static java.util.Collections.sort;
import static java.util.Collections.unmodifiableList;
import static java.util.logging.Level.WARNING;
import static java.util.logging.Logger.getLogger;
import static org.briarproject.bramble.util.LogUtils.logException;
@@ -105,8 +107,7 @@ class ScreenFilterMonitorImpl implements ScreenFilterMonitor, Service {
@UiThread
public Collection<AppDetails> getApps() {
if (cachedApps != null) return cachedApps;
Set<String> allowed = prefs.getStringSet(PREF_KEY_ALLOWED,
Collections.emptySet());
Set<String> allowed = prefs.getStringSet(PREF_KEY_ALLOWED, emptySet());
List<AppDetails> apps = new ArrayList<>();
List<PackageInfo> packageInfos =
pm.getInstalledPackages(GET_PERMISSIONS);
@@ -117,8 +118,8 @@ class ScreenFilterMonitorImpl implements ScreenFilterMonitor, Service {
apps.add(new AppDetails(name, packageInfo.packageName));
}
}
Collections.sort(apps, (a, b) -> a.name.compareTo(b.name));
apps = Collections.unmodifiableList(apps);
sort(apps, (a, b) -> a.name.compareTo(b.name));
apps = unmodifiableList(apps);
cachedApps = apps;
return apps;
}
@@ -127,8 +128,7 @@ class ScreenFilterMonitorImpl implements ScreenFilterMonitor, Service {
@UiThread
public void allowApps(Collection<String> packageNames) {
cachedApps = null;
Set<String> allowed = prefs.getStringSet(PREF_KEY_ALLOWED,
Collections.emptySet());
Set<String> allowed = prefs.getStringSet(PREF_KEY_ALLOWED, emptySet());
Set<String> merged = new HashSet<>(allowed);
merged.addAll(packageNames);
prefs.edit().putStringSet(PREF_KEY_ALLOWED, merged).apply();

View File

@@ -4,10 +4,11 @@ import org.briarproject.briar.api.blog.BlogCommentHeader;
import org.briarproject.briar.api.blog.BlogPostHeader;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import static java.util.Collections.sort;
// This class is not thread-safe
class BlogCommentItem extends BlogPostItem {
@@ -20,7 +21,7 @@ class BlogCommentItem extends BlogPostItem {
BlogCommentItem(BlogCommentHeader header) {
super(header, null);
postHeader = collectComments(header);
Collections.sort(comments, COMPARATOR);
sort(comments, COMPARATOR);
}
private BlogPostHeader collectComments(BlogPostHeader header) {

View File

@@ -7,7 +7,6 @@ import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.net.wifi.WifiInfo;
import android.net.wifi.WifiManager;
import android.os.Build;
import android.os.Environment;
import android.os.Handler;
import android.os.Looper;
@@ -23,7 +22,6 @@ import org.briarproject.briar.android.logging.BriefLogFormatter;
import java.io.File;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.concurrent.Callable;
@@ -41,6 +39,8 @@ import static android.content.Context.WIFI_SERVICE;
import static android.net.ConnectivityManager.TYPE_MOBILE;
import static android.net.ConnectivityManager.TYPE_WIFI;
import static android.net.wifi.WifiManager.WIFI_STATE_ENABLED;
import static android.os.Build.VERSION.SDK_INT;
import static java.util.Collections.unmodifiableMap;
import static org.briarproject.bramble.util.PrivacyUtils.scrubInetAddress;
import static org.briarproject.bramble.util.PrivacyUtils.scrubMacAddress;
import static org.briarproject.bramble.util.StringUtils.isNullOrEmpty;
@@ -90,7 +90,7 @@ public class BriarReportPrimer implements ReportPrimer {
ActivityManager.MemoryInfo mem = new ActivityManager.MemoryInfo();
am.getMemoryInfo(mem);
String systemMemory;
if (Build.VERSION.SDK_INT >= 16) {
if (SDK_INT >= 16) {
systemMemory = (mem.totalMem / 1024 / 1024) + " MiB total, "
+ (mem.availMem / 1024 / 1204) + " MiB free, "
+ (mem.threshold / 1024 / 1024) + " MiB threshold";
@@ -213,7 +213,7 @@ public class BriarReportPrimer implements ReportPrimer {
bt.getScanMode() == SCAN_MODE_CONNECTABLE_DISCOVERABLE;
// Is Bluetooth LE scanning and advertising supported?
boolean btLeApi = false, btLeScan = false, btLeAdvertise = false;
if (bt != null && Build.VERSION.SDK_INT >= 21) {
if (bt != null && SDK_INT >= 21) {
btLeApi = true;
btLeScan = bt.getBluetoothLeScanner() != null;
btLeAdvertise = bt.getBluetoothLeAdvertiser() != null;
@@ -255,7 +255,7 @@ public class BriarReportPrimer implements ReportPrimer {
// Git commit ID
customData.put("Commit ID", BuildConfig.GitHash);
return Collections.unmodifiableMap(customData);
return unmodifiableMap(customData);
}
}

View File

@@ -42,7 +42,6 @@ import org.briarproject.briar.android.Localizer;
import org.briarproject.briar.android.navdrawer.NavDrawerActivity;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Locale;
import java.util.logging.Logger;
@@ -67,6 +66,7 @@ import static android.provider.Settings.EXTRA_CHANNEL_ID;
import static android.provider.Settings.System.DEFAULT_NOTIFICATION_URI;
import static android.support.v4.view.ViewCompat.LAYOUT_DIRECTION_LTR;
import static android.widget.Toast.LENGTH_SHORT;
import static java.util.Arrays.asList;
import static java.util.logging.Level.INFO;
import static java.util.logging.Level.WARNING;
import static java.util.logging.Logger.getLogger;
@@ -222,7 +222,7 @@ public class SettingsFragment extends PreferenceFragmentCompat
if (SDK_INT < 27) {
// remove System Default Theme option
List<CharSequence> entries =
new ArrayList<>(Arrays.asList(theme.getEntries()));
new ArrayList<>(asList(theme.getEntries()));
entries.remove(getString(R.string.pref_theme_system));
theme.setEntries(entries.toArray(new CharSequence[0]));
}

View File

@@ -1,7 +1,6 @@
package org.briarproject.briar.android.splash;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.support.v7.preference.PreferenceManager;
@@ -21,6 +20,7 @@ import java.util.logging.Logger;
import javax.inject.Inject;
import static android.os.Build.VERSION.SDK_INT;
import static java.util.logging.Logger.getLogger;
import static org.briarproject.briar.android.TestingConstants.EXPIRY_DATE;
@@ -40,7 +40,7 @@ public class SplashScreenActivity extends BaseActivity {
public void onCreate(Bundle state) {
super.onCreate(state);
if (Build.VERSION.SDK_INT >= 21) {
if (SDK_INT >= 21) {
getWindow().setExitTransition(new Fade());
}

View File

@@ -28,12 +28,12 @@ import org.briarproject.briar.api.client.PostHeader;
import org.briarproject.briar.api.client.ThreadedMessage;
import java.util.Collection;
import java.util.Collections;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.Executor;
import java.util.logging.Logger;
import static java.util.Collections.singletonList;
import static java.util.logging.Level.INFO;
import static java.util.logging.Level.WARNING;
import static java.util.logging.Logger.getLogger;
@@ -186,7 +186,7 @@ public abstract class ThreadListControllerImpl<G extends NamedGroup, I extends T
@Override
public void markItemRead(I item) {
markItemsRead(Collections.singletonList(item));
markItemsRead(singletonList(item));
}
@Override

View File

@@ -8,7 +8,6 @@ import android.annotation.TargetApi;
import android.content.Context;
import android.content.SharedPreferences;
import android.graphics.Rect;
import android.os.Build;
import android.preference.PreferenceManager;
import android.support.annotation.UiThread;
import android.util.AttributeSet;
@@ -26,6 +25,7 @@ import java.util.logging.Logger;
import javax.annotation.Nullable;
import static android.content.Context.WINDOW_SERVICE;
import static android.os.Build.VERSION.SDK_INT;
import static android.view.Surface.ROTATION_270;
import static android.view.Surface.ROTATION_90;
import static java.util.Objects.requireNonNull;
@@ -106,7 +106,7 @@ public class KeyboardAwareLinearLayout extends LinearLayout {
return;
}
if (viewInset == 0 && Build.VERSION.SDK_INT >= 21)
if (viewInset == 0 && SDK_INT >= 21)
viewInset = getViewInset();
int availableHeight =
getRootView().getHeight() - statusBarHeight - viewInset;

View File

@@ -21,8 +21,7 @@ import org.robolectric.Robolectric;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.annotation.Config;
import java.util.Arrays;
import static java.util.Arrays.asList;
import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertTrue;
import static org.briarproject.bramble.api.identity.AuthorInfo.Status.UNKNOWN;
@@ -91,7 +90,7 @@ public class ForumActivityTest {
forumItems[i].setLevel(LEVELS[i]);
}
ThreadItemList<ForumItem> list = new ThreadItemListImpl<>();
list.addAll(Arrays.asList(forumItems));
list.addAll(asList(forumItems));
return list;
}