Skip to content
Snippets Groups Projects
Select Git revision
  • d1901e09fcf5be95ef0f30e14b669df4c31d5cc4
  • master default protected
  • exec_auto_adjust_trace
  • let_variables
  • v1.4.1
  • v1.4.0
  • v1.3.0
  • v1.2.0
  • v1.1.0
  • v1.0.0
10 results

LoadCellCommand.java

  • Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    LoadCellCommand.java 1.51 KiB
    package de.prob2.jupyter.commands;
    
    import java.util.List;
    import java.util.Map;
    
    import com.google.inject.Inject;
    
    import de.prob.scripting.ClassicalBFactory;
    import de.prob.statespace.AnimationSelector;
    import de.prob.statespace.Trace;
    
    import de.prob2.jupyter.ProBKernel;
    
    import io.github.spencerpark.jupyter.messages.DisplayData;
    
    import org.jetbrains.annotations.NotNull;
    
    public final class LoadCellCommand implements CellCommand {
    	private final @NotNull ClassicalBFactory classicalBFactory;
    	private final @NotNull AnimationSelector animationSelector;
    	
    	@Inject
    	private LoadCellCommand(final @NotNull ClassicalBFactory classicalBFactory, final @NotNull AnimationSelector animationSelector) {
    		super();
    		
    		this.classicalBFactory = classicalBFactory;
    		this.animationSelector = animationSelector;
    	}
    	
    	@Override
    	public @NotNull String getSyntax() {
    		return "::load [PREF=VALUE ...]\nMACHINE\n...\nEND";
    	}
    	
    	@Override
    	public @NotNull String getShortHelp() {
    		return "Load the machine source code from the body.";
    	}
    	
    	@Override
    	public @NotNull DisplayData run(final @NotNull ProBKernel kernel, final @NotNull String argString, final @NotNull String body) {
    		final List<String> args = CommandUtils.splitArgs(argString);
    		final Map<String, String> preferences = CommandUtils.parsePreferences(args);
    		
    		this.animationSelector.changeCurrentAnimation(new Trace(this.classicalBFactory.create(body).load(preferences)));
    		return new DisplayData("Loaded machine: " + this.animationSelector.getCurrentTrace().getModel());
    	}
    }