1 package org.apache.commons.jcs.auxiliary.disk.block;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.io.Externalizable;
23 import java.io.IOException;
24 import java.io.ObjectInput;
25 import java.io.ObjectOutput;
26 import java.io.Serializable;
27
28
29
30
31
32
33
34
35 public class BlockDiskElementDescriptor<K>
36 implements Serializable, Externalizable
37 {
38
39 private static final long serialVersionUID = -1400659301208101411L;
40
41
42 private K key;
43
44
45 private int[] blocks;
46
47
48
49
50 public void setKey( K key )
51 {
52 this.key = key;
53 }
54
55
56
57
58 public K getKey()
59 {
60 return key;
61 }
62
63
64
65
66 public void setBlocks( int[] blocks )
67 {
68 this.blocks = blocks;
69 }
70
71
72
73
74
75
76 public int[] getBlocks()
77 {
78 return blocks;
79 }
80
81
82
83
84
85
86 @Override
87 public String toString()
88 {
89 StringBuilder buf = new StringBuilder();
90 buf.append( "\nBlockDiskElementDescriptor" );
91 buf.append( "\n key [" + this.getKey() + "]" );
92 buf.append( "\n blocks [" );
93 if ( this.getBlocks() != null )
94 {
95 for ( int i = 0; i < blocks.length; i++ )
96 {
97 buf.append( this.getBlocks()[i] );
98 }
99 }
100 buf.append( "]" );
101 return buf.toString();
102 }
103
104
105
106
107
108
109
110 @Override
111 @SuppressWarnings("unchecked")
112 public void readExternal( ObjectInput input )
113 throws IOException, ClassNotFoundException
114 {
115 this.key = (K) input.readObject();
116 this.blocks = (int[]) input.readObject();
117 }
118
119
120
121
122
123
124
125 @Override
126 public void writeExternal( ObjectOutput output )
127 throws IOException
128 {
129 output.writeObject( this.key );
130 output.writeObject( this.blocks );
131 }
132 }