import java.util.TreeSet;
import java.util.regex.Pattern;
+import org.forester.phylogeny.PhylogenyNode;
+import org.forester.phylogeny.data.Distribution;
+import org.forester.phylogeny.data.Sequence;
+import org.forester.phylogeny.data.Taxonomy;
+
public final class ForesterUtil {
public final static String FILE_SEPARATOR = System.getProperty( "file.separator" );
private ForesterUtil() {
}
+ public static void ensurePresenceOfTaxonomy( final PhylogenyNode node ) {
+ if ( !node.getNodeData().isHasTaxonomy() ) {
+ node.getNodeData().setTaxonomy( new Taxonomy() );
+ }
+ }
+
+ public static void ensurePresenceOfSequence( final PhylogenyNode node ) {
+ if ( !node.getNodeData().isHasSequence() ) {
+ node.getNodeData().setSequence( new Sequence() );
+ }
+ }
+
+ final public static void ensurePresenceOfDistribution( final PhylogenyNode node ) {
+ if ( !node.getNodeData().isHasDistribution() ) {
+ node.getNodeData().setDistribution( new Distribution( "" ) );
+ }
+ }
+
+ final public static void ensurePresenceOfDate( final PhylogenyNode node ) {
+ if ( !node.getNodeData().isHasDate() ) {
+ node.getNodeData().setDate( new org.forester.phylogeny.data.Date() );
+ }
+ }
+
final public static void appendSeparatorIfNotEmpty( final StringBuffer sb, final char separator ) {
if ( sb.length() > 0 ) {
sb.append( separator );
System.exit( -1 );
}
+ public static void fatalErrorIfFileNotReadable( final String prg_name, final File file ) {
+ final String error = isReadableFile( file );
+ if ( !isEmpty( error ) ) {
+ System.err.println();
+ System.err.println( "[" + prg_name + "] > " + error );
+ System.err.println();
+ System.exit( -1 );
+ }
+ }
+
public static String[] file2array( final File file ) throws IOException {
final List<String> list = file2list( file );
final String[] ary = new String[ list.size() ];
}
final public static boolean isEven( final int n ) {
- return n % 2 == 0;
+ return ( n % 2 ) == 0;
}
/**
if ( ( a.length < 1 ) || ( b.length < 1 ) ) {
return false;
}
- for( int i = 0; i < a.length; ++i ) {
- final String ai = a[ i ];
- for( int j = 0; j < b.length; ++j ) {
- if ( ( ai != null ) && ( b[ j ] != null ) && ai.equals( b[ j ] ) ) {
+ for( final String ai : a ) {
+ for( final String element : b ) {
+ if ( ( ai != null ) && ( element != null ) && ai.equals( element ) ) {
return true;
}
}
}
final public static void printErrorMessage( final String prg_name, final String message ) {
- System.out.println( "[" + prg_name + "] > error: " + message );
+ System.err.println( "[" + prg_name + "] > error: " + message );
}
final public static void printProgramInformation( final String prg_name, final String prg_version, final String date ) {
*/
final public static String removeWhiteSpace( String s ) {
int i;
- for( i = 0; i <= s.length() - 1; i++ ) {
+ for( i = 0; i <= ( s.length() - 1 ); i++ ) {
if ( ( s.charAt( i ) == ' ' ) || ( s.charAt( i ) == '\t' ) || ( s.charAt( i ) == '\n' )
|| ( s.charAt( i ) == '\r' ) ) {
s = s.substring( 0, i ) + s.substring( i + 1 );
final public static String stringArrayToString( final String[] a, final String separator ) {
final StringBuilder sb = new StringBuilder();
if ( ( a != null ) && ( a.length > 0 ) ) {
- for( int i = 0; i < a.length - 1; ++i ) {
+ for( int i = 0; i < ( a.length - 1 ); ++i ) {
sb.append( a[ i ] + separator );
}
sb.append( a[ a.length - 1 ] );
final public static String stringListToString( final List<String> l, final String separator ) {
final StringBuilder sb = new StringBuilder();
if ( ( l != null ) && ( l.size() > 0 ) ) {
- for( int i = 0; i < l.size() - 1; ++i ) {
+ for( int i = 0; i < ( l.size() - 1 ); ++i ) {
sb.append( l.get( i ) + separator );
}
sb.append( l.get( l.size() - 1 ) );
final public static void unexpectedFatalError( final String prg_name, final Exception e ) {
System.err.println();
System.err.println( "[" + prg_name
- + "] > unexpected error (Should not have occured! Please contact program author(s).)" );
+ + "] > Unexpected error. Should not have occured! Please contact program author(s)." );
e.printStackTrace( System.err );
System.err.println();
System.exit( -1 );
final public static void unexpectedFatalError( final String prg_name, final String message ) {
System.err.println();
System.err.println( "[" + prg_name
- + "] > unexpected error. Should not have occured! Please contact program author(s)." );
+ + "] > Unexpected error. Should not have occured! Please contact program author(s)." );
System.err.println( message );
System.err.println();
System.exit( -1 );
final public static void unexpectedFatalError( final String prg_name, final String message, final Exception e ) {
System.err.println();
System.err.println( "[" + prg_name
- + "] > unexpected error. Should not have occured! Please contact program author(s)." );
+ + "] > Unexpected error. Should not have occured! Please contact program author(s)." );
System.err.println( message );
e.printStackTrace( System.err );
System.err.println();
ls = -1;
start = i + 1;
}
- if ( i > start + width - 1 ) {
+ if ( i > ( ( start + width ) - 1 ) ) {
if ( ls != -1 ) {
sb.setCharAt( ls, '\n' );
start = ls + 1;