All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.beust.jcommander.converters.DefaultListConverter Maven / Gradle / Ivy

There is a newer version: 1.82
Show newest version
package com.beust.jcommander.converters;

import com.beust.jcommander.IStringConverter;
import com.beust.jcommander.internal.Lists;

import java.util.List;

/**
 * A converter to obtain a list of elements.
 * @param  the element type
 * @author simon04
 */
public class DefaultListConverter implements IStringConverter> {

  private final IParameterSplitter splitter;
  private final IStringConverter converter;

  /**
   * Constructs a new converter.
   * @param splitter to split value into list of arguments
   * @param converter to convert list of arguments to target element type
   */
  public DefaultListConverter(IParameterSplitter splitter, IStringConverter converter) {
    this.splitter = splitter;
    this.converter = converter;
  }

  @Override
  public List convert(String value) {
    List result = Lists.newArrayList();
    for (String param : splitter.split(value)) {
      result.add(converter.convert(param));
    }
    return result;
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy