Evaporation.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;
/**
*
* @author Lucas Yaege
*/
public class Evaporation
{
public Double[] monthly;
public boolean dryOnly;
private DecimalFormat decimalFormat = new DecimalFormat( "#.00" );
public Evaporation()
{
monthly = new Double[12];
dryOnly = true;
}
@Override
public String toString()
{
return toString( 17 );
}
public String toString( int padDistance )
{
StringBuilder builder = new StringBuilder();
builder.append( "[EVAPORATION]\n" );
builder.append( StringUtils.rightPad( ";;Data Source", padDistance ) ).append( "Parameters\n" );
builder.append( ";;-------------- ----------------\n" );
builder.append( StringUtils.rightPad( "MONTHLY", padDistance ) );
for ( Double evap : monthly )
{
String formattedEvap = decimalFormat.format( evap );
String paddedEvap = StringUtils.rightPad( formattedEvap, 6 );
builder.append( paddedEvap );
}
String dryOnlyString = ( dryOnly ) ? "YES" : "NO";
builder.append( "\n" );
builder.append( StringUtils.rightPad( "DRY_ONLY", padDistance ) ).append( dryOnlyString );
builder.append( "\n\n" );
return builder.toString();
}
public void parse( String line )
{
if( line.startsWith( "MONTHLY" ) )
{
addMonthly( line );
}
else if( line.startsWith( "DRY_ONLY" ) )
{
addDryOnly( line );
}
}
public void setMonthly( Double[] evaporation )
{
monthly = evaporation;
}
private void addMonthly( String line )
{
String[] monthlyParams = line.split( " +" );
for ( int i = 1; i < monthlyParams.length; i++ )
{
monthly[i - 1] = Double.parseDouble( monthlyParams[i] );
}
}
private void addDryOnly( String line )
{
String noSpacing = line.replaceAll( " +", " " );
String[] dry = noSpacing.split( " " );
dryOnly = Boolean.parseBoolean( dry[1] );
}
}