Skip to content
Snippets Groups Projects
Commit 6f5a772f authored by dgelessus's avatar dgelessus
Browse files

Use LoadedMachine instead of getChildren in :browse

parent a9b592ec
No related branches found
No related tags found
No related merge requests found
...@@ -3,17 +3,12 @@ package de.prob2.jupyter.commands; ...@@ -3,17 +3,12 @@ package de.prob2.jupyter.commands;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Comparator; import java.util.Comparator;
import java.util.List; import java.util.List;
import java.util.function.Function;
import java.util.stream.Collectors;
import com.google.inject.Inject; import com.google.inject.Inject;
import de.prob.animator.domainobjects.FormulaExpand; import de.prob.animator.domainobjects.FormulaExpand;
import de.prob.model.representation.AbstractElement;
import de.prob.model.representation.Constant;
import de.prob.model.representation.Set;
import de.prob.model.representation.Variable;
import de.prob.statespace.AnimationSelector; import de.prob.statespace.AnimationSelector;
import de.prob.statespace.LoadedMachine;
import de.prob.statespace.Trace; import de.prob.statespace.Trace;
import de.prob.statespace.Transition; import de.prob.statespace.Transition;
...@@ -52,13 +47,8 @@ public final class BrowseCommand implements Command { ...@@ -52,13 +47,8 @@ public final class BrowseCommand implements Command {
return "The output shows the names of all sets, constants, and variables defined by the current machine, as well as a list of transitions that are available in the current state. Each transition has a numeric ID, which can be passed to `:exec` to execute that transition."; return "The output shows the names of all sets, constants, and variables defined by the current machine, as well as a list of transitions that are available in the current state. Each transition has a numeric ID, which can be passed to `:exec` to execute that transition.";
} }
private static <T extends AbstractElement> @NotNull String elementsToString( private static @NotNull String listToString(final List<String> list) {
final @NotNull AbstractElement element, return list.isEmpty() ? "(none)" : String.join(", ", list);
final @NotNull Class<T> clazz,
final @NotNull Function<@NotNull T, @NotNull String> func
) {
final String elements = element.getChildrenOfType(clazz).stream().map(func).collect(Collectors.joining(", "));
return elements.isEmpty() ? "(none)" : elements;
} }
@Override @Override
...@@ -69,14 +59,14 @@ public final class BrowseCommand implements Command { ...@@ -69,14 +59,14 @@ public final class BrowseCommand implements Command {
final Trace trace = this.animationSelector.getCurrentTrace(); final Trace trace = this.animationSelector.getCurrentTrace();
final StringBuilder sb = new StringBuilder("Machine: "); final StringBuilder sb = new StringBuilder("Machine: ");
final AbstractElement mainComponent = trace.getStateSpace().getMainComponent(); sb.append(trace.getStateSpace().getMainComponent());
sb.append(mainComponent); final LoadedMachine lm = trace.getStateSpace().getLoadedMachine();
sb.append("\nSets: "); sb.append("\nSets: ");
sb.append(elementsToString(mainComponent, Set.class, Set::getName)); sb.append(listToString(lm.getSetNames()));
sb.append("\nConstants: "); sb.append("\nConstants: ");
sb.append(elementsToString(mainComponent, Constant.class, Object::toString)); sb.append(listToString(lm.getConstantNames()));
sb.append("\nVariables: "); sb.append("\nVariables: ");
sb.append(elementsToString(mainComponent, Variable.class, Variable::getName)); sb.append(listToString(lm.getVariableNames()));
sb.append("\nOperations: "); sb.append("\nOperations: ");
final List<Transition> sortedTransitions = new ArrayList<>(trace.getNextTransitions(true, FormulaExpand.TRUNCATE)); final List<Transition> sortedTransitions = new ArrayList<>(trace.getNextTransitions(true, FormulaExpand.TRUNCATE));
// Transition IDs are strings, but they almost always contain numbers. // Transition IDs are strings, but they almost always contain numbers.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment