1 7 package org.jboss.cache.optimistic; 8 9 20 public class DefaultDataVersion implements DataVersion 21 { 22 private static final long serialVersionUID = -6896315742831861046L; 23 27 public static final DataVersion ZERO = new DefaultDataVersion(0L); 28 29 32 private static final DataVersion ONE = new DefaultDataVersion(1L); 33 34 37 private static final DataVersion TWO = new DefaultDataVersion(2L); 38 39 private long version; 40 41 44 public DefaultDataVersion() 45 { 46 } 47 48 51 public DefaultDataVersion(long version) 52 { 53 this.version = version; 54 } 55 56 59 public DataVersion increment() 60 { 61 if (this == ZERO) 62 { 63 return ONE; 64 } 65 if (this == ONE) 66 { 67 return TWO; 68 } 69 return new DefaultDataVersion(version + 1); 70 } 71 72 public boolean newerThan(DataVersion other) 73 { 74 if (other instanceof DefaultDataVersion) 75 { 76 DefaultDataVersion dvOther = (DefaultDataVersion) other; 77 return version > dvOther.version; 78 } 79 return false; 80 } 81 82 public String toString() 83 { 84 return "Ver=" + version; 85 } 86 87 public boolean equals(Object other) 88 { 89 if (other instanceof DefaultDataVersion) 90 { 91 return version == ((DefaultDataVersion) other).version; 92 } 93 return false; 94 } 95 96 public int hashCode() 97 { 98 return (int) version; 99 } 100 101 public long getRawVersion() 102 { 103 return version; 104 } 105 } 106 | Popular Tags |