Back to project page WineDB.
The source code is released under:
MIT License
If you think the Android project WineDB listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.selesse.android.winedb.winescraper; /* ww w . j a v a 2 s.co m*/ import android.util.Log; import com.google.common.base.Joiner; import com.google.common.collect.Lists; import com.selesse.android.winedb.database.Wine; import com.selesse.android.winedb.winescraper.impl.Semantics3WineScraper; import com.selesse.android.winedb.winescraper.impl.UPCDatabaseOrgWineScraper; import com.selesse.android.winedb.winescraper.impl.UPCDatabaseWineScraper; import java.util.Collections; import java.util.Comparator; import java.util.List; /** * Collection of wine scrapers that uses 1 or more wine scrapers to return results. * * @author Alex Selesse */ public class WineScrapers { private static final String TAG = WineScrapers.class.getSimpleName(); private final List<WineScraper> wineScrapers; public WineScrapers(String barcode) { UPCDatabaseWineScraper upcScraper = new UPCDatabaseWineScraper(barcode); UPCDatabaseOrgWineScraper upcOrgScraper = new UPCDatabaseOrgWineScraper(barcode); Semantics3WineScraper semanticsScraper = new Semantics3WineScraper(barcode); this.wineScrapers = Lists.newArrayList(semanticsScraper, upcScraper, upcOrgScraper); } public List<Wine> scrape() { List<Wine> scrapedWines = Lists.newArrayList(); for (WineScraper scraper : wineScrapers) { scrapedWines.addAll(scraper.scrape()); Log.e(TAG, "Error from " + scraper.getSourceName() + ": " + Joiner.on("\n").join(scraper.getErrors())); } Collections.sort(scrapedWines, new NumberOfFieldsComparator()); return scrapedWines; } /** * Wine Comparator that puts the wines with the most amount of fields first. */ public static class NumberOfFieldsComparator implements Comparator<Wine> { @Override public int compare(Wine w1, Wine w2) { return w2.getNumberOfFilledFields() - w1.getNumberOfFilledFields(); } } }