1 23 package info.monitorenter.util; 24 25 import java.util.Map ; 26 27 38 public final class TimeStampedValue implements Map.Entry , Comparable { 39 43 private long m_key; 44 45 46 private Object m_value; 47 48 60 public TimeStampedValue(final long key, final Object value) { 61 this.m_key = key; 62 this.m_value = value; 63 } 64 65 75 public TimeStampedValue(final Object value) { 76 this(System.currentTimeMillis(), value); 77 } 78 79 89 public Object getKey() { 90 return new Long (this.m_key); 91 } 92 93 101 public Object getValue() { 102 return this.m_value; 103 } 104 105 114 public long getTime() { 115 return this.m_key; 116 } 117 118 128 public boolean equals(final Object o) { 129 if (o == null) { 130 return false; 131 } 132 TimeStampedValue compare = null; 133 try { 134 compare = (TimeStampedValue) o; 135 } catch (ClassCastException e) { 136 return false; 137 } 138 if (this.getTime() == compare.getTime()) { 139 return true; 140 } 141 return false; 142 } 143 144 148 public int hashCode() { 149 int result = (int) this.m_key; 150 if (this.m_key > Integer.MAX_VALUE) { 151 result = -result; 152 } 153 return result; 154 155 } 156 157 168 public Object setValue(final Object value) { 169 Object ret = this.m_value; 170 this.m_value = value; 171 return ret; 172 } 173 174 181 public int compareTo(final java.lang.Object obj) { 182 TimeStampedValue other = (TimeStampedValue) obj; 183 if (this.m_key < other.m_key) { 184 return -1; 185 } 186 if (this.m_key == other.m_key) { 187 return 0; 188 } 189 return 1; 190 } 191 192 205 public boolean isPast() { 206 return this.m_key < System.currentTimeMillis(); 207 } 208 } 209 | Popular Tags |