⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 delegatingvehicletracker.java

📁 java concurrency in practice 源码. JAVA并发设计
💻 JAVA
字号:
package net.jcip.examples;import java.util.*;import java.util.concurrent.*;import java.awt.*;import java.awt.Point;import net.jcip.annotations.*;/** * DelegatingVehicleTracker * <p/> * Delegating thread safety to a ConcurrentHashMap * * @author Brian Goetz and Tim Peierls */@ThreadSafepublic class DelegatingVehicleTracker {    private final ConcurrentMap<String, Point> locations;    private final Map<String, Point> unmodifiableMap;    public DelegatingVehicleTracker(Map<String, Point> points) {        locations = new ConcurrentHashMap<String, Point>(points);        unmodifiableMap = Collections.unmodifiableMap(locations);    }    public Map<String, Point> 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)            throw new IllegalArgumentException("invalid vehicle name: " + id);    }    // Alternate version of getLocations (Listing 4.8)    public Map<String, Point> getLocationsAsStatic() {        return Collections.unmodifiableMap(                new HashMap<String, Point>(locations));    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -