Fixed static analysis warnings

* Using strings when characters could be used
* Unused imports
* String concatenation in a loop
This commit is contained in:
Anthony Restaino 2015-09-14 20:03:11 -04:00
parent 8a6ad81027
commit 2da5c4194c
7 changed files with 21 additions and 19 deletions

View File

@ -3,7 +3,6 @@ package acr.browser.lightning.utils;
import android.app.Activity; import android.app.Activity;
import android.content.Context; import android.content.Context;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.support.annotation.NonNull;
import android.support.v7.app.AlertDialog; import android.support.v7.app.AlertDialog;
import android.util.Log; import android.util.Log;

View File

@ -1220,13 +1220,13 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
void saveOpenTabs() { void saveOpenTabs() {
if (mPreferences.getRestoreLostTabsEnabled()) { if (mPreferences.getRestoreLostTabsEnabled()) {
String s = ""; StringBuilder s = new StringBuilder(mWebViewList.size() * 50);
for (int n = 0, size = mWebViewList.size(); n < size; n++) { for (int n = 0, size = mWebViewList.size(); n < size; n++) {
if (!mWebViewList.get(n).getUrl().isEmpty()) { if (!mWebViewList.get(n).getUrl().isEmpty()) {
s = s + mWebViewList.get(n).getUrl() + "|$|SEPARATOR|$|"; s.append(mWebViewList.get(n).getUrl()).append("|$|SEPARATOR|$|");
} }
} }
mPreferences.setMemoryUrl(s); mPreferences.setMemoryUrl(s.toString());
} }
} }

View File

@ -48,11 +48,11 @@ import acr.browser.lightning.utils.Utils;
public class SearchAdapter extends BaseAdapter implements Filterable { public class SearchAdapter extends BaseAdapter implements Filterable {
private final List<HistoryItem> mHistory = new ArrayList<>(); private final List<HistoryItem> mHistory = new ArrayList<>(5);
private final List<HistoryItem> mBookmarks = new ArrayList<>(); private final List<HistoryItem> mBookmarks = new ArrayList<>(5);
private final List<HistoryItem> mSuggestions = new ArrayList<>(); private final List<HistoryItem> mSuggestions = new ArrayList<>(5);
private final List<HistoryItem> mFilteredList = new ArrayList<>(); private final List<HistoryItem> mFilteredList = new ArrayList<>(5);
private final List<HistoryItem> mAllBookmarks = new ArrayList<>(); private final List<HistoryItem> mAllBookmarks = new ArrayList<>(5);
private final Object mLock = new Object(); private final Object mLock = new Object();
private HistoryDatabase mDatabaseHandler; private HistoryDatabase mDatabaseHandler;
private final Context mContext; private final Context mContext;

View File

@ -204,24 +204,24 @@ public class Converter {
int lastEncIndex; int lastEncIndex;
if (startChar == '\'') if (startChar == '\'')
// if we have charset='something' // if we have charset='something'
lastEncIndex = str.indexOf("'", ++encIndex + clength); lastEncIndex = str.indexOf('\'', ++encIndex + clength);
else if (startChar == '\"') else if (startChar == '\"')
// if we have charset="something" // if we have charset="something"
lastEncIndex = str.indexOf("\"", ++encIndex + clength); lastEncIndex = str.indexOf('\"', ++encIndex + clength);
else { else {
// if we have "text/html; charset=utf-8" // if we have "text/html; charset=utf-8"
int first = str.indexOf("\"", encIndex + clength); int first = str.indexOf('\"', encIndex + clength);
if (first < 0) if (first < 0)
first = Integer.MAX_VALUE; first = Integer.MAX_VALUE;
// or "text/html; charset=utf-8 " // or "text/html; charset=utf-8 "
int sec = str.indexOf(" ", encIndex + clength); int sec = str.indexOf(' ', encIndex + clength);
if (sec < 0) if (sec < 0)
sec = Integer.MAX_VALUE; sec = Integer.MAX_VALUE;
lastEncIndex = Math.min(first, sec); lastEncIndex = Math.min(first, sec);
// or "text/html; charset=utf-8 ' // or "text/html; charset=utf-8 '
int third = str.indexOf("'", encIndex + clength); int third = str.indexOf('\'', encIndex + clength);
if (third > 0) if (third > 0)
lastEncIndex = Math.min(lastEncIndex, third); lastEncIndex = Math.min(lastEncIndex, third);
} }

View File

@ -28,6 +28,7 @@ import java.net.URL;
import java.util.LinkedHashSet; import java.util.LinkedHashSet;
import java.util.Set; import java.util.Set;
import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicInteger;
import java.util.regex.Pattern;
import java.util.zip.GZIPInputStream; import java.util.zip.GZIPInputStream;
import java.util.zip.Inflater; import java.util.zip.Inflater;
import java.util.zip.InflaterInputStream; import java.util.zip.InflaterInputStream;
@ -39,6 +40,8 @@ import java.util.zip.InflaterInputStream;
*/ */
public class HtmlFetcher { public class HtmlFetcher {
private static final Pattern SPACE = Pattern.compile(" ");
static { static {
SHelper.enableCookieMgmt(); SHelper.enableCookieMgmt();
SHelper.enableUserAgentOverwrite(); SHelper.enableUserAgentOverwrite();
@ -50,8 +53,8 @@ public class HtmlFetcher {
String line; String line;
Set<String> existing = new LinkedHashSet<>(); Set<String> existing = new LinkedHashSet<>();
while ((line = reader.readLine()) != null) { while ((line = reader.readLine()) != null) {
int index1 = line.indexOf("\""); int index1 = line.indexOf('\"');
int index2 = line.indexOf("\"", index1 + 1); int index2 = line.indexOf('\"', index1 + 1);
String url = line.substring(index1 + 1, index2); String url = line.substring(index1 + 1, index2);
String domainStr = SHelper.extractDomain(url, true); String domainStr = SHelper.extractDomain(url, true);
String counterStr = ""; String counterStr = "";
@ -381,7 +384,7 @@ public class HtmlFetcher {
newUrl = hConn.getHeaderField("Location"); newUrl = hConn.getHeaderField("Location");
// Note that the max recursion level is 5. // Note that the max recursion level is 5.
if (responseCode / 100 == 3 && newUrl != null && num_redirects < 5) { if (responseCode / 100 == 3 && newUrl != null && num_redirects < 5) {
newUrl = newUrl.replaceAll(" ", "+"); newUrl = SPACE.matcher(newUrl).replaceAll("+");
// some services use (none-standard) utf8 in their location header // some services use (none-standard) utf8 in their location header
if (urlAsString.startsWith("http://bit.ly") if (urlAsString.startsWith("http://bit.ly")
|| urlAsString.startsWith("http://is.gd")) || urlAsString.startsWith("http://is.gd"))

View File

@ -230,7 +230,7 @@ public class JResult implements Serializable {
} }
public void addLink(String url, String text, Integer pos) { public void addLink(String url, String text, Integer pos) {
Map link = new HashMap(); Map<String, String> link = new HashMap<>();
link.put("url", url); link.put("url", url);
link.put("text", text); link.put("text", text);
link.put("offset", String.valueOf(pos)); link.put("offset", String.valueOf(pos));

View File

@ -193,7 +193,7 @@ public class SHelper {
url = url.substring("m.".length()); url = url.substring("m.".length());
} }
int slashIndex = url.indexOf("/"); int slashIndex = url.indexOf('/');
if (slashIndex > 0) if (slashIndex > 0)
url = url.substring(0, slashIndex); url = url.substring(0, slashIndex);