1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 package org.nnsoft.sameas4j.cache;
23
24 import static java.lang.String.format;
25
26 import java.io.Serializable;
27
28
29
30
31 public final class CacheKey implements Serializable {
32
33
34
35
36 private static final long serialVersionUID = 634054729365372230L;
37
38
39
40
41 private final String service;
42
43
44
45
46 private final long lastModified;
47
48
49
50
51
52
53
54 public CacheKey(String service, long lastModified) {
55 if (service == null) {
56 throw new IllegalArgumentException("Parameter 'service' must not be null");
57 }
58
59 this.service = service;
60 this.lastModified = lastModified;
61 }
62
63
64
65
66
67
68 public String getService() {
69 return this.service;
70 }
71
72
73
74
75
76
77 public long getLastModified() {
78 return this.lastModified;
79 }
80
81
82
83
84 @Override
85 public int hashCode() {
86 final int prime = 31;
87 int result = 1;
88 result = prime * result + (int) (lastModified ^ (lastModified >>> 32));
89 result = prime * result + this.service.hashCode();
90 return result;
91 }
92
93
94
95
96 @Override
97 public boolean equals(Object obj) {
98 if (this == obj) {
99 return true;
100 }
101
102 if (obj == null) {
103 return false;
104 }
105
106 if (getClass() != obj.getClass()) {
107 return false;
108 }
109
110 CacheKey other = (CacheKey) obj;
111 if (this.lastModified != other.getLastModified()) {
112 return false;
113 }
114 if (this.service == null) {
115 if (other.getService() != null) {
116 return false;
117 }
118 } else if (!this.service.equals(other.getService())) {
119 return false;
120 }
121
122 return true;
123 }
124
125
126
127
128 @Override
129 public String toString() {
130 return format("CacheKey (service=%s, lastModified=%s)", service, lastModified);
131 }
132
133 }