mahout-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Karl Wettin (JIRA)" <j...@apache.org>
Subject [jira] Commented: (MAHOUT-49) ParameterEnumerable
Date Sat, 19 Apr 2008 01:34:28 GMT

    [ https://issues.apache.org/jira/browse/MAHOUT-49?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12590661#action_12590661
] 

Karl Wettin commented on MAHOUT-49:
-----------------------------------

Something like this:
{code:java}
public interface ParameterEnumerable {

  public abstract int numberOfParameters();
  public abstract Enumeration<Parameter> enumerateParameters();

  public interface Parameter<T> {
    /** @return */
    public abstract String name();
    /** @return */
    public abstract String description();
    /** @return */
    public abstract Class<T> type();
    /** @param stringValue */
    public abstract void setStringValue(String stringValue);
    /** @return */
    public abstract String getStringValue();
    /** @param value*/
    public abstract void setValue(T value);
    /** @return */
    public abstract T getValue();
    /** @return */
    public abstract T defaultValue();

  }

  public abstract class AbstractParameter<T> implements Parameter<T> {

    private T value;
    private String name;
    private String description;
    private Class<T> type;
    private T defaultValue;

    protected AbstractParameter(Class<T> type, T value, T defaultValue, String name,
String description) {
      this.type = type;
      this.value = value;
      this.defaultValue = defaultValue;
      this.name = name;
      this.description = description;
    }

    public String name() {
      return name;
    }
    public String description() {
      return description;
    }
    public Class<T> type() {
      return type;
    }
    public T defaultValue() {
      return defaultValue;
    }
    public T getValue() {
      return value;
    }
    public void setValue(T value) {
      this.value = value;
    }
  }

  public static class Generalizations {
    public static String help(ParameterEnumerable enumerable) {

      int numChars = 100; // just to be sure
      int longestName = 0;
      for (Enumeration<Parameter> parameters = enumerable.enumerateParameters(); parameters.hasMoreElements();)
{
        Parameter parameter = parameters.nextElement();
        int parameterNameLength = parameter.name().length();
        if (parameterNameLength > longestName) {
          longestName = parameterNameLength;
        }
        numChars += parameter.description().length();
      }

      int distanceBetweenNameAndDescription = 4;
      numChars += (longestName + distanceBetweenNameAndDescription) * enumerable.numberOfParameters();

      StringBuilder sb = new StringBuilder(numChars);
      for (Enumeration<Parameter> parameters = enumerable.enumerateParameters(); parameters.hasMoreElements();)
{
        Parameter parameter = parameters.nextElement();
        sb.append(parameter.name());
        for (int i = 0; i < longestName - parameter.name().length() + distanceBetweenNameAndDescription;
i++) {
          sb.append(' ');
        }
        sb.append(parameter.description());
        sb.append('\n');
      }
      return sb.toString();
    }
  }
}
{code}

> ParameterEnumerable
> -------------------
>
>                 Key: MAHOUT-49
>                 URL: https://issues.apache.org/jira/browse/MAHOUT-49
>             Project: Mahout
>          Issue Type: New Feature
>            Reporter: Karl Wettin
>            Assignee: Karl Wettin
>
> A utility package used to 
>  * configure class
>  * create default configuration files
>  * parse main method arguments
>  * produce human readable help
>  * getters and setters for value as object and string, for future generic reflection
based GUI.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


Mime
View raw message