当前位置 : 主页 > 编程语言 > c++ >

基于监视器模式的车辆追踪

来源:互联网 收集:自由互联 发布时间:2021-06-30
java concurrent /** 基于监视器模式的车辆追踪 */public class MonitorVehicleTracker {private final Map locations;public MonitorVehicleTracker(Map locations) { this.locations = deepCopy(locations); } public synchronized Map getLoca
java concurrent
/** 基于监视器模式的车辆追踪 */
public class MonitorVehicleTracker {

	private final Map
 
   locations;
	
	public MonitorVehicleTracker(Map
  
    locations) { this.locations = deepCopy(locations); } public synchronized Map
   
     getLocations() { return deepCopy(locations); } public synchronized MutablePoint getLocation(String id) { MutablePoint loc = locations.get(id); return loc == null ? null : new MutablePoint(loc); } public synchronized void setLocation(String id, int x, int y) { MutablePoint loc = locations.get(id); if (loc == null) System.out.println("No such ID: " + id); loc.x = x; loc.y = y; } private Map
    
      deepCopy(Map
     
       m) { Map
      
        result = new HashMap
       
        (); for (String id : m.keySet()) { result.put(id, new MutablePoint(m.get(id))); } return Collections.unmodifiableMap(result); } }
       
      
     
    
   
  
 
网友评论