Fix OPOIFS generics warnings

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1688920 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Nick Burch 2015-07-02 22:36:45 +00:00
parent 605b16c061
commit 305d31a998
6 changed files with 36 additions and 47 deletions

View File

@ -209,7 +209,7 @@ public final class OPOIFSDocument implements BATManaged, BlockWritable, POIFSVie
/** /**
* @return array of SmallDocumentBlocks; may be empty, cannot be null * @return array of SmallDocumentBlocks; may be empty, cannot be null
*/ */
public BlockWritable[] getSmallBlocks() { public SmallDocumentBlock[] getSmallBlocks() {
return _small_store.getBlocks(); return _small_store.getBlocks();
} }

View File

@ -73,7 +73,7 @@ public class OPOIFSFileSystem
} }
private PropertyTable _property_table; private PropertyTable _property_table;
private List<POIFSViewable> _documents; private List<OPOIFSDocument> _documents;
private DirectoryNode _root; private DirectoryNode _root;
/** /**
@ -90,7 +90,7 @@ public class OPOIFSFileSystem
{ {
HeaderBlock header_block = new HeaderBlock(bigBlockSize); HeaderBlock header_block = new HeaderBlock(bigBlockSize);
_property_table = new PropertyTable(header_block); _property_table = new PropertyTable(header_block);
_documents = new ArrayList<POIFSViewable>(); _documents = new ArrayList<OPOIFSDocument>();
_root = null; _root = null;
} }

View File

@ -40,7 +40,7 @@ public class SmallBlockTableWriter
implements BlockWritable, BATManaged implements BlockWritable, BATManaged
{ {
private BlockAllocationTableWriter _sbat; private BlockAllocationTableWriter _sbat;
private List _small_blocks; private List<SmallDocumentBlock> _small_blocks;
private int _big_block_count; private int _big_block_count;
private RootProperty _root; private RootProperty _root;
@ -50,20 +50,17 @@ public class SmallBlockTableWriter
* @param documents a List of POIFSDocument instances * @param documents a List of POIFSDocument instances
* @param root the Filesystem's root property * @param root the Filesystem's root property
*/ */
public SmallBlockTableWriter(final POIFSBigBlockSize bigBlockSize, public SmallBlockTableWriter(final POIFSBigBlockSize bigBlockSize,
final List documents, final List<OPOIFSDocument> documents,
final RootProperty root) final RootProperty root)
{ {
_sbat = new BlockAllocationTableWriter(bigBlockSize); _sbat = new BlockAllocationTableWriter(bigBlockSize);
_small_blocks = new ArrayList(); _small_blocks = new ArrayList<SmallDocumentBlock>();
_root = root; _root = root;
Iterator iter = documents.iterator();
while (iter.hasNext()) for (OPOIFSDocument doc : documents)
{ {
OPOIFSDocument doc = ( OPOIFSDocument ) iter.next(); SmallDocumentBlock[] blocks = doc.getSmallBlocks();
BlockWritable[] blocks = doc.getSmallBlocks();
if (blocks.length != 0) if (blocks.length != 0)
{ {
@ -143,11 +140,8 @@ public class SmallBlockTableWriter
public void writeBlocks(final OutputStream stream) public void writeBlocks(final OutputStream stream)
throws IOException throws IOException
{ {
Iterator iter = _small_blocks.iterator(); for (BlockWritable block : _small_blocks) {
block.writeBlocks(stream);
while (iter.hasNext())
{
(( BlockWritable ) iter.next()).writeBlocks(stream);
} }
} }

View File

@ -29,8 +29,6 @@ import org.apache.poi.poifs.common.POIFSBigBlockSize;
/** /**
* Storage for documents that are too small to use regular * Storage for documents that are too small to use regular
* DocumentBlocks for their data * DocumentBlocks for their data
*
* @author Marc Johnson (mjohnson at apache dot org)
*/ */
public final class SmallDocumentBlock implements BlockWritable, ListManagedBlock { public final class SmallDocumentBlock implements BlockWritable, ListManagedBlock {
private static final int BLOCK_SHIFT = 6; private static final int BLOCK_SHIFT = 6;
@ -49,7 +47,7 @@ public final class SmallDocumentBlock implements BlockWritable, ListManagedBlock
System.arraycopy(data, index * _block_size, _data, 0, _block_size); System.arraycopy(data, index * _block_size, _data, 0, _block_size);
} }
private SmallDocumentBlock(final POIFSBigBlockSize bigBlockSize) protected SmallDocumentBlock(final POIFSBigBlockSize bigBlockSize)
{ {
_bigBlockSize = bigBlockSize; _bigBlockSize = bigBlockSize;
_blocks_per_big_block = getBlocksPerBigBlock(bigBlockSize); _blocks_per_big_block = getBlocksPerBigBlock(bigBlockSize);
@ -110,7 +108,7 @@ public final class SmallDocumentBlock implements BlockWritable, ListManagedBlock
* *
* @return number of big blocks the list encompasses * @return number of big blocks the list encompasses
*/ */
public static int fill(POIFSBigBlockSize bigBlockSize, List blocks) public static int fill(POIFSBigBlockSize bigBlockSize, List<SmallDocumentBlock> blocks)
{ {
int _blocks_per_big_block = getBlocksPerBigBlock(bigBlockSize); int _blocks_per_big_block = getBlocksPerBigBlock(bigBlockSize);
@ -168,12 +166,12 @@ public final class SmallDocumentBlock implements BlockWritable, ListManagedBlock
* *
* @return a List of SmallDocumentBlock's extracted from the input * @return a List of SmallDocumentBlock's extracted from the input
*/ */
public static List extract(POIFSBigBlockSize bigBlockSize, ListManagedBlock [] blocks) public static List<SmallDocumentBlock> extract(POIFSBigBlockSize bigBlockSize, ListManagedBlock [] blocks)
throws IOException throws IOException
{ {
int _blocks_per_big_block = getBlocksPerBigBlock(bigBlockSize); int _blocks_per_big_block = getBlocksPerBigBlock(bigBlockSize);
List sdbs = new ArrayList(); List<SmallDocumentBlock> sdbs = new ArrayList<SmallDocumentBlock>();
for (int j = 0; j < blocks.length; j++) for (int j = 0; j < blocks.length; j++)
{ {
@ -205,6 +203,11 @@ public final class SmallDocumentBlock implements BlockWritable, ListManagedBlock
return size * _block_size; return size * _block_size;
} }
protected int getSmallBlocksPerBigBlock()
{
return _blocks_per_big_block;
}
private static SmallDocumentBlock makeEmptySmallDocumentBlock(POIFSBigBlockSize bigBlockSize) private static SmallDocumentBlock makeEmptySmallDocumentBlock(POIFSBigBlockSize bigBlockSize)
{ {
SmallDocumentBlock block = new SmallDocumentBlock(bigBlockSize); SmallDocumentBlock block = new SmallDocumentBlock(bigBlockSize);

View File

@ -23,24 +23,19 @@ import java.util.*;
/** /**
* A list of SmallDocumentBlocks instances, and methods to manage the list * A list of SmallDocumentBlocks instances, and methods to manage the list
*
* @author Marc Johnson (mjohnson at apache dot org)
*/ */
public class SmallDocumentBlockList public class SmallDocumentBlockList
extends BlockListImpl extends BlockListImpl
{ {
/** /**
* Constructor SmallDocumentBlockList * Constructor SmallDocumentBlockList
* *
* @param blocks a list of SmallDocumentBlock instances * @param blocks a list of SmallDocumentBlock instances
*/ */
public SmallDocumentBlockList(final List blocks) public SmallDocumentBlockList(final List<SmallDocumentBlock> blocks)
{ {
setBlocks(( SmallDocumentBlock [] ) blocks setBlocks(blocks.toArray(new SmallDocumentBlock[blocks.size()]));
.toArray(new SmallDocumentBlock[ blocks.size() ])); }
} }
} // end public class SmallDocumentBlockList

View File

@ -21,13 +21,12 @@ import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Iterator;
import java.util.List; import java.util.List;
import org.apache.poi.poifs.common.POIFSConstants;
import junit.framework.TestCase; import junit.framework.TestCase;
import org.apache.poi.poifs.common.POIFSConstants;
/** /**
* Class to test SmallDocumentBlock functionality * Class to test SmallDocumentBlock functionality
* *
@ -53,7 +52,7 @@ public final class TestSmallDocumentBlock extends TestCase {
throws IOException throws IOException
{ {
ByteArrayInputStream stream = new ByteArrayInputStream(_testdata); ByteArrayInputStream stream = new ByteArrayInputStream(_testdata);
List documents = new ArrayList(); List<DocumentBlock> documents = new ArrayList<DocumentBlock>();
while (true) while (true)
{ {
@ -66,9 +65,8 @@ public final class TestSmallDocumentBlock extends TestCase {
} }
} }
SmallDocumentBlock[] results = SmallDocumentBlock[] results =
SmallDocumentBlock SmallDocumentBlock.convert(POIFSConstants.SMALLER_BIG_BLOCK_SIZE_DETAILS,
.convert(POIFSConstants.SMALLER_BIG_BLOCK_SIZE_DETAILS,( BlockWritable [] ) documents documents.toArray(new DocumentBlock[ 0 ]), _testdata_size);
.toArray(new DocumentBlock[ 0 ]), _testdata_size);
assertEquals("checking correct result size: ", assertEquals("checking correct result size: ",
(_testdata_size + 63) / 64, results.length); (_testdata_size + 63) / 64, results.length);
@ -142,20 +140,20 @@ public final class TestSmallDocumentBlock extends TestCase {
{ {
for (int j = 0; j <= 8; j++) for (int j = 0; j <= 8; j++)
{ {
List<Object> foo = new ArrayList<Object>(); List<SmallDocumentBlock> blocks = new ArrayList<SmallDocumentBlock>();
for (int k = 0; k < j; k++) for (int k = 0; k < j; k++)
{ {
foo.add(new Object()); blocks.add(new SmallDocumentBlock(POIFSConstants.SMALLER_BIG_BLOCK_SIZE_DETAILS));
} }
int result = SmallDocumentBlock.fill(POIFSConstants.SMALLER_BIG_BLOCK_SIZE_DETAILS,foo); int result = SmallDocumentBlock.fill(POIFSConstants.SMALLER_BIG_BLOCK_SIZE_DETAILS, blocks);
assertEquals("correct big block count: ", (j + 7) / 8, result); assertEquals("correct big block count: ", (j + 7) / 8, result);
assertEquals("correct small block count: ", 8 * result, assertEquals("correct small block count: ", 8 * result,
foo.size()); blocks.size());
for (int m = j; m < foo.size(); m++) for (int m = j; m < blocks.size(); m++)
{ {
BlockWritable block = ( BlockWritable ) foo.get(m); BlockWritable block = blocks.get(m);
ByteArrayOutputStream stream = new ByteArrayOutputStream(); ByteArrayOutputStream stream = new ByteArrayOutputStream();
block.writeBlocks(stream); block.writeBlocks(stream);
@ -208,13 +206,12 @@ public final class TestSmallDocumentBlock extends TestCase {
{ {
new RawDataBlock(new ByteArrayInputStream(data)) new RawDataBlock(new ByteArrayInputStream(data))
}; };
List output = SmallDocumentBlock.extract(POIFSConstants.SMALLER_BIG_BLOCK_SIZE_DETAILS,blocks); List<SmallDocumentBlock> output = SmallDocumentBlock.extract(POIFSConstants.SMALLER_BIG_BLOCK_SIZE_DETAILS,blocks);
Iterator iter = output.iterator();
offset = 0; offset = 0;
while (iter.hasNext()) for (SmallDocumentBlock block : output)
{ {
byte[] out_data = (( SmallDocumentBlock ) iter.next()).getData(); byte[] out_data = block.getData();
assertEquals("testing block at offset " + offset, 64, assertEquals("testing block at offset " + offset, 64,
out_data.length); out_data.length);