mirror of https://github.com/apache/poi.git
bug 59748: replace Hashtable with HashMap; contributed by Axel Howind
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1750168 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
2ca32da045
commit
b849a0c162
|
@ -18,7 +18,7 @@ package org.apache.poi.hssf.eventusermodel;
|
||||||
|
|
||||||
import java.text.NumberFormat;
|
import java.text.NumberFormat;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Hashtable;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
@ -45,7 +45,7 @@ public class FormatTrackingHSSFListener implements HSSFListener {
|
||||||
private final HSSFListener _childListener;
|
private final HSSFListener _childListener;
|
||||||
private final HSSFDataFormatter _formatter;
|
private final HSSFDataFormatter _formatter;
|
||||||
private final NumberFormat _defaultFormat;
|
private final NumberFormat _defaultFormat;
|
||||||
private final Map<Integer, FormatRecord> _customFormatRecords = new Hashtable<Integer, FormatRecord>();
|
private final Map<Integer, FormatRecord> _customFormatRecords = new HashMap<Integer, FormatRecord>();
|
||||||
private final List<ExtendedFormatRecord> _xfRecords = new ArrayList<ExtendedFormatRecord>();
|
private final List<ExtendedFormatRecord> _xfRecords = new ArrayList<ExtendedFormatRecord>();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -33,9 +33,8 @@ import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Hashtable;
|
import java.util.HashMap;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
@ -155,7 +154,7 @@ public final class HSSFWorkbook extends POIDocument implements org.apache.poi.ss
|
||||||
* this holds the HSSFFont objects attached to this workbook.
|
* this holds the HSSFFont objects attached to this workbook.
|
||||||
* We only create these from the low level records as required.
|
* We only create these from the low level records as required.
|
||||||
*/
|
*/
|
||||||
private Hashtable<Short,HSSFFont> fonts;
|
private Map<Short,HSSFFont> fonts;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* holds whether or not to preserve other nodes in the POIFS. Used
|
* holds whether or not to preserve other nodes in the POIFS. Used
|
||||||
|
@ -1204,7 +1203,7 @@ public final class HSSFWorkbook extends POIDocument implements org.apache.poi.ss
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public HSSFFont getFontAt(short idx) {
|
public HSSFFont getFontAt(short idx) {
|
||||||
if(fonts == null) fonts = new Hashtable<Short, HSSFFont>();
|
if(fonts == null) fonts = new HashMap<Short, HSSFFont>();
|
||||||
|
|
||||||
// So we don't confuse users, give them back
|
// So we don't confuse users, give them back
|
||||||
// the same object every time, but create
|
// the same object every time, but create
|
||||||
|
@ -1228,7 +1227,7 @@ public final class HSSFWorkbook extends POIDocument implements org.apache.poi.ss
|
||||||
* and that's not something you should normally do
|
* and that's not something you should normally do
|
||||||
*/
|
*/
|
||||||
protected void resetFontCache() {
|
protected void resetFontCache() {
|
||||||
fonts = new Hashtable<Short, HSSFFont>();
|
fonts = new HashMap<Short, HSSFFont>();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -19,7 +19,7 @@ package org.apache.poi.hssf.util;
|
||||||
|
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Hashtable;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import org.apache.poi.ss.usermodel.Color;
|
import org.apache.poi.ss.usermodel.Color;
|
||||||
|
@ -57,18 +57,18 @@ public class HSSFColor implements Color {
|
||||||
return indexHash;
|
return indexHash;
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* This function returns all the Colours, stored in a Hashtable that
|
* This function returns all the Colours, stored in a Map that
|
||||||
* can be edited. No caching is performed. If you don't need to edit
|
* can be edited. No caching is performed. If you don't need to edit
|
||||||
* the table, then call {@link #getIndexHash()} which returns a
|
* the table, then call {@link #getIndexHash()} which returns a
|
||||||
* statically cached imuatable map of colours.
|
* statically cached imuatable map of colours.
|
||||||
*/
|
*/
|
||||||
public final static Hashtable<Integer,HSSFColor> getMutableIndexHash() {
|
public final static Map<Integer,HSSFColor> getMutableIndexHash() {
|
||||||
return createColorsByIndexMap();
|
return createColorsByIndexMap();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Hashtable<Integer,HSSFColor> createColorsByIndexMap() {
|
private static Map<Integer,HSSFColor> createColorsByIndexMap() {
|
||||||
HSSFColor[] colors = getAllColors();
|
HSSFColor[] colors = getAllColors();
|
||||||
Hashtable<Integer,HSSFColor> result = new Hashtable<Integer,HSSFColor>(colors.length * 3 / 2);
|
Map<Integer,HSSFColor> result = new HashMap<Integer,HSSFColor>(colors.length * 3 / 2);
|
||||||
|
|
||||||
for (int i = 0; i < colors.length; i++) {
|
for (int i = 0; i < colors.length; i++) {
|
||||||
HSSFColor color = colors[i];
|
HSSFColor color = colors[i];
|
||||||
|
@ -148,16 +148,16 @@ public class HSSFColor implements Color {
|
||||||
* it takes to create it once per request but you will not hold onto it
|
* it takes to create it once per request but you will not hold onto it
|
||||||
* if you have none of those requests.
|
* if you have none of those requests.
|
||||||
*
|
*
|
||||||
* @return a hashtable containing all colors keyed by String gnumeric-like triplets
|
* @return a Map containing all colors keyed by String gnumeric-like triplets
|
||||||
*/
|
*/
|
||||||
public final static Hashtable<String,HSSFColor> getTripletHash()
|
public final static Map<String,HSSFColor> getTripletHash()
|
||||||
{
|
{
|
||||||
return createColorsByHexStringMap();
|
return createColorsByHexStringMap();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Hashtable<String,HSSFColor> createColorsByHexStringMap() {
|
private static Map<String,HSSFColor> createColorsByHexStringMap() {
|
||||||
HSSFColor[] colors = getAllColors();
|
HSSFColor[] colors = getAllColors();
|
||||||
Hashtable<String,HSSFColor> result = new Hashtable<String,HSSFColor>(colors.length * 3 / 2);
|
Map<String,HSSFColor> result = new HashMap<String,HSSFColor>(colors.length * 3 / 2);
|
||||||
|
|
||||||
for (int i = 0; i < colors.length; i++) {
|
for (int i = 0; i < colors.length; i++) {
|
||||||
HSSFColor color = colors[i];
|
HSSFColor color = colors[i];
|
||||||
|
@ -1683,7 +1683,7 @@ public class HSSFColor implements Color {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Special Default/Normal/Automatic color.
|
* Special Default/Normal/Automatic color.
|
||||||
* <p><i>Note:</i> This class is NOT in the default HashTables returned by HSSFColor.
|
* <p><i>Note:</i> This class is NOT in the default Map returned by HSSFColor.
|
||||||
* The index is a special case which is interpreted in the various setXXXColor calls.
|
* The index is a special case which is interpreted in the various setXXXColor calls.
|
||||||
*
|
*
|
||||||
* @author Jason
|
* @author Jason
|
||||||
|
|
|
@ -30,7 +30,7 @@ import java.net.URISyntaxException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.Hashtable;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.concurrent.locks.ReentrantReadWriteLock;
|
import java.util.concurrent.locks.ReentrantReadWriteLock;
|
||||||
|
@ -145,8 +145,8 @@ public abstract class OPCPackage implements RelationshipSource, Closeable {
|
||||||
* Initialize the package instance.
|
* Initialize the package instance.
|
||||||
*/
|
*/
|
||||||
private void init() {
|
private void init() {
|
||||||
this.partMarshallers = new Hashtable<ContentType, PartMarshaller>(5);
|
this.partMarshallers = new HashMap<ContentType, PartMarshaller>(5);
|
||||||
this.partUnmarshallers = new Hashtable<ContentType, PartUnmarshaller>(2);
|
this.partUnmarshallers = new HashMap<ContentType, PartUnmarshaller>(2);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Add 'default' unmarshaller
|
// Add 'default' unmarshaller
|
||||||
|
|
|
@ -17,8 +17,10 @@
|
||||||
|
|
||||||
package org.apache.poi.openxml4j.opc.internal;
|
package org.apache.poi.openxml4j.opc.internal;
|
||||||
|
|
||||||
import java.util.Hashtable;
|
import java.util.Collections;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Map.Entry;
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
@ -53,17 +55,17 @@ public final class ContentType {
|
||||||
/**
|
/**
|
||||||
* Type in Type/Subtype.
|
* Type in Type/Subtype.
|
||||||
*/
|
*/
|
||||||
private String type;
|
private final String type;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Subtype
|
* Subtype
|
||||||
*/
|
*/
|
||||||
private String subType;
|
private final String subType;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parameters
|
* Parameters
|
||||||
*/
|
*/
|
||||||
private Hashtable<String, String> parameters;
|
private final Map<String, String> parameters;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Media type compiled pattern, without parameters
|
* Media type compiled pattern, without parameters
|
||||||
|
@ -160,7 +162,7 @@ public final class ContentType {
|
||||||
this.subType = mMediaType.group(2);
|
this.subType = mMediaType.group(2);
|
||||||
|
|
||||||
// Parameters
|
// Parameters
|
||||||
this.parameters = new Hashtable<String, String>(1);
|
this.parameters = new HashMap<String, String>();
|
||||||
// Java RegExps are unhelpful, and won't do multiple group captures
|
// Java RegExps are unhelpful, and won't do multiple group captures
|
||||||
// See http://docs.oracle.com/javase/6/docs/api/java/util/regex/Pattern.html#cg
|
// See http://docs.oracle.com/javase/6/docs/api/java/util/regex/Pattern.html#cg
|
||||||
if (mMediaType.groupCount() >= 5) {
|
if (mMediaType.groupCount() >= 5) {
|
||||||
|
@ -169,6 +171,11 @@ public final class ContentType {
|
||||||
this.parameters.put(mParams.group(1), mParams.group(2));
|
this.parameters.put(mParams.group(1), mParams.group(2));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
// missing media type and subtype
|
||||||
|
this.type = "";
|
||||||
|
this.subType = "";
|
||||||
|
this.parameters = Collections.emptyMap();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -187,7 +194,7 @@ public final class ContentType {
|
||||||
retVal.append(this.getSubType());
|
retVal.append(this.getSubType());
|
||||||
|
|
||||||
if (withParameters) {
|
if (withParameters) {
|
||||||
for (Map.Entry<String, String> me : parameters.entrySet()) {
|
for (Entry<String, String> me : parameters.entrySet()) {
|
||||||
retVal.append(";");
|
retVal.append(";");
|
||||||
retVal.append(me.getKey());
|
retVal.append(me.getKey());
|
||||||
retVal.append("=");
|
retVal.append("=");
|
||||||
|
|
|
@ -181,48 +181,56 @@ public final class TestContentType extends TestCase {
|
||||||
|
|
||||||
// Check the types on everything
|
// Check the types on everything
|
||||||
for (PackagePart part : p.getParts()) {
|
for (PackagePart part : p.getParts()) {
|
||||||
|
final String contentType = part.getContentType();
|
||||||
|
final ContentType details = part.getContentTypeDetails();
|
||||||
|
final int length = details.getParameterKeys().length;
|
||||||
|
final boolean hasParameters = details.hasParameters();
|
||||||
|
|
||||||
// _rels type doesn't have any params
|
// _rels type doesn't have any params
|
||||||
if (part.isRelationshipPart()) {
|
if (part.isRelationshipPart()) {
|
||||||
assertEquals(ContentTypes.RELATIONSHIPS_PART, part.getContentType());
|
assertEquals(ContentTypes.RELATIONSHIPS_PART, contentType);
|
||||||
assertEquals(ContentTypes.RELATIONSHIPS_PART, part.getContentTypeDetails().toString());
|
assertEquals(ContentTypes.RELATIONSHIPS_PART, details.toString());
|
||||||
assertEquals(false, part.getContentTypeDetails().hasParameters());
|
assertEquals(false, hasParameters);
|
||||||
assertEquals(0, part.getContentTypeDetails().getParameterKeys().length);
|
assertEquals(0, length);
|
||||||
}
|
}
|
||||||
// Core type doesn't have any params
|
// Core type doesn't have any params
|
||||||
else if (part.getPartName().toString().equals("/docProps/core.xml")) {
|
else if (part.getPartName().toString().equals("/docProps/core.xml")) {
|
||||||
assertEquals(ContentTypes.CORE_PROPERTIES_PART, part.getContentType());
|
assertEquals(ContentTypes.CORE_PROPERTIES_PART, contentType);
|
||||||
assertEquals(ContentTypes.CORE_PROPERTIES_PART, part.getContentTypeDetails().toString());
|
assertEquals(ContentTypes.CORE_PROPERTIES_PART, details.toString());
|
||||||
assertEquals(false, part.getContentTypeDetails().hasParameters());
|
assertEquals(false, hasParameters);
|
||||||
assertEquals(0, part.getContentTypeDetails().getParameterKeys().length);
|
assertEquals(0, length);
|
||||||
}
|
}
|
||||||
// Global Crs types do have params
|
// Global Crs types do have params
|
||||||
else if (part.getPartName().toString().equals("/global1dCrs.xml")) {
|
else if (part.getPartName().toString().equals("/global1dCrs.xml")) {
|
||||||
assertEquals(typeResqml, part.getContentType().substring(0, typeResqml.length()));
|
assertTrue(part.getContentType().startsWith(typeResqml));
|
||||||
assertEquals(typeResqml, part.getContentTypeDetails().toString(false));
|
assertEquals(typeResqml, details.toString(false));
|
||||||
assertEquals(true, part.getContentTypeDetails().hasParameters());
|
assertEquals(true, hasParameters);
|
||||||
assertEquals(typeResqml+";version=2.0;type=obj_global1dCrs", part.getContentTypeDetails().toString());
|
assertContains("version=2.0", details.toString());
|
||||||
assertEquals(2, part.getContentTypeDetails().getParameterKeys().length);
|
assertContains("type=obj_global1dCrs", details.toString());
|
||||||
assertEquals("2.0", part.getContentTypeDetails().getParameter("version"));
|
assertEquals(2, length);
|
||||||
assertEquals("obj_global1dCrs", part.getContentTypeDetails().getParameter("type"));
|
assertEquals("2.0", details.getParameter("version"));
|
||||||
|
assertEquals("obj_global1dCrs", details.getParameter("type"));
|
||||||
}
|
}
|
||||||
else if (part.getPartName().toString().equals("/global2dCrs.xml")) {
|
else if (part.getPartName().toString().equals("/global2dCrs.xml")) {
|
||||||
assertEquals(typeResqml, part.getContentType().substring(0, typeResqml.length()));
|
assertTrue(part.getContentType().startsWith(typeResqml));
|
||||||
assertEquals(typeResqml, part.getContentTypeDetails().toString(false));
|
assertEquals(typeResqml, details.toString(false));
|
||||||
assertEquals(true, part.getContentTypeDetails().hasParameters());
|
assertEquals(true, hasParameters);
|
||||||
assertEquals(typeResqml+";version=2.0;type=obj_global2dCrs", part.getContentTypeDetails().toString());
|
assertContains("version=2.0", details.toString());
|
||||||
assertEquals(2, part.getContentTypeDetails().getParameterKeys().length);
|
assertContains("type=obj_global2dCrs", details.toString());
|
||||||
assertEquals("2.0", part.getContentTypeDetails().getParameter("version"));
|
assertEquals(2, length);
|
||||||
assertEquals("obj_global2dCrs", part.getContentTypeDetails().getParameter("type"));
|
assertEquals("2.0", details.getParameter("version"));
|
||||||
|
assertEquals("obj_global2dCrs", details.getParameter("type"));
|
||||||
}
|
}
|
||||||
// Other thingy
|
// Other thingy
|
||||||
else if (part.getPartName().toString().equals("/myTestingGuid.xml")) {
|
else if (part.getPartName().toString().equals("/myTestingGuid.xml")) {
|
||||||
assertEquals(typeResqml, part.getContentType().substring(0, typeResqml.length()));
|
assertTrue(part.getContentType().startsWith(typeResqml));
|
||||||
assertEquals(typeResqml, part.getContentTypeDetails().toString(false));
|
assertEquals(typeResqml, details.toString(false));
|
||||||
assertEquals(true, part.getContentTypeDetails().hasParameters());
|
assertEquals(true, hasParameters);
|
||||||
assertEquals(typeResqml+";version=2.0;type=obj_tectonicBoundaryFeature", part.getContentTypeDetails().toString());
|
assertContains("version=2.0", details.toString());
|
||||||
assertEquals(2, part.getContentTypeDetails().getParameterKeys().length);
|
assertContains("type=obj_tectonicBoundaryFeature", details.toString());
|
||||||
assertEquals("2.0", part.getContentTypeDetails().getParameter("version"));
|
assertEquals(2, length);
|
||||||
assertEquals("obj_tectonicBoundaryFeature", part.getContentTypeDetails().getParameter("type"));
|
assertEquals("2.0", details.getParameter("version"));
|
||||||
|
assertEquals("obj_tectonicBoundaryFeature", details.getParameter("type"));
|
||||||
}
|
}
|
||||||
// That should be it!
|
// That should be it!
|
||||||
else {
|
else {
|
||||||
|
@ -230,4 +238,8 @@ public final class TestContentType extends TestCase {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void assertContains(String needle, String haystack) {
|
||||||
|
assertTrue(haystack.contains(needle));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,7 +22,7 @@ import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Hashtable;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.StringTokenizer;
|
import java.util.StringTokenizer;
|
||||||
|
|
||||||
|
@ -44,7 +44,7 @@ public final class ChunkFactory {
|
||||||
* Key is a Chunk's type, value is an array of its CommandDefinitions
|
* Key is a Chunk's type, value is an array of its CommandDefinitions
|
||||||
*/
|
*/
|
||||||
private final Map<Integer, CommandDefinition[]> chunkCommandDefinitions =
|
private final Map<Integer, CommandDefinition[]> chunkCommandDefinitions =
|
||||||
new Hashtable<Integer, CommandDefinition[]>();
|
new HashMap<Integer, CommandDefinition[]>();
|
||||||
/**
|
/**
|
||||||
* What the name is of the chunk table definitions file?
|
* What the name is of the chunk table definitions file?
|
||||||
* This file comes from the scratchpad resources directory.
|
* This file comes from the scratchpad resources directory.
|
||||||
|
@ -105,7 +105,7 @@ public final class ChunkFactory {
|
||||||
|
|
||||||
CommandDefinition[] defs = defsL.toArray(new CommandDefinition[defsL.size()]);
|
CommandDefinition[] defs = defsL.toArray(new CommandDefinition[defsL.size()]);
|
||||||
|
|
||||||
// Add to the hashtable
|
// Add to the map
|
||||||
chunkCommandDefinitions.put(Integer.valueOf(chunkType), defs);
|
chunkCommandDefinitions.put(Integer.valueOf(chunkType), defs);
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
|
|
|
@ -20,7 +20,7 @@ package org.apache.poi.hslf.record;
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
import java.util.Hashtable;
|
import java.util.Map;
|
||||||
|
|
||||||
import org.apache.poi.poifs.crypt.CipherAlgorithm;
|
import org.apache.poi.poifs.crypt.CipherAlgorithm;
|
||||||
import org.apache.poi.poifs.crypt.EncryptionInfo;
|
import org.apache.poi.poifs.crypt.EncryptionInfo;
|
||||||
|
@ -123,7 +123,7 @@ public final class DocumentEncryptionAtom extends PositionDependentRecordAtom {
|
||||||
out.write(data, 0, bos.getWriteIndex());
|
out.write(data, 0, bos.getWriteIndex());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateOtherRecordReferences(Hashtable<Integer,Integer> oldToNewReferencesLookup) {
|
public void updateOtherRecordReferences(Map<Integer,Integer> oldToNewReferencesLookup) {
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,7 +22,7 @@ import java.io.ByteArrayOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
import java.util.Hashtable;
|
import java.util.Map;
|
||||||
import java.util.zip.DeflaterOutputStream;
|
import java.util.zip.DeflaterOutputStream;
|
||||||
import java.util.zip.InflaterInputStream;
|
import java.util.zip.InflaterInputStream;
|
||||||
|
|
||||||
|
@ -184,7 +184,7 @@ public class ExOleObjStg extends RecordAtom implements PositionDependentRecord,
|
||||||
myLastOnDiskOffset = offset;
|
myLastOnDiskOffset = offset;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateOtherRecordReferences(Hashtable<Integer,Integer> oldToNewReferencesLookup) {
|
public void updateOtherRecordReferences(Map<Integer,Integer> oldToNewReferencesLookup) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -20,8 +20,10 @@ package org.apache.poi.hslf.record;
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
import java.util.Hashtable;
|
import java.util.Collections;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Map.Entry;
|
||||||
import java.util.TreeMap;
|
import java.util.TreeMap;
|
||||||
|
|
||||||
import org.apache.poi.hslf.exceptions.CorruptPowerPointFileException;
|
import org.apache.poi.hslf.exceptions.CorruptPowerPointFileException;
|
||||||
|
@ -52,7 +54,7 @@ public final class PersistPtrHolder extends PositionDependentRecordAtom
|
||||||
* You always need to check the most recent PersistPtrHolder
|
* You always need to check the most recent PersistPtrHolder
|
||||||
* that knows about a given slide to find the right location
|
* that knows about a given slide to find the right location
|
||||||
*/
|
*/
|
||||||
private Hashtable<Integer,Integer> _slideLocations;
|
private Map<Integer,Integer> _slideLocations;
|
||||||
|
|
||||||
private static final BitField persistIdFld = new BitField(0X000FFFFF);
|
private static final BitField persistIdFld = new BitField(0X000FFFFF);
|
||||||
private static final BitField cntPersistFld = new BitField(0XFFF00000);
|
private static final BitField cntPersistFld = new BitField(0XFFF00000);
|
||||||
|
@ -64,7 +66,7 @@ public final class PersistPtrHolder extends PositionDependentRecordAtom
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the list of slides that this PersistPtrHolder knows about.
|
* Get the list of slides that this PersistPtrHolder knows about.
|
||||||
* (They will be the keys in the hashtable for looking up the positions
|
* (They will be the keys in the map for looking up the positions
|
||||||
* of these slides)
|
* of these slides)
|
||||||
*/
|
*/
|
||||||
public int[] getKnownSlideIDs() {
|
public int[] getKnownSlideIDs() {
|
||||||
|
@ -80,8 +82,8 @@ public final class PersistPtrHolder extends PositionDependentRecordAtom
|
||||||
* Get the lookup from slide numbers to byte offsets, for the slides
|
* Get the lookup from slide numbers to byte offsets, for the slides
|
||||||
* known about by this PersistPtrHolder.
|
* known about by this PersistPtrHolder.
|
||||||
*/
|
*/
|
||||||
public Hashtable<Integer,Integer> getSlideLocationsLookup() {
|
public Map<Integer,Integer> getSlideLocationsLookup() {
|
||||||
return _slideLocations;
|
return Collections.unmodifiableMap(_slideLocations);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -104,7 +106,7 @@ public final class PersistPtrHolder extends PositionDependentRecordAtom
|
||||||
// base number for these entries
|
// base number for these entries
|
||||||
// count * 32 bit offsets
|
// count * 32 bit offsets
|
||||||
// Repeat as many times as you have data
|
// Repeat as many times as you have data
|
||||||
_slideLocations = new Hashtable<Integer,Integer>();
|
_slideLocations = new HashMap<Integer,Integer>();
|
||||||
_ptrData = new byte[len-8];
|
_ptrData = new byte[len-8];
|
||||||
System.arraycopy(source,start+8,_ptrData,0,_ptrData.length);
|
System.arraycopy(source,start+8,_ptrData,0,_ptrData.length);
|
||||||
|
|
||||||
|
@ -157,10 +159,10 @@ public final class PersistPtrHolder extends PositionDependentRecordAtom
|
||||||
* At write-out time, update the references to the sheets to their
|
* At write-out time, update the references to the sheets to their
|
||||||
* new positions
|
* new positions
|
||||||
*/
|
*/
|
||||||
public void updateOtherRecordReferences(Hashtable<Integer,Integer> oldToNewReferencesLookup) {
|
public void updateOtherRecordReferences(Map<Integer,Integer> oldToNewReferencesLookup) {
|
||||||
// Loop over all the slides we know about
|
// Loop over all the slides we know about
|
||||||
// Find where they used to live, and where they now live
|
// Find where they used to live, and where they now live
|
||||||
for (Map.Entry<Integer,Integer> me : _slideLocations.entrySet()) {
|
for (Entry<Integer,Integer> me : _slideLocations.entrySet()) {
|
||||||
Integer oldPos = me.getValue();
|
Integer oldPos = me.getValue();
|
||||||
Integer newPos = oldToNewReferencesLookup.get(oldPos);
|
Integer newPos = oldToNewReferencesLookup.get(oldPos);
|
||||||
|
|
||||||
|
@ -182,7 +184,7 @@ public final class PersistPtrHolder extends PositionDependentRecordAtom
|
||||||
byte intbuf[] = new byte[4];
|
byte intbuf[] = new byte[4];
|
||||||
int lastPersistEntry = -1;
|
int lastPersistEntry = -1;
|
||||||
int lastSlideId = -1;
|
int lastSlideId = -1;
|
||||||
for (Map.Entry<Integer,Integer> me : orderedSlideLocations.entrySet()) {
|
for (Entry<Integer,Integer> me : orderedSlideLocations.entrySet()) {
|
||||||
int nextSlideId = me.getKey();
|
int nextSlideId = me.getKey();
|
||||||
int offset = me.getValue();
|
int offset = me.getValue();
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
==================================================================== */
|
==================================================================== */
|
||||||
|
|
||||||
package org.apache.poi.hslf.record;
|
package org.apache.poi.hslf.record;
|
||||||
import java.util.Hashtable;
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Records which either care about where they are on disk, or have other
|
* Records which either care about where they are on disk, or have other
|
||||||
|
@ -47,5 +47,5 @@ public interface PositionDependentRecord
|
||||||
* Offer the record the list of records that have changed their
|
* Offer the record the list of records that have changed their
|
||||||
* location as part of the writeout.
|
* location as part of the writeout.
|
||||||
*/
|
*/
|
||||||
public void updateOtherRecordReferences(Hashtable<Integer,Integer> oldToNewReferencesLookup);
|
public void updateOtherRecordReferences(Map<Integer,Integer> oldToNewReferencesLookup);
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
==================================================================== */
|
==================================================================== */
|
||||||
|
|
||||||
package org.apache.poi.hslf.record;
|
package org.apache.poi.hslf.record;
|
||||||
import java.util.Hashtable;
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A special (and dangerous) kind of Record Atom that cares about where
|
* A special (and dangerous) kind of Record Atom that cares about where
|
||||||
|
@ -48,5 +48,5 @@ public abstract class PositionDependentRecordAtom extends RecordAtom implements
|
||||||
* Allows records to update their internal pointers to other records
|
* Allows records to update their internal pointers to other records
|
||||||
* locations
|
* locations
|
||||||
*/
|
*/
|
||||||
public abstract void updateOtherRecordReferences(Hashtable<Integer,Integer> oldToNewReferencesLookup);
|
public abstract void updateOtherRecordReferences(Map<Integer,Integer> oldToNewReferencesLookup);
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
==================================================================== */
|
==================================================================== */
|
||||||
|
|
||||||
package org.apache.poi.hslf.record;
|
package org.apache.poi.hslf.record;
|
||||||
import java.util.Hashtable;
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A special (and dangerous) kind of Record Container, for which other
|
* A special (and dangerous) kind of Record Container, for which other
|
||||||
|
@ -60,7 +60,7 @@ public abstract class PositionDependentRecordContainer extends RecordContainer i
|
||||||
* Since we're a container, we don't mind if other records move about.
|
* Since we're a container, we don't mind if other records move about.
|
||||||
* If we're told they have, just return straight off.
|
* If we're told they have, just return straight off.
|
||||||
*/
|
*/
|
||||||
public void updateOtherRecordReferences(Hashtable<Integer,Integer> oldToNewReferencesLookup) {
|
public void updateOtherRecordReferences(Map<Integer,Integer> oldToNewReferencesLookup) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,7 +22,7 @@ import org.apache.poi.util.LittleEndianConsts;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
import java.util.Hashtable;
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A UserEdit Atom (type 4085). Holds information which bits of the file
|
* A UserEdit Atom (type 4085). Holds information which bits of the file
|
||||||
|
@ -146,7 +146,7 @@ public final class UserEditAtom extends PositionDependentRecordAtom
|
||||||
* At write-out time, update the references to PersistPtrs and
|
* At write-out time, update the references to PersistPtrs and
|
||||||
* other UserEditAtoms to point to their new positions
|
* other UserEditAtoms to point to their new positions
|
||||||
*/
|
*/
|
||||||
public void updateOtherRecordReferences(Hashtable<Integer,Integer> oldToNewReferencesLookup) {
|
public void updateOtherRecordReferences(Map<Integer,Integer> oldToNewReferencesLookup) {
|
||||||
// Look up the new positions of our preceding UserEditAtomOffset
|
// Look up the new positions of our preceding UserEditAtomOffset
|
||||||
if(lastUserEditAtomOffset != 0) {
|
if(lastUserEditAtomOffset != 0) {
|
||||||
Integer newLocation = oldToNewReferencesLookup.get(Integer.valueOf(lastUserEditAtomOffset));
|
Integer newLocation = oldToNewReferencesLookup.get(Integer.valueOf(lastUserEditAtomOffset));
|
||||||
|
|
|
@ -28,7 +28,7 @@ import java.security.GeneralSecurityException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Hashtable;
|
import java.util.Map;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.NavigableMap;
|
import java.util.NavigableMap;
|
||||||
|
@ -464,7 +464,7 @@ public final class HSLFSlideShowImpl extends POIDocument implements Closeable {
|
||||||
// For position dependent records, hold where they were and now are
|
// For position dependent records, hold where they were and now are
|
||||||
// As we go along, update, and hand over, to any Position Dependent
|
// As we go along, update, and hand over, to any Position Dependent
|
||||||
// records we happen across
|
// records we happen across
|
||||||
Hashtable<Integer,Integer> oldToNewPositions = new Hashtable<Integer,Integer>();
|
Map<Integer,Integer> oldToNewPositions = new HashMap<Integer,Integer>();
|
||||||
|
|
||||||
// First pass - figure out where all the position dependent
|
// First pass - figure out where all the position dependent
|
||||||
// records are going to end up, in the new scheme
|
// records are going to end up, in the new scheme
|
||||||
|
|
|
@ -60,8 +60,8 @@ public final class TestReWriteSanity extends TestCase {
|
||||||
// Find the location of the PersistPtrIncrementalBlocks and
|
// Find the location of the PersistPtrIncrementalBlocks and
|
||||||
// UserEditAtoms
|
// UserEditAtoms
|
||||||
Record[] r = wss.getRecords();
|
Record[] r = wss.getRecords();
|
||||||
Map<Integer,Record> pp = new Hashtable<Integer,Record>();
|
Map<Integer,Record> pp = new HashMap<Integer,Record>();
|
||||||
Map<Integer,Object> ue = new Hashtable<Integer,Object>();
|
Map<Integer,Object> ue = new HashMap<Integer,Object>();
|
||||||
ue.put(Integer.valueOf(0),Integer.valueOf(0)); // Will show 0 if first
|
ue.put(Integer.valueOf(0),Integer.valueOf(0)); // Will show 0 if first
|
||||||
int pos = 0;
|
int pos = 0;
|
||||||
int lastUEPos = -1;
|
int lastUEPos = -1;
|
||||||
|
|
|
@ -17,7 +17,7 @@
|
||||||
|
|
||||||
package org.apache.poi.hssf.util;
|
package org.apache.poi.hssf.util;
|
||||||
|
|
||||||
import java.util.Hashtable;
|
import java.util.Map;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
import junit.framework.TestCase;
|
||||||
/**
|
/**
|
||||||
|
@ -40,7 +40,7 @@ public final class TestHSSFColor extends TestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testTrippletHash() {
|
public void testTrippletHash() {
|
||||||
Hashtable tripplets = HSSFColor.getTripletHash();
|
Map<String, HSSFColor> tripplets = HSSFColor.getTripletHash();
|
||||||
|
|
||||||
assertEquals(
|
assertEquals(
|
||||||
HSSFColor.MAROON.class,
|
HSSFColor.MAROON.class,
|
||||||
|
|
Loading…
Reference in New Issue