@Test public void testConvertFromCSV_EdgeCases() throws Exception { assertNull(ProductSetPersistable.convertFromCSV("")); try { ProductSetPersistable.convertFromCSV(null); fail(); } catch (NullPointerException expected) { } }
public static ProductSet convertFromCSV(String text) { String trimmedText = text.trim(); if (trimmedText.startsWith("#") || trimmedText.isEmpty()) { return null; } String[] splits = trimmedText.split(";"); String productType; String name; String path; Date date1; Date date2; String regionName = null; String regionWKT = null; String[] bandNames = new String[0]; String geoInventory = null; if (splits.length >= 5) { productType = nullAware(splits[0]); name = nullAware(splits[1]); path = nullAware(splits[2]); date1 = asDate(splits[3]); date2 = asDate(splits[4]); } else { return null; } if (splits.length >= 7) { regionName = nullAware(splits[5]); regionWKT = nullAware(splits[6]); } if (splits.length >= 8) { String bandNameCSV = nullAware(splits[7]); if (bandNameCSV != null && !bandNameCSV.isEmpty()) { bandNames = bandNameCSV.split(","); } } if (splits.length >= 9) { geoInventory = nullAware(splits[8]); } return new ProductSet(productType, name, path, date1, date2, regionName, regionWKT, bandNames, geoInventory); }
ProductSetPersistable { public static ProductSet convertFromCSV(String text) { String trimmedText = text.trim(); if (trimmedText.startsWith("#") || trimmedText.isEmpty()) { return null; } String[] splits = trimmedText.split(";"); String productType; String name; String path; Date date1; Date date2; String regionName = null; String regionWKT = null; String[] bandNames = new String[0]; String geoInventory = null; if (splits.length >= 5) { productType = nullAware(splits[0]); name = nullAware(splits[1]); path = nullAware(splits[2]); date1 = asDate(splits[3]); date2 = asDate(splits[4]); } else { return null; } if (splits.length >= 7) { regionName = nullAware(splits[5]); regionWKT = nullAware(splits[6]); } if (splits.length >= 8) { String bandNameCSV = nullAware(splits[7]); if (bandNameCSV != null && !bandNameCSV.isEmpty()) { bandNames = bandNameCSV.split(","); } } if (splits.length >= 9) { geoInventory = nullAware(splits[8]); } return new ProductSet(productType, name, path, date1, date2, regionName, regionWKT, bandNames, geoInventory); } }
ProductSetPersistable { public static ProductSet convertFromCSV(String text) { String trimmedText = text.trim(); if (trimmedText.startsWith("#") || trimmedText.isEmpty()) { return null; } String[] splits = trimmedText.split(";"); String productType; String name; String path; Date date1; Date date2; String regionName = null; String regionWKT = null; String[] bandNames = new String[0]; String geoInventory = null; if (splits.length >= 5) { productType = nullAware(splits[0]); name = nullAware(splits[1]); path = nullAware(splits[2]); date1 = asDate(splits[3]); date2 = asDate(splits[4]); } else { return null; } if (splits.length >= 7) { regionName = nullAware(splits[5]); regionWKT = nullAware(splits[6]); } if (splits.length >= 8) { String bandNameCSV = nullAware(splits[7]); if (bandNameCSV != null && !bandNameCSV.isEmpty()) { bandNames = bandNameCSV.split(","); } } if (splits.length >= 9) { geoInventory = nullAware(splits[8]); } return new ProductSet(productType, name, path, date1, date2, regionName, regionWKT, bandNames, geoInventory); } private  ProductSetPersistable(); }
ProductSetPersistable { public static ProductSet convertFromCSV(String text) { String trimmedText = text.trim(); if (trimmedText.startsWith("#") || trimmedText.isEmpty()) { return null; } String[] splits = trimmedText.split(";"); String productType; String name; String path; Date date1; Date date2; String regionName = null; String regionWKT = null; String[] bandNames = new String[0]; String geoInventory = null; if (splits.length >= 5) { productType = nullAware(splits[0]); name = nullAware(splits[1]); path = nullAware(splits[2]); date1 = asDate(splits[3]); date2 = asDate(splits[4]); } else { return null; } if (splits.length >= 7) { regionName = nullAware(splits[5]); regionWKT = nullAware(splits[6]); } if (splits.length >= 8) { String bandNameCSV = nullAware(splits[7]); if (bandNameCSV != null && !bandNameCSV.isEmpty()) { bandNames = bandNameCSV.split(","); } } if (splits.length >= 9) { geoInventory = nullAware(splits[8]); } return new ProductSet(productType, name, path, date1, date2, regionName, regionWKT, bandNames, geoInventory); } private  ProductSetPersistable(); static String convertToCSV(ProductSet productSet); static ProductSet convertFromCSV(String text); }
ProductSetPersistable { public static ProductSet convertFromCSV(String text) { String trimmedText = text.trim(); if (trimmedText.startsWith("#") || trimmedText.isEmpty()) { return null; } String[] splits = trimmedText.split(";"); String productType; String name; String path; Date date1; Date date2; String regionName = null; String regionWKT = null; String[] bandNames = new String[0]; String geoInventory = null; if (splits.length >= 5) { productType = nullAware(splits[0]); name = nullAware(splits[1]); path = nullAware(splits[2]); date1 = asDate(splits[3]); date2 = asDate(splits[4]); } else { return null; } if (splits.length >= 7) { regionName = nullAware(splits[5]); regionWKT = nullAware(splits[6]); } if (splits.length >= 8) { String bandNameCSV = nullAware(splits[7]); if (bandNameCSV != null && !bandNameCSV.isEmpty()) { bandNames = bandNameCSV.split(","); } } if (splits.length >= 9) { geoInventory = nullAware(splits[8]); } return new ProductSet(productType, name, path, date1, date2, regionName, regionWKT, bandNames, geoInventory); } private  ProductSetPersistable(); static String convertToCSV(ProductSet productSet); static ProductSet convertFromCSV(String text); static final String FILENAME; static final String INDEX; }