| %line | %branch | |||||||||
|---|---|---|---|---|---|---|---|---|---|---|
| org.apache.jcs.auxiliary.disk.block.BlockDiskElementDescriptor |
|
|
| 1 | package org.apache.jcs.auxiliary.disk.block; |
|
| 2 | ||
| 3 | /* |
|
| 4 | * Licensed to the Apache Software Foundation (ASF) under one |
|
| 5 | * or more contributor license agreements. See the NOTICE file |
|
| 6 | * distributed with this work for additional information |
|
| 7 | * regarding copyright ownership. The ASF licenses this file |
|
| 8 | * to you under the Apache License, Version 2.0 (the |
|
| 9 | * "License"); you may not use this file except in compliance |
|
| 10 | * with the License. You may obtain a copy of the License at |
|
| 11 | * |
|
| 12 | * http://www.apache.org/licenses/LICENSE-2.0 |
|
| 13 | * |
|
| 14 | * Unless required by applicable law or agreed to in writing, |
|
| 15 | * software distributed under the License is distributed on an |
|
| 16 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
|
| 17 | * KIND, either express or implied. See the License for the |
|
| 18 | * specific language governing permissions and limitations |
|
| 19 | * under the License. |
|
| 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 | * This represents an element on disk. This is used when we persist the keys. We only store the |
|
| 30 | * block addresses in memory. We don't need the length here, since all the blocks are the same size |
|
| 31 | * receyle bin. |
|
| 32 | * <p> |
|
| 33 | * @author Aaron Smuts |
|
| 34 | */ |
|
| 35 | 55946 | public class BlockDiskElementDescriptor |
| 36 | implements Serializable, Externalizable |
|
| 37 | { |
|
| 38 | /** Don't change */ |
|
| 39 | private static final long serialVersionUID = -1400659301208101411L; |
|
| 40 | ||
| 41 | /** The key */ |
|
| 42 | private Serializable key; |
|
| 43 | ||
| 44 | /** The array of block numbers */ |
|
| 45 | private int[] blocks; |
|
| 46 | ||
| 47 | /** |
|
| 48 | * @param key The key to set. |
|
| 49 | */ |
|
| 50 | public void setKey( Serializable key ) |
|
| 51 | { |
|
| 52 | 22302 | this.key = key; |
| 53 | 22309 | } |
| 54 | ||
| 55 | /** |
|
| 56 | * @return Returns the key. |
|
| 57 | */ |
|
| 58 | public Serializable getKey() |
|
| 59 | { |
|
| 60 | 33649 | return key; |
| 61 | } |
|
| 62 | ||
| 63 | /** |
|
| 64 | * @param blocks The blocks to set. |
|
| 65 | */ |
|
| 66 | public void setBlocks( int[] blocks ) |
|
| 67 | { |
|
| 68 | 22321 | this.blocks = blocks; |
| 69 | 22327 | } |
| 70 | ||
| 71 | /** |
|
| 72 | * This holds the block numbers. An item my be dispersed between multiple blocks. |
|
| 73 | * <p> |
|
| 74 | * @return Returns the blocks. |
|
| 75 | */ |
|
| 76 | public int[] getBlocks() |
|
| 77 | { |
|
| 78 | 33649 | return blocks; |
| 79 | } |
|
| 80 | ||
| 81 | /** |
|
| 82 | * For debugging. |
|
| 83 | * <p> |
|
| 84 | * @return Info on the descriptor. |
|
| 85 | */ |
|
| 86 | public String toString() |
|
| 87 | { |
|
| 88 | 0 | StringBuffer buf = new StringBuffer(); |
| 89 | 0 | buf.append( "\nBlockDiskElementDescriptor" ); |
| 90 | 0 | buf.append( "\n key [" + this.getKey() + "]" ); |
| 91 | 0 | buf.append( "\n blocks [" ); |
| 92 | 0 | if ( this.getBlocks() != null ) |
| 93 | { |
|
| 94 | 0 | for ( int i = 0; i < blocks.length; i++ ) |
| 95 | { |
|
| 96 | 0 | buf.append( this.getBlocks()[i] ); |
| 97 | } |
|
| 98 | } |
|
| 99 | 0 | buf.append( "]" ); |
| 100 | 0 | return buf.toString(); |
| 101 | } |
|
| 102 | ||
| 103 | /** |
|
| 104 | * Saves on reflection. |
|
| 105 | * <p> |
|
| 106 | * (non-Javadoc) |
|
| 107 | * @see java.io.Externalizable#readExternal(java.io.ObjectInput) |
|
| 108 | */ |
|
| 109 | public void readExternal( ObjectInput input ) |
|
| 110 | throws IOException, ClassNotFoundException |
|
| 111 | { |
|
| 112 | 33649 | this.key = (Serializable) input.readObject(); |
| 113 | 33649 | this.blocks = (int[]) input.readObject(); |
| 114 | 33649 | } |
| 115 | ||
| 116 | /** |
|
| 117 | * Saves on reflection. |
|
| 118 | * <p> |
|
| 119 | * (non-Javadoc) |
|
| 120 | * @see java.io.Externalizable#writeExternal(java.io.ObjectOutput) |
|
| 121 | */ |
|
| 122 | public void writeExternal( ObjectOutput output ) |
|
| 123 | throws IOException |
|
| 124 | { |
|
| 125 | 22366 | output.writeObject( this.key ); |
| 126 | 22371 | output.writeObject( this.blocks ); |
| 127 | 22377 | } |
| 128 | } |
| This report is generated by jcoverage, Maven and Maven JCoverage Plugin. |