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

com.carrotsearch.console.jcommander.converters.BooleanConverter Maven / Gradle / Ivy

The newest version!
/*
 * console-tools
 *
 * Copyright (C) 2019, Carrot Search s.c.
 * All rights reserved.
 */
package com.carrotsearch.console.jcommander.converters;

import com.carrotsearch.console.jcommander.ParameterException;

/**
 * Converts a string to a boolean.
 *
 * @author cbeust
 */
public class BooleanConverter extends BaseConverter {

  public BooleanConverter(String optionName) {
    super(optionName);
  }

  public Boolean convert(String value) {
    if ("false".equalsIgnoreCase(value) || "true".equalsIgnoreCase(value)) {
      return Boolean.parseBoolean(value);
    } else {
      throw new ParameterException(getErrorString(value, "a boolean"));
    }
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy