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
*/
public BlockWritable[] getSmallBlocks() {
public SmallDocumentBlock[] getSmallBlocks() {
return _small_store.getBlocks();
}

View File

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

View File

@ -40,7 +40,7 @@ public class SmallBlockTableWriter
implements BlockWritable, BATManaged
{
private BlockAllocationTableWriter _sbat;
private List _small_blocks;
private List<SmallDocumentBlock> _small_blocks;
private int _big_block_count;
private RootProperty _root;
@ -50,20 +50,17 @@ public class SmallBlockTableWriter
* @param documents a List of POIFSDocument instances
* @param root the Filesystem's root property
*/
public SmallBlockTableWriter(final POIFSBigBlockSize bigBlockSize,
final List documents,
final List<OPOIFSDocument> documents,
final RootProperty root)
{
_sbat = new BlockAllocationTableWriter(bigBlockSize);
_small_blocks = new ArrayList();
_small_blocks = new ArrayList<SmallDocumentBlock>();
_root = root;
Iterator iter = documents.iterator();
while (iter.hasNext())
for (OPOIFSDocument doc : documents)
{
OPOIFSDocument doc = ( OPOIFSDocument ) iter.next();
BlockWritable[] blocks = doc.getSmallBlocks();
SmallDocumentBlock[] blocks = doc.getSmallBlocks();
if (blocks.length != 0)
{
@ -143,11 +140,8 @@ public class SmallBlockTableWriter
public void writeBlocks(final OutputStream stream)
throws IOException
{
Iterator iter = _small_blocks.iterator();
while (iter.hasNext())
{
(( BlockWritable ) iter.next()).writeBlocks(stream);
for (BlockWritable block : _small_blocks) {
block.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
* DocumentBlocks for their data
*
* @author Marc Johnson (mjohnson at apache dot org)
*/
public final class SmallDocumentBlock implements BlockWritable, ListManagedBlock {
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);
}
private SmallDocumentBlock(final POIFSBigBlockSize bigBlockSize)
protected SmallDocumentBlock(final POIFSBigBlockSize bigBlockSize)
{
_bigBlockSize = 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
*/
public static int fill(POIFSBigBlockSize bigBlockSize, List blocks)
public static int fill(POIFSBigBlockSize bigBlockSize, List<SmallDocumentBlock> blocks)
{
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
*/
public static List extract(POIFSBigBlockSize bigBlockSize, ListManagedBlock [] blocks)
public static List<SmallDocumentBlock> extract(POIFSBigBlockSize bigBlockSize, ListManagedBlock [] blocks)
throws IOException
{
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++)
{
@ -204,6 +202,11 @@ public final class SmallDocumentBlock implements BlockWritable, ListManagedBlock
{
return size * _block_size;
}
protected int getSmallBlocksPerBigBlock()
{
return _blocks_per_big_block;
}
private static SmallDocumentBlock makeEmptySmallDocumentBlock(POIFSBigBlockSize bigBlockSize)
{

View File

@ -23,24 +23,19 @@ import java.util.*;
/**
* A list of SmallDocumentBlocks instances, and methods to manage the list
*
* @author Marc Johnson (mjohnson at apache dot org)
*/
public class SmallDocumentBlockList
extends BlockListImpl
{
/**
* Constructor SmallDocumentBlockList
*
* @param blocks a list of SmallDocumentBlock instances
*/
public SmallDocumentBlockList(final List blocks)
public SmallDocumentBlockList(final List<SmallDocumentBlock> blocks)
{
setBlocks(( SmallDocumentBlock [] ) blocks
.toArray(new SmallDocumentBlock[ blocks.size() ]));
setBlocks(blocks.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.IOException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.apache.poi.poifs.common.POIFSConstants;
import junit.framework.TestCase;
import org.apache.poi.poifs.common.POIFSConstants;
/**
* Class to test SmallDocumentBlock functionality
*
@ -53,7 +52,7 @@ public final class TestSmallDocumentBlock extends TestCase {
throws IOException
{
ByteArrayInputStream stream = new ByteArrayInputStream(_testdata);
List documents = new ArrayList();
List<DocumentBlock> documents = new ArrayList<DocumentBlock>();
while (true)
{
@ -66,9 +65,8 @@ public final class TestSmallDocumentBlock extends TestCase {
}
}
SmallDocumentBlock[] results =
SmallDocumentBlock
.convert(POIFSConstants.SMALLER_BIG_BLOCK_SIZE_DETAILS,( BlockWritable [] ) documents
.toArray(new DocumentBlock[ 0 ]), _testdata_size);
SmallDocumentBlock.convert(POIFSConstants.SMALLER_BIG_BLOCK_SIZE_DETAILS,
documents.toArray(new DocumentBlock[ 0 ]), _testdata_size);
assertEquals("checking correct result size: ",
(_testdata_size + 63) / 64, results.length);
@ -142,20 +140,20 @@ public final class TestSmallDocumentBlock extends TestCase {
{
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++)
{
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 small block count: ", 8 * result,
foo.size());
for (int m = j; m < foo.size(); m++)
blocks.size());
for (int m = j; m < blocks.size(); m++)
{
BlockWritable block = ( BlockWritable ) foo.get(m);
BlockWritable block = blocks.get(m);
ByteArrayOutputStream stream = new ByteArrayOutputStream();
block.writeBlocks(stream);
@ -208,13 +206,12 @@ public final class TestSmallDocumentBlock extends TestCase {
{
new RawDataBlock(new ByteArrayInputStream(data))
};
List output = SmallDocumentBlock.extract(POIFSConstants.SMALLER_BIG_BLOCK_SIZE_DETAILS,blocks);
Iterator iter = output.iterator();
List<SmallDocumentBlock> output = SmallDocumentBlock.extract(POIFSConstants.SMALLER_BIG_BLOCK_SIZE_DETAILS,blocks);
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,
out_data.length);