File D:\maven-qcr-plugin-testsunitaires\qcr4java\h2-1.3.170-sources\target\site\qc\lecode\util\CacheObject.java.html

1 /*
2 * Copyright 2004-2011 H2 Group. Multiple-Licensed under the H2 License,
3 * Version 1.0, and under the Eclipse Public License, Version 1.0
4 * (http://h2database.com/html/license.html).
5 * Initial Developer: H2 Group
6 */
7 package org.h2.util;
8
9 import org.h2.constant.SysProperties;
10 import org.h2.message.DbException;
11
12 /**
13 * The base object for all cached objects.
14 */
15 public abstract class CacheObject implements Comparable<CacheObject> {
16
17 /**
18 * The previous element in the LRU linked list. If the previous element is
19 * the head, then this element is the most recently used object.
20 */
21 public CacheObject cachePrevious;
22
23 /**
24 * The next element in the LRU linked list. If the next element is the head,
25 * then this element is the least recently used object.
26 */
27 public CacheObject cacheNext;
28
29 /**
30 * The next element in the hash chain.
31 */
32 public CacheObject cacheChained;
33
34 private int pos;
35 private boolean changed;
36
37 /**
38 * Check if the object can be removed from the cache.
39 * For example pinned objects can not be removed.
40 *
41 * @return true if it can be removed
42 */
43 public abstract boolean canRemove();
44
45 /**
46 * Get the estimated used memory.
47 *
48 * @return number of words (one word is 4 bytes)
49 */
50 public abstract int getMemory();
51
52 public void setPos(int pos) {
53 if (SysProperties.CHECK) {
54 if (cachePrevious != null || cacheNext != null || cacheChained != null) {
55 DbException.throwInternalError("setPos too late");
56 }
57 }
58 this.pos = pos;
59 }
60
61 public int getPos() {
62 return pos;
63 }
64
65 /**
66 * Check if this cache object has been changed and thus needs to be written
67 * back to the storage.
68 *
69 * @return if it has been changed
70 */
71 public boolean isChanged() {
72 return changed;
73 }
74
75 public void setChanged(boolean b) {
76 changed = b;
77 }
78
79 public int compareTo(CacheObject other) {
80 return MathUtils.compareInt(getPos(), other.getPos());
81 }
82
83 public boolean isStream() {
84 return false;
85 }
86
87 }
88