-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathShapeCache.java
More file actions
30 lines (23 loc) · 850 Bytes
/
Copy pathShapeCache.java
File metadata and controls
30 lines (23 loc) · 850 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
package prototype;
import prototype.shapte.Circle;
import prototype.shapte.Rectangle;
import prototype.shapte.Shape;
import java.util.Hashtable;
public class ShapeCache {
private static Hashtable<String, Shape> shapeMap = new Hashtable<String, Shape>();
public static Shape getShape(String shapeId) {
Shape shapeCache = shapeMap.get(shapeId);
return (Shape) shapeCache.clone();
}
// 对每种形状都运行数据库查询,并创建该形状
// shapeMap.put(shapeKey, shape);
// 例如,我们要添加三种形状
public static void loadCache() {
Circle circle = new Circle();
circle.setId("1");
shapeMap.put(circle.getId(), circle);
Rectangle rectangle = new Rectangle();
rectangle.setId("2");
shapeMap.put(rectangle.getId(), rectangle);
}
}