View Javadoc

1   package cz.cuni.amis.pogamut.unreal.communication.messages;
2   
3   import java.io.Serializable;
4   import java.util.HashMap;
5   import java.util.Map;
6   
7   import cz.cuni.amis.pogamut.base.communication.worldview.object.WorldObjectId;
8   import cz.cuni.amis.utils.token.Token;
9   import cz.cuni.amis.utils.token.Tokens;
10  
11  /**
12   * Interface that is returning an unique id of the world object. The id must be unique
13   * among all the objects in the world.
14   * <p><p>
15   * hashmaps/sets.
16   * 
17   * @author Jimmy
18   */
19  public class UnrealId extends WorldObjectId implements Serializable {
20  	
21  	/**
22  	 * For wrappers...
23  	 */
24  	protected UnrealId() {
25  		super("wrapper");
26  	}
27  	
28  	private UnrealId(String unrealStringId) {
29  		super(unrealStringId);
30  	}
31  	
32  	private UnrealId(Token id) {
33  		super(id);
34  	}
35  	
36  	private UnrealId(UnrealId id) {
37  		super(id.token);
38  	}
39  	
40  	private static Map<String, UnrealId> map = new HashMap<String, UnrealId>();
41  	
42  	public static final UnrealId NONE = UnrealId.get(Tokens.NONE_TOKEN.getToken());
43  
44  	/**
45  	 * stringId == is the String representation of Unreal ID that is generated & managed by underlying UT2004 server.
46  	 * <p>
47  	 * Note that if you run some map from cmdline, NavPoint-s name prefix is generated
48  	 * case censitive. So on win platform you can run map "CtF-losTFAith", which will
49  	 * start correct map (file system not case sensitive) and navpoints will be
50  	 * seen with different prefix name as if you start map "CTF-LostFaith".
51  	 * </p>
52  	 *
53  	 * @param unrealStringId
54  	 * @return
55  	 */
56  	public static UnrealId get(String unrealStringId) {
57  		UnrealId id = null;
58  		id = map.get(unrealStringId);
59  		if (id != null) return id;
60  		synchronized(map) {
61  			id = map.get(unrealStringId);
62  			if (id != null) return id;
63  			id = new UnrealId(unrealStringId);
64  			map.put(unrealStringId, id);
65  			return id;
66  		}
67  	}
68  	
69  	
70  }