// Path: src/main/java/fi/helsinki/cs/ttk91/TTK91AddressOutOfBounds.java
// public class TTK91AddressOutOfBounds extends TTK91RuntimeException {
//     public TTK91AddressOutOfBounds(String message) {
//         super(message);
//     }
// }


import fi.helsinki.cs.ttk91.TTK91AddressOutOfBounds;
// Copyright © 2004-2006 University of Helsinki, Department of Computer Science
// Copyright © 2012 various contributors
// This software is released under GNU Lesser General Public License 2.1.
// The license text is at http://www.gnu.org/licenses/lgpl-2.1.html

package fi.helsinki.cs.titokone;


/**
 * This class can load a TTK91Application. It changes the processor
 * state accordingly. Everything is loaded when loadApplication is
 * called. Function returns the state of memory after loading. If it
 * runs out of memory it throws a TTK91AddressOutOfBounds exception.
 */
public class Loader {

    /**
     * This variable holds the current application to be loaded.
     */
    private Application application;


    private Processor processor;

    private BinaryInterpreter binInterpreter;

    public Loader(Processor processor) {
        String errorMessage;
        if (processor == null) {
            errorMessage = new Message("Null is an invalid parameter," +
                    " instance of {0} required.",
                    Processor.class.getName()).toString();
            throw new IllegalArgumentException(errorMessage);
        }
        this.processor = processor;
        binInterpreter = new BinaryInterpreter();
    }

    /**
     * You can set the file to load. Each time an application is set to load, the counter is set to
     * one.
     */
    public void setApplicationToLoad(Application application) {
        String errorMessage;
        if (application == null) {
            errorMessage = new Message("Null is an invalid parameter," +
                    " instance of {0} required.",
                    Application.class.getName()).toString();
            throw new IllegalArgumentException(errorMessage);
        }
        this.application = application;
    }

    /**
     * Loads an application to memory. LoadInfo contains all the needed information about the process.
     *
     * @return Info from the load procedure, null if no application has been set for loading.
     */
// Path: src/main/java/fi/helsinki/cs/ttk91/TTK91AddressOutOfBounds.java
// public class TTK91AddressOutOfBounds extends TTK91RuntimeException {
//     public TTK91AddressOutOfBounds(String message) {
//         super(message);
//     }
// }


// Path: src/main/java/fi/helsinki/cs/titokone/Loader.java
import fi.helsinki.cs.ttk91.TTK91AddressOutOfBounds;

// Copyright © 2004-2006 University of Helsinki, Department of Computer Science
// Copyright © 2012 various contributors
// This software is released under GNU Lesser General Public License 2.1.
// The license text is at http://www.gnu.org/licenses/lgpl-2.1.html

package fi.helsinki.cs.titokone;


/**
 * This class can load a TTK91Application. It changes the processor
 * state accordingly. Everything is loaded when loadApplication is
 * called. Function returns the state of memory after loading. If it
 * runs out of memory it throws a TTK91AddressOutOfBounds exception.
 */
public class Loader {

    /**
     * This variable holds the current application to be loaded.
     */
    private Application application;


    private Processor processor;

    private BinaryInterpreter binInterpreter;

    public Loader(Processor processor) {
        String errorMessage;
        if (processor == null) {
            errorMessage = new Message("Null is an invalid parameter," +
                    " instance of {0} required.",
                    Processor.class.getName()).toString();
            throw new IllegalArgumentException(errorMessage);
        }
        this.processor = processor;
        binInterpreter = new BinaryInterpreter();
    }

    /**
     * You can set the file to load. Each time an application is set to load, the counter is set to
     * one.
     */
    public void setApplicationToLoad(Application application) {
        String errorMessage;
        if (application == null) {
            errorMessage = new Message("Null is an invalid parameter," +
                    " instance of {0} required.",
                    Application.class.getName()).toString();
            throw new IllegalArgumentException(errorMessage);
        }
        this.application = application;
    }

    /**
     * Loads an application to memory. LoadInfo contains all the needed information about the process.
     *
     * @return Info from the load procedure, null if no application has been set for loading.
     */
    public LoadInfo loadApplication() throws TTK91AddressOutOfBounds {