xlson / groovycsv

A simple CSV parsing library for groovy
http://xlson.com/groovycsv/
Other
139 stars 32 forks source link

Don't make members private #49

Open xpusostomos opened 3 years ago

xpusostomos commented 3 years ago

Making things private (as opposed to protected) in an object language is extremely anti-social, because it prevents people from inheriting and expanding the class. For example, I wrote the below code to try and overcome issue #48 (i.e. stop getProperty() from throwing an exception), but it failed to compile because the members of CsvIterator are private. Don't do that. Make all data members protected.

        CsvParser p = new CsvParser() {
            // all this code is so we can have a csv line that doesn't throw
            // an exception if some columns are missing.
            Iterator parse(Map args = [:], Reader reader) {
                def csvReader = createCSVReader(args, reader)
                def columnNames = parseColumnNames(args, csvReader)
                new CsvIterator(columnNames, csvReader) {
                    def next() {
                        throwsExceptionIfClosed()
                        new PropertyMapper(columns: this.columns, values: this.nextValue) {
                            def propertyMissing(String name) {
                                def index = this.columns[name]
                                if (index != null) {
                                    values[index]
                                } else {
                                    return null
                                }
                            }
                        }
                    }
                }
            }
        }
ppazos commented 1 year ago

@xpusostomos why you don't send a PR or make a fork to fix it?