<commit_before>package to.mmo.cmdlineoptions;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.HashMap;

/**
 * Written by <NAME>, (c) 2013
 * For use under the BSD 2-clause License, or in other words: 
 * Do what you want with it as long as you leave all copyright notices where they are
 *  and don't bother me when you break your pc. :)
 */


public class CmdOptions {

  private static CmdOptions instance;

  public static class Option {
    public String name;
    public String cmdOption;
    public String longCmdOption;
    public String description;
    public String defaultParameter;
    public String[] possibleParams;
    public String[] alternatives;
    public boolean set;
    public ArrayList<String> values;

    public Option() {
      values = new ArrayList<String>();
    }

    public String toString() {
      String ret = name + " (" + longCmdOption + (cmdOption != null ? "/" + cmdOption : "") + ")"
          + (defaultParameter != null ? ": default=" + defaultParameter : "") + (description != null ? "\n\t\t" + description : "");
      if (possibleParams != null) {
        boolean start = true;
        ret += "\n\t\t(Possible parameters: ";
        for (String s : possibleParams) {
          ret += (start ? "" : ", ") + s;
          start = false;
        }
        ret += ")";
      }
      if (set) {
        ret += "\n\t\t--> current Setting: ";
        if (values.size() > 0) {
          boolean start = true;
          for (String s : values) {
            ret += (start ? "" : ",") + s;
            start = false;
          }
        } else {
          ret += "true";
        }
        // ret += "\n";
      }
      return ret;
    }
  }

  private HashMap<String, Option> options;

  private CmdOptions() {
    options = new HashMap<String, Option>();
    this.setOption("help", "--help", "-h", null, "Show all possible options and their parameters.", null, new String[] { "-?" });
  }

  public static CmdOptions i() {
    if (instance == null) {
      instance = new CmdOptions();
    }
    return instance;
  }

  public String[] getOption(String name) {
    if (options.get(name).values.size() > 0)
      return options.get(name).values.toArray(new String[0]);
    else if (options.get(name).defaultParameter != null)
      return new String[] { options.get(name).defaultParameter };
    return null;
  }

  public Integer[] getOptionAsInt(String name) {
    if (options.get(name).values.size() > 0) {
      ArrayList<Integer> list = new ArrayList<Integer>();
      for (String o : options.get(name).values) {
        list.add(Integer.parseInt(o));
      }
      return list.toArray(new Integer[0]);
    } else if (options.get(name).defaultParameter != null)
      return new Integer[] { Integer.parseInt(options.get(name).defaultParameter) };
    return null;
  }

  public Double[] getOptionAsDouble(String name) {
    if (options.get(name).values.size() > 0) {
      ArrayList<Double> list = new ArrayList<Double>();
      for (String o : options.get(name).values) {
        list.add(Double.parseDouble(o));
      }
      return list.toArray(new Double[0]);
    } else if (options.get(name).defaultParameter != null)
      return new Double[] { Double.parseDouble(options.get(name).defaultParameter) };
    return null;
  }

  public boolean isSet(String option) {
    return options.get(option).set;
  }

  public boolean isSet(String option, String parameter) {
    for (String o : options.get(option).values) {
      if (o.equals(parameter)) {
        return true;
      }
    }
    return false;
  }

  public void setOption(String name, String longcmd, String cmd, String defaultparam, String description) {
    this.setOption(name, longcmd, cmd, defaultparam, description, null, null);
  }

  public void setOption(String name, String longcmd, String cmd, String defaultparam, String description, String[] possibleParams, String[] alternatives) {
    Option o = new Option();
    o.cmdOption = cmd;
    o.name = name;
    o.longCmdOption = longcmd;
    o.defaultParameter = defaultparam;
    o.description = description;
    o.alternatives = alternatives;
    o.possibleParams = possibleParams;
    options.put(name, o);
  }

  public String toString(boolean help) {
    StringBuilder b = new StringBuilder();
    if (help) {
      b.append("Possible options:\n");
    }
    b.append("-options\n");
    Option[] vars = options.values().toArray(new Option[0]);
    Arrays.sort(vars, new Comparator<Option>() {
      @Override
      public int compare(Option o1, Option o2) {
        return o1.name.compareTo(o2.name);
      }
    });
    for (Option o : vars) {
      b.append("\t").append(o.toString()).append("\n");
    }
    b.append("/options\n");
    return b.toString();
  }

  public void parse(String[] args) {
    // now parse
    if (args.length > 0) {
      int l = 0, i = 0;
      String arg = null;
      // iterate through all options
      for (; i < args.length; ++i) {
        arg = args[i];
        Option o = null;
        // search for correct option<commit_msg>removed unused variable<commit_after>package to.mmo.cmdlineoptions;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.HashMap;

/**
 * Written by <NAME>, (c) 2013
 * For use under the BSD 2-clause License, or in other words: 
 * Do what you want with it as long as you leave all copyright notices where they are
 *  and don't bother me when you break your pc. :)
 */


public class CmdOptions {

  private static CmdOptions instance;

  private static class Option {
    public String name;
    public String cmdOption;
    public String longCmdOption;
    public String description;
    public String defaultParameter;
    public String[] possibleParams;
    public String[] alternatives;
    public boolean set;
    public ArrayList<String> values;

    public Option() {
      values = new ArrayList<String>();
    }

    public String toString() {
      String ret = name + " (" + longCmdOption + (cmdOption != null ? "/" + cmdOption : "") + ")"
          + (defaultParameter != null ? ": default=" + defaultParameter : "") + (description != null ? "\n\t\t" + description : "");
      if (possibleParams != null) {
        boolean start = true;
        ret += "\n\t\t(Possible parameters: ";
        for (String s : possibleParams) {
          ret += (start ? "" : ", ") + s;
          start = false;
        }
        ret += ")";
      }
      if (set) {
        ret += "\n\t\t--> current Setting: ";
        if (values.size() > 0) {
          boolean start = true;
          for (String s : values) {
            ret += (start ? "" : ",") + s;
            start = false;
          }
        } else {
          ret += "true";
        }
        // ret += "\n";
      }
      return ret;
    }
  }

  private HashMap<String, Option> options;

  private CmdOptions() {
    options = new HashMap<String, Option>();
    this.setOption("help", "--help", "-h", null, "Show all possible options and their parameters.", null, new String[] { "-?" });
  }

  public static CmdOptions i() {
    if (instance == null) {
      instance = new CmdOptions();
    }
    return instance;
  }

  public String[] getOption(String name) {
    if (options.get(name).values.size() > 0)
      return options.get(name).values.toArray(new String[0]);
    else if (options.get(name).defaultParameter != null)
      return new String[] { options.get(name).defaultParameter };
    return null;
  }

  public Integer[] getOptionAsInt(String name) {
    if (options.get(name).values.size() > 0) {
      ArrayList<Integer> list = new ArrayList<Integer>();
      for (String o : options.get(name).values) {
        list.add(Integer.parseInt(o));
      }
      return list.toArray(new Integer[0]);
    } else if (options.get(name).defaultParameter != null)
      return new Integer[] { Integer.parseInt(options.get(name).defaultParameter) };
    return null;
  }

  public Double[] getOptionAsDouble(String name) {
    if (options.get(name).values.size() > 0) {
      ArrayList<Double> list = new ArrayList<Double>();
      for (String o : options.get(name).values) {
        list.add(Double.parseDouble(o));
      }
      return list.toArray(new Double[0]);
    } else if (options.get(name).defaultParameter != null)
      return new Double[] { Double.parseDouble(options.get(name).defaultParameter) };
    return null;
  }

  public boolean isSet(String option) {
    return options.get(option).set;
  }

  public boolean isSet(String option, String parameter) {
    for (String o : options.get(option).values) {
      if (o.equals(parameter)) {
        return true;
      }
    }
    return false;
  }

  public void setOption(String name, String longcmd, String cmd, String defaultparam, String description) {
    this.setOption(name, longcmd, cmd, defaultparam, description, null, null);
  }

  public void setOption(String name, String longcmd, String cmd, String defaultparam, String description, String[] possibleParams, String[] alternatives) {
    Option o = new Option();
    o.cmdOption = cmd;
    o.name = name;
    o.longCmdOption = longcmd;
    o.defaultParameter = defaultparam;
    o.description = description;
    o.alternatives = alternatives;
    o.possibleParams = possibleParams;
    options.put(name, o);
  }

  public String toString(boolean help) {
    StringBuilder b = new StringBuilder();
    if (help) {
      b.append("Possible options:\n");
    }
    b.append("-options\n");
    Option[] vars = options.values().toArray(new Option[0]);
    Arrays.sort(vars, new Comparator<Option>() {
      @Override
      public int compare(Option o1, Option o2) {
        return o1.name.compareTo(o2.name);
      }
    });
    for (Option o : vars) {
      b.append("\t").append(o.toString()).append("\n");
    }
    b.append("/options\n");
    return b.toString();
  }

  public void parse(String[] args) {
    // now parse
    if (args.length > 0) {
      int i = 0;
      String arg = null;
      // iterate through all options
      for (; i < args.length; ++i) {
        arg = args[i];
        Option o = null;
        // search for correct option
{'fraction_non_alphanumeric': 0.13799882052290152, 'fraction_numerical': 0.0038333005700805977, 'mean_word_length': 2.5852713178294575, 'pattern_counts': {'":': 2, '<': 25, '<?xml version=': 0, '>': 35, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6070519', 'n_tokens_mistral': 3012, 'n_tokens_neox': 2959, 'n_words': 843}