Browse Source

Clean up AdBlock class

* use interface instead of concrete class
* inline initialization of static variable
* remove redundant field and variable initialization
* replace single-character string with char
master
Miłosz Sieradzki 11 years ago
parent
commit
dafd684096
  1. 14
      src/acr/browser/lightning/AdBlock.java

14
src/acr/browser/lightning/AdBlock.java

@ -10,21 +10,19 @@ import java.io.InputStream;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.net.URI; import java.net.URI;
import java.net.URISyntaxException; import java.net.URISyntaxException;
import java.util.SortedMap;
import java.util.TreeMap; import java.util.TreeMap;
public class AdBlock { public class AdBlock {
private static TreeMap<String, Integer> mAdBlockMap = null; private static SortedMap<String, Integer> mAdBlockMap =
new TreeMap<String, Integer>(String.CASE_INSENSITIVE_ORDER);
private SharedPreferences mPreferences; private SharedPreferences mPreferences;
private boolean mBlockAds = false; private boolean mBlockAds;
public AdBlock(Context context) { public AdBlock(Context context) {
if (mAdBlockMap == null) {
mAdBlockMap = new TreeMap<String, Integer>(
String.CASE_INSENSITIVE_ORDER);
}
if (mAdBlockMap.isEmpty()) { if (mAdBlockMap.isEmpty()) {
fillSearchTree(context); fillSearchTree(context);
} }
@ -68,7 +66,7 @@ public class AdBlock {
if (!mBlockAds) { if (!mBlockAds) {
return false; return false;
} }
String domain = ""; String domain;
try { try {
domain = getDomainName(url); domain = getDomainName(url);
} catch (URISyntaxException e) { } catch (URISyntaxException e) {
@ -79,7 +77,7 @@ public class AdBlock {
} }
private static String getDomainName(String url) throws URISyntaxException { private static String getDomainName(String url) throws URISyntaxException {
int index = url.indexOf("/", 8); int index = url.indexOf('/', 8);
if (index != -1) { if (index != -1) {
url = url.substring(0, index); url = url.substring(0, index);
} }

Loading…
Cancel
Save