File: AgedNode.java

package info (click to toggle)
libglazedlists-java 1.9.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 3,024 kB
  • ctags: 4,252
  • sloc: java: 22,561; xml: 818; sh: 51; makefile: 5
file content (74 lines) | stat: -rw-r--r-- 2,049 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/* Glazed Lists                                                 (c) 2003-2006 */
/* http://publicobject.com/glazedlists/                      publicobject.com,*/
/*                                                     O'Dell Engineering Ltd.*/
package ca.odell.glazedlists.impl.adt;

/**
 * A thin wrapper class for Objects to be inserted in the
 * age sorted tree representation of the cache.
 *
 * @author <a href="mailto:kevin@swank.ca">Kevin Maltby</a>
 */
public final class AgedNode {

    /** provide times of nodes relative to one-another */
    private static long nextTimestamp = 0;

    /** The corresponding node in the index tree */
    private SparseListNode indexNode = null;
    /** The timestamp corresponding to the last access of this node */
    private long timestamp = 0;
    /** The value to this node */
    private Object value = null;

    /**
     * Creates a new AgedNode object to store in the age sorted tree
     *
     * @param indexNode The related node in the indexing tree
     * @param value The value to assign to this node
     */
    public AgedNode(SparseListNode indexNode, Object value) {
        this.indexNode = indexNode;
        this.value =  value;
        timestamp = nextTimestamp();
    }

    private static synchronized final long nextTimestamp() {
        return nextTimestamp++;
    }

    /**
     * Retrieves the value of this node.
     *
     * This is an access, and as such, this node must be re-ordered
     *
     * @return The value of this node
     */
    public Object getValue() {
        timestamp = nextTimestamp();
        return value;
    }

    /**
     * Retrieves the index node for this node.
     *
     * @return The index node
     */
    public SparseListNode getIndexNode() {
        return indexNode;
    }

    /**
     * Retrieves the age of this node.
     *
     * @return The age of this node
     */
    public long getTimestamp() {
        return timestamp;
    }

    @Override
    public String toString() {
        return "[AgedNode: " + value + "]";
    }
}