View Javadoc

1   package nl.tudelft.goal.unreal.util;
2   
3   import nl.tudelft.goal.unreal.messages.Key;
4   import cz.cuni.amis.pogamut.base.agent.IAgentId;
5   
6   public class EnvironmentUtil {
7   
8   	/**
9   	 * Simplifies a given string representation of an AgentID by removing the
10  	 * UUID making it human readable.
11  	 * 
12  	 * By the specs of the agentID this should still result in a unique but
13  	 * readable ID.
14  	 * 
15  	 * @param iAgentId
16  	 * @return the agentID without the UUID.
17  	 */
18  	public static String simplefyID(IAgentId agentID) {
19  		String token = agentID.getToken();
20  		int index = token.lastIndexOf('/');
21  		// If the expected separator could not be found, use the whole string.
22  		if (index < 0) {
23  			return token;
24  		}
25  
26  		return token.substring(0, index);
27  	}
28  
29  	/**
30  	 * Returns a comma separated string of enum constants. When the enum
31  	 * implements the {@link Key} interface the human readable version will be
32  	 * used.
33  	 * 
34  	 * @param type
35  	 * @return
36  	 */
37  	public static <E extends Enum<E>> String listValid(Class<E> type) {
38  
39  		String ret = "";
40  
41  		E[] keys = type.getEnumConstants();
42  		for (int i = 0; i < keys.length; i++) {
43  
44  			if (keys[i] instanceof Key) {
45  				ret += ((Key) keys[i]).getKey();
46  			} else {
47  				ret += keys[i].name().toLowerCase();
48  			}
49  
50  			if (i < keys.length - 1)
51  				ret += ", ";
52  		}
53  		return ret;
54  	}
55  
56  }