Tidy up some of the IntMapper/UnicodeString bits with generics
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@900376 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
6605995ac6
commit
0111e33db5
@ -31,9 +31,9 @@ import org.apache.poi.util.IntMapper;
|
||||
class SSTDeserializer
|
||||
{
|
||||
|
||||
private IntMapper strings;
|
||||
private IntMapper<UnicodeString> strings;
|
||||
|
||||
public SSTDeserializer( IntMapper strings )
|
||||
public SSTDeserializer( IntMapper<UnicodeString> strings )
|
||||
{
|
||||
this.strings = strings;
|
||||
}
|
||||
@ -46,14 +46,14 @@ class SSTDeserializer
|
||||
public void manufactureStrings( int stringCount, RecordInputStream in )
|
||||
{
|
||||
for (int i=0;i<stringCount;i++) {
|
||||
//Extract exactly the count of strings from the SST record.
|
||||
// Extract exactly the count of strings from the SST record.
|
||||
UnicodeString str = new UnicodeString(in);
|
||||
addToStringTable( strings, str );
|
||||
}
|
||||
}
|
||||
|
||||
static public void addToStringTable( IntMapper strings, UnicodeString string )
|
||||
static public void addToStringTable( IntMapper<UnicodeString> strings, UnicodeString string )
|
||||
{
|
||||
strings.add(string );
|
||||
}
|
||||
strings.add(string);
|
||||
}
|
||||
}
|
||||
|
@ -60,7 +60,7 @@ public final class SSTRecord extends ContinuableRecord {
|
||||
|
||||
/** according to docs ONLY SST */
|
||||
private int field_2_num_unique_strings;
|
||||
private IntMapper field_3_strings;
|
||||
private IntMapper<UnicodeString> field_3_strings;
|
||||
|
||||
private SSTDeserializer deserializer;
|
||||
|
||||
@ -73,7 +73,7 @@ public final class SSTRecord extends ContinuableRecord {
|
||||
{
|
||||
field_1_num_strings = 0;
|
||||
field_2_num_unique_strings = 0;
|
||||
field_3_strings = new IntMapper();
|
||||
field_3_strings = new IntMapper<UnicodeString>();
|
||||
deserializer = new SSTDeserializer(field_3_strings);
|
||||
}
|
||||
|
||||
@ -130,7 +130,7 @@ public final class SSTRecord extends ContinuableRecord {
|
||||
*/
|
||||
public UnicodeString getString(int id )
|
||||
{
|
||||
return (UnicodeString) field_3_strings.get( id );
|
||||
return field_3_strings.get( id );
|
||||
}
|
||||
|
||||
|
||||
@ -149,7 +149,7 @@ public final class SSTRecord extends ContinuableRecord {
|
||||
.append( Integer.toHexString( getNumUniqueStrings() ) ).append( "\n" );
|
||||
for ( int k = 0; k < field_3_strings.size(); k++ )
|
||||
{
|
||||
UnicodeString s = (UnicodeString)field_3_strings.get( k );
|
||||
UnicodeString s = field_3_strings.get( k );
|
||||
buffer.append( " .string_" + k + " = " )
|
||||
.append( s.getDebugInfo() ).append( "\n" );
|
||||
}
|
||||
@ -245,7 +245,7 @@ public final class SSTRecord extends ContinuableRecord {
|
||||
// we initialize our fields
|
||||
field_1_num_strings = in.readInt();
|
||||
field_2_num_unique_strings = in.readInt();
|
||||
field_3_strings = new IntMapper();
|
||||
field_3_strings = new IntMapper<UnicodeString>();
|
||||
deserializer = new SSTDeserializer(field_3_strings);
|
||||
deserializer.manufactureStrings( field_2_num_unique_strings, in );
|
||||
}
|
||||
@ -255,7 +255,7 @@ public final class SSTRecord extends ContinuableRecord {
|
||||
* @return an iterator of the strings we hold. All instances are
|
||||
* UnicodeStrings
|
||||
*/
|
||||
Iterator getStrings()
|
||||
Iterator<UnicodeString> getStrings()
|
||||
{
|
||||
return field_3_strings.iterator();
|
||||
}
|
||||
|
@ -32,7 +32,7 @@ final class SSTSerializer {
|
||||
private final int _numStrings;
|
||||
private final int _numUniqueStrings;
|
||||
|
||||
private final IntMapper strings;
|
||||
private final IntMapper<UnicodeString> strings;
|
||||
|
||||
/** Offsets from the beginning of the SST record (even across continuations) */
|
||||
private final int[] bucketAbsoluteOffsets;
|
||||
@ -40,7 +40,7 @@ final class SSTSerializer {
|
||||
private final int[] bucketRelativeOffsets;
|
||||
int startOfSST, startOfRecord;
|
||||
|
||||
public SSTSerializer( IntMapper strings, int numStrings, int numUniqueStrings )
|
||||
public SSTSerializer( IntMapper<UnicodeString> strings, int numStrings, int numUniqueStrings )
|
||||
{
|
||||
this.strings = strings;
|
||||
_numStrings = numStrings;
|
||||
@ -78,9 +78,9 @@ final class SSTSerializer {
|
||||
return getUnicodeString(strings, index);
|
||||
}
|
||||
|
||||
private static UnicodeString getUnicodeString( IntMapper strings, int index )
|
||||
private static UnicodeString getUnicodeString( IntMapper<UnicodeString> strings, int index )
|
||||
{
|
||||
return ( (UnicodeString) strings.get( index ) );
|
||||
return ( strings.get( index ) );
|
||||
}
|
||||
|
||||
public int[] getBucketAbsoluteOffsets()
|
||||
|
@ -34,10 +34,9 @@ import org.apache.poi.util.LittleEndianOutput;
|
||||
* Title: Unicode String<p/>
|
||||
* Description: Unicode String - just standard fields that are in several records.
|
||||
* It is considered more desirable then repeating it in all of them.<p/>
|
||||
* This is often called a XLUnicodeRichExtendedString in MS documentation.<p/>
|
||||
* REFERENCE: PG 264 Microsoft Excel 97 Developer's Kit (ISBN: 1-57231-498-2)<p/>
|
||||
* @author Andrew C. Oliver
|
||||
* @author Marc Johnson (mjohnson at apache dot org)
|
||||
* @author Glen Stampoultzis (glens at apache.org)
|
||||
* REFERENCE: PG 951 Excel Binary File Format (.xls) Structure Specification v20091214
|
||||
*/
|
||||
public final class UnicodeString implements Comparable<UnicodeString> {
|
||||
private short field_1_charCount;
|
||||
@ -46,6 +45,7 @@ public final class UnicodeString implements Comparable<UnicodeString> {
|
||||
private List<FormatRun> field_4_format_runs;
|
||||
private byte[] field_5_ext_rst;
|
||||
private static final BitField highByte = BitFieldFactory.getInstance(0x1);
|
||||
// 0x2 is reserved
|
||||
private static final BitField extBit = BitFieldFactory.getInstance(0x4);
|
||||
private static final BitField richText = BitFieldFactory.getInstance(0x8);
|
||||
|
||||
|
@ -34,10 +34,10 @@ import java.util.*;
|
||||
* @author Jason Height
|
||||
*/
|
||||
|
||||
public class IntMapper
|
||||
public class IntMapper<T>
|
||||
{
|
||||
private List elements;
|
||||
private Map valueKeyMap;
|
||||
private List<T> elements;
|
||||
private Map<T,Integer> valueKeyMap;
|
||||
|
||||
private static final int _default_size = 10;
|
||||
|
||||
@ -52,8 +52,8 @@ public class IntMapper
|
||||
|
||||
public IntMapper(final int initialCapacity)
|
||||
{
|
||||
elements = new ArrayList(initialCapacity);
|
||||
valueKeyMap = new HashMap(initialCapacity);
|
||||
elements = new ArrayList<T>(initialCapacity);
|
||||
valueKeyMap = new HashMap<T,Integer>(initialCapacity);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -64,12 +64,11 @@ public class IntMapper
|
||||
* @return true (as per the general contract of the Collection.add
|
||||
* method).
|
||||
*/
|
||||
|
||||
public boolean add(final Object value)
|
||||
public boolean add(final T value)
|
||||
{
|
||||
int index = elements.size();
|
||||
elements.add(value);
|
||||
valueKeyMap.put(value, Integer.valueOf(index));
|
||||
valueKeyMap.put(value, index);
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -77,18 +76,18 @@ public class IntMapper
|
||||
return elements.size();
|
||||
}
|
||||
|
||||
public Object get(int index) {
|
||||
public T get(int index) {
|
||||
return elements.get(index);
|
||||
}
|
||||
|
||||
public int getIndex(Object o) {
|
||||
Integer i = ((Integer)valueKeyMap.get(o));
|
||||
public int getIndex(T o) {
|
||||
Integer i = valueKeyMap.get(o);
|
||||
if (i == null)
|
||||
return -1;
|
||||
return i.intValue();
|
||||
}
|
||||
|
||||
public Iterator iterator() {
|
||||
public Iterator<T> iterator() {
|
||||
return elements.iterator();
|
||||
}
|
||||
} // end public class IntMapper
|
||||
|
Loading…
Reference in New Issue
Block a user