基于委托的车辆追踪器 /** 基于委托的车辆追踪器 */public class DelegatingVehicleTracker {private final ConcurrentHashMap locations;private final Map unmodifiableMap; public DelegatingVehicleTracker(Map points) { locations
/** 基于委托的车辆追踪器 */ public class DelegatingVehicleTracker { private final ConcurrentHashMaplocations; private final Map unmodifiableMap; public DelegatingVehicleTracker(Map points) { locations = new ConcurrentHashMap (); unmodifiableMap = Collections.unmodifiableMap(locations); } public Map getLocations() { return unmodifiableMap; } public Point getLocation(String id) { return locations.get(id); } public void setLocation(String id, int x, int y) { if (locations.replace(id, new Point(x, y)) != null) System.out.println("invalid vehicle name : " + id); } }