Search in sources :

Example 1 with EContinent

use of com.helger.masterdata.locale.EContinent in project ph-masterdata by phax.

the class MainReadCountry2Continent method main.

public static void main(final String[] args) {
    final IReadableResource aRes = new ClassPathResource("country2continent.xlsx");
    final Workbook aWB = ExcelReadHelper.readWorkbookFromInputStream(aRes);
    final Sheet aSheet = aWB.getSheetAt(0);
    // Skip one row
    int nRow = 1;
    int nNotFound = 0;
    final ICommonsNavigableMap<Locale, EContinent> aMap = new CommonsTreeMap<>(IComparator.getComparatorCollating(Locale::getCountry, LOC));
    while (true) {
        final Row aRow = aSheet.getRow(nRow);
        if (aRow == null)
            break;
        final String sContinent = ExcelReadHelper.getCellValueString(aRow.getCell(0));
        if (StringHelper.hasNoText(sContinent))
            break;
        final EContinent eContinent = _findContinent(sContinent);
        final String sCountryName = ExcelReadHelper.getCellValueString(aRow.getCell(1));
        final Locale aCountry = _findCountryComplex(sCountryName);
        if (aCountry == null) {
            LOGGER.info("No such country: '" + sCountryName + "'");
            ++nNotFound;
        } else {
            final EContinent eOld = aMap.put(aCountry, eContinent);
            if (eOld != null)
                LOGGER.info("Country " + aCountry.getDisplayCountry(LOC) + " is assigned to " + eContinent.getDisplayText(LOC) + " and " + eOld.getDisplayText(LOC));
        }
        ++nRow;
    }
    LOGGER.info("Countries not found: " + nNotFound);
    for (final Map.Entry<Locale, EContinent> e : aMap.entrySet()) {
        LOGGER.info("s_aMap.put (CountryCache.getCountry (\"" + e.getKey().getCountry() + "\"), EContinent." + e.getValue().name() + "),");
    }
}
Also used : Locale(java.util.Locale) IReadableResource(com.helger.commons.io.resource.IReadableResource) ClassPathResource(com.helger.commons.io.resource.ClassPathResource) Workbook(org.apache.poi.ss.usermodel.Workbook) CommonsTreeMap(com.helger.commons.collection.impl.CommonsTreeMap) Row(org.apache.poi.ss.usermodel.Row) Sheet(org.apache.poi.ss.usermodel.Sheet) CommonsTreeMap(com.helger.commons.collection.impl.CommonsTreeMap) ICommonsNavigableMap(com.helger.commons.collection.impl.ICommonsNavigableMap) Map(java.util.Map) EContinent(com.helger.masterdata.locale.EContinent)

Aggregations

CommonsTreeMap (com.helger.commons.collection.impl.CommonsTreeMap)1 ICommonsNavigableMap (com.helger.commons.collection.impl.ICommonsNavigableMap)1 ClassPathResource (com.helger.commons.io.resource.ClassPathResource)1 IReadableResource (com.helger.commons.io.resource.IReadableResource)1 EContinent (com.helger.masterdata.locale.EContinent)1 Locale (java.util.Locale)1 Map (java.util.Map)1 Row (org.apache.poi.ss.usermodel.Row)1 Sheet (org.apache.poi.ss.usermodel.Sheet)1 Workbook (org.apache.poi.ss.usermodel.Workbook)1