Subarea.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.text.DecimalFormat;
import org.apache.commons.lang3.StringUtils;
import static utils.StringHelpers.splitWithQuotes;

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

    String subcatchment;
    double nImperv;
    double nPerv;
    double sImperv;
    double sPerv;
    double pctZero;
    String routeTo;
    double pctRouted;

    DecimalFormat df = new DecimalFormat( "#.###" );

    public Subarea()
    {

    }

    public Subarea( String line )
    {
        String[] parts = splitWithQuotes( line );
        this.subcatchment = parts[0];
        this.nImperv = Double.parseDouble( parts[1] );
        this.nPerv = Double.parseDouble( parts[2] );
        this.sImperv = Double.parseDouble( parts[3] );
        this.sPerv = Double.parseDouble( parts[4] );
        this.pctZero = Double.parseDouble( parts[5] );
        this.routeTo = parts[6];

        if ( parts.length > 7 && !parts[7].isEmpty() ) //No promises this parameter is included in the input file.
        {
            this.pctRouted = Double.parseDouble( parts[7] );
        }
        else
        {
            this.pctRouted = Double.MIN_VALUE;
        }
    }

    public Subarea( String subcatchment, Double nImperv, Double nPerv,
            Double sImperv, Double sPerv, int pctZero,
            String routeTo, int pctRouted )
    {
        this.subcatchment = subcatchment;
        this.nImperv = nImperv;
        this.nPerv = nPerv;
        this.sImperv = sImperv;
        this.sPerv = sPerv;
        this.pctZero = pctZero;
        this.routeTo = routeTo;
        this.pctRouted = pctRouted;
    }

    public Subarea( String subcatchment, Double nImperv, Double nPerv,
            Double sImperv, Double sPerv, int pctZero,
            String routeTo )
    {
        this.subcatchment = subcatchment;
        this.nImperv = nImperv;
        this.nPerv = nPerv;
        this.sImperv = sImperv;
        this.sPerv = sPerv;
        this.pctZero = pctZero;
        this.routeTo = routeTo;
        this.pctRouted = Double.MIN_VALUE;
    }

    @Override
    public String toString()
    {
        return toString( 17, 40 );
    }

    public String toString( int padDistance, int namePadDistance )
    {
        StringBuilder sb = new StringBuilder();

        sb.append( StringUtils.rightPad( this.subcatchment, namePadDistance ) );
        sb.append( StringUtils.rightPad( df.format( this.nImperv ), padDistance ) );
        sb.append( StringUtils.rightPad( df.format( this.nPerv ), padDistance ) );
        sb.append( StringUtils.rightPad( df.format( this.sImperv ), padDistance ) );
        sb.append( StringUtils.rightPad( df.format( this.sPerv ), padDistance ) );
        sb.append( StringUtils.rightPad( df.format( this.pctZero ), padDistance ) );
        sb.append( StringUtils.rightPad( String.valueOf( this.routeTo ), padDistance ) );
        if ( this.pctRouted != Double.MIN_VALUE )
        {
            sb.append( StringUtils.rightPad( df.format( this.pctRouted ), padDistance ) );
        }

        sb.append( "\n" );
        return sb.toString();
    }

}