summaryrefslogtreecommitdiff
path: root/BJC-Utils2/src/main/java/bjc/utils/cli/fds/FDSMode.java
blob: 60aeb387e5929e30a2e9c77580d70076d4c7eeaa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
package bjc.utils.cli.fds;

import java.util.Arrays;
import java.util.Collection;
import java.util.List;

import bjc.utils.cli.CommandHelp;
import bjc.utils.cli.NullHelp;

/**
 * A collection of related FDS commands.
 * 
 * @author bjculkin
 *
 * @param <S>
 *                The FDS state type.
 */
public interface FDSMode<S> {
	/**
	 * The default help for anything in a mode command.
	 */
	public static final List<CommandHelp> DEFAULT_HELP = Arrays.asList(new NullHelp());

	/**
	 * Get the name of this mode.
	 * 
	 * @return The mode of this name.
	 */
	default String getName() {
		return "Unnamed Mode";
	}

	/**
	 * Get all the characters that are registered to something in this mode.
	 * 
	 * In this context, something means a command or submode.
	 * 
	 * @return All of the characters registered to something in this mode.
	 */
	String[] registeredChars();

	/*
	 * Check for the existence of commands/submodes.
	 */

	/**
	 * Check if there is a command registered to the given character.
	 * 
	 * @param c
	 *                The character to check
	 * 
	 * @return Whether or not there is a command bound to that character.
	 */
	boolean hasCommand(String c);

	/**
	 * Check if there is a submode registered to the given character.
	 * 
	 * @param c
	 *                The character to check
	 * 
	 * @return Whether or not there is a submode bound to that character.
	 */
	boolean hasSubmode(String c);

	/*
	 * Get commands and submodes.
	 */

	/**
	 * Get the command attached to a given character.
	 * 
	 * @param c
	 *                The character to get the command for.
	 * 
	 * @return The command bound to that character.
	 * 
	 * @throws FDSException
	 *                 If there is no command bound to that character.
	 */
	FDSCommand<S> getCommand(String c) throws FDSException;

	/**
	 * Get the command attached to a given character.
	 * 
	 * @param c
	 *                The character to get the command for.
	 * 
	 * @return The command bound to that character.
	 * 
	 * @throws FDSException
	 *                 If there is no command bound to that character.
	 */
	FDSMode<S> getSubmode(String c) throws FDSException;

	/*
	 * Help utilities
	 */
	/**
	 * Get the help for what's bound to a character.
	 * 
	 * This should be one line.
	 * 
	 * @param c
	 *                The character to look at the help for.
	 * 
	 * @return The help for what's bound to the character.
	 */
	default Collection<CommandHelp> getHelp(String c) {
		return DEFAULT_HELP;
	}
}