Package gannuNLP.data

Source Code of gannuNLP.data.ParamHandler

package gannuNLP.data;

import gannuUtil.KeyString;

import java.util.ArrayList;

/**
* Base object for anything needing parameters.
* @author Francisco Viveros-Jiménez
*
*/

public class ParamHandler {
  /**
   *
   * @return A simplified version of this.getParameterString() for file naming.
   */
  public String getSimplifiedParameterString()
  {
    String x="";
    if(this.params!=null)
    {
      for(KeyString aux:this.params)
      {
        x+=aux.getKey().substring(0,3)+"="+aux.getString()+",";
      }
    }
    return x.substring(0,x.length()-1);
  }
  /**
   *
   * @return this.params
   */
  public ArrayList<KeyString> getParams() {
    return params;
  }
  /**
   * ArrayList for containing extra parameters and its values.
   */
  ArrayList<KeyString> params;
  public String toString()
  {
    return this.getParameterString();
  }
  /**
   *
   * @return An String like "param1:value1;(paramN:valueN;)*)".
   */
  public String getParameterString()
  {
    String x="";
    if(this.params!=null)
      for(KeyString aux:this.params)
      {
        x+=aux.toString()+";";
      }
    return x;
  }
  /**
   * Method for adding extra parameters.
   * Parameters should be written in the format "Parameter1:Value1;[ParameterN:ValueN]*".
   * @param string String containing the values and names of the extra parameters.
   */
  public void addParameters(String string) {
    String aux[]=string.split(";");
    for(String param:aux)
    {
      String x[]=param.split(":");
      if(x.length>1)
        this.params.add(new KeyString(x[0],x[1]));
    }

  }
  /**
   * Method for re-setting the parameters.
   * Parameters should be written in the format "Parameter1:Value1;[ParameterN:ValueN]*".
   * @param string String containing the values and names of the parameters.
   */
  public void setParameters(String string) {
    String aux[]=string.split(";");
    this.params.clear();
    for(String param:aux)
    {
      String x[]=param.split(":");
      if(x.length>1)
        this.params.add(new KeyString(x[0],x[1]));
    }

  }

  /**
   * Instantiates a new ParamHandler without initial parameter values.
   */
  public ParamHandler()
  {
    this.params=new ArrayList<KeyString>();
  }
  /**
   * Instantiates a new ParamHandler with the specified initial parameters.
   * Parameters should be written in the format "Parameter1:Value1;[ParameterN:ValueN]*".
   * @param string String containing the values and names of the extra parameters.
   */
  public ParamHandler(String string)
  {
    this.params=new ArrayList<KeyString>();
    this.addParameters(string);
  }
  /**
   * Returns the value of the target parameter.
   * @param Key The desired parameter.
   * @return The value of the specified parameter.
   */
  public String getValue(String Key)
  {
    int index=this.params.indexOf(new KeyString(Key));
    if(index>=0)
      return this.params.get(index).getString();
    else
      return null;
  }
 
}
TOP

Related Classes of gannuNLP.data.ParamHandler

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.