package de.lmu.ifi.dbs.elki.utilities.optionhandling;
/*
This file is part of ELKI:
Environment for Developing KDD-Applications Supported by Index-Structures
Copyright (C) 2012
Ludwig-Maximilians-Universität München
Lehr- und Forschungseinheit für Datenbanksysteme
ELKI Development Team
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see .
*/
import java.util.Collection;
import java.util.List;
import de.lmu.ifi.dbs.elki.logging.LoggingUtil;
import de.lmu.ifi.dbs.elki.utilities.ClassGenericsUtil;
import de.lmu.ifi.dbs.elki.utilities.FormatUtil;
import de.lmu.ifi.dbs.elki.utilities.documentation.DocumentationUtil;
import de.lmu.ifi.dbs.elki.utilities.documentation.Reference;
import de.lmu.ifi.dbs.elki.utilities.optionhandling.parameterization.SerializedParameterization;
import de.lmu.ifi.dbs.elki.utilities.optionhandling.parameterization.TrackParameters;
import de.lmu.ifi.dbs.elki.utilities.optionhandling.parameters.Parameter;
import de.lmu.ifi.dbs.elki.utilities.pairs.Pair;
/**
* Utility functions related to Option handling.
*
* @apiviz.uses Parameter
*/
public final class OptionUtil {
/**
* Returns a string representation of the specified list of options containing
* the names of the options.
*
* @param Option type
* @param options the list of options
* @return the names of the options
*/
public static > String optionsNamesToString(List options) {
StringBuffer buffer = new StringBuffer();
buffer.append("[");
for(int i = 0; i < options.size(); i++) {
buffer.append(options.get(i).getName());
if(i != options.size() - 1) {
buffer.append(",");
}
}
buffer.append("]");
return buffer.toString();
}
/**
* Returns a string representation of the specified list of options containing
* the names of the options.
*
* @param Option type
* @param options the list of options
* @return the names of the options
*/
public static > String optionsNamesToString(O[] options) {
StringBuffer buffer = new StringBuffer();
buffer.append("[");
for(int i = 0; i < options.length; i++) {
buffer.append(options[i].getName());
if(i != options.length - 1) {
buffer.append(",");
}
}
buffer.append("]");
return buffer.toString();
}
/**
* Returns a string representation of the list of number parameters containing
* the names and the values of the parameters.
*
* @param Parameter type
* @param parameters the list of number parameters
* @return the names and the values of the parameters
*/
public static > String parameterNamesAndValuesToString(List parameters) {
StringBuffer buffer = new StringBuffer();
buffer.append("[");
for(int i = 0; i < parameters.size(); i++) {
buffer.append(parameters.get(i).getName());
buffer.append(":");
buffer.append(parameters.get(i).getValueAsString());
if(i != parameters.size() - 1) {
buffer.append(", ");
}
}
buffer.append("]");
return buffer.toString();
}
/**
* Format a list of options (and associated owning objects) for console help
* output.
*
* @param buf Serialization buffer
* @param width Screen width
* @param indent Indentation string
* @param options List of options
*/
public static void formatForConsole(StringBuffer buf, int width, String indent, Collection>> options) {
for(Pair