@Test public void toMapTest() throws IllegalArgumentException, IOException { TreeSet<Object[]> data = CSVReader.readCsv(LOGGER, csv, ",", new SetComparator<Integer>(new IntegerCaster(),2,false), false, false); Object[] first = data.first(); Assert.assertNotNull(first); Assert.assertNotNull(first[2].equals("23")); Assert.assertTrue(first[3].equals("23_airtmp_mn.tif")); Object[] last = data.last(); Assert.assertNotNull(last); Assert.assertNotNull(last[2].equals("38213")); Assert.assertTrue(last[4].equals("SOLAW:lw_scar")); }
public static <T, D extends Set<Object[]>> D readCsv(final Logger LOGGER, final File csv, final String separator, final SetComparator<T> comparator, final boolean randomRowSize, final boolean failsOnError) throws IllegalArgumentException, IOException { if (csv == null || separator == null) throw new IllegalArgumentException("Unable to run with null csv file or separator"); if (!csv.isFile()) throw new IllegalArgumentException("Unable to run: passed csv is not a file: " + csv); FileReader fr = null; BufferedReader reader = null; try { fr = new FileReader(csv); reader = new BufferedReader(fr); D ret = null; String line = reader.readLine(); int size = -1; if (line != null) { final String[] values = line.split(separator); size = values.length; if (size < 2) { throw new IllegalArgumentException( "Unable to use an ordered map column size is less than 2."); } if (comparator != null) { ret = (D) new TreeSet<Object[]>(comparator); } else { if (failsOnError) { throw new IllegalArgumentException( "Unable to use an ordered map, some arguments are not valid."); } if (LOGGER != null && LOGGER.isWarnEnabled()) { LOGGER.warn("Unable to use an ordered map continuing with a LinkedHashSet."); } ret = (D) new LinkedHashSet<Object[]>(); } } else { throw new IllegalArgumentException("Unable read lines."); } while (line != null) { if (LOGGER != null && LOGGER.isInfoEnabled()) { LOGGER.info("Reading line: " + line); } Object[] row = line.split(separator); if (row.length == size || randomRowSize){ ret.add(row); }else { if (failsOnError) { throw new IllegalArgumentException("Wrong row size: " + row.length + " should be: " + size); } if (LOGGER != null && LOGGER.isWarnEnabled()) { LOGGER.warn("SKIPPING: Wrong row size: " + row.length + " should be: " + size); } } line = reader.readLine(); } return ret; } finally { try { if (reader != null) reader.close(); } catch (IOException e) { } try { if (fr != null) fr.close(); } catch (IOException e) { } } }
CSVReader { public static <T, D extends Set<Object[]>> D readCsv(final Logger LOGGER, final File csv, final String separator, final SetComparator<T> comparator, final boolean randomRowSize, final boolean failsOnError) throws IllegalArgumentException, IOException { if (csv == null || separator == null) throw new IllegalArgumentException("Unable to run with null csv file or separator"); if (!csv.isFile()) throw new IllegalArgumentException("Unable to run: passed csv is not a file: " + csv); FileReader fr = null; BufferedReader reader = null; try { fr = new FileReader(csv); reader = new BufferedReader(fr); D ret = null; String line = reader.readLine(); int size = -1; if (line != null) { final String[] values = line.split(separator); size = values.length; if (size < 2) { throw new IllegalArgumentException( "Unable to use an ordered map column size is less than 2."); } if (comparator != null) { ret = (D) new TreeSet<Object[]>(comparator); } else { if (failsOnError) { throw new IllegalArgumentException( "Unable to use an ordered map, some arguments are not valid."); } if (LOGGER != null && LOGGER.isWarnEnabled()) { LOGGER.warn("Unable to use an ordered map continuing with a LinkedHashSet."); } ret = (D) new LinkedHashSet<Object[]>(); } } else { throw new IllegalArgumentException("Unable read lines."); } while (line != null) { if (LOGGER != null && LOGGER.isInfoEnabled()) { LOGGER.info("Reading line: " + line); } Object[] row = line.split(separator); if (row.length == size || randomRowSize){ ret.add(row); }else { if (failsOnError) { throw new IllegalArgumentException("Wrong row size: " + row.length + " should be: " + size); } if (LOGGER != null && LOGGER.isWarnEnabled()) { LOGGER.warn("SKIPPING: Wrong row size: " + row.length + " should be: " + size); } } line = reader.readLine(); } return ret; } finally { try { if (reader != null) reader.close(); } catch (IOException e) { } try { if (fr != null) fr.close(); } catch (IOException e) { } } } }
CSVReader { public static <T, D extends Set<Object[]>> D readCsv(final Logger LOGGER, final File csv, final String separator, final SetComparator<T> comparator, final boolean randomRowSize, final boolean failsOnError) throws IllegalArgumentException, IOException { if (csv == null || separator == null) throw new IllegalArgumentException("Unable to run with null csv file or separator"); if (!csv.isFile()) throw new IllegalArgumentException("Unable to run: passed csv is not a file: " + csv); FileReader fr = null; BufferedReader reader = null; try { fr = new FileReader(csv); reader = new BufferedReader(fr); D ret = null; String line = reader.readLine(); int size = -1; if (line != null) { final String[] values = line.split(separator); size = values.length; if (size < 2) { throw new IllegalArgumentException( "Unable to use an ordered map column size is less than 2."); } if (comparator != null) { ret = (D) new TreeSet<Object[]>(comparator); } else { if (failsOnError) { throw new IllegalArgumentException( "Unable to use an ordered map, some arguments are not valid."); } if (LOGGER != null && LOGGER.isWarnEnabled()) { LOGGER.warn("Unable to use an ordered map continuing with a LinkedHashSet."); } ret = (D) new LinkedHashSet<Object[]>(); } } else { throw new IllegalArgumentException("Unable read lines."); } while (line != null) { if (LOGGER != null && LOGGER.isInfoEnabled()) { LOGGER.info("Reading line: " + line); } Object[] row = line.split(separator); if (row.length == size || randomRowSize){ ret.add(row); }else { if (failsOnError) { throw new IllegalArgumentException("Wrong row size: " + row.length + " should be: " + size); } if (LOGGER != null && LOGGER.isWarnEnabled()) { LOGGER.warn("SKIPPING: Wrong row size: " + row.length + " should be: " + size); } } line = reader.readLine(); } return ret; } finally { try { if (reader != null) reader.close(); } catch (IOException e) { } try { if (fr != null) fr.close(); } catch (IOException e) { } } }  }
CSVReader { public static <T, D extends Set<Object[]>> D readCsv(final Logger LOGGER, final File csv, final String separator, final SetComparator<T> comparator, final boolean randomRowSize, final boolean failsOnError) throws IllegalArgumentException, IOException { if (csv == null || separator == null) throw new IllegalArgumentException("Unable to run with null csv file or separator"); if (!csv.isFile()) throw new IllegalArgumentException("Unable to run: passed csv is not a file: " + csv); FileReader fr = null; BufferedReader reader = null; try { fr = new FileReader(csv); reader = new BufferedReader(fr); D ret = null; String line = reader.readLine(); int size = -1; if (line != null) { final String[] values = line.split(separator); size = values.length; if (size < 2) { throw new IllegalArgumentException( "Unable to use an ordered map column size is less than 2."); } if (comparator != null) { ret = (D) new TreeSet<Object[]>(comparator); } else { if (failsOnError) { throw new IllegalArgumentException( "Unable to use an ordered map, some arguments are not valid."); } if (LOGGER != null && LOGGER.isWarnEnabled()) { LOGGER.warn("Unable to use an ordered map continuing with a LinkedHashSet."); } ret = (D) new LinkedHashSet<Object[]>(); } } else { throw new IllegalArgumentException("Unable read lines."); } while (line != null) { if (LOGGER != null && LOGGER.isInfoEnabled()) { LOGGER.info("Reading line: " + line); } Object[] row = line.split(separator); if (row.length == size || randomRowSize){ ret.add(row); }else { if (failsOnError) { throw new IllegalArgumentException("Wrong row size: " + row.length + " should be: " + size); } if (LOGGER != null && LOGGER.isWarnEnabled()) { LOGGER.warn("SKIPPING: Wrong row size: " + row.length + " should be: " + size); } } line = reader.readLine(); } return ret; } finally { try { if (reader != null) reader.close(); } catch (IOException e) { } try { if (fr != null) fr.close(); } catch (IOException e) { } } }  static D readCsv(final Logger LOGGER, final File csv,
            final String separator, final SetComparator<T> comparator, final boolean randomRowSize,
            final boolean failsOnError); }
CSVReader { public static <T, D extends Set<Object[]>> D readCsv(final Logger LOGGER, final File csv, final String separator, final SetComparator<T> comparator, final boolean randomRowSize, final boolean failsOnError) throws IllegalArgumentException, IOException { if (csv == null || separator == null) throw new IllegalArgumentException("Unable to run with null csv file or separator"); if (!csv.isFile()) throw new IllegalArgumentException("Unable to run: passed csv is not a file: " + csv); FileReader fr = null; BufferedReader reader = null; try { fr = new FileReader(csv); reader = new BufferedReader(fr); D ret = null; String line = reader.readLine(); int size = -1; if (line != null) { final String[] values = line.split(separator); size = values.length; if (size < 2) { throw new IllegalArgumentException( "Unable to use an ordered map column size is less than 2."); } if (comparator != null) { ret = (D) new TreeSet<Object[]>(comparator); } else { if (failsOnError) { throw new IllegalArgumentException( "Unable to use an ordered map, some arguments are not valid."); } if (LOGGER != null && LOGGER.isWarnEnabled()) { LOGGER.warn("Unable to use an ordered map continuing with a LinkedHashSet."); } ret = (D) new LinkedHashSet<Object[]>(); } } else { throw new IllegalArgumentException("Unable read lines."); } while (line != null) { if (LOGGER != null && LOGGER.isInfoEnabled()) { LOGGER.info("Reading line: " + line); } Object[] row = line.split(separator); if (row.length == size || randomRowSize){ ret.add(row); }else { if (failsOnError) { throw new IllegalArgumentException("Wrong row size: " + row.length + " should be: " + size); } if (LOGGER != null && LOGGER.isWarnEnabled()) { LOGGER.warn("SKIPPING: Wrong row size: " + row.length + " should be: " + size); } } line = reader.readLine(); } return ret; } finally { try { if (reader != null) reader.close(); } catch (IOException e) { } try { if (fr != null) fr.close(); } catch (IOException e) { } } }  static D readCsv(final Logger LOGGER, final File csv,
            final String separator, final SetComparator<T> comparator, final boolean randomRowSize,
            final boolean failsOnError);  }