1 package org.apache.jcs.auxiliary.disk.indexed;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.io.Serializable;
23
24 /***
25 * Disk objects are located by descriptor entries. These are saved on shutdown and loaded into
26 * memory on startup.
27 */
28 public class IndexedDiskElementDescriptor
29 implements Serializable, Comparable
30 {
31 private static final long serialVersionUID = -3029163572847659450L;
32
33 /*** Position of the cache data entry on disk. */
34 long pos;
35
36 /*** Number of bytes the serialized form of the cache data takes. */
37 public int len;
38
39 /***
40 * Set the offset (i.e. position, and the size of the element)
41 * <p>
42 * @param pos
43 * @param data
44 */
45 public void init( long pos, byte[] data )
46 {
47 this.pos = pos;
48 this.len = data.length;
49 }
50
51 /*** Constructor for the DiskElementDescriptor object */
52 public IndexedDiskElementDescriptor()
53 {
54 super();
55 }
56
57 /***
58 * Constructs a usable disk element descriptor.
59 * <p>
60 * @param pos
61 * @param len
62 */
63 public IndexedDiskElementDescriptor( long pos, int len )
64 {
65 this.pos = pos;
66 this.len = len;
67 }
68
69 public String toString()
70 {
71 StringBuffer buf = new StringBuffer();
72 buf.append( "[DED: " );
73 buf.append( " pos = " + pos );
74 buf.append( " len = " + len );
75 buf.append( "]" );
76 return buf.toString();
77 }
78
79 /***
80 * Compares based on length.
81 * <p>
82 * @param o Object
83 * @return int
84 */
85 public int compareTo( Object o )
86 {
87 if ( o == null )
88 {
89 return 1;
90 }
91
92 int oLen = ( (IndexedDiskElementDescriptor) o ).len;
93 if ( oLen == len )
94 {
95 return 0;
96 }
97 else if ( oLen > len )
98 {
99 return -1;
100 }
101 else if ( oLen < len )
102 {
103 return 1;
104 }
105 return 0;
106 }
107 }