1

Given I have setup the following iterator (with domain being some class and input being some file):

BeanListProcessor<?> beanProcessor = new BeanListProcessor<Class<?>>((Class<Class<?>>) domain);
CsvParserSettings parserSettings = new CsvParserSettings();
parserSettings.setRowProcessor(beanProcessor);
parserSettings.setHeaderExtractionEnabled(true);
parserSettings.setDelimiterDetectionEnabled(true);
CsvRoutines routines = new CsvRoutines(parserSettings);
Iterator<?> it = routines.iterate(domain, input).iterator();

Why can't I use...

while (it.hasNext()) {
    Object record = it.next();
    it.remove();                
} 

...to remove a bean?

In other words what is the reason for this implementation in the class com.univocity.parsers.common.routine.AbstractRoutines?

@Override
public void remove() {
    throw new UnsupportedOperationException("Can't remove beans");
}

I need to remove the "top" bean before iterating to the next bean.

Sander_M
  • 1,109
  • 2
  • 18
  • 36

1 Answers1

2

I'm the author of the library and the reason you can't remove it it's because the beans are not kept in an in-memory list which you can manipulate at will.

These beans are parsed from the input as they are read, and the parser has no control over the input. The only sane option to deal with an unwanted bean is to ignore it: just call continue on your loop to move on to the next bean.

Hope this helps

Jeronimo Backes
  • 6,141
  • 2
  • 25
  • 29