All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.bnorm.infinite.file.FileStateMachineStructureFactory Maven / Gradle / Ivy

The newest version!
package com.bnorm.infinite.file;

import java.io.IOException;
import java.nio.file.Path;

import com.bnorm.infinite.InternalStateFactory;
import com.bnorm.infinite.StateMachineException;
import com.bnorm.infinite.StateMachineStructure;
import com.bnorm.infinite.StateMachineStructureFactory;
import com.bnorm.infinite.TransitionFactory;

/**
 * A factory for creating state machine structures for a file.
 *
 * @param  the class type of the states.
 * @param  the class type of the events.
 * @param  the class type of the context.
 * @author Brian Norman
 * @since 1.2.0
 */
public class FileStateMachineStructureFactory implements StateMachineStructureFactory {

    /** File location of the state machine text. */
    private final Path path;

    /** Reader used to interpret the state machine text. */
    private final StringStateMachineReader stateMachineReader;

    /**
     * Constructors a new FileStateMachineStructureFactory with the specified parameters.
     *
     * @param path the file location of the state machine text.
     * @param stateMachineReader the reader used to load the state machine.
     */
    public FileStateMachineStructureFactory(Path path, StringStateMachineReader stateMachineReader) {
        this.path = path;
        this.stateMachineReader = stateMachineReader;
    }

    @Override
    public StateMachineStructure create(InternalStateFactory internalStateFactory,
                                                 TransitionFactory transitionFactory) {
        try {
            return new FileStateMachineStructure<>(internalStateFactory, transitionFactory, path, stateMachineReader);
        } catch (IOException e) {
            throw new StateMachineException("Unable to read specified path [" + path + "]", e);
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy