1 /***
2 *
3 * Copyright 2005 LogicBlaze, Inc. http://www.logicblaze.com
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 *
17 **/
18 /***
19 *
20 * Copyright 2005 LogicBlaze, Inc. http://www.logicblaze.com
21 *
22 * Licensed under the Apache License, Version 2.0 (the "License");
23 * you may not use this file except in compliance with the License.
24 * You may obtain a copy of the License at
25 *
26 * http://www.apache.org/licenses/LICENSE-2.0
27 *
28 * Unless required by applicable law or agreed to in writing, software
29 * distributed under the License is distributed on an "AS IS" BASIS,
30 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
31 * See the License for the specific language governing permissions and
32 * limitations under the License.
33 *
34 **/
35
36 package org.logicblaze.lingo.util;
37
38 import java.util.Map;
39
40 /***
41 * Represents an entry in a {@link TimeoutMap}
42 *
43 * @version $Revision$
44 */
45 public class TimeoutMapEntry implements Comparable, Map.Entry {
46 private Object key;
47 private Object value;
48 private long timeout;
49 private long expireTime;
50
51 public TimeoutMapEntry(Object id, Object handler, long timeout) {
52 this.key = id;
53 this.value = handler;
54 this.timeout = timeout;
55 }
56
57 public Object getKey() {
58 return key;
59 }
60
61 public long getExpireTime() {
62 return expireTime;
63 }
64
65 public void setExpireTime(long expireTime) {
66 this.expireTime = expireTime;
67 }
68
69 public Object getValue() {
70 return value;
71 }
72
73 public Object setValue(Object value) {
74 Object oldValue = value;
75 this.value = value;
76 return oldValue;
77 }
78
79 public long getTimeout() {
80 return timeout;
81 }
82
83 public void setTimeout(long timeout) {
84 this.timeout = timeout;
85 }
86
87 public int compareTo(Object that) {
88 if (this == that) {
89 return 0;
90 }
91 if (that instanceof TimeoutMapEntry) {
92 return compareTo((TimeoutMapEntry) that);
93 }
94 return 1;
95 }
96
97 public int compareTo(TimeoutMapEntry that) {
98 long diff = this.expireTime - that.expireTime;
99 if (diff > 0) {
100 return 1;
101 }
102 else if (diff < 0) {
103 return -1;
104 }
105 return this.key.hashCode() - that.key.hashCode();
106 }
107
108 public String toString() {
109 return "Entry for key: " + key;
110 }
111 }