| 1 |
package org.apache.commons.jcs3.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 |
import java.util.Arrays; |
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
public class BlockDiskElementDescriptor<K> |
| 35 |
implements Serializable, Externalizable |
| 36 |
{ |
| 37 |
|
| 38 |
private static final long serialVersionUID = -1400659301208101411L; |
| 39 |
|
| 40 |
|
| 41 |
private K key; |
| 42 |
|
| 43 |
|
| 44 |
private int[] blocks; |
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
public BlockDiskElementDescriptor() |
| 50 |
{ |
| 51 |
super(); |
| 52 |
} |
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
public BlockDiskElementDescriptor(K key, int[] blocks) |
| 63 |
{ |
| 64 |
super(); |
| 65 |
this.key = key; |
| 66 |
this.blocks = blocks; |
| 67 |
} |
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
public void setKey( final K key ) |
| 73 |
{ |
| 74 |
this.key = key; |
| 75 |
} |
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
public K getKey() |
| 81 |
{ |
| 82 |
return key; |
| 83 |
} |
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
public void setBlocks( final int[] blocks ) |
| 89 |
{ |
| 90 |
this.blocks = blocks; |
| 91 |
} |
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
public int[] getBlocks() |
| 99 |
{ |
| 100 |
return blocks; |
| 101 |
} |
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
@Override |
| 109 |
public String toString() |
| 110 |
{ |
| 111 |
final StringBuilder buf = new StringBuilder(); |
| 112 |
buf.append( "\nBlockDiskElementDescriptor" ); |
| 113 |
buf.append( "\n key [" + this.getKey() + "]" ); |
| 114 |
buf.append( "\n blocks [" ); |
| 115 |
if ( this.getBlocks() != null ) |
| 116 |
{ |
| 117 |
Arrays.stream(this.getBlocks()).forEach(buf::append); |
| 118 |
} |
| 119 |
buf.append( "]" ); |
| 120 |
return buf.toString(); |
| 121 |
} |
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
@Override |
| 130 |
@SuppressWarnings("unchecked") |
| 131 |
public void readExternal( final ObjectInput input ) |
| 132 |
throws IOException, ClassNotFoundException |
| 133 |
{ |
| 134 |
this.key = (K) input.readObject(); |
| 135 |
this.blocks = (int[]) input.readObject(); |
| 136 |
} |
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
|
| 144 |
@Override |
| 145 |
public void writeExternal( final ObjectOutput output ) |
| 146 |
throws IOException |
| 147 |
{ |
| 148 |
output.writeObject( this.key ); |
| 149 |
output.writeObject( this.blocks ); |
| 150 |
} |
| 151 |
} |