View Javadoc

1   package cz.cuni.amis.pogamut.ut2004.communication.messages.custom;
2   
3   import cz.cuni.amis.pogamut.base3d.worldview.object.Location;
4   import cz.cuni.amis.pogamut.unreal.communication.messages.UnrealId;
5   
6   public interface ControlMessageTypeMapper<RESULT> {
7   	
8   	public RESULT map(Object value);
9   	
10  	// =============
11  	// DIRECT MAPPER
12  	// =============
13  	
14  	public static class DirectMapper<T> implements ControlMessageTypeMapper<T> {
15  
16  		@Override
17  		public T map(Object value) {
18  			return (T) value;
19  		}
20  		
21  	}
22  	
23  	public static final DirectMapper DIRECT_MAPPER = new DirectMapper();
24  	
25  	// ===================
26  	// STRING <-> UREANLID
27  	// ===================
28  	
29  	public static class String2UnrealIdMapper implements ControlMessageTypeMapper<UnrealId> {
30  
31  		@Override
32  		public UnrealId map(Object value) {
33  			if (value instanceof UnrealId) {
34  				return (UnrealId)value;
35  			}
36  			if (value instanceof String) {
37  				return UnrealId.get((String)value);
38  			}
39  			return null;
40  		}
41  		
42  	}
43  	
44  	public static final String2UnrealIdMapper STRING_2_UNREAL_ID_MAPPER = new String2UnrealIdMapper();
45  	
46  	public static class UnrealId2StringMapper implements ControlMessageTypeMapper<String> {
47  
48  		@Override
49  		public String map(Object value) {
50  			if (value instanceof UnrealId) {
51  				return ((UnrealId)value).getStringId();
52  			}
53  			if (value instanceof String) return (String)value;
54  			return null;
55  		}
56  		
57  	}
58  	
59  	public static final UnrealId2StringMapper UNREAL_ID_2_STRING_MAPPER = new UnrealId2StringMapper();
60  	
61  	// ===================
62  	// STRING <-> LOCATION
63  	// ===================
64  	
65  	public static class String2LocationMapper implements ControlMessageTypeMapper<Location> {
66  
67  		@Override
68  		public Location map(Object value) {
69  			if (value instanceof Location) {
70  				return (Location)value;
71  			}
72  			if (value instanceof String) {
73  				return new Location((String)value);
74  			}
75  			return null;
76  		}
77  		
78  	}
79  	
80  	public static final String2LocationMapper STRING_2_LOCATION_MAPPER = new String2LocationMapper();
81  	
82  	public static class Location2StringMapper implements ControlMessageTypeMapper<String> {
83  
84  		@Override
85  		public String map(Object value) {
86  			if (value instanceof Location) {
87  				return ((Location)value).toString();
88  			}
89  			if (value instanceof String) return (String)value;
90  			return null;
91  		}
92  		
93  	}
94  	
95  	public static final Location2StringMapper LOCATION_2_STRING_MAPPER = new Location2StringMapper();
96  	
97  
98  }