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

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

    String name;
    int elevation;
    String type;
    int stageData;
    boolean gated;
    String routeTo;

    public Outfall()
    {

    }

    public Outfall( String line )
    {
        this.stageData = Integer.MIN_VALUE; //trigger for not printing 0.

        String[] parts = splitWithQuotes( line );

        this.name = parts[0];
        this.elevation = Integer.parseInt( parts[1] );
        this.type = parts[2];

        //Both of the last two parameters are optional,
        //so we have to check if one, or the other, or both are missing.
        //thus all the if else ifs
        if ( parts.length == 4 )
        {
            //parts[3] can be either the 'elevation' int, the 'gated' boolean, or the 'routeTo' String since both are optional.
            if ( parts[3].equalsIgnoreCase( "yes" ) | parts[3].equalsIgnoreCase( "no" ) )
            {
                this.gated = Boolean.parseBoolean( parts[3] );
            }
            else
            {
                this.routeTo = parts[3];
            }
        }
        else if ( parts.length == 5 )
        {
            this.gated = Boolean.parseBoolean( parts[3] );
            this.routeTo = parts[4];
        }
    }

    public Outfall( String name, int elevation, String type, int stageData, boolean gated, String routeTo )
    {
        this.name = name;
        this.elevation = elevation;
        this.type = type;
        this.stageData = stageData;
        this.gated = gated;
        this.routeTo = routeTo;
    }

    public Outfall( String name, int elevation, String type )
    {
        this.name = name;
        this.elevation = elevation;
        this.type = type;
        this.routeTo = "";
        this.stageData = Integer.MIN_VALUE;
        this.gated = false;
    }

    public String getName()
    {
        return this.name;
    }

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

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

        //Data
        sb.append( StringUtils.rightPad( this.name, namePadDistance ) );
        sb.append( StringUtils.rightPad( String.valueOf( this.elevation ), padDistance ) );
        sb.append( StringUtils.rightPad( this.type, padDistance ) );
        sb.append( StringUtils.rightPad( ( this.stageData != Integer.MIN_VALUE )
                ? String.valueOf( this.stageData ) : "",
                padDistance ) );
        sb.append( StringUtils.rightPad( this.gated ? "YES" : "NO", padDistance ) );
        if ( this.routeTo != null && !this.routeTo.isEmpty() )
        {
            sb.append( StringUtils.rightPad( this.routeTo, namePadDistance ) );
        }

        return sb.toString();
    }

}