From 0c62d6a52afd4737175bb3f9413ddf437f3fdf90 Mon Sep 17 00:00:00 2001
From: dgelessus <dgelessus@users.noreply.github.com>
Date: Tue, 8 Dec 2020 15:10:57 +0100
Subject: [PATCH] Use new ProB 2 APIs for getting visualization commands by
 name

---
 .../java/de/prob2/jupyter/commands/DotCommand.java    | 11 ++++++-----
 .../java/de/prob2/jupyter/commands/TableCommand.java  |  6 +-----
 2 files changed, 7 insertions(+), 10 deletions(-)

diff --git a/src/main/java/de/prob2/jupyter/commands/DotCommand.java b/src/main/java/de/prob2/jupyter/commands/DotCommand.java
index 07ad616..ef05549 100644
--- a/src/main/java/de/prob2/jupyter/commands/DotCommand.java
+++ b/src/main/java/de/prob2/jupyter/commands/DotCommand.java
@@ -101,11 +101,12 @@ public final class DotCommand implements Command {
 		}
 		
 		final Trace trace = this.animationSelector.getCurrentTrace();
-		final DotVisualizationCommand dotCommand = DotVisualizationCommand.getAll(trace.getCurrentState())
-			.stream()
-			.filter(i -> command.equals(i.getCommand()))
-			.findAny()
-			.orElseThrow(() -> new UserErrorException("No such dot command: " + command));
+		final DotVisualizationCommand dotCommand;
+		try {
+			dotCommand = DotVisualizationCommand.getByName(command, trace.getCurrentState());
+		} catch (final IllegalArgumentException e) {
+			throw new UserErrorException("No such dot command: " + command, e);
+		}
 		
 		// Provide source code (if any) to error highlighter
 		final Supplier<String> execute = () -> dotCommand.visualizeAsSvgToString(dotCommandArgs);
diff --git a/src/main/java/de/prob2/jupyter/commands/TableCommand.java b/src/main/java/de/prob2/jupyter/commands/TableCommand.java
index 700da4a..cc54b69 100644
--- a/src/main/java/de/prob2/jupyter/commands/TableCommand.java
+++ b/src/main/java/de/prob2/jupyter/commands/TableCommand.java
@@ -73,11 +73,7 @@ public final class TableCommand implements Command {
 		final String code = kernel.insertLetVariables(args.get(EXPRESSION_PARAM));
 		final IEvalElement formula = CommandUtils.withSourceCode(code, () -> kernel.parseFormula(code, FormulaExpand.EXPAND));
 		
-		final TableData table = TableVisualizationCommand.getAll(trace.getCurrentState())
-			.stream()
-			.filter(c -> "expr_as_table".equals(c.getCommand()))
-			.findAny()
-			.orElseThrow(AssertionError::new)
+		final TableData table = TableVisualizationCommand.getByName(TableVisualizationCommand.EXPRESSION_AS_TABLE_NAME, trace.getCurrentState())
 			.visualize(Collections.singletonList(formula));
 		
 		final StringBuilder sbPlain = new StringBuilder();
-- 
GitLab