View Javadoc

1   package nl.tudelft.goal.unreal.messages;
2   
3   import java.util.logging.Level;
4   
5   import nl.tudelft.goal.ut2004.util.Skin;
6   
7   public enum BotParametersKey implements Key {
8   
9   	/**
10  	 * Name of the bot
11  	 */
12  	NAME("name"),
13  	/**
14  	 * Weather or not the bot aims ahead of the target.
15  	 * 
16  	 * Either "true" of "false".
17  	 */
18  	LEADTARGET("leadTarget"),
19  
20  	/**
21  	 * Log level used. Controls how many messages are displayed on the console.
22  	 * 
23  	 * Valid log levels are any from {@link Level}.
24  	 */
25  	LOGLEVEL("logLevel"),
26  	/**
27  	 * Skill of the bot between 0 (poor) and 7 (good).
28  	 * 
29  	 * Controls how well the bot aims.
30  	 */
31  	SKILL("skill"),
32  	/**
33  	 * Skin used by the bot.
34  	 * 
35  	 * Any one of {@link Skin} will do.
36  	 */
37  	SKIN("skin"),
38  	/**
39  	 * Team of the bot.
40  	 * 
41  	 * Either 0 (red) or 1 (blue).
42  	 * 
43  	 */
44  	TEAM("team"),
45  	/**
46  	 * Start location for the bot.
47  	 */
48  	STARTLOCATION("startLocation"), 
49  	/**
50  	 * Start rotation for the bot.
51  	 */
52  	STARTROTATION("startRotation");
53  
54  
55  	// Human readable (camelCase) form of the enum.
56  	private String key;
57  
58  	private BotParametersKey(String name) {
59  		this.key = name;
60  	}
61  
62  	/**
63  	 * 
64  	 * @return a human readable name.
65  	 */
66  	@Override
67  	public String toString() {
68  		return key;
69  	}
70  
71  	/**
72  	 * 
73  	 * @return a list of valid values as a string.
74  	 */
75  	private static String listValid() {
76  		String ret = "";
77  
78  		ConfigurationKey[] keys = ConfigurationKey.values();
79  		for (int i = 0; i < keys.length; i++) {
80  			ret += keys[i].toString();
81  
82  			if (i < keys.length - 1)
83  				ret += ", ";
84  		}
85  		return ret;
86  	}
87  
88  	/**
89  	 * Returns the enum with the value of the string. matches.
90  	 * 
91  	 * @param value
92  	 * @return an ParameterKey.
93  	 * @throws IllegalArgumentException
94  	 *             if the provided value was not a valid parameter key.
95  	 */
96  	public static BotParametersKey parseKey(String value) throws IllegalArgumentException {
97  		assert value != null;
98  
99  		for (BotParametersKey key : BotParametersKey.values()) {
100 			if (key.key.equalsIgnoreCase(value)) {
101 				return key;
102 			}
103 		}
104 
105 		String message = "%s is not a valid parameter key. Valid keys are: %s.";
106 		message = String.format(message, value, listValid());
107 		throw new IllegalArgumentException(message);
108 	}
109 
110 	public String getKey() {
111 		return key;
112 	}
113 }