1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package com.google.common.cache;
18
19 import static com.google.common.base.Preconditions.checkNotNull;
20
21 import com.google.common.annotations.Beta;
22 import com.google.common.annotations.GwtCompatible;
23 import com.google.common.base.Objects;
24
25 import java.util.Map.Entry;
26
27 import javax.annotation.Nullable;
28
29
30
31
32
33
34
35
36
37
38
39
40 @Beta
41 @GwtCompatible
42 public final class RemovalNotification<K, V> implements Entry<K, V> {
43 @Nullable private final K key;
44 @Nullable private final V value;
45 private final RemovalCause cause;
46
47 RemovalNotification(@Nullable K key, @Nullable V value, RemovalCause cause) {
48 this.key = key;
49 this.value = value;
50 this.cause = checkNotNull(cause);
51 }
52
53
54
55
56 public RemovalCause getCause() {
57 return cause;
58 }
59
60
61
62
63
64 public boolean wasEvicted() {
65 return cause.wasEvicted();
66 }
67
68 @Nullable @Override public K getKey() {
69 return key;
70 }
71
72 @Nullable @Override public V getValue() {
73 return value;
74 }
75
76 @Override public final V setValue(V value) {
77 throw new UnsupportedOperationException();
78 }
79
80 @Override public boolean equals(@Nullable Object object) {
81 if (object instanceof Entry) {
82 Entry<?, ?> that = (Entry<?, ?>) object;
83 return Objects.equal(this.getKey(), that.getKey())
84 && Objects.equal(this.getValue(), that.getValue());
85 }
86 return false;
87 }
88
89 @Override public int hashCode() {
90 K k = getKey();
91 V v = getValue();
92 return ((k == null) ? 0 : k.hashCode()) ^ ((v == null) ? 0 : v.hashCode());
93 }
94
95
96
97
98 @Override public String toString() {
99 return getKey() + "=" + getValue();
100 }
101 private static final long serialVersionUID = 0;
102 }