X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=forester%2Fjava%2Fsrc%2Forg%2Fforester%2Futil%2FForesterUtil.java;h=ef302002c9f3bd1d637b361d739750841dfb4998;hb=08bd889bc13de7415319ea7202d8afb27879c18d;hp=7b9fefa20e8e724acb9bef843f18f1eed696d0db;hpb=de8fbefc959f11af246340c4f903fb2983a95d4d;p=jalview.git diff --git a/forester/java/src/org/forester/util/ForesterUtil.java b/forester/java/src/org/forester/util/ForesterUtil.java index 7b9fefa..ef30200 100644 --- a/forester/java/src/org/forester/util/ForesterUtil.java +++ b/forester/java/src/org/forester/util/ForesterUtil.java @@ -61,6 +61,11 @@ import java.util.TreeMap; 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" ); @@ -90,16 +95,40 @@ public final class ForesterUtil { 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 ); } } - public static boolean isWindowns () { - return ForesterUtil.OS_NAME.toLowerCase().indexOf( "win" ) > -1; + public static boolean isWindowns() { + return ForesterUtil.OS_NAME.toLowerCase().indexOf( "win" ) > -1; } - + final public static String getForesterLibraryInformation() { return "forester " + ForesterConstants.FORESTER_VERSION + " (" + ForesterConstants.FORESTER_DATE + ")"; } @@ -335,6 +364,16 @@ public final class ForesterUtil { 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 list = file2list( file ); final String[] ary = new String[ list.size() ]; @@ -482,7 +521,7 @@ public final class ForesterUtil { } final public static boolean isEven( final int n ) { - return n % 2 == 0; + return ( n % 2 ) == 0; } /** @@ -502,10 +541,9 @@ public final class ForesterUtil { 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; } } @@ -733,7 +771,7 @@ public final class ForesterUtil { } 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 ) { @@ -808,7 +846,7 @@ public final class ForesterUtil { */ 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 ); @@ -874,7 +912,7 @@ public final class ForesterUtil { 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 ] ); @@ -897,7 +935,7 @@ public final class ForesterUtil { final public static String stringListToString( final List 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 ) ); @@ -955,7 +993,7 @@ public final class ForesterUtil { 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;