1 package com.atlassian.cache.hazelcast;
2
3 import com.google.common.base.Objects;
4
5 class Versioned<T>
6 {
7 @SuppressWarnings ("unchecked")
8 private static final Versioned EMPTY = new Versioned(null, 0L);
9
10 private final long version;
11 private final T value;
12
13 Versioned(T value, long version)
14 {
15 this.value = value;
16 this.version = version;
17 }
18
19 @SuppressWarnings ("unchecked")
20 public static <T> Versioned<T> empty()
21 {
22 return EMPTY;
23 }
24
25 public T getValue()
26 {
27 return value;
28 }
29
30 public long getVersion()
31 {
32 return version;
33 }
34
35 @Override
36 public boolean equals(Object o)
37 {
38 if (this == o)
39 {
40 return true;
41 }
42 if (o == null || getClass() != o.getClass())
43 {
44 return false;
45 }
46
47 Versioned that = (Versioned) o;
48 return Objects.equal(version, that.version) && Objects.equal(value, that.value);
49 }
50
51 @Override
52 public int hashCode()
53 {
54 int result = (int) (version ^ (version >>> 32));
55 result = 31 * result + (value != null ? value.hashCode() : 0);
56 return result;
57 }
58 }