RainGage.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.time.Duration;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.time.DurationFormatUtils;
import static utils.StringHelpers.convertStringToDurationString;
import static utils.StringHelpers.splitWithQuotes;
/**
*
* @author Lucas Yaege
*/
public class RainGage {
String name;
String format;
Duration interval;
double scf;
String source;
String fileName;
String sta;
String units;
int tSeries;
public RainGage()
{
}
public RainGage( String line )
{
String[] parts = splitWithQuotes( line );
this.name = parts[0];
this.format = parts[1];
this.interval = Duration.parse( convertStringToDurationString( parts[2] ) );
this.scf = Double.parseDouble( parts[3] );
this.source = parts[4];
this.fileName = parts[5];
this.sta = parts[6];
this.units = parts[7];
}
public RainGage( String name,
String format,
Duration interval,
double scf,
String source,
String fileName,
String sta,
String units,
int tSeries )
{
this.format = format;
this.interval = interval;
this.scf = scf;
this.source = source;
this.fileName = fileName;
this.sta = sta;
this.units = units;
this.tSeries = tSeries;
}
public RainGage( String name,
String format,
Duration interval,
double scf,
String source,
String fileName,
String sta,
String units )
{
this.name = name;
this.format = format;
this.interval = interval;
this.scf = scf;
this.source = source;
this.fileName = fileName;
this.sta = sta;
this.units = units;
}
@Override
public String toString()
{
return toString( 17 );
}
public String toString( int padDistance )
{
StringBuilder sb = new StringBuilder();
//Data
sb.append( StringUtils.rightPad( String.valueOf( this.name ), padDistance ) );
sb.append( StringUtils.rightPad( this.format, padDistance ) );
sb.append( StringUtils.rightPad(
DurationFormatUtils.formatDuration( this.interval.toMillis(), "H:MM" ), padDistance ) );
sb.append( StringUtils.rightPad( String.valueOf( this.scf ), padDistance ) );
sb.append( StringUtils.rightPad( this.source, padDistance ) );
if ( this.source.equalsIgnoreCase( "file" ) )
{
sb.append( StringUtils.rightPad( "\"" + this.fileName + "\"", this.fileName.length() + 6 ) );
sb.append( StringUtils.rightPad( this.sta, padDistance ) );
sb.append( StringUtils.rightPad( this.units, padDistance ) );
}
else
{
sb.append( StringUtils.rightPad( String.valueOf( this.tSeries ), padDistance ) );
}
return sb.toString();
}
}