class SSTDeserializer
{
- private IntMapper strings;
+ private IntMapper<UnicodeString> strings;
- public SSTDeserializer( IntMapper strings )
+ public SSTDeserializer( IntMapper<UnicodeString> strings )
{
this.strings = strings;
}
public void manufactureStrings( int stringCount, RecordInputStream in )
{
for (int i=0;i<stringCount;i++) {
- //Extract exactly the count of strings from the SST record.
- UnicodeString str = new UnicodeString(in);
- addToStringTable( strings, str );
- }
+ // 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 )
- {
- strings.add(string );
- }
- }
+ static public void addToStringTable( IntMapper<UnicodeString> strings, UnicodeString string )
+ {
+ strings.add(string);
+ }
+}
/** 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;
{
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);
}
*/
public UnicodeString getString(int id )
{
- return (UnicodeString) field_3_strings.get( id );
+ return field_3_strings.get( id );
}
.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" );
}
// 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 );
}
* @return an iterator of the strings we hold. All instances are
* UnicodeStrings
*/
- Iterator getStrings()
+ Iterator<UnicodeString> getStrings()
{
return field_3_strings.iterator();
}
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;
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;
{
if (k % ExtSSTRecord.DEFAULT_BUCKET_SIZE == 0)
{
- int rOff = out.getTotalSize();
+ int rOff = out.getTotalSize();
int index = k/ExtSSTRecord.DEFAULT_BUCKET_SIZE;
if (index < ExtSSTRecord.MAX_BUCKETS) {
- //Excel only indexes the first 128 buckets.
- bucketAbsoluteOffsets[index] = rOff;
- bucketRelativeOffsets[index] = rOff;
- }
- }
+ //Excel only indexes the first 128 buckets.
+ bucketAbsoluteOffsets[index] = rOff;
+ bucketRelativeOffsets[index] = rOff;
+ }
+ }
UnicodeString s = getUnicodeString(k);
s.serialize(out);
}
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()
* 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;
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);
* @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;
public IntMapper(final int initialCapacity)
{
- elements = new ArrayList(initialCapacity);
- valueKeyMap = new HashMap(initialCapacity);
+ elements = new ArrayList<T>(initialCapacity);
+ valueKeyMap = new HashMap<T,Integer>(initialCapacity);
}
/**
* @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;
}
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