Options.java [src/SwmmObjects] Revision: default  Date:
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package SwmmObjects;

import java.util.HashMap;
import org.apache.commons.lang3.StringUtils;

/**
 *
 * @author Lucas Yaege
 */
public class Options {

  private HashMap<String, String> options;

  public Options(){
    options = new HashMap<String, String>();
  }

  public void setDefaultOptions(){
    options.put( "FLOW_UNITS", "CFS" );
    options.put( "INFILTRATION", "MODIFIED_HORTON" );
    options.put( "FLOW_ROUTING", "STEADY" );
    options.put( "LINK_OFFSETS", "DEPTH" );
    options.put( "MIN_SLOPE", "0" );
    options.put( "ALLOW_PONDING", "NO" );
    options.put( "SKIP_STEADY_STATE", "NO" );
    options.put( "START_DATE", "03/05/1970" );
    options.put( "START_TIME", "00:00:00" );
    options.put( "REPORT_START_DATE", "01/01/1971" );
    options.put( "REPORT_START_TIME", "00:00:00" );
    options.put( "END_DATE", "12/29/2006" );
    options.put( "END_TIME", "14:00:00" );
    options.put( "SWEEP_START", "01/01" );
    options.put( "SWEEP_END", "12/31" );
    options.put( "DRY_DAYS", "0" );
    options.put( "REPORT_STEP", "1:00:00" );
    options.put( "WET_STEP", "00:05:00" );
    options.put( "DRY_STEP", "01:00:00" );
    options.put( "ROUTING_STEP", "0:00:30 " );
    //options.put("RULE_STEP", "00:00:00");

    options.put( "INERTIAL_DAMPING", "PARTIAL" );
    options.put( "NORMAL_FLOW_LIMITED", "BOTH" );
    options.put( "FORCE_MAIN_EQUATION", "H-W" );
    options.put( "VARIABLE_STEP", "0.75" );
    options.put( "LENGTHENING_STEP", "0" );
    options.put( "MIN_SURFAREA", "12.566" );
    options.put( "MAX_TRIALS", "8" );
    options.put( "HEAD_TOLERANCE", "0.005" );
    options.put( "SYS_FLOW_TOL", "5" );
    options.put( "LAT_FLOW_TOL", "5" );
    options.put( "MINIMUM_STEP", "0.5" );
    options.put( "THREADS", "4" );
  }

  public void setOption( String line ){
    String id = line.substring( 0, line.indexOf( " " ) );
    String value = line.substring(
            ( line.lastIndexOf( " " ) + 1 ),
            ( line.length() ) );
    options.put( id, value );
  }

  public void setOption( String id, String value ){
    options.put( id, value );
  }

  public void removeOption( String line ){
    String id = line.substring( 0, line.indexOf( " " ) );
    this.options.remove( id );
  }

  @Override
  public String toString(){
    StringBuilder builder = new StringBuilder();

    //get longest key in the options hashmap.
    int maxValueLength = 0;
    for ( String key : options.keySet() ) {
      if( key.length() > maxValueLength )
        maxValueLength = key.length();
    }

    builder.append( "[OPTIONS]\n" );
    builder.append( StringUtils.rightPad( ";;Options", maxValueLength + 2 ) ).append( "Value\n" );

    for ( String key : options.keySet() ) {
      String value = options.get( key );
      //use rightpad for proper alignment.
      builder.append( StringUtils.rightPad( key, maxValueLength + 2 ) ).append( value ).append( "\n" );
    }

    builder.append( "\n" );

    return builder.toString();
  }

}