JAL-2795 added error catching for invalid identifier
authorkjvdheide <kjvanderheide@dundee.ac.uk>
Mon, 30 Oct 2017 18:09:38 +0000 (18:09 +0000)
committerkjvdheide <kjvanderheide@dundee.ac.uk>
Mon, 30 Oct 2017 18:09:38 +0000 (18:09 +0000)
resources/lang/Messages.properties
src/jalview/ext/forester/ForesterMatrix.java

index 5d9bdff..0b52a27 100644 (file)
@@ -1067,6 +1067,7 @@ exception.couldnt_parse_sequence_line = Could not parse sequence line: {0}
 exception.unknown_annotation_detected = Unknown annotation detected: {0} {1}
 exception.couldnt_store_sequence_mappings = Couldn't store sequence mappings for {0}
 exception.matrix_too_many_iteration = Too many iterations in {0} (max is {1})
+exception.invalid_matrix_identifier = Name {0} not present in distance matrix.
 exception.browser_not_found = Exception in finding browser: {0}
 exception.browser_unable_to_locate = Unable to locate browser: {0}
 exception.invocation_target_exception_creating_aedesc = InvocationTargetException while creating AEDesc: {0}
index 5450afe..92e88c8 100644 (file)
@@ -2,11 +2,13 @@ package jalview.ext.forester;
 
 import jalview.datamodel.Sequence;
 import jalview.math.MatrixI;
+import jalview.util.MessageManager;
 
 import java.io.IOException;
 import java.io.Writer;
 import java.text.DecimalFormat;
 import java.text.NumberFormat;
+import java.util.NoSuchElementException;
 import java.util.stream.IntStream;
 
 import org.forester.evoinference.matrix.distance.DistanceMatrix;
@@ -55,12 +57,20 @@ public class ForesterMatrix implements DistanceMatrix
     return identifiers[i];
   }
 
+
   @Override
   public int getIndex(final String identifier)
   {
+    try {
     return IntStream.range(0, identifiers.length)
-            .filter(x -> identifier.equals(identifiers[x])).findFirst()
-            .orElse(-1);
+            .filter(x -> identifier.equals(identifiers[x])).findAny()
+            .getAsInt();
+    }
+    catch (NoSuchElementException ex) {
+      throw new Error(MessageManager.formatMessage(
+              "exception.invalid_matrix_identifier", new String[]
+              { identifier }));
+    }
   }
 
   /**