Subcatchment.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 Subcatchment {

    public String name;
    public String rainGage;
    public String outlet;
    public double area;
    public double percentImperv;
    public double width;
    public double percentSlope;
    public double curbLen;
    public double snowPack;
    public double length;

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

    public Subcatchment()
    {
    }

    public Subcatchment( String line )
    {
        String[] parts = splitWithQuotes( line );
        this.name = parts[0];
        this.rainGage = parts[1];
        this.outlet = parts[2];
        this.area = Double.parseDouble( parts[3] );
        this.percentImperv = Double.parseDouble( parts[4] );
        this.width = Double.parseDouble( parts[5] );
        this.percentSlope = Double.parseDouble( parts[6] );
        this.curbLen = Double.parseDouble( parts[7] );
        if ( parts.length > 8 && !parts[8].isEmpty() ) //No promises this is included, it's an optional parameter.
        {
            this.snowPack = Double.parseDouble( parts[8] );
        }
        else
        {
            this.snowPack = Double.MIN_VALUE;
        }
    }

    public Subcatchment( String name, String rainGage, String outlet,
            double area, double percentImperv, double width,
            int percentSlope, int curbLen, int snowPack )
    {
        this.name = name;
        this.rainGage = rainGage;
        this.outlet = outlet;
        this.area = area;
        this.percentImperv = percentImperv;
        this.width = width;
        this.percentSlope = percentSlope;
        this.curbLen = curbLen;
        this.snowPack = snowPack;
    }

    public Subcatchment( String name, String rainGage, String outlet,
            double area, double percentImperv, double width, double length,
            double percentSlope, double curbLen )
    {
        this.name = name;
        this.rainGage = rainGage;
        this.outlet = outlet;
        this.area = area;
        this.percentImperv = percentImperv;
        this.width = width;
        this.length = length;
        this.percentSlope = percentSlope;
        this.curbLen = curbLen;
        this.snowPack = Double.MIN_VALUE;
    }

    public Subcatchment deepClone()
    {
        Subcatchment s = new Subcatchment();
        s.name = this.name;
        s.rainGage = this.rainGage;
        s.outlet = this.outlet;
        s.area = this.area;
        s.percentImperv = this.percentImperv;
        s.width = this.width;
        s.percentSlope = this.percentSlope;
        s.curbLen = this.curbLen;
        s.snowPack = this.snowPack;
        s.length = this.length;
        return s;
    }

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

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

        //Data
        sb.append( StringUtils.rightPad( String.valueOf( this.name ), namePadDistance ) );
        sb.append( StringUtils.rightPad( String.valueOf( this.rainGage ), namePadDistance ) );
        sb.append( StringUtils.rightPad( String.valueOf( this.outlet ), namePadDistance ) );
        sb.append( StringUtils.rightPad( df.format( this.area ), padDistance ) );
        sb.append( StringUtils.rightPad( df.format( this.percentImperv ), padDistance ) );
        sb.append( StringUtils.rightPad( df.format( this.width ), padDistance ) );
        sb.append( StringUtils.rightPad( df.format( this.percentSlope ), padDistance ) );
        sb.append( StringUtils.rightPad( String.valueOf( this.curbLen ), padDistance ) );
        if ( this.snowPack != Double.MIN_VALUE )
        {
            sb.append( StringUtils.rightPad( String.valueOf( this.snowPack ), padDistance ) );
        }

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

}