Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: adblockplussbrowser/src/org/adblockplus/sbrowser/contentblocker/engine/DefaultSubscriptions.java

Issue 29436555: Issue 5231 - Use Java 7 features (Closed)
Patch Set: Created May 11, 2017, 6:30 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: adblockplussbrowser/src/org/adblockplus/sbrowser/contentblocker/engine/DefaultSubscriptions.java
===================================================================
--- a/adblockplussbrowser/src/org/adblockplus/sbrowser/contentblocker/engine/DefaultSubscriptions.java
+++ b/adblockplussbrowser/src/org/adblockplus/sbrowser/contentblocker/engine/DefaultSubscriptions.java
@@ -30,21 +30,21 @@ import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;
final class DefaultSubscriptions
{
- private final List<DefaultSubscriptionInfo> subscriptions = new ArrayList<DefaultSubscriptionInfo>();
- private final List<DefaultSubscriptionInfo> linearSubscriptions = new ArrayList<DefaultSubscriptionInfo>();
- private final HashMap<String, DefaultSubscriptionInfo> urlMap = new HashMap<String, DefaultSubscriptionInfo>();
- private final List<DefaultSubscriptionInfo> adsSubscriptions = new ArrayList<DefaultSubscriptionInfo>();
- private final List<DefaultSubscriptionInfo> otherSubscriptions = new ArrayList<DefaultSubscriptionInfo>();
+ private final List<DefaultSubscriptionInfo> subscriptions = new ArrayList<>();
+ private final List<DefaultSubscriptionInfo> linearSubscriptions = new ArrayList<>();
+ private final HashMap<String, DefaultSubscriptionInfo> urlMap = new HashMap<>();
+ private final List<DefaultSubscriptionInfo> adsSubscriptions = new ArrayList<>();
+ private final List<DefaultSubscriptionInfo> otherSubscriptions = new ArrayList<>();
private DefaultSubscriptions initialize()
{
this.listSubscriptions(this.linearSubscriptions);
for (final DefaultSubscriptionInfo s : this.linearSubscriptions)
{
final String url = s.getUrl();
@@ -65,17 +65,17 @@ final class DefaultSubscriptions
}
}
return this;
}
public List<Subscription> createSubscriptions() throws IOException
{
- final ArrayList<Subscription> subs = new ArrayList<Subscription>();
+ final ArrayList<Subscription> subs = new ArrayList<>();
for (DefaultSubscriptionInfo info : this.linearSubscriptions)
{
if (!info.getUrl().isEmpty())
{
final Subscription sub = Subscription.create(info.getUrl());
sub.putMeta(Subscription.KEY_TITLE, info.getTitle());
subs.add(sub);
}
@@ -121,40 +121,35 @@ final class DefaultSubscriptions
{
final SAXParserFactory factory = SAXParserFactory.newInstance();
factory.setValidating(false);
final SAXParser parser = factory.newSAXParser();
final SubscriptionParser handler = new SubscriptionParser();
parser.parse(in, handler);
return handler.subscriptions.initialize();
}
- catch (final ParserConfigurationException e)
+ catch (final ParserConfigurationException | SAXException e)
{
- throw new IOException("ParserConfigurationException: " + e.getMessage());
- }
- catch (final SAXException e)
- {
- e.printStackTrace();
- throw new IOException("SAXException: " + e.getMessage());
+ throw new IOException(e.getClass().getSimpleName() + ": " + e.getMessage());
}
}
private static class SubscriptionParser extends DefaultHandler
{
private boolean inSubscriptions = false;
private boolean inVariants = false;
private final static String KEY_SUPPLEMENTS = "supplements";
private final static String KEY_SUBSCRIPTIONS = "subscriptions";
private final static String KEY_SUBSCRIPTION = "subscription";
private final static String KEY_VARIANTS = "variants";
private final static String KEY_VARIANT = "variant";
private final DefaultSubscriptions subscriptions = new DefaultSubscriptions();
- private final LinkedList<DefaultSubscriptionInfo> subscriptionStack = new LinkedList<DefaultSubscriptionInfo>();
+ private final LinkedList<DefaultSubscriptionInfo> subscriptionStack = new LinkedList<>();
private DefaultSubscriptionInfo subscription = null;
private DefaultSubscriptionInfo variant = null;
@Override
public void startElement(final String uri, final String localName, final String qName,
final Attributes attributes) throws SAXException
{
super.startElement(uri, localName, qName, attributes);

Powered by Google App Engine
This is Rietveld