View Javadoc
1   package au.gov.amsa.navigation.ais;
2   
3   import java.util.HashMap;
4   import java.util.Map;
5   import java.util.concurrent.ConcurrentHashMap;
6   
7   import au.gov.amsa.navigation.Identifier;
8   
9   import com.google.common.base.Optional;
10  
11  public class VesselProperties {
12  
13  	public static enum Key {
14  		DESTINATION;
15  	}
16  
17  	private Map<Identifier, Map<Key, ValueAndTime>> map = new ConcurrentHashMap<Identifier, Map<Key, ValueAndTime>>();
18  
19  	public synchronized void add(Identifier id, Key key, Object value, long time) {
20  		Optional<Map<Key, ValueAndTime>> props = Optional.fromNullable(map.get(id));
21  		HashMap<Key, ValueAndTime> p;
22  		if (!props.isPresent())
23  			p = new HashMap<Key,ValueAndTime>();
24  		else 
25  			p = new HashMap<Key,ValueAndTime>(props.get());
26  		Optional<ValueAndTime> v = Optional.fromNullable(p.get(key));
27  		if (!v.isPresent() || v.get().getTime() <time) {
28  			p.put(key,new ValueAndTime(value, time));
29  			map.put(id, p);
30  		}
31  	}
32  	
33  
34  }