duplicate....
[jalview.git] / forester / java / src / org / forester / util / ForesterUtil.java
index 08c3b9e..043df39 100644 (file)
@@ -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,6 +95,30 @@ 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 );
@@ -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<String> list = file2list( file );
         final String[] ary = new String[ list.size() ];