From 956eee960b27a9cd6bec91f55bdd063dd0410e0e Mon Sep 17 00:00:00 2001 From: kjvdheide Date: Mon, 30 Oct 2017 18:09:38 +0000 Subject: [PATCH] JAL-2795 added error catching for invalid identifier --- resources/lang/Messages.properties | 1 + src/jalview/ext/forester/ForesterMatrix.java | 14 ++++++++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/resources/lang/Messages.properties b/resources/lang/Messages.properties index 5d9bdff..0b52a27 100644 --- a/resources/lang/Messages.properties +++ b/resources/lang/Messages.properties @@ -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} diff --git a/src/jalview/ext/forester/ForesterMatrix.java b/src/jalview/ext/forester/ForesterMatrix.java index 5450afe..92e88c8 100644 --- a/src/jalview/ext/forester/ForesterMatrix.java +++ b/src/jalview/ext/forester/ForesterMatrix.java @@ -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 })); + } } /** -- 1.7.10.2