View Javadoc

1   /**
2    * BaseUnrealEnvironment, an implementation of the environment interface standard that 
3    * facilitates the connection between GOAL and the UT2004 engine. 
4    * 
5    * Copyright (C) 2012 BaseUnrealEnvironment authors.
6    * 
7    * This program is free software: you can redistribute it and/or modify it under
8    * the terms of the GNU General Public License as published by the Free Software
9    * Foundation, either version 3 of the License, or (at your option) any later
10   * version.
11   * 
12   * This program is distributed in the hope that it will be useful, but WITHOUT
13   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14   * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
15   * details.
16   * 
17   * You should have received a copy of the GNU General Public License along with
18   * this program. If not, see <http://www.gnu.org/licenses/>.
19   */
20  package nl.tudelft.goal.unreal.messages;
21  
22  import java.util.logging.Level;
23  
24  /**
25   * List of valid parameter keys that can be used to initialize the environment.
26   * 
27   * 
28   * @author M.P. Korstanje
29   * 
30   */
31  public enum Key {
32  
33  	/**
34  	 * List of names for bots.
35  	 * 
36  	 * The number of names provided matches the number of bots launched by the
37  	 * environment.
38  	 */
39  	BOTNAMES("botNames"),
40  	/**
41  	 * Address of the control server.
42  	 * 
43  	 * Should be of the form protocol//host:port
44  	 */
45  	CONTROLSERVER("controlServer"),
46  	/**
47  	 * Weather or not the bot aims ahead of the target.
48  	 * 
49  	 * Either "true" of "false".
50  	 */
51  	LEADTARGET("leadTarget"),
52  	/**
53  	 * Log level used. Controls how many messages are displayed on the console.
54  	 * 
55  	 * Valid log levels are any from {@link Level}.
56  	 */
57  	LOGLEVEL("logLevel"),
58  	/**
59  	 * Address of the unreal server.
60  	 * 
61  	 * Should be of the form protocol//host:port
62  	 */
63  	BOTSERVER("botServer"),
64  	/**
65  	 * Name used by the server. Any string.
66  	 */
67  	CONTROLSERVERNAME("controlServerName"),
68  	/**
69  	 * Skill of the bot between 0 (poor) and 7 (good).
70  	 * 
71  	 * Controls how well the bot aims.
72  	 */
73  	SKILL("skill"),
74  	/**
75  	 * Skin used by the bot.
76  	 * 
77  	 * Any one of {@link Skin} will do.
78  	 */
79  	SKIN("skin"),
80  	/**
81  	 * Team of the bot.
82  	 * 
83  	 * Either 0 (red) or 1 (blue).
84  	 * 
85  	 */
86  	TEAM("team"),
87  	/**
88  	 * Address for the visualizer service.
89  	 * 
90  	 */
91  	VISUALIZERSERVER("visualizer"),
92  
93  	/**
94  	 * Start location for the bot.
95  	 */
96  	STARTLOCATION("startLocation"), 
97  	
98  	/**
99  	 * Start rotation for the bot.
100 	 */
101 	STARTROTATION("startRotation");
102 
103 	// Human readable (camelCase) form of the enum.
104 	private String key;
105 
106 	private Key(String name) {
107 		this.key = name;
108 	}
109 
110 	/**
111 	 * 
112 	 * @return a human readable name.
113 	 */
114 	@Override
115 	public String toString() {
116 		return key;
117 	}
118 
119 	/**
120 	 * 
121 	 * @return a list of valid values as a string.
122 	 */
123 	private static String listValid() {
124 		String ret = "";
125 
126 		Key[] keys = Key.values();
127 		for (int i = 0; i < keys.length; i++) {
128 			ret += keys[i].toString();
129 
130 			if (i < keys.length - 1)
131 				ret += ", ";
132 		}
133 		return ret;
134 	}
135 
136 	/**
137 	 * Returns the enum with the value of the string. matches.
138 	 * 
139 	 * @param value
140 	 * @return an ParameterKey.
141 	 * @throws IllegalArgumentException
142 	 *             if the provided value was not a valid parameter key.
143 	 */
144 	public static Key parseKey(String value) throws IllegalArgumentException {
145 		assert value != null;
146 
147 		for (Key key : Key.values()) {
148 			if (key.key.equalsIgnoreCase(value)) {
149 				return key;
150 			}
151 		}
152 
153 		String message = "%s is not a valid parameter key. Valid keys are: %s.";
154 		message = String.format(message, value, listValid());
155 		throw new IllegalArgumentException(message);
156 	}
157 
158 	public Object getKey() {
159 		return key;
160 	}
161 }