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

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

fix various Sonar issues:

  • squid:S1068: Unused private fields should be removed
  • squid:S1155: Collection.isEmpty() should be used to test for emptiness
  • squid:S1185: Overriding methods should do more than simply call the same method in the super class
  • squid:S1694: An abstract class should have both abstract and concrete methods
  • squid:S1905: Redundant casts should not be used
  • squid:S2065: Fields in non-serializable classes should not be "transient"
  • squid:S2583: Conditions should not unconditionally evaluate to "TRUE" or to "FALSE"
  • squid:ModifiersOrderCheck: Modifiers should be declared in the correct order
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 * @since 8168
14 */
15public class CacheEntryAttributes extends ElementAttributes {
16 private static final long serialVersionUID = 1L; //version
17 private final Map<String, String> attrs = new HashMap<String, String>();
18 private static final String NO_TILE_AT_ZOOM = "noTileAtZoom";
19 private static final String ETAG = "Etag";
20 private static final String LAST_MODIFICATION = "lastModification";
21 private static final String EXPIRATION_TIME = "expirationTime";
22
23 /**
24 * Constructs a new {@code CacheEntryAttributes}.
25 */
26 public CacheEntryAttributes() {
27 super();
28 attrs.put(NO_TILE_AT_ZOOM, "false");
29 attrs.put(ETAG, null);
30 attrs.put(LAST_MODIFICATION, "0");
31 attrs.put(EXPIRATION_TIME, "0");
32 }
33
34 public boolean isNoTileAtZoom() {
35 return Boolean.toString(true).equals(attrs.get(NO_TILE_AT_ZOOM));
36 }
37 public void setNoTileAtZoom(boolean noTileAtZoom) {
38 attrs.put(NO_TILE_AT_ZOOM, Boolean.toString(noTileAtZoom));
39 }
40 public String getEtag() {
41 return attrs.get(ETAG);
42 }
43 public void setEtag(String etag) {
44 attrs.put(ETAG, etag);
45 }
46
47 private long getLongAttr(String key) {
48 try {
49 return Long.parseLong(attrs.get(key));
50 } catch (NumberFormatException e) {
51 attrs.put(key, "0");
52 return 0;
53 }
54 }
55
56 public long getLastModification() {
57 return getLongAttr(LAST_MODIFICATION);
58 }
59 public void setLastModification(long lastModification) {
60 attrs.put(LAST_MODIFICATION, Long.toString(lastModification));
61 }
62 public long getExpirationTime() {
63 return getLongAttr(EXPIRATION_TIME);
64 }
65 public void setExpirationTime(long expirationTime) {
66 attrs.put(EXPIRATION_TIME, Long.toString(expirationTime));
67 }
68
69}
Note: See TracBrowser for help on using the repository browser.