source: josm/trunk/src/org/openstreetmap/josm/data/cache/CacheEntryAttributes.java@ 8308

Last change on this file since 8308 was 8308, checked in by Don-vip, 9 years ago

fix potential NPEs and Sonar issues related to serialization

File size: 2.1 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.data.cache;
3
4import java.util.HashMap;
5import java.util.Map;
6
7import org.apache.commons.jcs.engine.ElementAttributes;
8
9/**
10 * Class that contains attirubtes for JCS cache entries. Parameters are used to properly handle HTTP caching
11 *
12 * @author Wiktor Niesiobędzki
13 *
14 */
15public class CacheEntryAttributes extends ElementAttributes {
16 private static final long serialVersionUID = 1L; //version
17 private transient Map<String, String> attrs = new HashMap<String, String>();
18 private final static String NO_TILE_AT_ZOOM = "noTileAtZoom";
19 private final static String ETAG = "Etag";
20 private final static String LAST_MODIFICATION = "lastModification";
21 private final static String EXPIRATION_TIME = "expirationTime";
22
23 public CacheEntryAttributes() {
24 super();
25 attrs.put(NO_TILE_AT_ZOOM, "false");
26 attrs.put(ETAG, null);
27 attrs.put(LAST_MODIFICATION, "0");
28 attrs.put(EXPIRATION_TIME, "0");
29 }
30
31 public boolean isNoTileAtZoom() {
32 return Boolean.toString(true).equals(attrs.get(NO_TILE_AT_ZOOM));
33 }
34 public void setNoTileAtZoom(boolean noTileAtZoom) {
35 attrs.put(NO_TILE_AT_ZOOM, Boolean.toString(noTileAtZoom));
36 }
37 public String getEtag() {
38 return attrs.get(ETAG);
39 }
40 public void setEtag(String etag) {
41 attrs.put(ETAG, etag);
42 }
43
44 private long getLongAttr(String key) {
45 try {
46 return Long.parseLong(attrs.get(key));
47 } catch (NumberFormatException e) {
48 attrs.put(key, "0");
49 return 0;
50 }
51 }
52
53 public long getLastModification() {
54 return getLongAttr(LAST_MODIFICATION);
55 }
56 public void setLastModification(long lastModification) {
57 attrs.put(LAST_MODIFICATION, Long.toString(lastModification));
58 }
59 public long getExpirationTime() {
60 return getLongAttr(EXPIRATION_TIME);
61 }
62 public void setExpirationTime(long expirationTime) {
63 attrs.put(EXPIRATION_TIME, Long.toString(expirationTime));
64 }
65
66}
Note: See TracBrowser for help on using the repository browser.