001package jmri.jmrit.logixng;
002
003import java.io.PrintWriter;
004import java.util.Locale;
005
006import jmri.Manager;
007
008/**
009 * Manager for GlobalVariable
010 *
011 * @author Dave Duchamp       Copyright (C) 2007
012 * @author Daniel Bergqvist   Copyright (C) 2022
013 */
014public interface GlobalVariableManager extends Manager<GlobalVariable> {
015
016    /**
017     * Create a new GlobalVariable if the GlobalVariable does not exist.
018     *
019     * @param systemName the system name
020     * @param userName   the user name
021     * @return a new GlobalVariable or null if unable to create
022     */
023    GlobalVariable createGlobalVariable(String systemName, String userName)
024            throws IllegalArgumentException;
025
026    /**
027     * For use with User GUI, to allow the auto generation of systemNames, where
028     * the user can optionally supply a username.
029     *
030     * @param userName the user name
031     * @return a new GlobalVariable or null if unable to create
032     */
033    GlobalVariable createGlobalVariable(String userName)
034            throws IllegalArgumentException;
035
036    /**
037     * Locate via user name, then system name if needed. Does not create a new
038     * one if nothing found
039     *
040     * @param name User name or system name to match
041     * @return null if no match found
042     */
043    GlobalVariable getGlobalVariable(String name);
044
045    /** {@inheritDoc} */
046    @Override
047    GlobalVariable getByUserName(String name);
048
049    /** {@inheritDoc} */
050    @Override
051    GlobalVariable getBySystemName(String name);
052
053    /**
054     * Create a new system name for a GlobalVariable.
055     * @return a new system name
056     */
057    String getAutoSystemName();
058
059    /**
060     * {@inheritDoc}
061     *
062     * The sub system prefix for the GlobalVariableManager is
063     * {@link #getSystemNamePrefix() } and "GV";
064     */
065    @Override
066    default String getSubSystemNamePrefix() {
067        return getSystemNamePrefix() + "GV";
068    }
069
070    /**
071     * Delete GlobalVariable by removing it from the manager. The GlobalVariable must first
072     * be deactivated so it stops processing.
073     *
074     * @param x the GlobalVariable to delete
075     */
076    void deleteGlobalVariable(GlobalVariable x);
077
078    /**
079     * Print the tree to a stream.
080     *
081     * @param locale The locale to be used
082     * @param writer the stream to print the tree to
083     * @param indent the indentation of each level
084     */
085    void printTree(Locale locale, PrintWriter writer, String indent);
086
087}